Skip to contentSkip to conversation

multipath: fix multipath locking

PATCH In review Benjamin Marzinski 3 participants 3 messages Nov 5, 2010 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 multipath: fix multipath locking

In lock_multipath(), if multipathd fails halfway though locking the the path devices, it doesn't unlock the ones that it already has locked. This patch fixes that.

---
 libmultipath/configure.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
libmultipath/configure.c +15 -1
Index: multipath-tools/libmultipath/configure.c
===================================================================
@@ -284,6 +284,7 @@ lock_multipath (struct multipath * mpp, 
 	struct pathgroup * pgp;
 	struct path * pp;
 	int i, j;
+	int x, y;
 
 	if (!mpp || !mpp->pg)
 		return 0;
@@ -294,12 +295,25 @@ lock_multipath (struct multipath * mpp, 
 		vector_foreach_slot(pgp->paths, pp, j) {
 			if (lock && flock(pp->fd, LOCK_EX | LOCK_NB) &&
 			    errno == EWOULDBLOCK)
-				return 1;
+				goto fail;
 			else if (!lock)
 				flock(pp->fd, LOCK_UN);
 		}
 	}
 	return 0;
+fail:
+	vector_foreach_slot (mpp->pg, pgp, x) {
+		if (x > i)
+			return 1;
+		if (!pgp->paths)
+			continue;
+		vector_foreach_slot(pgp->paths, pp, y) {
+			if (x == i && y > j)
+				return 1;
+			flock(pp->fd, LOCK_UN);
+		}
+	}
+	return 1;
 }
 
 /*
#1 lore raw
Quoted 9 lines · Benjamin Marzinski [[email protected]] wrote:
libmultipath/configure.c +1 -1
@@ -294,12 +295,25 @@ lock_multipath (struct multipath * mpp, 
 		vector_foreach_slot(pgp->paths, pp, j) {
 			if (lock && flock(pp->fd, LOCK_EX | LOCK_NB) &&
 			    errno == EWOULDBLOCK)
-				return 1;
+				goto fail;
 			else if (!lock)
 				flock(pp->fd, LOCK_UN);
 		}

libmultipath/configure.c lock_multipath (struct multipath * mpp, · line 311

Quoted 10 lines
libmultipath/configure.c +8 -0
 	}
 	return 0;
+fail:
+	vector_foreach_slot (mpp->pg, pgp, x) {
+		if (x > i)
+			return 1;
+		if (!pgp->paths)
+			continue;
+		vector_foreach_slot(pgp->paths, pp, y) {
+			if (x == i && y > j)

Path 'j' has failed to get the lock dropping us to the fail label. We should NOT be unlocking for path "j", so the above if expression should be "(x ==i && y >= j)" instead.

Otherwise, it looks good.

Quoted 5 lines
libmultipath/configure.c +5 -0
+				return 1;
+			flock(pp->fd, LOCK_UN);
+		}
+	}
+	return 1;
#2 lore raw

Applied with fix,
Thanks.

Quoted 37 lines · Malahal Naineni
Quoted 9 lines · Benjamin Marzinski [[email protected]] wrote:
libmultipath/configure.c +1 -1
@@ -294,12 +295,25 @@ lock_multipath (struct multipath * mpp, 
 		vector_foreach_slot(pgp->paths, pp, j) {
 			if (lock && flock(pp->fd, LOCK_EX | LOCK_NB) &&
 			    errno == EWOULDBLOCK)
-				return 1;
+				goto fail;
 			else if (!lock)
 				flock(pp->fd, LOCK_UN);
 		}

libmultipath/configure.c lock_multipath (struct multipath * mpp, · line 311

Quoted 10 lines
libmultipath/configure.c +8 -0
 	}
 	return 0;
+fail:
+	vector_foreach_slot (mpp->pg, pgp, x) {
+		if (x > i)
+			return 1;
+		if (!pgp->paths)
+			continue;
+		vector_foreach_slot(pgp->paths, pp, y) {
+			if (x == i && y > j)

Path 'j' has failed to get the lock dropping us to the fail label. We should NOT be unlocking for path "j", so the above if expression should be "(x ==i && y >= j)" instead.

Otherwise, it looks good.

libmultipath/configure.c lock_multipath (struct multipath * mpp, · line 316

Quoted 5 lines
libmultipath/configure.c +5 -0
+				return 1;
+			flock(pp->fd, LOCK_UN);
+		}
+	}
+	return 1;

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel