[Ocfs2-commits] zab commits r1765 - trunk/cluster
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Wed Jan 12 19:41:20 CST 2005
Author: zab
Date: 2005-01-12 19:41:18 -0600 (Wed, 12 Jan 2005)
New Revision: 1765
Modified:
trunk/cluster/tcp.c
Log:
o clean up the net handler locking
Modified: trunk/cluster/tcp.c
===================================================================
--- trunk/cluster/tcp.c 2005-01-13 01:09:52 UTC (rev 1764)
+++ trunk/cluster/tcp.c 2005-01-13 01:41:18 UTC (rev 1765)
@@ -34,7 +34,6 @@
* - find explicit stack call to drain rx queue
* - simplify rx thread exit path (completion, etc)
* - goto out style exiting
- * - push net_handler_lock into lookup_handler, add add call
* - implement net_remove_handlers
* - check stack to be sure that blocking rx waits for all data
* - if spin sending be sure to exclude concurrent racing senders
@@ -141,6 +140,7 @@
static int __init net_driver_entry (void);
static int net_init_driver(void);
static void __exit net_driver_exit (void);
+static int net_add_handler(net_msg_handler *nmh);
static void net_remove_handlers(void);
static int net_check_message_valid(net_msg *msg, u32 len);
static void net_dump_and_close_sock(struct socket *sock, struct inode *inode);
@@ -163,46 +163,29 @@
//////////////////////
-
-
-
-/* use if already holding net_handler_lock */
-static inline void __net_get_handler(net_msg_handler *nmh)
+static void net_get_handler(net_msg_handler *nmh)
{
atomic_inc(&nmh->refcnt);
}
-static inline void net_get_handler(net_msg_handler *nmh)
+/* called with net_handler_lock held so we can verify the flags :/ */
+static void __net_put_handler(net_msg_handler *nmh)
{
- spin_lock(&net_handler_lock);
- __net_get_handler(nmh);
- spin_unlock(&net_handler_lock);
-}
-
-
-/* use if already holding net_handler_lock */
-static inline void __net_put_handler(net_msg_handler *nmh)
-{
- atomic_dec(&nmh->refcnt);
- if (!atomic_read(&nmh->refcnt)) {
+ if (atomic_dec_and_test(&nmh->refcnt)) {
if (nmh->flags & NET_HND_IN_USE)
netprintk0("EEEEK! killing inuse handler! bugbug!\n");
kfree(nmh);
}
}
-static inline void net_put_handler(net_msg_handler *nmh)
+static void net_put_handler(net_msg_handler *nmh)
{
- if (atomic_dec_and_lock(&nmh->refcnt, &net_handler_lock)) {
- if (nmh->flags & NET_HND_IN_USE)
- netprintk0("EEEEK! killing inuse handler! bugbug!\n");
- kfree(nmh);
- spin_unlock(&net_handler_lock);
- }
+ spin_lock(&net_handler_lock);
+ __net_put_handler(nmh);
+ spin_unlock(&net_handler_lock);
}
-
DECLARE_MUTEX(net_state_lock);
u32 net_driver_state = NET_DRIVER_UNINITED;
u32 net_num_dispatched = 0;
@@ -613,6 +596,7 @@
{
net_msg_handler *nmh, *found=NULL;
u32 packet_len = sizeof(net_msg) + max_len;
+ int ret;
if (packet_len < NET_MIN_MSG_LEN || packet_len > NET_MAX_MSG_LEN) {
netprintk("max_len for message handler out of range: %u\n",
@@ -659,30 +643,20 @@
INIT_LIST_HEAD(&nmh->list);
net_get_handler(nmh);
-
- /* add the new handler, checking for pre-existing */
- spin_lock(&net_handler_lock);
- found = net_lookup_handler(msg_type, key);
- if (!found) {
- list_add_tail(&nmh->list, &net_handlers);
- } else {
- spin_unlock(&net_handler_lock);
+ ret = net_add_handler(nmh);
+ if (ret) {
net_put_handler(found);
netprintk("message handler for type %u, key %u already exists!!!\n",
msg_type, key);
- /* this should destroy it */
- net_put_handler(nmh);
- return -EEXIST;
}
- spin_unlock(&net_handler_lock);
- return 0;
+ return ret;
}
EXPORT_SYMBOL(net_register_handler);
/* net_handler_lock should be held */
-net_msg_handler * net_lookup_handler(u32 msg_type, u32 key)
+net_msg_handler * __net_lookup_handler(u32 msg_type, u32 key)
{
net_msg_handler *ret;
struct list_head *iter;
@@ -690,16 +664,47 @@
list_for_each(iter, &net_handlers) {
ret = list_entry(iter, net_msg_handler, list);
if (ret->msg_type == msg_type && ret->key == key) {
- __net_get_handler(ret);
+ net_get_handler(ret);
return ret;
}
}
return NULL;
}
+net_msg_handler * net_lookup_handler(u32 msg_type, u32 key)
+{
+ net_msg_handler *ret;
+ spin_lock(&net_handler_lock);
+ ret = __net_lookup_handler(msg_type, key);
+ spin_unlock(&net_handler_lock);
+ return ret;
+}
+static int net_add_handler(net_msg_handler *nmh)
+{
+ net_msg_handler *existing;
+ int ret;
+
+ spin_lock(&net_handler_lock);
+
+ existing = __net_lookup_handler(nmh->msg_type, nmh->key);
+ if (existing != NULL) {
+ __net_put_handler(existing);
+ ret = -EEXIST;
+ goto out;
+ }
+
+ list_add_tail(&nmh->list, &net_handlers);
+ ret = 0;
+
+out:
+ spin_unlock(&net_handler_lock);
+ return ret;
+}
+
+
/* TODO Fix */
static void net_remove_handlers(void)
{
@@ -903,10 +908,7 @@
}
spin_unlock(&net->sock_lock);
-
- spin_lock(&net_handler_lock);
handler = net_lookup_handler(msg_type, key);
- spin_unlock(&net_handler_lock);
if (!handler) {
netprintk("no such message type: %u/%u\n", msg_type, key);
@@ -1037,10 +1039,7 @@
}
spin_unlock(&net->sock_lock);
-
- spin_lock(&net_handler_lock);
handler = net_lookup_handler(msg_type, key);
- spin_unlock(&net_handler_lock);
if (!handler) {
netprintk("no such message type: %u/%u\n", msg_type, key);
@@ -1238,9 +1237,7 @@
}
/* find a handler for it */
- spin_lock(&net_handler_lock);
hnd = net_lookup_handler(hdr.msg_type, hdr.key);
- spin_unlock(&net_handler_lock);
if (!hnd) {
err = -EINVAL;
More information about the Ocfs2-commits
mailing list