[SSI] openssi/kernel/cluster/ssi/util rmtfb.c,1.32,1.33

Roger Tsang <[email protected]> Mon, 17 Jan 2011 06:19:48 +0000
Newsgroups gmane.linux.cluster.ssic.cvs
Message-ID <[email protected]>
Update of /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/util
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv23906/cluster/ssi/util

Modified Files:
      Tag: OPENSSI-FC
	rmtfb.c 
Log Message:
cluster/ssi/util/rmtfb.c
- rmtfb_newcli: move the test for filesystem support from rmtfb_getcli_id() to this function. fix test was not done in other rmtfb_newcli() call paths and can hide future compatibility issues with newer base kernels.
- rmtfb_setcli_open: handle error -EAGAIN. ICS can return -EAGAIN. fix lost message on -EAGAIN.
- rmtfb_setclr_cli: handle error -EAGAIN. ICS can return -EAGAIN. fix lost message on -EAGAIN.

cluster/ssi/util/rmtfb.c (#ifndef RFBDEBUG)
- de-activate rfb_magic field in rmtfb_cli structure when not debugging.
- ftocli: de-activate debug code.
- ftocli: always inline this function when not debugging.
- rmtfb_putsvr: no longer do sanity check on passed argument. check is not required in most cases. caller must ensure valid argument is passed to this function.
- rmtfb_rclose: print error message if there is no rfb to close.
- SSI_XXX_stalecli: de-activate debug code.

cluster/ssi/util/rmtfb.c (#ifdef RMTFB_REFCNT_FIX)
- rmtfb_rclose: no need to call rmtfb_clrcli() after server went down. fixes rmtfb_rclose() reporting -ERFB_TRYAGAIN errors after server is rebooted. old rmtfb_svr structure is gone.


Index: rmtfb.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/util/rmtfb.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- rmtfb.c	15 Dec 2010 06:46:12 -0000	1.32
+++ rmtfb.c	17 Jan 2011 06:19:45 -0000	1.33
@@ -54,8 +54,10 @@
 
 #define rmtfb_maxloops HZ
 
+#ifdef RFBDEBUG
 #define RMTFB_MAGIC 0xDEAD2A9E
 #define RMTFB_VALID(_rfb) ((_rfb)->rfb_magic == RMTFB_MAGIC)
+#endif
 
 #define rmtfb_tbllen (PAGE_SIZE / sizeof(struct hlist_head))
 static unsigned int rmtfb_tblbits;
@@ -125,23 +127,34 @@
  * Support Routines
  */
 
+#ifdef RMTFB_REFCNT_FIX
 #define rmtfb_get(_rfb) atomic_inc(&(_rfb)->rfb_refcnt)
+#endif
 
 #define ftoi(_fp) ((_fp)->f_dentry->d_inode)
 
-#ifndef RMTFB_REFCNT_FIX
+#ifndef RFBDEBUG
 static inline
 #endif
 struct rmtfb_cli *
 ftocli(struct file *file)
 {
+#ifndef RFBDEBUG
+	return (struct rmtfb_cli *) file->private_data;
+#else
 	struct rmtfb_cli *rfb;
 
+	if (!file->private_data)
+		return NULL;
 	rfb = (struct rmtfb_cli *)file->private_data;
-	if (!rfb || !RMTFB_VALID(rfb))
+	if (!RMTFB_VALID(rfb))
 		return NULL;
 	BUG_ON(rfb->common.rfb_file != file);
+#ifdef RMTFB_REFCNT_FIX
+	BUG_ON(atomic_read(&rfb->rfb_refcnt) < 1);
+#endif
 	return rfb;
+#endif /* RFBDEBUG */
 }
 
 static inline unsigned long
@@ -231,7 +244,9 @@
 	 *	file->private_data->common.rfb_file == file
 	 */
 	/* fput(rfb->common.rfb_file); */
+#ifdef RFBDEBUG
 	rfb->rfb_magic = 0;
+#endif
 #ifdef RMTFB_KMEM_CACHE
 	call_rcu(&rfb->rfb_rhead, rmtfb_cli_free);
 #else
@@ -460,15 +475,26 @@
 	if (error)
 		goto out;
 	ssi_procstate_get(&pstate);
-	ret = RMTFB_SETOPEN(
-			rfb->rfb_server,
-			&error,
-			&pstate,
-			path,
-			file->f_flags,
-			rfb->common.rfb_id,
-			this_node);
-	SSI_ASSERT(error != -EINVAL);
+	for (;;) {
+		ret = RMTFB_SETOPEN(
+				rfb->rfb_server,
+				&error,
+				&pstate,
+				path,
+				file->f_flags,
+				rfb->common.rfb_id,
+				this_node);
+		if (error == -EAGAIN) {
+			idelay(HZ/10);
+			if (signal_pending(current)) {
+				error = -EINTR;
+				break;
+			}
+			continue;
+		}
+		SSI_ASSERT(error != -EINVAL);
+		break;
+	}
 	if (ret)
 		error = ret;
 	reop_export_path_free(&path);
@@ -484,15 +510,26 @@
 	ssi_procstate_t pstate;
 
 	ssi_procstate_get(&pstate);
-	ret = RMTFB_SETCLR(
-			rfb->rfb_server,
-			&error,
-			&pstate,
-			rmtfb_gethandle(rfb, &svrhandle),
-			this_node,
-			set);
-	SSI_ASSERT(error != -EINVAL);
-	return ret ? ret : error;
+	for (;;) {
+		ret = RMTFB_SETCLR(
+				rfb->rfb_server,
+				&error,
+				&pstate,
+				rmtfb_gethandle(rfb, &svrhandle),
+				this_node,
+				set);
+		if (error == -EAGAIN) {
+			idelay(HZ/10);
+			if (signal_pending(current)) {
+				error = -EINTR;
+				break;
+			}
+			continue;
+		}
+		SSI_ASSERT(error != -EINVAL);
+		break;
+	}
+	return ret ? : error;
 }
 
 static inline int
@@ -516,12 +553,14 @@
 static inline int
 SSI_XXX_stalecli(struct rmtfb_cli *rfb)
 {
+#ifdef RFBDEBUG
 	struct rmtfb_cli *myself = rfb->common.rfb_file->private_data;
 	if (rfb != myself) {
 		printk(KERN_ERR "rmtfb_badops: stale client structure: %p\n",
 				rfb);
 		return -1;
 	}
+#endif
 	return 0;
 }
 
@@ -855,11 +894,7 @@
 void
 rmtfb_putsvr(struct rmtfb_svr *rfb)
 {
-#ifndef RFBDEBUG
-	WARN_ON(IS_ERR(rfb));
-	if (!rfb || IS_ERR(rfb))
-		return;
-#else
+#ifdef RFBDEBUG
 	if (!rfb || IS_ERR(rfb)) {
 		printk(KERN_DEBUG "rmtfb_putsvr: !rfb or IS_ERR(rfb)\n");
 		return;
@@ -917,12 +952,10 @@
 
 #ifdef RMTFB_REFCNT_FIX
 	rfb = ftocli(file);
-	if (!rfb)
-		return NULL;
-
-	/* No race here. file->private_data has rfb reference */
-	rmtfb_get(rfb);
-
+	if (rfb) {
+		/* No race here. file struct has final reference */
+		rmtfb_get(rfb);
+	}
 	return rfb;
 #else
 	return ftocli(file);
@@ -1074,15 +1107,6 @@
 		sock->ssi_rfb_svr = svr;
 	}
 
-	if (file->private_data) {
-		printk(KERN_ERR
-			"rmtfb_getcli_id: non-exportable filesystem (%s)\n",
-			file->f_vfsmnt->mnt_sb->s_type->name);
-		fput(file);
-		rfb = ERR_PTR(-EOPNOTSUPP);
-		goto out;
-	}
-
 	rfb = rmtfb_newcli(file, id, svr, 0);
 	if (IS_ERR(rfb))
 		fput(file);
@@ -1097,7 +1121,9 @@
 #ifdef RMTFB_REFCNT_FIX
 void rmtfb_putcli(struct rmtfb_cli *rfb)
 {
+#ifdef RFBDEBUG
 	BUG_ON(!RMTFB_VALID(rfb));
+#endif
 #ifdef RMTFB_HASH_LOCKLESS
 	if (!atomic_dec_and_lock(&rfb->rfb_refcnt, &rmtfb_clitbl_lock))
 		return;
@@ -1166,7 +1192,9 @@
 	if (rfb) {
 		/* SSI: Skipped get_file(). See rmtfb_freecli() */
 		rmtfb_new_prep(&rfb->common, file, id);
+#ifdef RFBDEBUG
 		rfb->rfb_magic = RMTFB_MAGIC;
+#endif
 		rfb->rfb_server = svr;
 	}
 	return rfb;
@@ -1371,6 +1399,13 @@
 
 	SSI_ASSERT(svr && !inval(1,svr));
 
+	if (unlikely(file->private_data)) {
+		printk(KERN_ERR "%s: non-exportable filesystem (%s)\n",
+			__FUNCTION__, file->f_vfsmnt->mnt_sb->s_type->name);
+		error = -EOPNOTSUPP;
+		goto out;
+	}
+
 	rfb = rmtfb_cli_alloc(file, id, svr);
 	if (!rfb) {
 		error = -ENOMEM;
@@ -1385,7 +1420,7 @@
 		else
 			error = rmtfb_setcli_open(rfb);
 		SSI_ASSERT(error != -EINVAL);
-		if (error) {
+		if (unlikely(error)) {
 			rmtfb_freecli(rfb);
 			goto out;
 		}
@@ -1416,9 +1451,11 @@
 		}
 		if (old) {
 			up(&rmtfb_newcli_lock);
+#ifdef RMTFB_REFCNT_FIX
 			/* Undo rmtfb_setcli_re/open() */
 			if (!noremote)
 				(void) rmtfb_clrcli(rfb);
+#endif
 			rmtfb_freecli(rfb);
 			rfb = old;
 			goto out;
@@ -1429,7 +1466,7 @@
 	if (!noremote)
 		rmtfb_remote_tty_ino(file, svr);
 #endif
-	/* SSI_XXX: overrides struct socket->file->f_op */
+	/* SSI: overrides struct socket->file->f_op */
 	file->f_op = &ssidev_remote_fops;
 
 	file->private_data = rfb;
@@ -1486,7 +1523,9 @@
 #ifdef RMTFB_REFCNT_FIX
 	atomic_set(&newrfb->rfb_refcnt, 1);
 #endif
+#ifdef RFBDEBUG
 	newrfb->rfb_magic = RMTFB_MAGIC;
+#endif
 	newrfb->rfb_server = svr;
 #endif /* !RMTFB_KMEM_CACHE */
 
@@ -1598,13 +1637,13 @@
 	struct rmtfb_cli *rfb;
 	int error = 0;
 
-#if 0
-	SSI_ASSERT(file);
-#endif
 	rfb = ftocli(file);
 #ifdef RMTFB_REFCNT_FIX
-	if (!rfb)
-		return 0; /* client@server */
+	if (unlikely(!rfb)) {
+		/* SSI_XXX: client@server. sock->ssi_rfb_id == 0 */
+		printk(KERN_ERR "%s: file has no rfb\n", __FUNCTION__);
+		return 0;
+	}
 #else
 	SSI_ASSERT(rfb);
 #endif
@@ -1615,6 +1654,11 @@
 	 */
 	if (rfb->rfb_server != CLUSTERNODE_INVAL)
 #endif
+	/* SSI: release rmtfb_svr reference held during sock->ops->accept() */
+#ifdef RMTFB_REFCNT_FIX
+	/* Skip if file->f_op == &ssidev_bad_fops, server went down. */
+	if (file->f_op != &ssidev_bad_fops)
+#endif
 		error = rmtfb_clrcli(rfb);
 	SSI_ASSERT(error != -EINVAL);
 #ifndef RFBDEBUG
@@ -1628,14 +1672,15 @@
 #endif /* RFBDEBUG */
 
 #ifdef RMTFB_REFCNT_FIX
-	/* Release file->private_data */
-	rmtfb_putcli(rfb);
 	file->private_data = NULL;
+	rmtfb_putcli(rfb); /* Release file->private_data */
 #else
 	LOCK_EXCL_RW_LOCK(&rmtfb_clitbl_lock);
 	hlist_del(&rfb->common.rfb_hash);
 	UNLOCK_EXCL_RW_LOCK(&rmtfb_clitbl_lock);
+#ifdef RFBDEBUG
 	rfb->rfb_magic = 0;
+#endif
 	kfree(rfb);
 #endif /* !RMTFB_REFCNT_FIX */
 
@@ -1744,7 +1789,9 @@
 	printk(TAB "rfbhash(id) = 0x%x\n", (unsigned int) rfbhash(id));
 	printk(TAB "rfb_file = 0x%p\n", (void *) file);
 	printk(TAB "rfb_id = %lu\n", id);
+#ifdef RFBDEBUG
 	printk(TAB "rfb_magic = 0x%x\n", (unsigned int) rfb->rfb_magic);
+#endif
 	printk(TAB "rfb_server = %d\n", (int) server);
 }
 


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl