Skip to contentSkip to conversation

Setting "user_friendly_names" to "yes" causes dm-mp to occasionally miss a mpath device during configuration

Bug 217014 Christophe Varoqui 2 participants 2 messages Nov 27, 2006 1 message not in the archive Device mapper

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Nice fix, thank you.
Merged.

Quoted 208 lines · Le lundi 27 novembre 2006 à 11:30 -0500, [email protected] a écrit :

Please do not reply directly to this email. All additional comments should be made in the comments box of this bug report.

Summary: Setting "user_friendly_names" to "yes" causes dm-mp to occasionally miss a mpath device during configuration

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=217014

------- Additional Comments From [email protected] 2006-11-27 11:29 EST ------- The posix file byte range locks used to provide atomicity for accessing the entries in the multipath bindings file get released from whenever __any__ descriptor or FILE structure for that file is closed. This patch delays the fclose() for the FILE structures used within lookup_binding() and rlookup_binding() until there is no more need for the atomicity.

Without this patch I could fairly easily get two multipath mpath0 entries in /var/lib/multipath/bindings by running 8 concurrent instances of multipath
(8) while with the patch I cannot get this problem to occur.

libmultipath/alias.c +55 -40
index 6d103d7..86cae9b 100644
@@ -166,28 +166,14 @@ fail:
 
 
 static int
-lookup_binding(int fd, char *map_wwid, char **map_alias)
+lookup_binding(FILE *f, char *map_wwid, char **map_alias)
 {
 	char buf[LINE_MAX];
-	FILE *f;
 	unsigned int line_nr = 0;
-	int scan_fd;
 	int id = 0;
 
 	*map_alias = NULL;
-	scan_fd = dup(fd);
-	if (scan_fd < 0) {
-		condlog(0, "Cannot dup bindings file descriptor : %s",
-			strerror(errno));
-		return -1;
-	}
-	f = fdopen(scan_fd, "r");
-	if (!f) {
-		condlog(0, "cannot fdopen on bindings file descriptor : %s",
-			strerror(errno));
-		close(scan_fd);
-		return -1;
-	}
+
 	while (fgets(buf, LINE_MAX, f)) {
 		char *c, *alias, *wwid;
 		int curr_id;
@@ -215,38 +201,22 @@ lookup_binding(int fd, char *map_wwid, c
 			if (*map_alias == NULL)
 				condlog(0, "Cannot copy alias from bindings "
 					"file : %s", strerror(errno));
-			fclose(f);
 			return id;
 		}
 	}
 	condlog(3, "No matching wwid [%s] in bindings file.", map_wwid);
-	fclose(f);
 	return id;
 }	
 
 static int
-rlookup_binding(int fd, char **map_wwid, char *map_alias)
+rlookup_binding(FILE *f, char **map_wwid, char *map_alias)
 {
 	char buf[LINE_MAX];
-	FILE *f;
 	unsigned int line_nr = 0;
-	int scan_fd;
 	int id = 0;
 
 	*map_wwid = NULL;
-	scan_fd = dup(fd);
-	if (scan_fd < 0) {
-		condlog(0, "Cannot dup bindings file descriptor : %s",
-			strerror(errno));
-		return -1;
-	}
-	f = fdopen(scan_fd, "r");
-	if (!f) {
-		condlog(0, "cannot fdopen on bindings file descriptor : %s",
-			strerror(errno));
-		close(scan_fd);
-		return -1;
-	}
+
 	while (fgets(buf, LINE_MAX, f)) {
 		char *c, *alias, *wwid;
 		int curr_id;
@@ -274,12 +244,10 @@ rlookup_binding(int fd, char **map_wwid,
 			if (*map_wwid == NULL)
 				condlog(0, "Cannot copy alias from bindings "
 					"file : %s", strerror(errno));
-			fclose(f);
 			return id;
 		}
 	}
 	condlog(3, "No matching alias [%s] in bindings file.", map_alias);
-	fclose(f);
 	return id;
 }	
 
