multipath: fix multipath locking
authorBenjamin Marzinski <bmarzins@redhat.com>
Fri, 5 Nov 2010 04:59:46 +0000 (23:59 -0500)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Fri, 5 Nov 2010 07:08:09 +0000 (08:08 +0100)
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.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
libmultipath/configure.c

index f32a484..a40bef3 100644 (file)
@@ -284,6 +284,7 @@ lock_multipath (struct multipath * mpp, int lock)
        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, int lock)
                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;
 }
 
 /*