X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=net%2Ftipc%2Fport.c;h=757de38fe6afcf84bf69d3d98114fe0bdfea9a34;hb=59f0c4523fdea865fab7d69d878269992a9d08dd;hp=e2646a96935df6edad1a8f7c39885d8f244aca41;hpb=ba73d4c84a7344f1b5635c2b4e96796e8c13a126;p=linux-2.6 diff --git a/net/tipc/port.c b/net/tipc/port.c index e2646a9693..757de38fe6 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c @@ -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; } @@ -1053,6 +1055,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 +1063,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; @@ -1240,6 +1244,28 @@ exit: return res; } +/** + * tipc_disconnect_port - disconnect port from peer + * + * Port must be locked. + */ + +int tipc_disconnect_port(struct tipc_port *tp_ptr) +{ + int res; + + if (tp_ptr->connected) { + tp_ptr->connected = 0; + /* let timer expire on it's own to avoid deadlock! */ + tipc_nodesub_unsubscribe( + &((struct port *)tp_ptr)->subscription); + res = TIPC_OK; + } else { + res = -ENOTCONN; + } + return res; +} + /* * tipc_disconnect(): Disconnect port form peer. * This is a node local operation. @@ -1248,17 +1274,12 @@ exit: int tipc_disconnect(u32 ref) { struct port *p_ptr; - int res = -ENOTCONN; + int res; p_ptr = tipc_port_lock(ref); if (!p_ptr) return -EINVAL; - if (p_ptr->publ.connected) { - p_ptr->publ.connected = 0; - /* let timer expire on it's own to avoid deadlock! */ - tipc_nodesub_unsubscribe(&p_ptr->subscription); - res = TIPC_OK; - } + res = tipc_disconnect_port((struct tipc_port *)p_ptr); tipc_port_unlock(p_ptr); return res; }