Blame SOURCES/0094-RHBZ-1086825-cleanup-remap.patch

f20720
---
f20720
 libmultipath/alias.c   |   31 +++++++++++++++----------------
f20720
 libmultipath/propsel.c |    4 ++--
f20720
 2 files changed, 17 insertions(+), 18 deletions(-)
f20720
f20720
Index: multipath-tools-130222/libmultipath/alias.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/alias.c
f20720
+++ multipath-tools-130222/libmultipath/alias.c
f20720
@@ -149,13 +149,11 @@ rlookup_binding(FILE *f, char *buff, cha
f20720
 {
f20720
 	char line[LINE_MAX];
f20720
 	unsigned int line_nr = 0;
f20720
-	int id = 0;
f20720
 
f20720
 	buff[0] = '\0';
f20720
 
f20720
 	while (fgets(line, LINE_MAX, f)) {
f20720
 		char *c, *alias, *wwid;
f20720
-		int curr_id;
f20720
 
f20720
 		line_nr++;
f20720
 		c = strpbrk(line, "#\n\r");
f20720
@@ -164,9 +162,6 @@ rlookup_binding(FILE *f, char *buff, cha
f20720
 		alias = strtok(line, " \t");
f20720
 		if (!alias) /* blank line */
f20720
 			continue;
f20720
-		curr_id = scan_devname(alias, prefix);
f20720
-		if (curr_id >= id)
f20720
-			id = curr_id + 1;
f20720
 		wwid = strtok(NULL, " \t");
f20720
 		if (!wwid){
f20720
 			condlog(3,
f20720
@@ -184,16 +179,12 @@ rlookup_binding(FILE *f, char *buff, cha
f20720
 				"\nSetting wwid to %s", alias, wwid);
f20720
 			strncpy(buff, wwid, WWID_SIZE);
f20720
 			buff[WWID_SIZE - 1] = '\0';
f20720
-			return id;
f20720
+			return 0;
f20720
 		}
f20720
 	}
f20720
 	condlog(3, "No matching alias [%s] in bindings file.", map_alias);
f20720
 
f20720
-	/* Get the theoretical id for this map alias.
f20720
-	 * Used by use_existing_alias
f20720
-	 */
f20720
-	id = scan_devname(map_alias, prefix);
f20720
-	return id;
f20720
+	return -1;
f20720
 }
f20720
 
f20720
 static char *
f20720
@@ -264,9 +255,7 @@ use_existing_alias (char *wwid, char *fi
f20720
 	/* lookup the binding. if it exsists, the wwid will be in buff
f20720
 	 * either way, id contains the id for the alias
f20720
 	 */
f20720
-	id = rlookup_binding(f , buff,  alias_old, prefix);
f20720
-	if (id < 0)
f20720
-		goto out;
f20720
+	rlookup_binding(f, buff, alias_old, prefix);
f20720
 
f20720
 	if (strlen(buff) > 0) {
f20720
 		/* if buff is our wwid, it's already
f20720
@@ -279,11 +268,21 @@ use_existing_alias (char *wwid, char *fi
f20720
 			condlog(0, "alias %s already bound to wwid %s, cannot reuse",
f20720
 				alias_old, buff);
f20720
 		}
f20720
-		goto out;	
f20720
+		goto out;
f20720
 	}
f20720
 
f20720
 	/* allocate the existing alias in the bindings file */
f20720
-	if (can_write && id && !bindings_read_only) {
f20720
+	id = scan_devname(alias_old, prefix);
f20720
+	if (id <= 0)
f20720
+		goto out;
f20720
+
f20720
+	if (fflush(f) != 0) {
f20720
+		condlog(0, "cannot fflush bindings file stream : %s",
f20720
+			strerror(errno));
f20720
+		goto out;
f20720
+	}
f20720
+
f20720
+	if (can_write && !bindings_read_only) {
f20720
 		alias = allocate_binding(fd, wwid, id, prefix);
f20720
 		condlog(0, "Allocated existing binding [%s] for WWID [%s]",
f20720
 			alias, wwid);
f20720
Index: multipath-tools-130222/libmultipath/propsel.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/propsel.c
f20720
+++ multipath-tools-130222/libmultipath/propsel.c
f20720
@@ -263,13 +263,13 @@ select_alias (struct multipath * mp)
f20720
 		goto out;
f20720
 
f20720
 	select_alias_prefix(mp);
f20720
-	
f20720
+
f20720
 	if (strlen(mp->alias_old) > 0) {
f20720
 		mp->alias = use_existing_alias(mp->wwid, conf->bindings_file,
f20720
 				mp->alias_old, mp->alias_prefix,
f20720
 				conf->bindings_read_only);
f20720
 		memset (mp->alias_old, 0, WWID_SIZE);
f20720
-	} 
f20720
+	}
f20720
 
f20720
 	if (mp->alias == NULL)
f20720
 		mp->alias = get_user_friendly_alias(mp->wwid,