[SSI] openssi/kernel/ipc shm.c,1.34,1.35

Roger Tsang <[email protected]> Sat, 03 Apr 2010 19:46:00 +0000
Newsgroups gmane.linux.cluster.ssic.cvs
Message-ID <[email protected]>
Update of /cvsroot/ssic-linux/openssi/kernel/ipc
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv30698/kernel/ipc

Modified Files:
      Tag: OPENSSI-FC
	shm.c 
Log Message:
- sys_shmctl()
  - Move SSI code into new functions shm_find_svr_node() and ssi_shmctl_info().
  - Fix processing bogus data for SHM_INFO command on ssi_shmctl() error.
- ssi_shmctl()
  - Fix returning bogus on RPC error.
  - Handle ICS -EAGAIN error.
- do_ssi_shm_noclients() handle RIPC_SHM_NOCLIENTS() -EAGAIN error.

 cluster/ssi/ipc/ipcshm_svr.c |   28 ++--
 ipc/shm.c                    |  199 +++++++++++++++++------------------
 2 files changed, 111 insertions(+), 116 deletions(-)


Index: shm.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/kernel/ipc/shm.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- shm.c	29 Mar 2010 06:17:00 -0000	1.34
+++ shm.c	3 Apr 2010 19:45:58 -0000	1.35
@@ -571,12 +571,10 @@
 #ifdef CONFIG_SSI
 		if (shp->shm_node != this_node)
 			continue;
-		else {
-			inode = shm_svr_get_inode(i);
-			if (inode == NULL) {
-				printk("no server structure\n");
-				continue;
-			}
+		inode = shm_svr_get_inode(i);
+		if (inode == NULL) {
+			printk("no server structure\n");
+			continue;
 		}
 #else
 		inode = shp->shm_file->f_dentry->d_inode;
@@ -595,6 +593,87 @@
 	}
 }
 