@@ -327,7 +295,8 @@ char *
 get_user_friendly_alias(char *wwid, char *file)
 {
 	char *alias;
-	int fd, id;
+	int fd, scan_fd, id;
+	FILE *f;
 
 	if (!wwid || *wwid == '\0') {
 		condlog(3, "Cannot find binding for empty WWID");
@@ -337,14 +306,37 @@ get_user_friendly_alias(char *wwid, char
 	fd = open_bindings_file(file);
 	if (fd < 0)
 		return NULL;
-	id = lookup_binding(fd, wwid, &alias);
+
+	scan_fd = dup(fd);
+	if (scan_fd < 0) {
+		condlog(0, "Cannot dup bindings file descriptor : %s",
+			strerror(errno));
+		close(fd);
+		return NULL;
+	}
+
+	f = fdopen(scan_fd, "r");
+	if (!f) {
+		condlog(0, "cannot fdopen on bindings file descriptor : %s",
+			strerror(errno));
+		close(scan_fd);
+		close(fd);
+		return NULL;
+	}
+
+	id = lookup_binding(f, wwid, &alias);
 	if (id < 0) {
+		fclose(f);
+		close(scan_fd);
 		close(fd);
 		return NULL;
 	}
+
 	if (!alias)
 		alias = allocate_binding(fd, wwid, id);
 
+	fclose(f);
+	close(scan_fd);
 	close(fd);
 	return alias;
 }
@@ -353,7 +345,8 @@ char *
 get_user_friendly_wwid(char *alias, char *file)
 {
 	char *wwid;
-	int fd, id;
+	int fd, scan_fd, id;
+	FILE *f;
 
 	if (!alias || *alias == '\0') {
 		condlog(3, "Cannot find binding for empty alias");
@@ -363,12 +356,34 @@ get_user_friendly_wwid(char *alias, char
 	fd = open_bindings_file(file);
 	if (fd < 0)
 		return NULL;
-	id = rlookup_binding(fd, &wwid, alias);
+
+	scan_fd = dup(fd);
+	if (scan_fd < 0) {
+		condlog(0, "Cannot dup bindings file descriptor : %s",
+			strerror(errno));
+		close(fd);
+		return NULL;
+	}
+
+	f = fdopen(scan_fd, "r");
+	if (!f) {
+		condlog(0, "cannot fdopen on bindings file descriptor : %s",
+			strerror(errno));
+		close(scan_fd);
+		close(fd);
+		return NULL;
+	}
+
+	id = rlookup_binding(f, &wwid, alias);
 	if (id < 0) {
+		fclose(f);
+		close(scan_fd);
 		close(fd);
 		return NULL;
 	}
 
+	fclose(f);
+	close(scan_fd);
 	close(fd);
 	return wwid;
 }
#2 lore raw

RE: [Bug 217014] Setting "user_friendly_names" to "yes" causesdm-mp to occasionally miss a mpath device during configuration

Sorry, but I didn't send it to you directly since I mistakenly thought you had already merged in the fix after I had initially sent out this patch to the dm-devel list on 7/17.

Quoted 238 lines

-----Original Message-----
From: Christophe Varoqui [mailto:[email protected]]
Sent: Monday, November 27, 2006 5:10 PM
To: goggin, edward
Cc: device-mapper development
Subject: Re: [Bug 217014] Setting "user_friendly_names" to "yes" causesdm-mp to occasionally miss a mpath device during configuration

Nice fix, thank you.
Merged.

Quoted 4 lines · Le lundi 27 novembre 2006 à 11:30 -0500, [email protected] a écrit :

Please do not reply directly to this email. All additional comments should be made in the comments box of this bug report.

Summary: Setting "user_friendly_names" to "yes" causes

dm-mp to occasionally miss a mpath device during configuration

Quoted 9 lines

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=217014

------- Additional Comments From [email protected]

2006-11-27 11:29 EST -------

Quoted 1 line

The posix file byte range locks used to provide atomicity

for accessing the

Quoted 1 line

entries in the multipath bindings file get released from

whenever __any__

Quoted 1 line

descriptor or FILE structure for that file is closed. This

patch delays the

Quoted 4 lines

fclose() for the FILE structures used within lookup_binding() and rlookup_binding() until there is no more need for the atomicity.

Without this patch I could fairly easily get two multipath

mpath0 entries

Quoted 1 line

in /var/lib/multipath/bindings by running 8 concurrent

instances of multipath

Quoted 19 lines

(8) while with the patch I cannot get this problem to occur.

libmultipath/alias.c +1 -3
index 6d103d7..86cae9b 100644
@@ -166,28 +166,14 @@ fail:
 
 
 static int
-lookup_binding(int fd, char *map_wwid, char **map_alias)
+lookup_binding(FILE *f, char *map_wwid, char **map_alias)
 {
 	char buf[LINE_MAX];
-	FILE *f;
 	unsigned int line_nr = 0;
-	int scan_fd;
 	int id = 0;
 

libmultipath/alias.c fail: · line 186

Quoted 10 lines
libmultipath/alias.c +0 -9
 	*map_alias = NULL;
-	scan_fd = dup(fd);
-	if (scan_fd < 0) {
-		condlog(0, "Cannot dup bindings file descriptor : %s",
-			strerror(errno));
-		return -1;
-	}
-	f = fdopen(scan_fd, "r");
-	if (!f) {
-		condlog(0, "cannot fdopen on bindings file 

descriptor : %s",

libmultipath/alias.c lookup_binding(int fd, char *map_wwid, c · line 202

Quoted 11 lines
libmultipath/alias.c +1 -4
-			strerror(errno));
-		close(scan_fd);
-		return -1;
-	}
+
 	while (fgets(buf, LINE_MAX, f)) {
 		char *c, *alias, *wwid;
 		int curr_id;
@@ -215,38 +201,22 @@ lookup_binding(int fd, char *map_wwid, c
 			if (*map_alias == NULL)
 				condlog(0, "Cannot copy alias 

from bindings "

Quoted 20 lines
libmultipath/alias.c +1 -5
 					"file : %s", strerror(errno));
-			fclose(f);
 			return id;
 		}
 	}
 	condlog(3, "No matching wwid [%s] in bindings file.", map_wwid);
-	fclose(f);
 	return id;
 }	
 
 static int
-rlookup_binding(int fd, char **map_wwid, char *map_alias)
+rlookup_binding(FILE *f, char **map_wwid, char *map_alias)
 {
 	char buf[LINE_MAX];
-	FILE *f;
 	unsigned int line_nr = 0;
-	int scan_fd;
 	int id = 0;
 

libmultipath/alias.c lookup_binding(int fd, char *map_wwid, c · line 245

Quoted 10 lines
libmultipath/alias.c +0 -9
 	*map_wwid = NULL;
-	scan_fd = dup(fd);
-	if (scan_fd < 0) {
-		condlog(0, "Cannot dup bindings file descriptor : %s",
-			strerror(errno));
-		return -1;
-	}
-	f = fdopen(scan_fd, "r");
-	if (!f) {
-		condlog(0, "cannot fdopen on bindings file 

descriptor : %s",

libmultipath/alias.c rlookup_binding(int fd, char **map_wwid, · line 245

Quoted 11 lines
libmultipath/alias.c +1 -4
-			strerror(errno));
-		close(scan_fd);
-		return -1;
-	}
+
 	while (fgets(buf, LINE_MAX, f)) {
 		char *c, *alias, *wwid;
 		int curr_id;
@@ -274,12 +244,10 @@ rlookup_binding(int fd, char **map_wwid,
 			if (*map_wwid == NULL)
 				condlog(0, "Cannot copy alias 

from bindings "

libmultipath/alias.c rlookup_binding(int fd, char **map_wwid, · line 250

Quoted 6 lines
libmultipath/alias.c +0 -1
 					"file : %s", strerror(errno));
-			fclose(f);
 			return id;
 		}
 	}
 	condlog(3, "No matching alias [%s] in bindings file.", 

map_alias);

Quoted 21 lines
libmultipath/alias.c +4 -3
-	fclose(f);
 	return id;
 }	
 
@@ -327,7 +295,8 @@ char *
 get_user_friendly_alias(char *wwid, char *file)
 {
 	char *alias;
-	int fd, id;
+	int fd, scan_fd, id;
+	FILE *f;
 
 	if (!wwid || *wwid == '\0') {
 		condlog(3, "Cannot find binding for empty WWID");
@@ -337,14 +306,37 @@ get_user_friendly_alias(char *wwid, char
 	fd = open_bindings_file(file);
 	if (fd < 0)
 		return NULL;
-	id = lookup_binding(fd, wwid, &alias);
+
+	scan_fd = dup(fd);

libmultipath/alias.c get_user_friendly_alias(char *wwid, char · line 320

Quoted 10 lines
libmultipath/alias.c +10 -0
+	if (scan_fd < 0) {
+		condlog(0, "Cannot dup bindings file descriptor : %s",
+			strerror(errno));
+		close(fd);
+		return NULL;
+	}
+
+	f = fdopen(scan_fd, "r");
+	if (!f) {
+		condlog(0, "cannot fdopen on bindings file 

descriptor : %s",

Quoted 39 lines
libmultipath/alias.c +16 -2
+			strerror(errno));
+		close(scan_fd);
+		close(fd);
+		return NULL;
+	}
+
+	id = lookup_binding(f, wwid, &alias);
 	if (id < 0) {
+		fclose(f);
+		close(scan_fd);
 		close(fd);
 		return NULL;
 	}
+
 	if (!alias)
 		alias = allocate_binding(fd, wwid, id);
 
+	fclose(f);
+	close(scan_fd);
 	close(fd);
 	return alias;
 }
@@ -353,7 +345,8 @@ char *
 get_user_friendly_wwid(char *alias, char *file)
 {
 	char *wwid;
-	int fd, id;
+	int fd, scan_fd, id;
+	FILE *f;
 
 	if (!alias || *alias == '\0') {
 		condlog(3, "Cannot find binding for empty alias");
@@ -363,12 +356,34 @@ get_user_friendly_wwid(char *alias, char
 	fd = open_bindings_file(file);
 	if (fd < 0)
 		return NULL;
-	id = rlookup_binding(fd, &wwid, alias);
+
+	scan_fd = dup(fd);

libmultipath/alias.c get_user_friendly_wwid(char *alias, char · line 370

Quoted 10 lines
libmultipath/alias.c +10 -0
+	if (scan_fd < 0) {
+		condlog(0, "Cannot dup bindings file descriptor : %s",
+			strerror(errno));
+		close(fd);
+		return NULL;
+	}
+
+	f = fdopen(scan_fd, "r");
+	if (!f) {
+		condlog(0, "cannot fdopen on bindings file 

descriptor : %s",

Quoted 20 lines
libmultipath/alias.c +11 -0
+			strerror(errno));
+		close(scan_fd);
+		close(fd);
+		return NULL;
+	}
+
+	id = rlookup_binding(f, &wwid, alias);
 	if (id < 0) {
+		fclose(f);
+		close(scan_fd);
 		close(fd);
 		return NULL;
 	}
 
+	fclose(f);
+	close(scan_fd);
 	close(fd);
 	return wwid;
 }