Skip to contentSkip to conversation

libmultipath: merge update_multipath_table() and update_multipath_status()

PATCH Superseded [email protected] 2 participants 4 messages Mar 17, 2021 – Mar 18, 2021 Device mapper

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libmultipath: merge update_multipath_table() and update_multipath_status()

From: Martin Wilck <[email protected]>

Since 378cb66 ("multipath: use update_pathvec_from_dm()"), we remove paths and even pathgroups from multipathd's data structures in update_multipath_table() if these paths are found to be non-existent. But update_multipath_status() is called afterwards, and it uses the kernel's mapping of pathgroups and paths, which won't match any more if any members had been removed. disassemble_status() returns an error if the number of path groups doesn't match, causing the entire structure setup to fail. And because disassemble_status() doesn't check the dev_t against the corresponding values in multipathd's data structures, it may assign wrong DM state to paths.

Fix this by calling disassemble_status() before making any changes to the data structure in update_pathvec_from_dm(). This can be easily done, because every call to update_multipath_status() is preceded by a call to update_multipath_table() anyway, and vice versa. So we simply merge the two functions into one. This actually simplifies the code for all callers.

As we remove a symbol, the major library version must be bumped.

---
 libmpathpersist/mpath_persist.c   |  1 -
 libmultipath/libmultipath.version | 30 ++++++++-----------------
 libmultipath/structs_vec.c        | 37 ++++++-------------------------
 multipath/main.c                  |  6 ++---
 multipathd/main.c                 |  5 +----
 5 files changed, 19 insertions(+), 60 deletions(-)
libmpathpersist/mpath_persist.c +0 -1
index 5c95af2..190e970 100644
@@ -408,7 +408,6 @@ get_mpvec (vector curmp, vector pathvec, char * refwwid)
 			continue;
 
 		if (update_multipath_table(mpp, pathvec, DI_CHECKER) != DMP_OK ||
-		    update_multipath_status(mpp) != DMP_OK ||
 		    update_mpp_paths(mpp, pathvec)) {
 			condlog(1, "error parsing map %s", mpp->wwid);
 			remove_map(mpp, pathvec, curmp, PURGE_VEC);
libmultipath/libmultipath.version +9 -21
index e9b4608..0cff311 100644
@@ -31,7 +31,7 @@
  *   The new version inherits the previous ones.
  */
 
-LIBMULTIPATH_4.0.0 {
+LIBMULTIPATH_5.0.0 {
 global:
 	/* symbols referenced by multipath and multipathd */
 	add_foreign;
@@ -198,7 +198,6 @@ global:
 	uevent_is_mpath;
 	uevent_listen;
 	update_mpp_paths;
-	update_multipath_status;
 	update_multipath_strings;
 	update_multipath_table;
 	update_pathvec_from_dm;
@@ -256,33 +255,22 @@ global:
 	libmultipath_init;
 	libmultipath_exit;
 
-local:
-	*;
-};
-
-LIBMULTIPATH_4.1.0 {
-global:
+	/* added in 4.1.0 */
 	libmp_verbosity;
-} LIBMULTIPATH_4.0.0;
 
-LIBMULTIPATH_4.2.0 {
-global:
+	/* added in 4.2.0 */
 	dm_prereq;
 	skip_libmp_dm_init;
-} LIBMULTIPATH_4.1.0;
 
-LIBMULTIPATH_4.3.0 {
-global:
+	/* added in 4.3.0 */
 	start_checker_thread;
-} LIBMULTIPATH_4.2.0;
 
-LIBMULTIPATH_4.4.0 {
-global:
+	/* added in 4.4.0 */
 	get_next_string;
-} LIBMULTIPATH_4.3.0;
 
-LIBMULITIPATH_4.5.0 {
-global:
+	/* added in 4.5.0 */
 	get_vpd_sgio;
 	trigger_partitions_udev_change;
-} LIBMULTIPATH_4.4.0;
+local:
+	*;
+};
libmultipath/structs_vec.c +7 -30
index 57cd88a..33c522f 100644
@@ -432,31 +432,14 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags)
 		return DMP_ERR;
 	}
 
-	/* FIXME: we should deal with the return value here */
-	update_pathvec_from_dm(pathvec, mpp, flags);
-
-	return DMP_OK;
-}
-
-int
-update_multipath_status (struct multipath *mpp)
-{
-	int r = DMP_ERR;
-	char status[PARAMS_SIZE] = {0};
-
-	if (!mpp)
-		return r;
-
-	r = dm_get_status(mpp->alias, status);
-	if (r != DMP_OK) {
+	*params = '\0';
+	if (dm_get_status(mpp->alias, params) != DMP_OK)
 		condlog(3, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting status" : "map not present");
-		return r;
-	}
-
-	if (disassemble_status(status, mpp)) {
+	else if (disassemble_status(params, mpp))
 		condlog(3, "%s: cannot disassemble status", mpp->alias);
-		return DMP_ERR;
-	}
+
+	/* FIXME: we should deal with the return value here */
+	update_pathvec_from_dm(pathvec, mpp, flags);
 
 	return DMP_OK;
 }
@@ -536,19 +519,13 @@ update_multipath_strings(struct multipath *mpp, vector pathvec)
 	mpp->pg = NULL;
 
 	r = update_multipath_table(mpp, pathvec, 0);
-	if (r != DMP_OK)
-		return r;
 	sync_paths(mpp, pathvec);
 
-	r = update_multipath_status(mpp);
-	if (r != DMP_OK)
-		return r;
-
 	vector_foreach_slot(mpp->pg, pgp, i)
 		if (pgp->paths)
 			path_group_prio_update(pgp);
 
-	return DMP_OK;
+	return r;
 }
 
 static void enter_recovery_mode(struct multipath *mpp)
multipath/main.c +2 -4
index 3f97582..ef89c7c 100644
@@ -196,8 +196,7 @@ get_dm_mpvec (enum mpath_cmds cmd, vector curmp, vector pathvec, char * refwwid)
 			continue;
 		}
 
-		if (update_multipath_table(mpp, pathvec, flags) != DMP_OK ||
-		    update_multipath_status(mpp) != DMP_OK) {
+		if (update_multipath_table(mpp, pathvec, flags) != DMP_OK) {
 			condlog(1, "error parsing map %s", mpp->wwid);
 			remove_map(mpp, pathvec, curmp, PURGE_VEC);
 			i--;
@@ -263,8 +262,7 @@ static int check_usable_paths(struct config *conf,
 	if (mpp == NULL)
 		goto free;
 
-	if (update_multipath_table(mpp, pathvec, 0) != DMP_OK ||
-		    update_multipath_status(mpp) != DMP_OK)
+	if (update_multipath_table(mpp, pathvec, 0) != DMP_OK)
 		    goto free;
 
 	vector_foreach_slot (mpp->pg, pg, i) {
multipathd/main.c +1 -4
index e0797cc..154a4ee 100644
@@ -559,8 +559,6 @@ add_map_without_path (struct vectors *vecs, const char *alias)
 
 	if (update_multipath_table(mpp, vecs->pathvec, 0) != DMP_OK)
 		goto out;
-	if (update_multipath_status(mpp) != DMP_OK)
-		goto out;
 
 	if (!vector_alloc_slot(vecs->mpvec))
 		goto out;
@@ -1469,8 +1467,7 @@ map_discovery (struct vectors * vecs)
 		return 1;
 
 	vector_foreach_slot (vecs->mpvec, mpp, i)
-		if (update_multipath_table(mpp, vecs->pathvec, 0) != DMP_OK ||
-		    update_multipath_status(mpp) != DMP_OK) {
+		if (update_multipath_table(mpp, vecs->pathvec, 0) != DMP_OK) {
 			remove_map(mpp, vecs->pathvec, vecs->mpvec, PURGE_VEC);
 			i--;
 		}
Signature · 7 lines
2.30.1


--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#1 lore raw

PATCH 2/2 11-dm-mpath.rules: run "multipath -U" with -v1

From: Martin Wilck <[email protected]>

In cases where some path devices are temporarily unavailable (e.g. failover), high amounts of error messages such as these are seen:

Feb 27 08:02:03 ictm1608s02h1 multipath[1420]: get_udev_device: failed to look up 65:224 with type 1
Feb 27 08:02:03 ictm1608s02h1 multipath[1420]: 3600a098000aada210000f1625de51ed9: discarding non-existing path 65:224

This is because every invocation of "multipath -U" prints these messages at the default log level (-v2). In the case of "multipath -U", these messages aren't important, and in failover situations, "multipath -U" is run pretty often, spamming the log with many similar messages.

Generally reducing the log level of these messages would be wrong, because they are important for multipathd's operation, to verify that multipathd does the right thing when discovering a discrepancy between the dm state and the devices present in the system. Therefore, just decrease the verbosity with which we invoke "multipath -U" in the udev rules.

---
 multipath/11-dm-mpath.rules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
multipath/11-dm-mpath.rules +1 -1
index cd522e8..d191ae8 100644
@@ -32,7 +32,7 @@ ACTION=="add", ENV{.MPATH_DEVICE_READY_OLD}=="1", GOTO="paths_ok"
 
 # Check the map state directly with multipath -U.
 # This doesn't attempt I/O on the device.
-PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -U %k", GOTO="paths_ok"
+PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -U -v1 %k", GOTO="paths_ok"
 ENV{MPATH_DEVICE_READY}="0", GOTO="mpath_action"
 LABEL="paths_ok"
 
Signature · 7 lines
2.30.1


--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on v1 2/2
#2 lore raw

Re: [dm-devel] [PATCH 2/2] 11-dm-mpath.rules: run "multipath -U" with -v1

Quoted 13 lines · On Wed, Mar 17, 2021 at 06:27:27PM +0100, [email protected] wrote:

From: Martin Wilck <[email protected]>

In cases where some path devices are temporarily unavailable (e.g. failover), high amounts of error messages such as these are seen:

Feb 27 08:02:03 ictm1608s02h1 multipath[1420]: get_udev_device: failed to look up 65:224 with type 1
Feb 27 08:02:03 ictm1608s02h1 multipath[1420]: 3600a098000aada210000f1625de51ed9: discarding non-existing path 65:224

This is because every invocation of "multipath -U" prints these messages at the default log level (-v2). In the case of "multipath -U", these messages aren't important, and in failover situations, "multipath -U" is run pretty often, spamming the log with many similar messages.

Quoted 6 lines

Generally reducing the log level of these messages would be wrong, because they are important for multipathd's operation, to verify that multipathd does the right thing when discovering a discrepancy between the dm state and the devices present in the system. Therefore, just decrease the verbosity with which we invoke "multipath -U" in the udev rules.

Quoted 20 lines
---
 multipath/11-dm-mpath.rules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
multipath/11-dm-mpath.rules +1 -1
index cd522e8..d191ae8 100644
@@ -32,7 +32,7 @@ ACTION=="add", ENV{.MPATH_DEVICE_READY_OLD}=="1", GOTO="paths_ok"
 
 # Check the map state directly with multipath -U.
 # This doesn't attempt I/O on the device.
-PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -U %k", GOTO="paths_ok"
+PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -U -v1 %k", GOTO="paths_ok"
 ENV{MPATH_DEVICE_READY}="0", GOTO="mpath_action"
 LABEL="paths_ok"
 
Signature · 1 line
2.30.1

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

#3 lore raw
In reply to [email protected]
Quoted 13 lines · On Wed, Mar 17, 2021 at 06:27:26PM +0100, [email protected] wrote:

From: Martin Wilck <[email protected]>

Since 378cb66 ("multipath: use update_pathvec_from_dm()"), we remove paths and even pathgroups from multipathd's data structures in update_multipath_table() if these paths are found to be non-existent. But update_multipath_status() is called afterwards, and it uses the kernel's mapping of pathgroups and paths, which won't match any more if any members had been removed. disassemble_status() returns an error if the number of path groups doesn't match, causing the entire structure setup to fail. And because disassemble_status() doesn't check the dev_t against the corresponding values in multipathd's data structures, it may assign wrong DM state to paths.

Quoted 8 lines

Fix this by calling disassemble_status() before making any changes to the data structure in update_pathvec_from_dm(). This can be easily done, because every call to update_multipath_status() is preceded by a call to update_multipath_table() anyway, and vice versa. So we simply merge the two functions into one. This actually simplifies the code for all callers.

As we remove a symbol, the major library version must be bumped.

A few small questions and comments below

Quoted 110 lines
---
 libmpathpersist/mpath_persist.c   |  1 -
 libmultipath/libmultipath.version | 30 ++++++++-----------------
 libmultipath/structs_vec.c        | 37 ++++++-------------------------
 multipath/main.c                  |  6 ++---
 multipathd/main.c                 |  5 +----
 5 files changed, 19 insertions(+), 60 deletions(-)
libmpathpersist/mpath_persist.c +0 -1
index 5c95af2..190e970 100644
@@ -408,7 +408,6 @@ get_mpvec (vector curmp, vector pathvec, char * refwwid)
 			continue;
 
 		if (update_multipath_table(mpp, pathvec, DI_CHECKER) != DMP_OK ||
-		    update_multipath_status(mpp) != DMP_OK ||
 		    update_mpp_paths(mpp, pathvec)) {
 			condlog(1, "error parsing map %s", mpp->wwid);
 			remove_map(mpp, pathvec, curmp, PURGE_VEC);
libmultipath/libmultipath.version +9 -21
index e9b4608..0cff311 100644
@@ -31,7 +31,7 @@
  *   The new version inherits the previous ones.
  */
 
-LIBMULTIPATH_4.0.0 {
+LIBMULTIPATH_5.0.0 {
 global:
 	/* symbols referenced by multipath and multipathd */
 	add_foreign;
@@ -198,7 +198,6 @@ global:
 	uevent_is_mpath;
 	uevent_listen;
 	update_mpp_paths;
-	update_multipath_status;
 	update_multipath_strings;
 	update_multipath_table;
 	update_pathvec_from_dm;
@@ -256,33 +255,22 @@ global:
 	libmultipath_init;
 	libmultipath_exit;
 
-local:
-	*;
-};
-
-LIBMULTIPATH_4.1.0 {
-global:
+	/* added in 4.1.0 */
 	libmp_verbosity;
-} LIBMULTIPATH_4.0.0;
 
-LIBMULTIPATH_4.2.0 {
-global:
+	/* added in 4.2.0 */
 	dm_prereq;
 	skip_libmp_dm_init;
-} LIBMULTIPATH_4.1.0;
 
-LIBMULTIPATH_4.3.0 {
-global:
+	/* added in 4.3.0 */
 	start_checker_thread;
-} LIBMULTIPATH_4.2.0;
 
-LIBMULTIPATH_4.4.0 {
-global:
+	/* added in 4.4.0 */
 	get_next_string;
-} LIBMULTIPATH_4.3.0;
 
-LIBMULITIPATH_4.5.0 {
-global:
+	/* added in 4.5.0 */
 	get_vpd_sgio;
 	trigger_partitions_udev_change;
-} LIBMULTIPATH_4.4.0;
+local:
+	*;
+};
libmultipath/structs_vec.c +1 -17
index 57cd88a..33c522f 100644
@@ -432,31 +432,14 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags)
 		return DMP_ERR;
 	}
 
-	/* FIXME: we should deal with the return value here */
-	update_pathvec_from_dm(pathvec, mpp, flags);
-
-	return DMP_OK;
-}
-
-int
-update_multipath_status (struct multipath *mpp)
-{
-	int r = DMP_ERR;
-	char status[PARAMS_SIZE] = {0};
-
-	if (!mpp)
-		return r;
-
-	r = dm_get_status(mpp->alias, status);
-	if (r != DMP_OK) {
+	*params = '\0';

libmultipath/structs_vec.c update_multipath_table (struct multipath *mpp, vector pathvec, int flags) · line 459

Quoted 10 lines
libmultipath/structs_vec.c +2 -6
+	if (dm_get_status(mpp->alias, params) != DMP_OK)
 		condlog(3, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting status" : "map not present");
-		return r;
-	}
-
-	if (disassemble_status(status, mpp)) {
+	else if (disassemble_status(params, mpp))
 		condlog(3, "%s: cannot disassemble status", mpp->alias);
-		return DMP_ERR;
-	}

Is the idea that updating the path/pathgroup status is not critical, so even if it fails, update_multipath_table() can still succeed? That makes some sense, but it seems like failing to update the status is at least not expected, so we should increase the log level.

libmultipath/structs_vec.c update_multipath_strings(struct multipath *mpp, vector pathvec) · line 540

Quoted 12 lines
libmultipath/structs_vec.c +3 -2
+
+	/* FIXME: we should deal with the return value here */
+	update_pathvec_from_dm(pathvec, mpp, flags);
 
 	return DMP_OK;
 }
@@ -536,19 +519,13 @@ update_multipath_strings(struct multipath *mpp, vector pathvec)
 	mpp->pg = NULL;
 
 	r = update_multipath_table(mpp, pathvec, 0);
-	if (r != DMP_OK)
-		return r;

This one makes less sense to me. If we failed getting the table, why do we still sync the paths? Admittedly, it's hard to know what the right thing to do is, when we fail to get the table.

-Ben

Quoted 64 lines
libmultipath/structs_vec.c +1 -5
 	sync_paths(mpp, pathvec);
 
-	r = update_multipath_status(mpp);
-	if (r != DMP_OK)
-		return r;
-
 	vector_foreach_slot(mpp->pg, pgp, i)
 		if (pgp->paths)
 			path_group_prio_update(pgp);
 
-	return DMP_OK;
+	return r;
 }
 
 static void enter_recovery_mode(struct multipath *mpp)
multipath/main.c +2 -4
index 3f97582..ef89c7c 100644
@@ -196,8 +196,7 @@ get_dm_mpvec (enum mpath_cmds cmd, vector curmp, vector pathvec, char * refwwid)
 			continue;
 		}
 
-		if (update_multipath_table(mpp, pathvec, flags) != DMP_OK ||
-		    update_multipath_status(mpp) != DMP_OK) {
+		if (update_multipath_table(mpp, pathvec, flags) != DMP_OK) {
 			condlog(1, "error parsing map %s", mpp->wwid);
 			remove_map(mpp, pathvec, curmp, PURGE_VEC);
 			i--;
@@ -263,8 +262,7 @@ static int check_usable_paths(struct config *conf,
 	if (mpp == NULL)
 		goto free;
 
-	if (update_multipath_table(mpp, pathvec, 0) != DMP_OK ||
-		    update_multipath_status(mpp) != DMP_OK)
+	if (update_multipath_table(mpp, pathvec, 0) != DMP_OK)
 		    goto free;
 
 	vector_foreach_slot (mpp->pg, pg, i) {
multipathd/main.c +1 -4
index e0797cc..154a4ee 100644
@@ -559,8 +559,6 @@ add_map_without_path (struct vectors *vecs, const char *alias)
 
 	if (update_multipath_table(mpp, vecs->pathvec, 0) != DMP_OK)
 		goto out;
-	if (update_multipath_status(mpp) != DMP_OK)
-		goto out;
 
 	if (!vector_alloc_slot(vecs->mpvec))
 		goto out;
@@ -1469,8 +1467,7 @@ map_discovery (struct vectors * vecs)
 		return 1;
 
 	vector_foreach_slot (vecs->mpvec, mpp, i)
-		if (update_multipath_table(mpp, vecs->pathvec, 0) != DMP_OK ||
-		    update_multipath_status(mpp) != DMP_OK) {
+		if (update_multipath_table(mpp, vecs->pathvec, 0) != DMP_OK) {
 			remove_map(mpp, vecs->pathvec, vecs->mpvec, PURGE_VEC);
 			i--;
 		}
Signature · 1 line
2.30.1

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