]> err.no Git - linux-2.6/blobdiff - net/tipc/port.c
tipc: Minor optimizations to received message processing
[linux-2.6] / net / tipc / port.c
index 2f5806410c644b5b970998a17c9630d5ccf8f5af..4dfef9e798e3e13aa47ed8b8071f47bef18809c7 100644 (file)
@@ -211,15 +211,18 @@ exit:
 }
 
 /**
- * tipc_createport_raw - create a native TIPC port
+ * tipc_createport_raw - create a generic TIPC port
  *
- * Returns local port reference
+ * Returns port reference, or 0 if unable to create it
+ *
+ * Note: The newly created port is returned in the locked state.
  */
 
 u32 tipc_createport_raw(void *usr_handle,
                        u32 (*dispatcher)(struct tipc_port *, struct sk_buff *),
                        void (*wakeup)(struct tipc_port *),
-                       const u32 importance)
+                       const u32 importance,
+                       struct tipc_port **tp_ptr)
 {
        struct port *p_ptr;
        struct tipc_msg *msg;
@@ -237,7 +240,6 @@ u32 tipc_createport_raw(void *usr_handle,
                return 0;
        }
 
-       tipc_port_lock(ref);
        p_ptr->publ.usr_handle = usr_handle;
        p_ptr->publ.max_pkt = MAX_PKT_DEFAULT;
        p_ptr->publ.ref = ref;
@@ -262,7 +264,7 @@ u32 tipc_createport_raw(void *usr_handle,
        INIT_LIST_HEAD(&p_ptr->port_list);
        list_add_tail(&p_ptr->port_list, &ports);
        spin_unlock_bh(&tipc_port_list_lock);
-       tipc_port_unlock(p_ptr);
+       *tp_ptr = &p_ptr->publ;
        return ref;
 }
 
@@ -778,6 +780,7 @@ void tipc_port_reinit(void)
                msg = &p_ptr->publ.phdr;
                if (msg_orignode(msg) == tipc_own_addr)
                        break;
+               msg_set_prevnode(msg, tipc_own_addr);
                msg_set_orignode(msg, tipc_own_addr);
        }
        spin_unlock_bh(&tipc_port_list_lock);
@@ -838,16 +841,13 @@ static void port_dispatcher_sigh(void *dummy)
                                u32 peer_node = port_peernode(p_ptr);
 
                                tipc_port_unlock(p_ptr);
+                               if (unlikely(!cb))
+                                       goto reject;
                                if (unlikely(!connected)) {
-                                       if (unlikely(published))
+                                       if (tipc_connect2port(dref, &orig))
                                                goto reject;
-                                       tipc_connect2port(dref,&orig);
-                               }
-                               if (unlikely(msg_origport(msg) != peer_port))
-                                       goto reject;
-                               if (unlikely(msg_orignode(msg) != peer_node))
-                                       goto reject;
-                               if (unlikely(!cb))
+                               } else if ((msg_origport(msg) != peer_port) ||
+                                          (msg_orignode(msg) != peer_node))
                                        goto reject;
                                if (unlikely(++p_ptr->publ.conn_unacked >=
                                             TIPC_FLOW_CONTROL_WIN))
@@ -862,9 +862,7 @@ static void port_dispatcher_sigh(void *dummy)
                                tipc_msg_event cb = up_ptr->msg_cb;
 
                                tipc_port_unlock(p_ptr);
-                               if (unlikely(connected))
-                                       goto reject;
-                               if (unlikely(!cb))
+                               if (unlikely(!cb || connected))
                                        goto reject;
                                skb_pull(buf, msg_hdr_sz(msg));
                                cb(usr_handle, dref, &buf, msg_data(msg),
@@ -877,11 +875,7 @@ static void port_dispatcher_sigh(void *dummy)
                                tipc_named_msg_event cb = up_ptr->named_msg_cb;
 
                                tipc_port_unlock(p_ptr);
-                               if (unlikely(connected))
-                                       goto reject;
-                               if (unlikely(!cb))
-                                       goto reject;
-                               if (unlikely(!published))
+                               if (unlikely(!cb || connected || !published))
                                        goto reject;
                                dseq.type =  msg_nametype(msg);
                                dseq.lower = msg_nameinst(msg);
@@ -908,11 +902,10 @@ err:
                                u32 peer_node = port_peernode(p_ptr);
 
                                tipc_port_unlock(p_ptr);
-                               if (!connected || !cb)
+                               if (!cb || !connected)
                                        break;
-                               if (msg_origport(msg) != peer_port)
-                                       break;
-                               if (msg_orignode(msg) != peer_node)
+                               if ((msg_origport(msg) != peer_port) ||
+                                   (msg_orignode(msg) != peer_node))
                                        break;
                                tipc_disconnect(dref);
                                skb_pull(buf, msg_hdr_sz(msg));
@@ -924,7 +917,7 @@ err:
                                tipc_msg_err_event cb = up_ptr->err_cb;
 
                                tipc_port_unlock(p_ptr);
-                               if (connected || !cb)
+                               if (!cb || connected)
                                        break;
                                skb_pull(buf, msg_hdr_sz(msg));
                                cb(usr_handle, dref, &buf, msg_data(msg),
@@ -937,7 +930,7 @@ err:
                                        up_ptr->named_err_cb;
 
                                tipc_port_unlock(p_ptr);
-                               if (connected || !cb)
+                               if (!cb || connected)
                                        break;
                                dseq.type =  msg_nametype(msg);
                                dseq.lower = msg_nameinst(msg);
@@ -1053,6 +1046,7 @@ int tipc_createport(u32 user_ref,
 {
        struct user_port *up_ptr;
        struct port *p_ptr;
+       struct tipc_port *tp_ptr;
        u32 ref;
 
        up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC);
@@ -1060,12 +1054,13 @@ int tipc_createport(u32 user_ref,
                warn("Port creation failed, no memory\n");
                return -ENOMEM;
        }
-       ref = tipc_createport_raw(NULL, port_dispatcher, port_wakeup, importance);
-       p_ptr = tipc_port_lock(ref);
-       if (!p_ptr) {
+       ref = tipc_createport_raw(NULL, port_dispatcher, port_wakeup,
+                                 importance, &tp_ptr);
+       if (ref == 0) {
                kfree(up_ptr);
                return -ENOMEM;
        }
+       p_ptr = (struct port *)tp_ptr;
 
        p_ptr->user_port = up_ptr;
        up_ptr->user_ref = user_ref;