+#ifdef CONFIG_SSI
+static int ssi_shmctl_info(struct shm_info *shm_info, struct shmid_ds __user *buf)
+{
+	nsc_nodelist_t *nl;
+	nsc_nlcookie_t cookie = CLUSTERNODE_INVAL;
+	clusternode_t svrnode;
+	int err, max_id=0;
+
+#ifndef IPC_SHM_RACE_FIX
+	/* SSI_XXX: RIPC_SHMCTL() could deadlock with another incoming
+	 * RPC from destination node such as RIPC_SHM_GET_NATTCHS()
+	 * which holds shm_ids.sem in ssi_shm_cleanup() path.
+	 */
+	down(&shm_ids.sem);
+#endif
+	nl = clms_get_nsc_nodelist(CLMS_NODE_UP);
+	while ((svrnode = nsc_nodelist_get_next(&cookie, nl))
+					!= CLUSTERNODE_INVAL) {
+		if (svrnode == this_node)
+			continue;
+		err = ssi_shmctl(svrnode, -1, SHM_INFO, buf);
+		if (err > 0) {
+			shm_info->used_ids += ((struct shm_info *)buf)->used_ids;
+			shm_info->shm_rss += ((struct shm_info *)buf)->shm_rss;
+			shm_info->shm_swp += ((struct shm_info *)buf)->shm_swp;
+			shm_info->shm_tot += ((struct shm_info *)buf)->shm_tot;
+			max_id += err;
+		}
+	}
+	NSC_NODELIST_FREE(nl);
+
+#ifdef IPC_SHM_RACE_FIX
+	/* Now obtain shm_ids.sem mutex because
+	 * ssi_shmctl() could deadlock with
+	 * another incoming RPC from destination node
+	 * that already holds shm_ids.sem mutex.
+	 */
+	down(&shm_ids.sem);
+#endif
+	shm_info->used_ids += shm_ids.in_use;
+	shm_get_stat (&shm_info->shm_rss, &shm_info->shm_swp);
+	shm_info->shm_tot += shm_tot;
+	shm_info->swap_attempts = 0;
+	shm_info->swap_successes = 0;
+	err = max_id + shm_ids.max_id;
+	up(&shm_ids.sem);
+	return err;
+}
+
+static int shm_find_svr_node(int shmid, int cmd, clusternode_t *svrnode)
+{
+	struct shmid_kernel *shp;
+	key_t key;
+	int flags, view, sz;
+
+	if (!cli_ipcname_findid(NAME_SERVICE_SHM, shmid, &key, svrnode,
+							&flags, &view, &sz))
+		return 0;
+
+	if ((cmd^IPC_64) == IPC_RMID) {
+		/* if its local & svr is down, then remove it */
+#ifdef IPC_SHM_RACE_FIX
+		shp = shm_cli_lock(shmid);
+		if (!shp)
+			return -EINVAL;
+		shm_cli_unlock(shp);
+		*svrnode = 0;
+#else
+		shp = shm_cli_get(shmid);
+		if (!shp)
+			return -EINVAL;
+		if (shp->shm_node != this_node)
+			*svrnode = 0;
+#endif
+		return 0;
+	}
+
+	return -EINVAL;
+}
+#endif /* CONFIG_SSI */
+
 asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf)
 {
 	struct shm_setbuf setbuf;
@@ -602,19 +681,13 @@
 	int err, version;
 
 #ifdef CONFIG_SSI
-	key_t key;
-	clusternode_t svrnode = 0;
-	int flags, view, sz;
-	int retry = 0;
-	int tmpcmd = cmd, remote_cmd=FALSE;
+	clusternode_t svrnode;
+	int retry = 0, tmpcmd = cmd;
 
 	if (shmid == -1) {
 		if ((cmd&SHM_INFO) != SHM_INFO)
 			return -EINVAL;
-		else {
-			shmid = 0;
-			remote_cmd = TRUE;
-		}
+		shmid = 0;
 	}
 #endif /* CONFIG_SSI */
 	if (cmd < 0 || shmid < 0) {
@@ -627,36 +700,11 @@
 #ifdef CONFIG_SSI
 	if ((shmid > 0)&&(cmd >= 0)) {
 svr_find:
-		if (cli_ipcname_findid(NAME_SERVICE_SHM, shmid, &key, 
-								&svrnode,
-								&flags,
-								&view,
-								&sz) < 0){
-
-			if ((cmd^IPC_64) == IPC_RMID) {
-				/* if its local & svr is down, then remove it */
-#ifdef IPC_SHM_RACE_FIX
-				shp = shm_cli_lock(shmid);
-				if (!shp)
-					return -EINVAL;
-				if (shp->shm_node != this_node)
-					svrnode = 0;
-				shm_cli_unlock(shp);
-#else
-				shp = shm_cli_get(shmid);
-				if (!shp)
-					return -EINVAL;
-				if (shp->shm_node != this_node)
-					svrnode = 0;
-#endif
-			}
-			else
-				return -EINVAL;
-		}
-		if (svrnode && svrnode != this_node) {
-			err = ssi_shmctl(svrnode, shmid, tmpcmd, buf);
+		err = shm_find_svr_node(shmid, cmd, &svrnode);
+		if (err)
 			return err;
-		}
+		if (svrnode != this_node)
+			return ssi_shmctl(svrnode, shmid, tmpcmd, buf);
 	}
 #endif /* CONFIG_SSI */
 
@@ -686,11 +734,6 @@
 	case SHM_INFO:
 	{
 		struct shm_info shm_info;
-#ifdef CONFIG_SSI
-		int max_id=0;
-		nsc_nodelist_t *nl;
-		nsc_nlcookie_t cookie;
-#endif /* CONFIG_SSI */
 
 		err = security_shm_shmctl(NULL, cmd);
 		if (err)
@@ -698,50 +741,9 @@
 
 		memset(&shm_info,0,sizeof(shm_info));
 #ifdef CONFIG_SSI
-#ifndef IPC_SHM_RACE_FIX
-		/* SSI_XXX: RIPC_SHMCTL() could deadlock with another incoming
-		 * RPC from destination node such as RIPC_SHM_GET_NATTCHS()
-		 * which holds shm_ids.sem in ssi_shm_cleanup() path.
-		 */
-		down(&shm_ids.sem);
-#endif
-		svrnode = 0;
-		if (!ssi_get_localview() && (remote_cmd == FALSE))
-		{
-		        nl = clms_get_nsc_nodelist(CLMS_NODE_UP);
-        		cookie = CLUSTERNODE_INVAL;
-        		svrnode = nsc_nodelist_get_next(&cookie, nl);
-        		for (;svrnode != CLUSTERNODE_INVAL;
-                		svrnode = nsc_nodelist_get_next(&cookie,nl)) 
-			{
-                		if( svrnode != this_node ) 
-				{
-					err = ssi_shmctl(svrnode, -1, SHM_INFO, buf);
-					if (err)
-					{
-						shm_info.used_ids += ((struct shm_info *)buf)->used_ids;
-						shm_info.shm_rss += ((struct shm_info *)buf)->shm_rss;
-						shm_info.shm_swp += ((struct shm_info *)buf)->shm_swp;
-						shm_info.shm_tot += ((struct shm_info *)buf)->shm_tot;
-						max_id += err;
-						err = 0;
-        				}
-                		}
-			}
-			NSC_NODELIST_FREE(nl);
-			memset(buf,0,sizeof(shm_info));
-#ifdef IPC_SHM_RACE_FIX
-			down(&shm_ids.sem);
-#endif
-			shm_info.used_ids += shm_ids.in_use;
-			shm_get_stat (&(((struct shm_info *)buf)->shm_rss), &(((struct shm_info *)buf)->shm_swp));
-			shm_info.shm_rss += ((struct shm_info *)buf)->shm_rss;
-			shm_info.shm_swp += ((struct shm_info *)buf)->shm_swp;
-			shm_info.shm_tot += shm_tot;
-			shm_info.swap_attempts = 0;
-			shm_info.swap_successes = 0;
-			err = max_id + shm_ids.max_id;
-			goto out_unlockall;
+		if (!ssi_get_localview() && !ssi_isremote()) {
+			err = ssi_shmctl_info(&shm_info, buf);
+			goto out_info;
 		}
 #endif /* CONFIG_SSI */
 		down(&shm_ids.sem);
@@ -751,10 +753,10 @@
 		shm_info.swap_attempts = 0;
 		shm_info.swap_successes = 0;
 		err = shm_ids.max_id;
+		up(&shm_ids.sem);
 #ifdef CONFIG_SSI
-out_unlockall:
+out_info:
 #endif /* CONFIG_SSI */
-		up(&shm_ids.sem);
 		if(copy_to_user (buf, &shm_info, sizeof(shm_info))) {
 			err = -EFAULT;
 			goto out;
@@ -774,14 +776,9 @@
 #ifdef CONFIG_SSI
 			if (!retry++)
 				goto svr_find;
-			else {
-				err = -EINVAL;
-				goto out;
-			}
-#else
+#endif /* CONFIG_SSI */
 			err = -EINVAL;
 			goto out;
-#endif /* !CONFIG_SSI */
 		}
 		else if(cmd==SHM_STAT) {
 			err = -EINVAL;


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev