[linux-cifs-client] [PATCH] umount.cifs: make mtab locking more reslilient

Jeff Layton jlayton at redhat.com
Sun Oct 5 00:41:38 GMT 2008


umount.cifs only attempts to lock the mtab once, and then gives up if
that fails. Have umount.cifs sleep .1s and then try to lock again if
it fails. Do this for up to 30s before giving up.

Signed-off-by: Jeff Layton <jlayton at redhat.com>
---
 source3/client/umount.cifs.c |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/source3/client/umount.cifs.c b/source3/client/umount.cifs.c
index 3e2415a..d9b8928 100644
--- a/source3/client/umount.cifs.c
+++ b/source3/client/umount.cifs.c
@@ -137,17 +137,31 @@ static int umount_check_perm(char * dir)
 	return rc;
 }
 
-static int lock_mtab(void)
+/*
+ * BB: Duplicate the scheme that util-linux-ng mount command uses. This
+ *     can leave MOUNTED_LOCK in place if the process is signalled.
+ */
+static int
+lock_mtab(void)
 {
-	int rc;
-	
-	rc = mknod(MOUNTED_LOCK , 0600, 0);
-	if(rc == -1)
-		printf("\ngetting lock file %s failed with %s\n",MOUNTED_LOCK,
-				strerror(errno));
-		
-	return rc;	
-	
+	int rc, numsleeps = 0;
+
+	rc = open(MOUNTED_LOCK, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
+	while (rc < 0 && numsleeps < 300) {
+		if (errno != EEXIST)
+			return 0;
+
+		usleep(100000);
+		numsleeps++;
+		rc = open(MOUNTED_LOCK, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
+	}
+
+	if (rc >= 0) {
+		close(rc);
+		return 1;
+	} else {
+		return 0;
+	}
 }
 
 static void unlock_mtab(void)
@@ -168,7 +182,7 @@ static int remove_from_mtab(char * mountpoint)
 
 	/* Do we first need to check if it is writable? */ 
 
-	if (lock_mtab()) {
+	if (!lock_mtab()) {
 		printf("Mount table locked\n");
 		return -EACCES;
 	}
-- 
1.5.5.1



More information about the linux-cifs-client mailing list