Fix muitpath/multipathd flush issue
Benjamin Marzinski
maintainerv2 cover Fix muitpath/multipathd flush issue
If a multipath device is removed, and check_path() checks one of its paths before multipathd processes either the uevent or the dm event from removing it, multipathd will recreate the removed device. This happens because check_path() will continute to check the removed device's former paths until an event arrives removing the device. A missing multpath device will cause the update_multipath_strings() call to fail, setting pp->dmstate to PSTATE_UNDEF. If the path is up, this dmstate will cause reinstate_path() to be called, which will also fail, because the multipath device doesn't exist. This will trigger a reload, restoring the recently removed device.
This patchset handles this is two ways. The first two patches directly fix these issues in check_path(), so that a missing multipath device will no longer get recreated when checking one of its former paths.
The other 5 patches add a "multipathd del maps" command, and make the mutipath command delegate flush operations to multipathd so multipathd's state remains in sync with the kernel's, while doing removes.
Changes from v1:
0001: This is completely different. I've change how patch 0002 detects
when a multipath device has disappeared. Instead of do_get_info, I need more return values on dm_get_map/status, and the update_multipath_* functions. I have used symbolic return values, which was the objection to the previous patch. I tried to picked generic enough names that they could be used for other devmapper.c functions as well.
0002: At Martin's suggestion, multipath now differentiates between dm
failures and a missing multipath device in update_multipath_strings(). So there is no need to recheck if the device is missing.
0006: Added some man page info that was previously in patch 0007
0007: Removed mentions of the -D option in the man page and usage
output.
I did not change anything about suspending the device on remove. It was not obvious how to break that up between multipath and multipathd, and there are likely still some conversations to be had about what we need to do to remove a device in multipath, and in what order. So, for now, I just kept all those functions the same, and just added the code necessary to make multpathd work with them correctly, as is.
Benjamin Marzinski (7):
libmultipath: make dm_get_map/status return codes symbolic
multipathd: fix check_path errors with removed map
libmultipath: make dm_flush_maps only return 0 on success
multipathd: add "del maps" multipathd command
multipath: make flushing maps work like other commands
multipath: delegate flushing maps to multipathd
multipath: add option to skip multipathd delegation
libmultipath/config.h | 4 ++- libmultipath/configure.h | 3 -- libmultipath/devmapper.c | 63 +++++++++++++++++++++++++------------- libmultipath/devmapper.h | 8 ++++- libmultipath/structs_vec.c | 45 +++++++++++++++------------ multipath/main.c | 44 ++++++++++++++++++-------- multipath/multipath.8 | 4 +-- multipathd/cli.c | 1 + multipathd/cli_handlers.c | 19 ++++++++++++ multipathd/cli_handlers.h | 1 + multipathd/main.c | 50 +++++++++++++----------------- multipathd/main.h | 1 + 12 files changed, 155 insertions(+), 88 deletions(-)
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 1/7 libmultipath: make dm_get_map/status return codes symbolic
dm_get_map() and dm_get_status() now use symbolic return codes. They also differentiate between failing to get information from device-mapper and not finding the requested device. These symboilc return codes are also used by update_multipath_* functions.
--- libmultipath/devmapper.c | 51 +++++++++++++++++++++++++------------- libmultipath/devmapper.h | 6 +++++ libmultipath/structs_vec.c | 45 +++++++++++++++++++-------------- multipathd/main.c | 12 ++++----- 4 files changed, 72 insertions(+), 42 deletions(-)
libmultipath/devmapper.c +34 -17
@@ -534,36 +534,43 @@ int dm_map_present(const char * str)int dm_get_map (const char *name,unsigned long long *size,char *outparams) { -int r =1 ; +int r =DMP_ERR ;struct dm_task *dmt;uint64_t start, length;char *target_type =NULL ;char *params =NULL ;if (!(dmt =libmp_dm_task_create (DM_DEVICE_TABLE ))) -return 1 ; +return r;if (!dm_task_set_name (dmt, name)) goto out;dm_task_no_open_count (dmt); -if (!dm_task_run (dmt)) + errno =0 ; +if (!dm_task_run (dmt)) { +if (errno ==ENXIO ) + r =DMP_FAIL ; goto out; + } + r =DMP_FAIL ;/* Fetch 1st target */ -dm_get_next_target (dmt,NULL , &start, &length, - &target_type, ¶ms); +if (dm_get_next_target (dmt,NULL , &start, &length, + &target_type, ¶ms) !=NULL ) +/* more than one target */ + goto out;if (size) *size = length;if (!outparams) { - r =0 ; + r =DMP_PASS ; goto out; }if (snprintf (outparams,PARAMS_SIZE ,"%s" , params) <=PARAMS_SIZE ) - r =0 ; + r =DMP_PASS ; out:dm_task_destroy (dmt);return r;
@@ -637,35 +644,45 @@ is_mpath_part(const char *part_name, const char *map_name)int dm_get_status (const char *name,char *outstatus) { -int r =1 ; +int r =DMP_ERR ;struct dm_task *dmt;uint64_t start, length;char *target_type =NULL ;char *status =NULL ;if (!(dmt =libmp_dm_task_create (DM_DEVICE_STATUS ))) -return 1 ; +return r;if (!dm_task_set_name (dmt, name)) goto out;dm_task_no_open_count (dmt); -if (!dm_task_run (dmt)) + errno =0 ; +if (!dm_task_run (dmt)) { +if (errno ==ENXIO ) + r =DMP_FAIL ; goto out; + } + r =DMP_FAIL ;/* Fetch 1st target */ -dm_get_next_target (dmt,NULL , &start, &length, - &target_type, &status); +if (dm_get_next_target (dmt,NULL , &start, &length, + &target_type, &status) !=NULL ) + goto out; + +if (!target_type ||strcmp (target_type,TGT_MPATH ) !=0 ) + goto out; +if (!status) {condlog (2 ,"get null status." ); goto out; }if (snprintf (outstatus,PARAMS_SIZE ,"%s" , status) <=PARAMS_SIZE ) - r =0 ; + r =DMP_PASS ; out: -if (r) +if (r !=DMP_PASS )condlog (0 ,"%s: error getting map status string" , name);dm_task_destroy (dmt);
@@ -920,7 +937,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,return 1 ;if (need_suspend && - !dm_get_map (mapname, &mapsize, params) && +dm_get_map (mapname, &mapsize, params) ==DMP_PASS &&strstr (params,"queue_if_no_path" )) {if (!dm_queue_if_no_path (mapname,0 )) queue_if_no_path =1 ;
@@ -1129,7 +1146,7 @@ struct multipath *dm_get_multipath(const char *name)if (!mpp->alias) goto out; -if (dm_get_map (name, &mpp->size,NULL )) +if (dm_get_map (name, &mpp->size,NULL ) !=DMP_PASS ) goto out;dm_get_uuid (name, mpp->wwid,WWID_SIZE );
@@ -1313,7 +1330,7 @@ do_foreach_partmaps (const char * mapname,/* * and we can fetch the map table from the kernel */ - !dm_get_map (names->name, &size, ¶ms[0 ]) && +dm_get_map (names->name, &size, ¶ms[0 ]) ==DMP_PASS &&/* * and the table maps over the multipath map
libmultipath/devmapper.h +6 -0
@@ -27,6 +27,12 @@#define UUID_PREFIX "mpath-"#define UUID_PREFIX_LEN (sizeof(UUID_PREFIX) - 1) +enum { +DMP_ERR =-1 , +DMP_PASS , +DMP_FAIL , +}; +void dm_init (int verbosity);int dm_prereq (unsigned int *v);void skip_libmp_dm_init (void );
libmultipath/structs_vec.c +26 -19
97 lines not on this page · raw message
multipathd/main.c +6 -6
@@ -418,7 +418,7 @@ int __setup_multipath(struct vectors *vecs, struct multipath *mpp, goto out; } -if (update_multipath_strings (mpp, vecs->pathvec,1 )) { +if (update_multipath_strings (mpp, vecs->pathvec,1 ) !=DMP_PASS ) {condlog (0 ,"%s: failed to setup multipath" , mpp->alias); goto out; }
@@ -557,9 +557,9 @@ add_map_without_path (struct vectors *vecs, const char *alias) mpp->mpe =find_mpe (conf->mptable, mpp->wwid);put_multipath_config (conf); -if (update_multipath_table (mpp, vecs->pathvec,1 )) +if (update_multipath_table (mpp, vecs->pathvec,1 ) !=DMP_PASS ) goto out; -if (update_multipath_status (mpp)) +if (update_multipath_status (mpp) !=DMP_PASS ) goto out;if (!vector_alloc_slot (vecs->mpvec))
@@ -1350,8 +1350,8 @@ map_discovery (struct vectors * vecs)return 1 ; vector_foreach_slot (vecs->mpvec, mpp, i) -if (update_multipath_table (mpp, vecs->pathvec,1 ) || -update_multipath_status (mpp)) { +if (update_multipath_table (mpp, vecs->pathvec,1 ) !=DMP_PASS || +update_multipath_status (mpp) !=DMP_PASS ) {remove_map (mpp, vecs,1 ); i--; }
@@ -2091,7 +2091,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * Synchronize with kernel state */ -if (update_multipath_strings (pp->mpp, vecs->pathvec,1 )) { +if (update_multipath_strings (pp->mpp, vecs->pathvec,1 ) !=DMP_PASS ) {condlog (1 ,"%s: Could not synchronize with kernel state" , pp->dev); pp->dmstate =PSTATE_UNDEF ;
Signature · 1 line
2.17.2
Re: [PATCH v2 1/7] libmultipath: make dm_get_map/status return codes symbolic
Quoted 34 lines · Benjamin Marzinski
dm_get_map()anddm_get_status()now use symbolic return codes. They also differentiate between failing to get information from device- mapper
and not finding the requested device. These symboilc return codes are also used by update_multipath_* functions.Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/devmapper.c | 51 +++++++++++++++++++++++++----------- -- libmultipath/devmapper.h | 6 +++++ libmultipath/structs_vec.c | 45 +++++++++++++++++++-------------- multipathd/main.c | 12 ++++----- 4 files changed, 72 insertions(+), 42 deletions(-)libmultipath/devmapper.c +2
-2@@ -534,36 +534,43 @@ int dm_map_present(const char * str)int dm_get_map (const char *name,unsigned long long *size,char *outparams) { -int r =1 ; +int r =DMP_ERR ;struct dm_task *dmt;uint64_t start, length;char *target_type =NULL ;char *params =NULL ;if (!(dmt =libmp_dm_task_create (DM_DEVICE_TABLE ))) -return 1 ; +return r;
libmultipath/devmapper.c int dm_map_present(const char * str) · line 554
Quoted 10 lines
libmultipath/devmapper.c +3
-1if (!dm_task_set_name (dmt, name)) goto out;dm_task_no_open_count (dmt); -if (!dm_task_run (dmt)) + errno =0 ; +if (!dm_task_run (dmt)) { +if (errno ==ENXIO )
Don't you have to use dm_task_get_errno(dmt) here?
errno might have been overwritten... if you are certain you don't need it, a comment explaining it would be helpful.
libmultipath/devmapper.c int dm_map_present(const char * str) · line 555
Quoted 1 line
libmultipath/devmapper.c +1
-0+ r =DMP_FAIL ;
You've created generic names, which is good, but these are perhaps a bit too generic. What's the difference bewteen DMP_FAIL and DMP_ERR? I can derive it from your code, but it's not obvious from the retcode names, and thus doesn't help the reader much. I suggest to keep DMT_ERR to denote a "generic" error condition, and use e.g. DMP_NOTFOUND for the other case.
Quoted 8 lines
libmultipath/devmapper.c +3
-2goto out; + } + r =DMP_FAIL ;/* Fetch 1st target */ -dm_get_next_target (dmt,NULL , &start, &length, - &target_type, ¶ms); + if (dm_get_next_target(dmt, NULL, &start, &length,
libmultipath/devmapper.c int dm_map_present(const char * str) · line 569
Quoted 10 lines
libmultipath/devmapper.c +4
-1+ &target_type, ¶ms) != NULL) +/* more than one target */ + goto out;if (size) *size = length;if (!outparams) { - r =0 ; + r =DMP_PASS ;
Nit: DMP_OK or DMP_SUCCESS would be more conventional for successful completion. "pass" sounds like something more specific to me, like having passed a test or a filter.
Quoted 27 lines
libmultipath/devmapper.c +1
-1goto out; }if (snprintf (outparams,PARAMS_SIZE ,"%s" , params) <=PARAMS_SIZE ) - r =0 ; + r =DMP_PASS ; out:libmultipath/devmapper.c +2
-2dm_task_destroy (dmt);return r;@@ -637,35 +644,45 @@ is_mpath_part(const char *part_name, const char *map_name)int dm_get_status (const char *name,char *outstatus) { -int r =1 ; +int r =DMP_ERR ;struct dm_task *dmt;uint64_t start, length;char *target_type =NULL ;char *status =NULL ;if (!(dmt =libmp_dm_task_create (DM_DEVICE_STATUS ))) -return 1 ; +return r;if (!dm_task_set_name (dmt, name)) goto out;
libmultipath/devmapper.c is_mpath_part(const char *part_name, const char · line 667
Quoted 10 lines
libmultipath/devmapper.c +5
-1dm_task_no_open_count (dmt); -if (!dm_task_run (dmt)) + errno =0 ; +if (!dm_task_run (dmt)) { +if (errno ==ENXIO ) + r =DMP_FAIL ; goto out; + }
see above
Quoted 63 lines
libmultipath/devmapper.c +10
-4+ r =DMP_FAIL ;/* Fetch 1st target */ -dm_get_next_target (dmt,NULL , &start, &length, - &target_type, &status); +if (dm_get_next_target (dmt,NULL , &start, &length, + &target_type, &status) !=NULL ) + goto out; + +if (!target_type ||strcmp (target_type,TGT_MPATH ) !=0 ) + goto out; +if (!status) {condlog (2 ,"get null status." ); goto out; }if (snprintf (outstatus,PARAMS_SIZE ,"%s" , status) <=PARAMS_SIZE ) - r =0 ; + r =DMP_PASS ; out: -if (r) +if (r !=DMP_PASS )condlog (0 ,"%s: error getting map status string" , name);libmultipath/devmapper.c +1
-1dm_task_destroy (dmt);@@ -920,7 +937,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, return 1;if (need_suspend && - !dm_get_map (mapname, &mapsize, params) && +dm_get_map (mapname, &mapsize, params) ==DMP_PASS &&strstr (params,"queue_if_no_path" )) {if (!dm_queue_if_no_path (mapname,0 ))libmultipath/devmapper.c +1
-1queue_if_no_path =1 ;@@ -1129,7 +1146,7 @@ struct multipath *dm_get_multipath(const char *name)if (!mpp->alias) goto out; -if (dm_get_map (name, &mpp->size,NULL )) +if (dm_get_map (name, &mpp->size,NULL ) !=DMP_PASS ) goto out;libmultipath/devmapper.c +1
-1dm_get_uuid (name, mpp->wwid,WWID_SIZE );@@ -1313,7 +1330,7 @@ do_foreach_partmaps (const char * mapname,/* * and we can fetch the map table from the kernel */ - !dm_get_map(names->name, &size, ¶ms[0]) && + dm_get_map(names->name, &size, ¶ms[0]) ==
DMP_PASS&&libmultipath/devmapper.c +0
-0/* * and the table maps over the multipath map libmultipath/devmapper.h +0
-0
libmultipath/devmapper.h line 35
Quoted 9 lines
libmultipath/devmapper.h +6
-0@@ -27,6 +27,12 @@#define UUID_PREFIX "mpath-"#define UUID_PREFIX_LEN (sizeof(UUID_PREFIX) - 1) +enum { +DMP_ERR =-1 , +DMP_PASS , +DMP_FAIL , +}; +
Nit: Why use both negative and positive numbers? It's not important, but I feel that unless we really want to treat DM_ERR in a very special way, it would be better to use only positive values. (Actually, if we go for some generalized retcode convention some day, we might save negative return values for standard libc errno values such as -ENOENT and use positive values for or own specific ones).
(We can change the numeric values later of course).
Cheers,
Martin
Quoted 166 lines
libmultipath/devmapper.h +0
-0void dm_init (int verbosity);int dm_prereq (unsigned int *v);void skip_libmp_dm_init (void );libmultipath/structs_vec.c +18
-14@@ -196,43 +196,47 @@ extract_hwe_from_path(struct multipath * mpp) int update_multipath_table (struct multipath *mpp, vector pathvec, int is_daemon) { + int r = DMP_ERR; char params[PARAMS_SIZE] = {0}; if (!mpp) - return 1; + return r; - if (dm_get_map(mpp->alias, &mpp->size, params)) { - condlog(3, "%s: cannot get map", mpp->alias); - return 1; + r = dm_get_map(mpp->alias, &mpp->size, params); + if (r != DMP_PASS) { + condlog(3, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting table" : "map not present"); + return r; } if (disassemble_map(pathvec, params, mpp, is_daemon)) { condlog(3, "%s: cannot disassemble map", mpp->alias); - return 1; + return DMP_ERR; } - return 0; + return DMP_PASS; } int update_multipath_status (struct multipath *mpp) { + int r = DMP_ERR; char status[PARAMS_SIZE] = {0}; if (!mpp) - return 1; + return r; - if (dm_get_status(mpp->alias, status)) { - condlog(3, "%s: cannot get status", mpp->alias); - return 1; + r = dm_get_status(mpp->alias, status); + if (r != DMP_PASS) { + condlog(3, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting status" : "map not present"); + return r; } if (disassemble_status(status, mpp)) { condlog(3, "%s: cannot disassemble status", mpp- >alias); - return 1; + return DMP_ERR; } - return 0; + return DMP_PASS; } void sync_paths(struct multipath *mpp, vector pathvec)@@ -264,10 +268,10 @@ int update_multipath_strings(struct multipath *mpp, vector pathvec, int is_daemon) { struct pathgroup *pgp; -int i; +int i, r =DMP_ERR ;if (!mpp) -return 1 ; +return r;update_mpp_paths (mpp, pathvec);libmultipath/structs_vec.c +8
-5condlog (4 ,"%s: %s" , mpp->alias, __FUNCTION__);@@ -276,18 +280,21 @@ update_multipath_strings(struct multipath *mpp, vector pathvec, int is_daemon) free_pgvec(mpp->pg, KEEP_PATHS); mpp->pg =NULL ; -if (update_multipath_table (mpp, pathvec, is_daemon)) -return 1 ; + r =update_multipath_table (mpp, pathvec, is_daemon); +if (r !=DMP_PASS ) +return r; +sync_paths (mpp, pathvec); -if (update_multipath_status (mpp)) -return 1 ; + r =update_multipath_status (mpp); +if (r !=DMP_PASS ) +return r; vector_foreach_slot(mpp->pg, pgp, i)if (pgp->paths)path_group_prio_update (pgp); -return 0 ; +return DMP_PASS ; }static void
enter_recovery_mode(struct multipath *mpp)multipathd/main.c +1
-1@@ -418,7 +418,7 @@ int __setup_multipath(struct vectors *vecs,struct multipath *mpp, goto out; } -if (update_multipath_strings (mpp, vecs->pathvec,1 )) { +if (update_multipath_strings (mpp, vecs->pathvec,1 ) !=DMP_PASS ) { condlog(0, "%s: failed to setup multipath", mpp-Quoted 1 line
alias);
multipathd/main.c +2
-2goto out; }@@ -557,9 +557,9 @@ add_map_without_path (struct vectors *vecs, const char *alias) mpp->mpe = find_mpe(conf->mptable, mpp->wwid);put_multipath_config (conf); -if (update_multipath_table (mpp, vecs->pathvec,1 )) +if (update_multipath_table (mpp, vecs->pathvec,1 ) !=DMP_PASS ) goto out; -if (update_multipath_status (mpp)) +if (update_multipath_status (mpp) !=DMP_PASS ) goto out;multipathd/main.c +1
-2if (!vector_alloc_slot (vecs->mpvec))@@ -1350,8 +1350,8 @@ map_discovery (struct vectors * vecs)return 1 ;vector_foreach_slot (vecs->mpvec, mpp, i) -if (update_multipath_table (mpp, vecs->pathvec,1 ) || -update_multipath_status (mpp)) { + if (update_multipath_table(mpp, vecs->pathvec, 1) !=
DMP_PASS||multipathd/main.c +2
-1+ update_multipath_status(mpp) != DMP_PASS) {remove_map (mpp, vecs,1 ); i--; }@@ -2091,7 +2091,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * Synchronize with kernel state */ -if (update_multipath_strings (pp->mpp, vecs->pathvec,1 )) { +if (update_multipath_strings (pp->mpp, vecs->pathvec,1 ) !=DMP_PASS ) { condlog(1, "%s: Could not synchronize with kernelstate",
multipathd/main.c +0
-0pp->dev); pp->dmstate =PSTATE_UNDEF ;
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH v2 1/7] libmultipath: make dm_get_map/status return codes symbolic
Quoted 41 lines · Martin Wilck
Quoted 40 lines · Benjamin Marzinski
dm_get_map()anddm_get_status()now use symbolic return codes. They also differentiate between failing to get information from device- mapper
and not finding the requested device. These symboilc return codes are also used by update_multipath_* functions.Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/devmapper.c | 51 +++++++++++++++++++++++++----------- -- libmultipath/devmapper.h | 6 +++++ libmultipath/structs_vec.c | 45 +++++++++++++++++++-------------- multipathd/main.c | 12 ++++----- 4 files changed, 72 insertions(+), 42 deletions(-)libmultipath/devmapper.c +2
-2@@ -534,36 +534,43 @@ int dm_map_present(const char * str)int dm_get_map (const char *name,unsigned long long *size,char *outparams) { -int r =1 ; +int r =DMP_ERR ;struct dm_task *dmt;uint64_t start, length;char *target_type =NULL ;char *params =NULL ;if (!(dmt =libmp_dm_task_create (DM_DEVICE_TABLE ))) -return 1 ; +return r;if (!dm_task_set_name (dmt, name)) goto out;dm_task_no_open_count (dmt);
Quoted 8 lines
libmultipath/devmapper.c int dm_map_present(const char * str) · line 553
Quoted 4 lines
libmultipath/devmapper.c +3
-1-if (!dm_task_run (dmt)) + errno =0 ; +if (!dm_task_run (dmt)) { +if (errno ==ENXIO )Don't you have to use
dm_task_get_errno(dmt)here?
errno might have been overwritten... if you are certain you don't need it, a comment explaining it would be helpful.
Err.. I didn't know that existed. Sure I can use it, and your other suggestions are reasonable as well
-Ben
Quoted 332 lines
libmultipath/devmapper.c int dm_map_present(const char * str) · line 555
Quoted 3 lines
libmultipath/devmapper.c +1
-0+ r =DMP_FAIL ;You've created generic names, which is good, but these are perhaps a bit too generic. What's the difference bewteen
DMP_FAILandDMP_ERR? I can derive it from your code, but it's not obvious from the retcode names, and thus doesn't help the reader much. I suggest to keepDMT_ERRto denote a "generic" error condition, and use e.g.DMP_NOTFOUNDfor the other case.Quoted 8 lines
libmultipath/devmapper.c +3
-2goto out; + } + r =DMP_FAIL ;/* Fetch 1st target */ -dm_get_next_target (dmt,NULL , &start, &length, - &target_type, ¶ms); + if (dm_get_next_target(dmt, NULL, &start, &length,libmultipath/devmapper.c int dm_map_present(const char * str) · line 569
Quoted 10 lines
libmultipath/devmapper.c +4
-1+ &target_type, ¶ms) != NULL) +/* more than one target */ + goto out;if (size) *size = length;if (!outparams) { - r =0 ; + r =DMP_PASS ;Nit:
DMP_OKorDMP_SUCCESSwould be more conventional for successful completion. "pass" sounds like something more specific to me, like having passed a test or a filter.Quoted 27 lines
libmultipath/devmapper.c +1
-1goto out; }if (snprintf (outparams,PARAMS_SIZE ,"%s" , params) <=PARAMS_SIZE ) - r =0 ; + r =DMP_PASS ; out:libmultipath/devmapper.c +2
-2dm_task_destroy (dmt);return r;@@ -637,35 +644,45 @@ is_mpath_part(const char *part_name, const char *map_name)int dm_get_status (const char *name,char *outstatus) { -int r =1 ; +int r =DMP_ERR ;struct dm_task *dmt;uint64_t start, length;char *target_type =NULL ;char *status =NULL ;if (!(dmt =libmp_dm_task_create (DM_DEVICE_STATUS ))) -return 1 ; +return r;if (!dm_task_set_name (dmt, name)) goto out;libmultipath/devmapper.c is_mpath_part(const char *part_name, const char · line 667
Quoted 10 lines
libmultipath/devmapper.c +5
-1dm_task_no_open_count (dmt); -if (!dm_task_run (dmt)) + errno =0 ; +if (!dm_task_run (dmt)) { +if (errno ==ENXIO ) + r =DMP_FAIL ; goto out; + }see above
Quoted 63 lines
libmultipath/devmapper.c +10
-4+ r =DMP_FAIL ;/* Fetch 1st target */ -dm_get_next_target (dmt,NULL , &start, &length, - &target_type, &status); +if (dm_get_next_target (dmt,NULL , &start, &length, + &target_type, &status) !=NULL ) + goto out; + +if (!target_type ||strcmp (target_type,TGT_MPATH ) !=0 ) + goto out; +if (!status) {condlog (2 ,"get null status." ); goto out; }if (snprintf (outstatus,PARAMS_SIZE ,"%s" , status) <=PARAMS_SIZE ) - r =0 ; + r =DMP_PASS ; out: -if (r) +if (r !=DMP_PASS )condlog (0 ,"%s: error getting map status string" , name);libmultipath/devmapper.c +1
-1dm_task_destroy (dmt);@@ -920,7 +937,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, return 1;if (need_suspend && - !dm_get_map (mapname, &mapsize, params) && +dm_get_map (mapname, &mapsize, params) ==DMP_PASS &&strstr (params,"queue_if_no_path" )) {if (!dm_queue_if_no_path (mapname,0 ))libmultipath/devmapper.c +1
-1queue_if_no_path =1 ;@@ -1129,7 +1146,7 @@ struct multipath *dm_get_multipath(const char *name)if (!mpp->alias) goto out; -if (dm_get_map (name, &mpp->size,NULL )) +if (dm_get_map (name, &mpp->size,NULL ) !=DMP_PASS ) goto out;libmultipath/devmapper.c +1
-1dm_get_uuid (name, mpp->wwid,WWID_SIZE );@@ -1313,7 +1330,7 @@ do_foreach_partmaps (const char * mapname,/* * and we can fetch the map table from the kernel */ - !dm_get_map(names->name, &size, ¶ms[0]) && + dm_get_map(names->name, &size, ¶ms[0]) ==
DMP_PASS&&libmultipath/devmapper.c +0
-0/* * and the table maps over the multipath map libmultipath/devmapper.h +0
-0libmultipath/devmapper.h line 35
Quoted 9 lines
libmultipath/devmapper.h +6
-0@@ -27,6 +27,12 @@#define UUID_PREFIX "mpath-"#define UUID_PREFIX_LEN (sizeof(UUID_PREFIX) - 1) +enum { +DMP_ERR =-1 , +DMP_PASS , +DMP_FAIL , +}; +Nit: Why use both negative and positive numbers? It's not important, but I feel that unless we really want to treat
DM_ERRin a very special way, it would be better to use only positive values. (Actually, if we go for some generalized retcode convention some day, we might save negative return values for standard libc errno values such as-ENOENTand use positive values for or own specific ones).(We can change the numeric values later of course).
Cheers,
MartinQuoted 166 lines
libmultipath/devmapper.h +0
-0void dm_init (int verbosity);int dm_prereq (unsigned int *v);void skip_libmp_dm_init (void );libmultipath/structs_vec.c +18
-14@@ -196,43 +196,47 @@ extract_hwe_from_path(struct multipath * mpp) int update_multipath_table (struct multipath *mpp, vector pathvec, int is_daemon) { + int r = DMP_ERR; char params[PARAMS_SIZE] = {0}; if (!mpp) - return 1; + return r; - if (dm_get_map(mpp->alias, &mpp->size, params)) { - condlog(3, "%s: cannot get map", mpp->alias); - return 1; + r = dm_get_map(mpp->alias, &mpp->size, params); + if (r != DMP_PASS) { + condlog(3, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting table" : "map not present"); + return r; } if (disassemble_map(pathvec, params, mpp, is_daemon)) { condlog(3, "%s: cannot disassemble map", mpp->alias); - return 1; + return DMP_ERR; } - return 0; + return DMP_PASS; } int update_multipath_status (struct multipath *mpp) { + int r = DMP_ERR; char status[PARAMS_SIZE] = {0}; if (!mpp) - return 1; + return r; - if (dm_get_status(mpp->alias, status)) { - condlog(3, "%s: cannot get status", mpp->alias); - return 1; + r = dm_get_status(mpp->alias, status); + if (r != DMP_PASS) { + condlog(3, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting status" : "map not present"); + return r; } if (disassemble_status(status, mpp)) { condlog(3, "%s: cannot disassemble status", mpp- >alias); - return 1; + return DMP_ERR; } - return 0; + return DMP_PASS; } void sync_paths(struct multipath *mpp, vector pathvec)@@ -264,10 +268,10 @@ int update_multipath_strings(struct multipath *mpp, vector pathvec, int is_daemon) { struct pathgroup *pgp; -int i; +int i, r =DMP_ERR ;if (!mpp) -return 1 ; +return r;update_mpp_paths (mpp, pathvec);libmultipath/structs_vec.c +8
-5condlog (4 ,"%s: %s" , mpp->alias, __FUNCTION__);@@ -276,18 +280,21 @@ update_multipath_strings(struct multipath *mpp, vector pathvec, int is_daemon) free_pgvec(mpp->pg, KEEP_PATHS); mpp->pg =NULL ; -if (update_multipath_table (mpp, pathvec, is_daemon)) -return 1 ; + r =update_multipath_table (mpp, pathvec, is_daemon); +if (r !=DMP_PASS ) +return r; +sync_paths (mpp, pathvec); -if (update_multipath_status (mpp)) -return 1 ; + r =update_multipath_status (mpp); +if (r !=DMP_PASS ) +return r; vector_foreach_slot(mpp->pg, pgp, i)if (pgp->paths)path_group_prio_update (pgp); -return 0 ; +return DMP_PASS ; }static void
enter_recovery_mode(struct multipath *mpp)multipathd/main.c +1
-1@@ -418,7 +418,7 @@ int __setup_multipath(struct vectors *vecs,struct multipath *mpp, goto out; } -if (update_multipath_strings (mpp, vecs->pathvec,1 )) { +if (update_multipath_strings (mpp, vecs->pathvec,1 ) !=DMP_PASS ) { condlog(0, "%s: failed to setup multipath", mpp-Quoted 1 line
alias);
multipathd/main.c +2
-2goto out; }@@ -557,9 +557,9 @@ add_map_without_path (struct vectors *vecs, const char *alias) mpp->mpe = find_mpe(conf->mptable, mpp->wwid);put_multipath_config (conf); -if (update_multipath_table (mpp, vecs->pathvec,1 )) +if (update_multipath_table (mpp, vecs->pathvec,1 ) !=DMP_PASS ) goto out; -if (update_multipath_status (mpp)) +if (update_multipath_status (mpp) !=DMP_PASS ) goto out;multipathd/main.c +1
-2if (!vector_alloc_slot (vecs->mpvec))@@ -1350,8 +1350,8 @@ map_discovery (struct vectors * vecs)return 1 ;vector_foreach_slot (vecs->mpvec, mpp, i) -if (update_multipath_table (mpp, vecs->pathvec,1 ) || -update_multipath_status (mpp)) { + if (update_multipath_table(mpp, vecs->pathvec, 1) !=
DMP_PASS||multipathd/main.c +2
-1+ update_multipath_status(mpp) != DMP_PASS) {remove_map (mpp, vecs,1 ); i--; }@@ -2091,7 +2091,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * Synchronize with kernel state */ -if (update_multipath_strings (pp->mpp, vecs->pathvec,1 )) { +if (update_multipath_strings (pp->mpp, vecs->pathvec,1 ) !=DMP_PASS ) { condlog(1, "%s: Could not synchronize with kernelstate",
multipathd/main.c +0
-0pp->dev); pp->dmstate =PSTATE_UNDEF ;Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH v2 2/7 multipathd: fix check_path errors with removed map
In reply to Benjamin MarzinskiIf a multipath device is removed during, or immediately before the call to check_path(), multipathd can behave incorrectly. A missing multpath device will cause update_multipath_strings() to fail, setting pp->dmstate to PSTATE_UNDEF. If the path is up, this state will cause reinstate_path() to be called, which will also fail. This will trigger a reload, restoring the recently removed device.
If update_multipath_strings() fails because there is no multipath device, check_path should just quit, since the remove dmevent and uevent are likely already queued up. Also, I don't see any reason to reload the multipath device if reinstate fails. This code was added by fac68d7a99ef17d496079538a5c6836acd7911ab, which clamined that reinstate could fail if the path was disabled. Looking through the current kernel code, I can't see any reason why a reinstate would fail, where a reload would help. If the path was missing from the multipath device, update_multipath_strings() would already catch that, and quit check_path() early, which make more sense to me than reloading does.
--- multipathd/main.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-)
multipathd/main.c +14 -23
@@ -1615,22 +1615,18 @@ fail_path (struct path * pp, int del_active)/* * caller must have locked the path list before calling that function */ -static int +static void reinstate_path (struct path * pp) { -int ret =0 ; -if (!pp->mpp) -return 0 ; +return ; -if (dm_reinstate_path (pp->mpp->alias, pp->dev_t)) { +if (dm_reinstate_path (pp->mpp->alias, pp->dev_t))condlog (0 ,"%s: reinstate failed" , pp->dev_t); - ret =1 ; - }else { +else {condlog (2 ,"%s: reinstated" , pp->dev_t);update_queue_mode_add_path (pp->mpp); } -return ret; } static void
@@ -2091,9 +2087,13 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * Synchronize with kernel state */ -if (update_multipath_strings (pp->mpp, vecs->pathvec,1 ) !=DMP_PASS ) { + ret =update_multipath_strings (pp->mpp, vecs->pathvec,1 ); +if (ret !=DMP_PASS ) {condlog (1 ,"%s: Could not synchronize with kernel state" , pp->dev); +if (ret ==DMP_FAIL ) +/* multipath device missing. Likely removed */ +return 0 ; pp->dmstate =PSTATE_UNDEF ; }/* if update_multipath_strings orphaned the path, quit early */
@@ -2183,12 +2183,8 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * reinstate this path */ -if (!disable_reinstate &&reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } +if (!disable_reinstate) +reinstate_path (pp); new_path_up =1 ;if (oldchkrstate !=PATH_UP && oldchkrstate !=PATH_GHOST )
@@ -2204,15 +2200,10 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)else if (newstate ==PATH_UP || newstate ==PATH_GHOST ) {if ((pp->dmstate ==PSTATE_FAILED || pp->dmstate ==PSTATE_UNDEF ) && - !disable_reinstate) { + !disable_reinstate)/* Clear IO errors */ -if (reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } - }else { +reinstate_path (pp); +else {LOG_MSG (4 , verbosity, pp);if (pp->checkint != max_checkint) {/*
Signature · 1 line
2.17.2
Re: [PATCH v2 2/7] multipathd: fix check_path errors with removed map
Quoted 66 lines · Benjamin Marzinski
If a multipath device is removed during, or immediately before the call
tocheck_path(), multipathd can behave incorrectly. A missing multpath
device will causeupdate_multipath_strings()to fail, settingpp->dmstatetoPSTATE_UNDEF. If the path is up, this state will causereinstate_path()to be called, which will also fail. This will trigger
a reload, restoring the recently removed device.If
update_multipath_strings()fails because there is no multipath device,check_pathshould just quit, since the remove dmevent and uevent
are likely already queued up. Also, I don't see any reason to reload the
multipath device if reinstate fails. This code was added byfac68d7a99ef17d496079538a5c6836acd7911ab, which clamined that reinstate
could fail if the path was disabled. Looking through the current kernel
code, I can't see any reason why a reinstate would fail, where a reload
would help. If the path was missing from the multipath device,update_multipath_strings()would already catch that, and quitcheck_path()early, which make more sense to me than reloading does.Signed-off-by Benjamin Marzinski <[email protected]>--- multipathd/main.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-)multipathd/main.c +0
-0@@ -1615,22 +1615,18 @@ fail_path (struct path * pp, int del_active)/* * caller must have locked the path list before calling that function
*/multipathd/main.c +4
-8-static int +static void reinstate_path (struct path * pp) { -int ret =0 ; -if (!pp->mpp) -return 0 ; +return ; -if (dm_reinstate_path (pp->mpp->alias, pp->dev_t)) { +if (dm_reinstate_path (pp->mpp->alias, pp->dev_t))condlog (0 ,"%s: reinstate failed" , pp->dev_t); - ret =1 ; - }else { +else {condlog (2 ,"%s: reinstated" , pp->dev_t);update_queue_mode_add_path (pp->mpp); } -return ret; } static void@@ -2091,9 +2087,13 @@ check_path (struct vectors * vecs, struct path* pp, unsigned int ticks)
multipathd/main.c check_path (struct vectors * vecs, struct path · line 2096
Quoted 10 lines
multipathd/main.c +2
-1/* * Synchronize with kernel state */ -if (update_multipath_strings (pp->mpp, vecs->pathvec,1 ) != DMP_PASS) { + ret =update_multipath_strings (pp->mpp, vecs->pathvec,1 ); +if (ret !=DMP_PASS ) {condlog (1 ,"%s: Could not synchronize with kernel state", pp->dev);
We could do even better here by printing different log messages in the two cases we differentiate.
Apart from that, ACK.
Quoted 43 lines
multipathd/main.c +3
-0+if (ret ==DMP_FAIL ) +/* multipath device missing. Likely removed */ +return 0 ;multipathd/main.c +2
-6pp->dmstate =PSTATE_UNDEF ; }/* if update_multipath_strings orphaned the path, quit early */ @@ -2183,12 +2183,8 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * reinstate this path */ -if (!disable_reinstate &&reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } +if (!disable_reinstate) +reinstate_path (pp); new_path_up =1 ;if (oldchkrstate !=
PATH_UP&& oldchkrstate !=PATH_GHOST)multipathd/main.c +3
-8@@ -2204,15 +2200,10 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) else if (newstate == PATH_UP || newstate == PATH_GHOST) {if ((pp->dmstate ==PSTATE_FAILED || pp->dmstate ==PSTATE_UNDEF ) && - !disable_reinstate) { + !disable_reinstate)/* Clear IO errors */ -if (reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } - }else { +reinstate_path (pp); +else {LOG_MSG (4 , verbosity, pp);if (pp->checkint != max_checkint) {/*
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH v2 2/7] multipathd: fix check_path errors with removed map
Quoted 64 lines · Martin Wilck
Quoted 63 lines · Benjamin Marzinski
If a multipath device is removed during, or immediately before the call
tocheck_path(), multipathd can behave incorrectly. A missing multpath
device will causeupdate_multipath_strings()to fail, settingpp->dmstatetoPSTATE_UNDEF. If the path is up, this state will causereinstate_path()to be called, which will also fail. This will trigger
a reload, restoring the recently removed device.If
update_multipath_strings()fails because there is no multipath device,check_pathshould just quit, since the remove dmevent and uevent
are likely already queued up. Also, I don't see any reason to reload the
multipath device if reinstate fails. This code was added byfac68d7a99ef17d496079538a5c6836acd7911ab, which clamined that reinstate
could fail if the path was disabled. Looking through the current kernel
code, I can't see any reason why a reinstate would fail, where a reload
would help. If the path was missing from the multipath device,update_multipath_strings()would already catch that, and quitcheck_path()early, which make more sense to me than reloading does.Signed-off-by Benjamin Marzinski <[email protected]>--- multipathd/main.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-)multipathd/main.c +0
-0@@ -1615,22 +1615,18 @@ fail_path (struct path * pp, int del_active)/* * caller must have locked the path list before calling that function
*/multipathd/main.c +4
-8-static int +static void reinstate_path (struct path * pp) { -int ret =0 ; -if (!pp->mpp) -return 0 ; +return ; -if (dm_reinstate_path (pp->mpp->alias, pp->dev_t)) { +if (dm_reinstate_path (pp->mpp->alias, pp->dev_t))condlog (0 ,"%s: reinstate failed" , pp->dev_t); - ret =1 ; - }else { +else {condlog (2 ,"%s: reinstated" , pp->dev_t);update_queue_mode_add_path (pp->mpp); } -return ret; }
Quoted 16 lines
multipathd/main.c check_path (struct vectors * vecs, struct path · line 2096
Quoted 13 lines
static void
multipathd/main.c +2
-1@@ -2091,9 +2087,13 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * Synchronize with kernel state */ -if (update_multipath_strings (pp->mpp, vecs->pathvec,1 ) != DMP_PASS) { + ret =update_multipath_strings (pp->mpp, vecs->pathvec,1 ); +if (ret !=DMP_PASS ) {condlog (1 ,"%s: Could not synchronize with kernel state", pp->dev);We could do even better here by printing different log messages in the two cases we differentiate.
Will do.
-Ben
Quoted 52 lines
Apart from that, ACK.
Quoted 43 lines
multipathd/main.c +3
-0+if (ret ==DMP_FAIL ) +/* multipath device missing. Likely removed */ +return 0 ;multipathd/main.c +2
-6pp->dmstate =PSTATE_UNDEF ; }/* if update_multipath_strings orphaned the path, quit early */ @@ -2183,12 +2183,8 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)/* * reinstate this path */ -if (!disable_reinstate &&reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } +if (!disable_reinstate) +reinstate_path (pp); new_path_up =1 ;if (oldchkrstate !=
PATH_UP&& oldchkrstate !=PATH_GHOST)multipathd/main.c +3
-8@@ -2204,15 +2200,10 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) else if (newstate == PATH_UP || newstate == PATH_GHOST) {if ((pp->dmstate ==PSTATE_FAILED || pp->dmstate ==PSTATE_UNDEF ) && - !disable_reinstate) { + !disable_reinstate)/* Clear IO errors */ -if (reinstate_path (pp)) { -condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs,1 ); - pp->tick =1 ; -return 0 ; - } - }else { +reinstate_path (pp); +else {LOG_MSG (4 , verbosity, pp);if (pp->checkint != max_checkint) {/*
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH v2 3/7 libmultipath: make dm_flush_maps only return 0 on success
In reply to Benjamin Marzinskidm_flush_maps() returned both 0 and 1 on error, depending on which part of the function it was in, but the caller was always treating 0 as a success. Make dm_flush_maps() always return 1 on error and 0 on success.
--- libmultipath/devmapper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libmultipath/devmapper.c +3 -2
@@ -1007,13 +1007,13 @@ dm_flush_map_nopaths(const char * mapname, int deferred_remove)int dm_flush_maps (int retries) { -int r =0 ; +int r =1 ;struct dm_task *dmt;struct dm_names *names;unsigned next =0 ;if (!(dmt =libmp_dm_task_create (DM_DEVICE_LIST ))) -return 0 ; +return r;dm_task_no_open_count (dmt);
@@ -1026,6 +1026,7 @@ int dm_flush_maps (int retries)if (!names->dev) goto out; + r =0 ; do { r |= dm_suspend_and_flush_map(names->name, retries); next = names->next;
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 4/7 multipathd: add "del maps" multipathd command
In reply to Benjamin MarzinskiThis will flush all multipath devices.
--- libmultipath/devmapper.c | 7 +++++-- libmultipath/devmapper.h | 2 +- multipath/main.c | 2 +- multipathd/cli.c | 1 + multipathd/cli_handlers.c | 19 +++++++++++++++++++ multipathd/cli_handlers.h | 1 + multipathd/main.c | 3 ++- multipathd/main.h | 1 + 8 files changed, 31 insertions(+), 5 deletions(-)
libmultipath/devmapper.c +5 -2
@@ -1005,7 +1005,7 @@ dm_flush_map_nopaths(const char * mapname, int deferred_remove)#endif -int dm_flush_maps (int retries) +int dm_flush_maps (int need_suspend,int retries) {int r =1 ;struct dm_task *dmt;
@@ -1028,7 +1028,10 @@ int dm_flush_maps (int retries) r =0 ;do { - r |=dm_suspend_and_flush_map (names->name, retries); +if (need_suspend) + r |=dm_suspend_and_flush_map (names->name, retries); +else + r |=dm_flush_map (names->name); next = names->next; names = (void *) names + next; }while (next);
libmultipath/devmapper.h +1 -1
@@ -57,7 +57,7 @@ int dm_flush_map_nopaths(const char * mapname, int deferred_remove);#define dm_suspend_and_flush_map (mapname, retries) \ _dm_flush_map(mapname, 1, 0, 1, retries)int dm_cancel_deferred_remove (struct multipath *mpp); -int dm_flush_maps (int retries); +int dm_flush_maps (int need_suspend,int retries);int dm_fail_path (const char * mapname,char * path);int dm_reinstate_path (const char * mapname,char * path);int dm_queue_if_no_path (const char *mapname,int enable);
multipath/main.c +1 -1
@@ -1096,7 +1096,7 @@ main (int argc, char *argv[]) goto out; }else if (conf->remove ==FLUSH_ALL ) { - r =dm_flush_maps (retries) ?RTVL_FAIL :RTVL_OK ; + r =dm_flush_maps (1 , retries) ?RTVL_FAIL :RTVL_OK ; goto out; }while ((r =configure (conf, cmd, dev_type, dev)) ==RTVL_RETRY )
multipathd/cli.c +1 -0
@@ -568,6 +568,7 @@ cli_init (void) {add_handler (DEL +PATH ,NULL );add_handler (ADD +MAP ,NULL );add_handler (DEL +MAP ,NULL ); +add_handler (DEL +MAPS ,NULL );add_handler (SWITCH +MAP +GROUP ,NULL );add_handler (RECONFIGURE ,NULL );add_handler (SUSPEND +MAP ,NULL );
multipathd/cli_handlers.c +19 -0
@@ -852,6 +852,25 @@ cli_del_map (void * v, char ** reply, int * len, void * data)return rc; } +int +cli_del_maps (void *v,char **reply,int *len,void *data) +{ +struct vectors * vecs = (struct vectors *)data; +struct multipath *mpp; +int i, ret =0 ; + +condlog (2 ,"remove maps (operator)" ); + vector_foreach_slot(vecs->mpvec, mpp, i) { +if (flush_map (mpp, vecs,0 )) + ret++; +else + i--; + } +/* flush any multipath maps that aren't currently known by multipathd */ + ret |=dm_flush_maps (0 ,0 ); +return ret; +} +int cli_reload (void *v,char **reply,int *len,void *data) {
multipathd/cli_handlers.h +1 -0
@@ -26,6 +26,7 @@ int cli_add_path (void * v, char ** reply, int * len, void * data);int cli_del_path (void * v,char ** reply,int * len,void * data);int cli_add_map (void * v,char ** reply,int * len,void * data);int cli_del_map (void * v,char ** reply,int * len,void * data); +int cli_del_maps (void * v,char ** reply,int * len,void * data);int cli_switch_group (void * v,char ** reply,int * len,void * data);int cli_reconfigure (void * v,char ** reply,int * len,void * data);int cli_resize (void * v,char ** reply,int * len,void * data);
multipathd/main.c +2 -1
@@ -635,7 +635,7 @@ sync_maps_state(vector mpvec)sync_map_state (mpp); } -static int +int flush_map (struct multipath * mpp,struct vectors * vecs,int nopaths) {int r;
@@ -1555,6 +1555,7 @@ uxlsnrloop (void * ap)set_handler_callback (DEL +PATH , cli_del_path);set_handler_callback (ADD +MAP , cli_add_map);set_handler_callback (DEL +MAP , cli_del_map); +set_handler_callback (DEL +MAPS , cli_del_maps);set_handler_callback (SWITCH +MAP +GROUP , cli_switch_group);set_unlocked_handler_callback (RECONFIGURE , cli_reconfigure);set_handler_callback (SUSPEND +MAP , cli_suspend);
multipathd/main.h +1 -0
@@ -28,6 +28,7 @@ int ev_add_path (struct path *, struct vectors *, int);int ev_remove_path (struct path *,struct vectors *,int );int ev_add_map (char *,const char *,struct vectors *);int ev_remove_map (char *,char *,int ,struct vectors *); +int flush_map (struct multipath *,struct vectors *,int );int set_config_state (enum daemon_status );void *mpath_alloc_prin_response (int prin_sa); int prin_do_scsi_ioctl(char *, int rq_servact, struct prin_resp * resp,
Signature · 1 line
2.17.2
Re: [PATCH v2 4/7] multipathd: add "del maps" multipathd command
Quoted 3 lines · Benjamin Marzinski
This will flush all multipath devices.
Signed-off-by Benjamin Marzinski <[email protected]>
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH v2 5/7 multipath: make flushing maps work like other commands
In reply to Benjamin MarzinskiThe config structure doesn't need a special variable just for removes. Multipath can just use the cmd variable, like it does for the other commands.
--- libmultipath/config.h | 3 ++- libmultipath/configure.h | 3 --- multipath/main.c | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-)
libmultipath/config.h +2 -1
@@ -38,6 +38,8 @@ enum mpath_cmds {CMD_ADD_WWID ,CMD_USABLE_PATHS ,CMD_DUMP_CONFIG , +CMD_FLUSH_ONE , + CMD_FLUSH_ALL, }; enum force_reload_types {
@@ -142,7 +144,6 @@ struct config {unsigned int max_checkint;bool use_watchdog;int pgfailback; -int remove;int rr_weight;int no_path_retry;int user_friendly_names;
libmultipath/configure.h +0 -3
@@ -45,9 +45,6 @@ enum { CP_RETRY, }; -#define FLUSH_ONE 1 -#define FLUSH_ALL 2 -struct vectors ; int setup_map (struct multipath * mpp, char * params, int params_size,
multipath/main.c +10 -10
@@ -909,10 +909,10 @@ main (int argc, char *argv[]) cmd =CMD_DRY_RUN ;break ;case 'f' : - conf->remove =FLUSH_ONE ; + cmd =CMD_FLUSH_ONE ;break ;case 'F' : - conf->remove =FLUSH_ALL ; + cmd =CMD_FLUSH_ALL ;break ;case 'l' :if (optarg && !strncmp (optarg,"l" ,1 ))
@@ -1053,6 +1053,10 @@ main (int argc, char *argv[])condlog (0 ,"the -w option requires a device" ); goto out; } +if (cmd ==CMD_FLUSH_ONE && dev_type !=DEV_DEVMAP ) { +condlog (0 ,"the -f option requires a map name to remove" ); + goto out; + }switch (delegate_to_multipathd (cmd, dev, dev_type, conf)) {case DELEGATE_OK :
@@ -1086,16 +1090,12 @@ main (int argc, char *argv[]) }if (retries <0 ) retries = conf->remove_retries; -if (conf->remove ==FLUSH_ONE ) { -if (dev_type ==DEV_DEVMAP ) { - r =dm_suspend_and_flush_map (dev, retries) ? -RTVL_FAIL :RTVL_OK ; - }else -condlog (0 ,"must provide a map name to remove" ); - +if (cmd ==CMD_FLUSH_ONE ) { + r =dm_suspend_and_flush_map (dev, retries) ? +RTVL_FAIL :RTVL_OK ; goto out; } -else if (conf->remove ==FLUSH_ALL ) { +else if (cmd ==CMD_FLUSH_ALL ) { r =dm_flush_maps (1 , retries) ?RTVL_FAIL :RTVL_OK ; goto out; }
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 6/7 multipath: delegate flushing maps to multipathd
In reply to Benjamin MarzinskiSince there can be problems with removing maps outside of multipathd, multipath should attempt to delegate this command to multipathd. However, multipathd doesn't attempt to suspend the device, in order to avoid potential hangs. If delegating to multipathd fails, multipath should try the remove itself.
--- multipath/main.c | 14 ++++++++++++++ multipath/multipath.8 | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-)
multipath/main.c +14 -0
@@ -820,6 +820,20 @@ int delegate_to_multipathd(enum mpath_cmds cmd,if (cmd ==CMD_CREATE && conf->force_reload ==FORCE_RELOAD_YES ) { p +=snprintf (p, n,"reconfigure" ); } +else if (cmd ==CMD_FLUSH_ONE && dev && dev_type ==DEV_DEVMAP ) { + p +=snprintf (p, n,"del map %s" , dev); +/* multipathd doesn't try as hard, to avoid potentially +* hanging. If it fails, retry with the regular multipath +* command */ + r =NOT_DELEGATED ; + } +else if (cmd ==CMD_FLUSH_ALL ) { + p +=snprintf (p, n,"del maps" ); +/* multipathd doesn't try as hard, to avoid potentially +* hanging. If it fails, retry with the regular multipath +* command */ + r =NOT_DELEGATED ; + }/* Add other translations here */ if (strlen (command) ==0 )
multipath/multipath.8 +2 -2
@@ -125,11 +125,11 @@ the system. Other operation modes are chosen by using one of the following command line switches: .TP .B \-f -Flush (remove) a multipath device map specified as parameter, if unused. +Flush (remove) a multipath device map specified as parameter, if unused. This operation is delegated to the multipathd daemon if it's running. . .TP .B \-F -Flush (remove) all unused multipath device maps. +Flush (remove) all unused multipath device maps. This operation is delegated to the multipathd daemon if it's running. . .TP .B \-l
Signature · 1 line
2.17.2
Re: [PATCH v2 6/7] multipath: delegate flushing maps to multipathd
Quoted 8 lines · Benjamin Marzinski
Since there can be problems with removing maps outside of multipathd, multipath should attempt to delegate this command to multipathd. However, multipathd doesn't attempt to suspend the device, in order to avoid potential hangs. If delegating to multipathd fails, multipath
should try the remove itself.Signed-off-by Benjamin Marzinski <[email protected]>
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH v2 7/7 multipath: add option to skip multipathd delegation
In reply to Benjamin MarzinskiAdd the -D option to allow users to skip delegating commands to multipathd.
--- libmultipath/config.h | 1 + multipath/main.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
libmultipath/config.h +1 -0
@@ -190,6 +190,7 @@ struct config {int ghost_delay;int find_multipaths_timeout;int marginal_pathgroups; +int skip_delegate;unsigned int version[3 ];unsigned int sequence_nr;
multipath/main.c +7 -1
@@ -817,6 +817,9 @@ int delegate_to_multipathd(enum mpath_cmds cmd, *p ='\0' ; n =sizeof (command); +if (conf->skip_delegate) +return NOT_DELEGATED ; +if (cmd ==CMD_CREATE && conf->force_reload ==FORCE_RELOAD_YES ) { p +=snprintf (p, n,"reconfigure" ); }
@@ -890,7 +893,7 @@ main (int argc, char *argv[]) multipath_conf = conf; conf->retrigger_tries =0 ; conf->force_sync =1 ; -while ((arg =getopt (argc, argv,":adcChl::eFfM:v:p:b:BrR:itTquUwW" )) !=EOF ) { +while ((arg =getopt (argc, argv,":adDcChl::eFfM:v:p:b:BrR:itTquUwW" )) !=EOF ) {switch (arg) {case 1 :printf ("optarg : %s\n" ,optarg);break ;
@@ -922,6 +925,9 @@ main (int argc, char *argv[])if (cmd ==CMD_CREATE ) cmd =CMD_DRY_RUN ;break ; +case 'D' : + conf->skip_delegate =1 ; +break ;case 'f' : cmd =CMD_FLUSH_ONE ;break ;
Signature · 1 line
2.17.2
Re: [PATCH v2 7/7] multipath: add option to skip multipathd delegation
Quoted 4 lines · Benjamin Marzinski
Add the -D option to allow users to skip delegating commands to multipathd.
Signed-off-by Benjamin Marzinski <[email protected]>
Quoted 4 lines
--- libmultipath/config.h | 1 + multipath/main.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer