linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / tipc / bcast.c
index 1bb7570..a7b04f3 100644 (file)
 #include "name_table.h"
 #include "bcast.h"
 
+
 #define MAX_PKT_DEFAULT_MCAST 1500     /* bcast link max packet size (fixed) */
 
 #define BCLINK_WIN_DEFAULT 20          /* bcast link window size (default) */
 
 #define BCLINK_LOG_BUF_SIZE 0
 
-/*
- * Loss rate for incoming broadcast frames; used to test retransmission code.
- * Set to N to cause every N'th frame to be discarded; 0 => don't discard any.
- */
-#define TIPC_BCAST_LOSS_RATE 0
-
 /**
  * struct bcbearer_pair - a pair of bearers used by broadcast link
  * @primary: pointer to primary bearer
@@ -81,14 +75,7 @@ struct bcbearer_pair {
  * @bearer: (non-standard) broadcast bearer structure
  * @media: (non-standard) broadcast media structure
  * @bpairs: array of bearer pairs
- * @bpairs_temp: temporary array of bearer pairs used by tipc_bcbearer_sort()
- * @remains: temporary node map used by tipc_bcbearer_send()
- * @remains_new: temporary node map used tipc_bcbearer_send()
- * 
- * Note: The fields labelled "temporary" are incorporated into the bearer
- * to avoid consuming potentially limited stack space through the use of
- * large local variables within multicast routines.  Concurrent access is
- * prevented through use of the spinlock "bc_lock".
+ * @bpairs_temp: array of bearer pairs used during creation of "bpairs"
  */
 
 struct bcbearer {
@@ -96,8 +83,6 @@ struct bcbearer {
        struct media media;
        struct bcbearer_pair bpairs[MAX_BEARERS];
        struct bcbearer_pair bpairs_temp[TIPC_MAX_LINK_PRI + 1];
-       struct node_map remains;
-       struct node_map remains_new;
 };
 
 /**
@@ -117,27 +102,27 @@ struct bclink {
 static struct bcbearer *bcbearer = NULL;
 static struct bclink *bclink = NULL;
 static struct link *bcl = NULL;
-static DEFINE_SPINLOCK(bc_lock);
+static spinlock_t bc_lock = SPIN_LOCK_UNLOCKED;
 
 char tipc_bclink_name[] = "multicast-link";
 
 
-static u32 buf_seqno(struct sk_buff *buf)
+static inline u32 buf_seqno(struct sk_buff *buf)
 {
        return msg_seqno(buf_msg(buf));
 } 
 
-static u32 bcbuf_acks(struct sk_buff *buf)
+static inline u32 bcbuf_acks(struct sk_buff *buf)
 {
        return (u32)(unsigned long)TIPC_SKB_CB(buf)->handle;
 }
 
-static void bcbuf_set_acks(struct sk_buff *buf, u32 acks)
+static inline void bcbuf_set_acks(struct sk_buff *buf, u32 acks)
 {
        TIPC_SKB_CB(buf)->handle = (void *)(unsigned long)acks;
 }
 
-static void bcbuf_decr_acks(struct sk_buff *buf)
+static inline void bcbuf_decr_acks(struct sk_buff *buf)
 {
        bcbuf_set_acks(buf, bcbuf_acks(buf) - 1);
 }
@@ -149,7 +134,7 @@ static void bcbuf_decr_acks(struct sk_buff *buf)
  * Called with 'node' locked, bc_lock unlocked
  */
 
-static void bclink_set_gap(struct node *n_ptr)
+static inline void bclink_set_gap(struct node *n_ptr)
 {
        struct sk_buff *buf = n_ptr->bclink.deferred_head;
 
@@ -169,7 +154,7 @@ static void bclink_set_gap(struct node *n_ptr)
  *       distribute NACKs, but tries to use the same spacing (divide by 16). 
  */
 
-static int bclink_ack_allowed(u32 n)
+static inline int bclink_ack_allowed(u32 n)
 {
        return((n % TIPC_MIN_LINK_WIN) == tipc_own_tag);
 }
@@ -180,18 +165,21 @@ static int bclink_ack_allowed(u32 n)
  * @after: sequence number of last packet to *not* retransmit
  * @to: sequence number of last packet to retransmit
  * 
- * Called with bc_lock locked
+ * Called with 'node' locked, bc_lock unlocked
  */
 
 static void bclink_retransmit_pkt(u32 after, u32 to)
 {
        struct sk_buff *buf;
 
+       spin_lock_bh(&bc_lock);
        buf = bcl->first_out;
        while (buf && less_eq(buf_seqno(buf), after)) {
                buf = buf->next;                
        }
-       tipc_link_retransmit(bcl, buf, mod(to - after));
+       if (buf != NULL)
+               tipc_link_retransmit(bcl, buf, mod(to - after));
+       spin_unlock_bh(&bc_lock);              
 }
 
 /** 
@@ -283,7 +271,7 @@ static void bclink_send_nack(struct node *n_ptr)
                msg_set_bcgap_to(msg, n_ptr->bclink.gap_to);
                msg_set_bcast_tag(msg, tipc_own_tag);
 
-               if (tipc_bearer_send(&bcbearer->bearer, buf, NULL)) {
+               if (tipc_bearer_send(&bcbearer->bearer, buf, 0)) {
                        bcl->stats.sent_nacks++;
                        buf_discard(buf);
                } else {
@@ -326,7 +314,7 @@ void tipc_bclink_check_gap(struct node *n_ptr, u32 last_sent)
  * Only tipc_net_lock set.
  */
 
-static void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to)
+void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to)
 {
        struct node *n_ptr = tipc_node_find(dest);
        u32 my_after, my_to;
@@ -358,10 +346,8 @@ static void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 g
                for (; buf; buf = buf->next) {
                        u32 seqno = buf_seqno(buf);
 
-                       if (mod(seqno - prev) != 1) {
+                       if (mod(seqno - prev) != 1)
                                buf = NULL;
-                               break;
-                       }
                        if (seqno == gap_after)
                                break;
                        prev = seqno;
@@ -413,10 +399,7 @@ int tipc_bclink_send_msg(struct sk_buff *buf)
  */
 
 void tipc_bclink_recv_pkt(struct sk_buff *buf)
-{
-#if (TIPC_BCAST_LOSS_RATE)
-       static int rx_count = 0;
-#endif
+{        
        struct tipc_msg *msg = buf_msg(buf);
        struct node* node = tipc_node_find(msg_prevnode(msg));
        u32 next_in;
@@ -437,31 +420,19 @@ void tipc_bclink_recv_pkt(struct sk_buff *buf)
                        tipc_node_lock(node);
                        tipc_bclink_acknowledge(node, msg_bcast_ack(msg));
                        tipc_node_unlock(node);
-                       spin_lock_bh(&bc_lock);
                        bcl->stats.recv_nacks++;
-                       bcl->owner->next = node;   /* remember requestor */
                        bclink_retransmit_pkt(msg_bcgap_after(msg),
                                              msg_bcgap_to(msg));
-                       bcl->owner->next = NULL;
-                       spin_unlock_bh(&bc_lock);              
                } else {
                        tipc_bclink_peek_nack(msg_destnode(msg),
-                                             msg_bcast_tag(msg),
-                                             msg_bcgap_after(msg),
-                                             msg_bcgap_to(msg));
+                                        msg_bcast_tag(msg),
+                                        msg_bcgap_after(msg),
+                                        msg_bcgap_to(msg));
                }
                buf_discard(buf);
                return;
        }
 
-#if (TIPC_BCAST_LOSS_RATE)
-       if (++rx_count == TIPC_BCAST_LOSS_RATE) {
-               rx_count = 0;
-               buf_discard(buf);
-               return;
-       }
-#endif
-
        tipc_node_lock(node);
 receive:
        deferred = node->bclink.deferred_head;
@@ -554,12 +525,14 @@ u32 tipc_bclink_acks_missing(struct node *n_ptr)
  * Returns 0 if packet sent successfully, non-zero if not
  */
 
-static int tipc_bcbearer_send(struct sk_buff *buf,
-                             struct tipc_bearer *unused1,
-                             struct tipc_media_addr *unused2)
+int tipc_bcbearer_send(struct sk_buff *buf,
+                      struct tipc_bearer *unused1,
+                      struct tipc_media_addr *unused2)
 {
        static int send_count = 0;
 
+       struct node_map remains;
+       struct node_map remains_new;
        int bp_index;
        int swap_time;
 
@@ -582,7 +555,7 @@ static int tipc_bcbearer_send(struct sk_buff *buf,
 
        /* Send buffer over bearers until all targets reached */
        
-       bcbearer->remains = tipc_cltr_bcast_nodes;
+       remains = tipc_cltr_bcast_nodes;
 
        for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) {
                struct bearer *p = bcbearer->bpairs[bp_index].primary;
@@ -591,8 +564,8 @@ static int tipc_bcbearer_send(struct sk_buff *buf,
                if (!p)
                        break;  /* no more bearers to try */
 
-               tipc_nmap_diff(&bcbearer->remains, &p->nodes, &bcbearer->remains_new);
-               if (bcbearer->remains_new.count == bcbearer->remains.count)
+               tipc_nmap_diff(&remains, &p->nodes, &remains_new);
+               if (remains_new.count == remains.count)
                        continue;       /* bearer pair doesn't add anything */
 
                if (!p->publ.blocked &&
@@ -610,10 +583,10 @@ swap:
                bcbearer->bpairs[bp_index].primary = s;
                bcbearer->bpairs[bp_index].secondary = p;
 update:
-               if (bcbearer->remains_new.count == 0)
+               if (remains_new.count == 0)
                        return TIPC_OK;
 
-               bcbearer->remains = bcbearer->remains_new;
+               remains = remains_new;
        }
        
        /* Unable to reach all targets */
@@ -778,7 +751,7 @@ int tipc_bclink_init(void)
        bclink = kmalloc(sizeof(*bclink), GFP_ATOMIC);
        if (!bcbearer || !bclink) {
  nomem:
-               warn("Multicast link creation failed, no memory\n");
+               warn("Memory squeeze; Failed to create multicast link\n");
                kfree(bcbearer);
                bcbearer = NULL;
                kfree(bclink);
@@ -796,7 +769,7 @@ int tipc_bclink_init(void)
        memset(bclink, 0, sizeof(struct bclink));
        INIT_LIST_HEAD(&bcl->waiting_ports);
        bcl->next_out_no = 1;
-       spin_lock_init(&bclink->node.lock);
+       bclink->node.lock =  SPIN_LOCK_UNLOCKED;        
        bcl->owner = &bclink->node;
         bcl->max_pkt = MAX_PKT_DEFAULT_MCAST;
        tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT);