[PATCH] fix: correct unlocking of map file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



1. Three missing map_unlock() calls were added.
2. Map file's lock must be released by an explicit LOCK_UN operation,
   because duplicated (e.g. created by fork()) descriptors
   inherit the lock. As a result child process which inherits open
   descriptors with lock can block another process of mdadm.

Signed-off-by: Lukasz Dorau <lukasz.dorau@xxxxxxxxx>
---
 Incremental.c |    3 +++
 mapfile.c     |    4 ++++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/Incremental.c b/Incremental.c
index 571d45d..b90089b 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -1472,6 +1472,7 @@ static int Incremental_container(struct supertype *st, char *devname,
 					"Cannot activate array(s).\n");
 		/* free container data and exit */
 		sysfs_free(list);
+		map_unlock(&map);
 		return 2;
 	}
 
@@ -1535,6 +1536,7 @@ static int Incremental_container(struct supertype *st, char *devname,
 					fprintf(stderr, Name ": array %s/%s is "
 						"explicitly ignored by mdadm.conf\n",
 						match->container, match->member);
+				map_unlock(&map);
 				return 2;
 			}
 			if (match)
@@ -1550,6 +1552,7 @@ static int Incremental_container(struct supertype *st, char *devname,
 		if (mdfd < 0) {
 			fprintf(stderr, Name ": failed to open %s: %s.\n",
 				chosen_name, strerror(errno));
+			map_unlock(&map);
 			return 2;
 		}
 
diff --git a/mapfile.c b/mapfile.c
index ff1e973..98c0780 100644
--- a/mapfile.c
+++ b/mapfile.c
@@ -149,6 +149,10 @@ int map_lock(struct map_ent **melp)
 void map_unlock(struct map_ent **melp)
 {
 	if (lf) {
+		/* lock must be released by an explicit LOCK_UN operation
+		 * because duplicated descriptors inherit the lock
+		 */
+		flock(fileno(lf), LOCK_UN);
 		/* must unlink before closing the file,
 		 * as only the owner of the lock may
 		 * unlink the file

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux