multipath cleanups
Subsystems (2)
Benjamin Marzinski
maintainerv2 cover multipath cleanups
Patches 0003 & 0004 fix an issue that I've seen with paths whose checker takes too long when multipathd is starting up and creating devices.
The others are minor build fixes or small cleanups to my previous patchset.
Changes in v2:
- patch 0003 no longer refactors count_active_paths(), as suggested by Martin Wilck
- Added patches 0007 & 0008, which are both unrelated minor changes.
Benjamin Marzinski (8):
Makefile.inc: trim extra information from systemd version
kpartx: fix -Wsign-compare error
libmultipath: refactor path counting
libmultipath: count pending paths as active on loads
libmultipath: deal with flushing no maps
multipath: deal with delegation failures correctly
multipathd: unset mpp->hwe when removing map
multipathd: log reason for calling domap()
Makefile.inc | 2 +- kpartx/kpartx.c | 2 +- libmpathpersist/mpath_persist.c | 4 ++-- libmultipath/devmapper.c | 5 +++-- libmultipath/structs.c | 38 +++++++++++++++++++++------------ libmultipath/structs.h | 2 +- libmultipath/structs_vec.c | 1 + multipath/main.c | 9 +++++--- multipathd/main.c | 14 ++++++++---- 9 files changed, 49 insertions(+), 28 deletions(-)
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 1/8 Makefile.inc: trim extra information from systemd version
Some systemd versions print extra information in the "pkg-config --modversion" output, which confuses make. Trim this off.
--- Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.inc +1 -1
@@ -37,7 +37,7 @@ endif ifndef SYSTEMD ifeq ($(shell pkg-config --modversion libsystemd >/dev/null 2>&1 && echo 1), 1) - SYSTEMD = $(shell pkg-config --modversion libsystemd) + SYSTEMD = $(shell pkg-config --modversion libsystemd | awk '{print $$1}') else ifeq ($(shell systemctl --version >/dev/null 2>&1 && echo 1), 1) SYSTEMD = $(shell systemctl --version 2> /dev/null | \
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 2/8 kpartx: fix -Wsign-compare error
In reply to Benjamin Marzinski--- kpartx/kpartx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kpartx/kpartx.c +1 -1
@@ -738,7 +738,7 @@ struct block {/* blknr is always in 512 byte blocks */ char *getblock (int fd,unsigned int blknr) { -unsigned int secsz =get_sector_size (fd); +int secsz =get_sector_size (fd);unsigned int blks_per_sec = secsz /512 ;unsigned int secnr = blknr / blks_per_sec;unsigned int blk_off = (blknr % blks_per_sec) *512 ;
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 3/8 libmultipath: refactor path counting
In reply to Benjamin Marzinskipathcountgr() is never used except by pathcount(), and neither is the special case for PATH_WILD. Simplify this and change it into a helper function that is called by pathcount, and will be used again in a future patch. Leave count_active_paths alone for the sake of compiler optimization.
Also use count_active_paths() in mpath_persist.
--- libmpathpersist/mpath_persist.c | 4 ++-- libmultipath/structs.c | 31 +++++++++++++++++-------------- libmultipath/structs.h | 1 - 3 files changed, 19 insertions(+), 17 deletions(-)
libmpathpersist/mpath_persist.c +2 -2
@@ -436,7 +436,7 @@ int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, all_tg_pt = (mpp->all_tg_pt ==ALL_TG_PT_ON || paramp->sa_flags &MPATH_F_ALL_TG_PT_MASK ); - active_pathcount =pathcount (mpp,PATH_UP ) +pathcount (mpp,PATH_GHOST ); + active_pathcount =count_active_paths (mpp);if (active_pathcount ==0 ) {condlog (0 ,"%s: no path available" , mpp->wwid);
@@ -648,7 +648,7 @@ int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,if (!mpp)return MPATH_PR_DMMP_ERROR ; - active_pathcount =pathcount (mpp,PATH_UP ) +pathcount (mpp,PATH_GHOST ); + active_pathcount =count_active_paths (mpp);struct threadinfo thread[active_pathcount];memset (thread,0 ,sizeof (thread));
libmultipath/structs.c +17 -14
@@ -455,30 +455,33 @@ find_path_by_devt (const struct _vector *pathvec, const char * dev_t)return NULL ; } -int pathcountgr (const struct pathgroup *pgp,int state) +static int do_pathcount (const struct multipath *mpp,const int *states, +unsigned int nr_states) { +struct pathgroup *pgp;struct path *pp;int count =0 ; -int i; +unsigned int i, j, k; - vector_foreach_slot (pgp->paths, pp, i) -if ((pp->state == state) || (state ==PATH_WILD )) - count++; +if (!mpp->pg || !nr_states) +return count; + vector_foreach_slot (mpp->pg, pgp, i) { + vector_foreach_slot (pgp->paths, pp, j) { +for (k =0 ; k < nr_states; k++) { +if (pp->state == states[k]) { + count++; +break ; + } + } + } + }return count; }int pathcount (const struct multipath *mpp,int state) { -struct pathgroup *pgp; -int count =0 ; -int i; - -if (mpp->pg) { -vector_foreach_slot (mpp->pg, pgp, i) - count += pathcountgr(pgp, state); - } -return count; +return do_pathcount (mpp, &state,1 ); }int count_active_paths (const struct multipath *mpp)
libmultipath/structs.h +0 -1
@@ -446,7 +446,6 @@ struct path * find_path_by_devt (const struct _vector *pathvec, const char *devtstruct path *find_path_by_dev (const struct _vector *pathvec,const char *dev);struct path *first_path (const struct multipath *mpp); -int pathcountgr (const struct pathgroup *,int );int pathcount (const struct multipath *,int );int count_active_paths (const struct multipath *);int pathcmp (const struct pathgroup *,const struct pathgroup *);
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 4/8 libmultipath: count pending paths as active on loads
In reply to Benjamin MarzinskiWhen multipath loads a table, it signals to udev if there are no active paths. Multipath wasn't counting pending paths as active. This meant that if all the paths were pending, udev would treat the device as not ready, and not run kpartx on it. Even if the pending paths later because active and were reinstated, the kernel would not send a new uevent, because from its point of view, they were always up.
The alternative would be to continue to treat them as failed in the udev rules, but then also tell the kernel that they were down, so that it would trigger a uevent when they were reinstated. However, this could lead to newly created multipath devices failing IO, simply because the path checkers hadn't returned yet. Having udev assume that the the device is up, like the kernel does, seems like the safer option.
--- libmultipath/devmapper.c | 3 ++- libmultipath/structs.c | 7 +++++++ libmultipath/structs.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-)
libmultipath/devmapper.c +2 -1
@@ -417,7 +417,8 @@ static uint16_t build_udev_flags(const struct multipath *mpp, int reload)/* DM_UDEV_DISABLE_LIBRARY_FALLBACK is added in dm_addmap */ return (mpp->skip_kpartx ==SKIP_KPARTX_ON ?MPATH_UDEV_NO_KPARTX_FLAG :0 ) | - ((count_active_paths (mpp) ==0 || mpp->ghost_delay_tick >0 ) ? + ((count_active_pending_paths (mpp) ==0 || + mpp->ghost_delay_tick >0 ) ?MPATH_UDEV_NO_PATHS_FLAG :0 ) | (reload && !mpp->force_udev_reload ?MPATH_UDEV_RELOAD_FLAG :0 );
libmultipath/structs.c +7 -0
@@ -503,6 +503,13 @@ int count_active_paths(const struct multipath *mpp)return count; } +int count_active_pending_paths (const struct multipath *mpp) +{ +int states[] = {PATH_UP ,PATH_GHOST ,PATH_PENDING }; + +return do_pathcount (mpp, states,3 ); +} +int pathcmp (const struct pathgroup *pgp,const struct pathgroup *cpgp) {int i, j;
libmultipath/structs.h +1 -0
@@ -448,6 +448,7 @@ struct path * first_path (const struct multipath *mpp);int pathcount (const struct multipath *,int );int count_active_paths (const struct multipath *); +int count_active_pending_paths (const struct multipath *);int pathcmp (const struct pathgroup *,const struct pathgroup *);int add_feature (char **,const char *);int remove_feature (char **,const char *);
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 5/8 libmultipath: deal with flushing no maps
In reply to Benjamin Marzinskidm_flush_maps() was failing if there were no device-mapper devices at all, instead of returning success, since there is nothing to do.
--- libmultipath/devmapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/devmapper.c +1 -1
@@ -1024,10 +1024,10 @@ int dm_flush_maps (int need_suspend, int retries)if (!(names =dm_task_get_names (dmt))) goto out; + r =0 ;if (!names->dev) goto out; - r =0 ; do { if (need_suspend) r |= dm_suspend_and_flush_map(names->name, retries);
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 6/8 multipath: deal with delegation failures correctly
In reply to Benjamin Marzinskidelegate_to_multipathd() was returning success, even if the multipathd command failed. Also, if the command was set to fail with NOT_DELEGATED, it shouldn't print any errors, since multipath will try to issue the command itself.
--- multipath/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
multipath/main.c +6 -3
@@ -861,9 +861,12 @@ int delegate_to_multipathd(enum mpath_cmds cmd, goto out; } -if (reply !=NULL && *reply !='\0' &&strcmp (reply,"ok\n" )) -printf ("%s" , reply); - r =DELEGATE_OK ; +if (reply !=NULL && *reply !='\0' ) { +if (strcmp (reply,"fail\n" )) + r =DELEGATE_OK ; +if (r !=NOT_DELEGATED &&strcmp (reply,"ok\n" )) +printf ("%s" , reply); + } out:FREE (reply);
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH v2 7/8 multipathd: unset mpp->hwe when removing map
In reply to Benjamin MarzinskiIf the map doesn't unset its hwe pointer before orphaning all the paths, multipathd will print a warning message in orphan_path() because of commit "libmultipath: warn if freeing path that holds mpp->hwe".
--- libmultipath/structs_vec.c | 1 + multipathd/main.c | 1 + 2 files changed, 2 insertions(+)
libmultipath/structs_vec.c +1 -0
@@ -129,6 +129,7 @@ remove_map(struct multipath * mpp, struct vectors * vecs, int purge_vec)/* * clear references to this map */ + mpp->hwe =NULL ;orphan_paths (vecs->pathvec, mpp,"map removed internally" ); if (purge_vec &&
multipathd/main.c +1 -0
@@ -666,6 +666,7 @@ flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths)condlog (2 ,"%s: map flushed" , mpp->alias); } + mpp->hwe =NULL ;orphan_paths (vecs->pathvec, mpp,"map flushed" );remove_map_and_stop_waiter (mpp, vecs);
Signature · 1 line
2.17.2
Re: [PATCH v2 7/8] multipathd: unset mpp->hwe when removing map
Quoted 6 lines · Benjamin Marzinski
If the map doesn't unset its hwe pointer before orphaning all the paths,
multipathd will print a warning message inorphan_path()because of commit "libmultipath: warn if freeing path that holdsmpp->hwe".Signed-off-by Benjamin Marzinski <[email protected]>
Do you have a specific reason to put "mpp->hwe = NULL" in the *callers* of orphan_paths()? I observed the same problem, and fixed it directly in orphan_paths() (the patch is part of in my upcoming v2 series).
Regards,
Martin
Quoted 31 lines
--- libmultipath/structs_vec.c | 1 + multipathd/main.c | 1 + 2 files changed, 2 insertions(+)libmultipath/structs_vec.c +1
-0@@ -129,6 +129,7 @@ remove_map(struct multipath * mpp, struct vectors * vecs, int purge_vec)/* * clear references to this map */ + mpp->hwe =NULL ;orphan_paths (vecs->pathvec, mpp,"map removed internally" );libmultipath/structs_vec.c +0
-0if (purge_vec &&multipathd/main.c +1
-0@@ -666,6 +666,7 @@ flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths)condlog (2 ,"%s: map flushed" , mpp->alias); } + mpp->hwe =NULL ;orphan_paths (vecs->pathvec, mpp,"map flushed" );remove_map_and_stop_waiter (mpp, vecs);
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 7/8] multipathd: unset mpp->hwe when removing map
Quoted 10 lines · Martin Wilck
Quoted 6 lines · Benjamin Marzinski
If the map doesn't unset its hwe pointer before orphaning all the paths,
multipathd will print a warning message inorphan_path()because of commit "libmultipath: warn if freeing path that holdsmpp->hwe".Signed-off-by Benjamin Marzinski <[email protected]>Do you have a specific reason to put "
mpp->hwe= NULL" in the *callers* oforphan_paths()?
Nope.
Quoted 3 lines
I observed the same problem, and fixed it
directly inorphan_paths()(the patch is part of in my upcoming v2 series).
we can go with yours then.
-Ben
Quoted 42 lines
Regards,
MartinQuoted 31 lines
--- libmultipath/structs_vec.c | 1 + multipathd/main.c | 1 + 2 files changed, 2 insertions(+)libmultipath/structs_vec.c +1
-0@@ -129,6 +129,7 @@ remove_map(struct multipath * mpp, struct vectors * vecs, int purge_vec)/* * clear references to this map */ + mpp->hwe =NULL ;orphan_paths (vecs->pathvec, mpp,"map removed internally" );libmultipath/structs_vec.c +0
-0if (purge_vec &&multipathd/main.c +1
-0@@ -666,6 +666,7 @@ flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths)condlog (2 ,"%s: map flushed" , mpp->alias); } + mpp->hwe =NULL ;orphan_paths (vecs->pathvec, mpp,"map flushed" );remove_map_and_stop_waiter (mpp, vecs);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 8/8 multipathd: log reason for calling domap()
In reply to Benjamin MarzinskiWhen multipathd calls domap(), it should also print the reason on log level 2, it already does this on every code path except when domap is called by the path_checker. Also, if __setup_multipath deletes the device, it should log that.
--- multipathd/main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
multipathd/main.c +9 -4
@@ -414,7 +414,7 @@ int __setup_multipath(struct vectors *vecs, struct multipath *mpp, {if (dm_get_info (mpp->alias, &mpp->dmi)) {/* Error accessing table */ -condlog (3 ,"%s: cannot access table" , mpp->alias); +condlog (2 ,"%s: cannot access table" , mpp->alias); goto out; }
@@ -2252,13 +2252,18 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)*/ condlog (4 ,"path prio refresh" ); -if (marginal_changed) +if (marginal_changed) { +condlog (2 ,"%s: path is %s marginal" , pp->dev, + (pp->marginal)?"now" :"no longer" );update_path_groups (pp->mpp, vecs,1 ); + }else if (update_prio (pp, new_path_up) && (pp->mpp->pgpolicyfn == (pgpolicyfn *)group_by_prio) && - pp->mpp->pgfailback == -FAILBACK_IMMEDIATE ) + pp->mpp->pgfailback == -FAILBACK_IMMEDIATE ) { +condlog (2 ,"%s: path priorities changed. reloading" , + pp->mpp->alias);update_path_groups (pp->mpp, vecs, !new_path_up); -else if (need_switch_pathgroup (pp->mpp,0 )) { + }else if (need_switch_pathgroup (pp->mpp,0 )) {if (pp->mpp->pgfailback >0 && (new_path_up || pp->mpp->failback_tick <=0 )) pp->mpp->failback_tick =
Signature · 1 line
2.17.2
Quoted 22 lines · Benjamin Marzinski
Patches 0003 & 0004 fix an issue that I've seen with paths whose checker
takes too long when multipathd is starting up and creating devices.The others are minor build fixes or small cleanups to my previous patchset.
Changes in v2:
- patch 0003 no longer refactorscount_active_paths(), as suggested by Martin Wilck
- Added patches 0007 & 0008, which are both unrelated minor changes.Benjamin Marzinski (8):
Makefile.inc: trim extra information from systemd version
kpartx: fix -Wsign-compare error
libmultipath: refactor path counting
libmultipath: count pending paths as active on loads
libmultipath: deal with flushing no maps
multipath: deal with delegation failures correctly
multipathd: unsetmpp->hwewhen removing map
multipathd: log reason for callingdomap()
Quoted 12 lines
Makefile.inc | 2 +- kpartx/kpartx.c | 2 +- libmpathpersist/mpath_persist.c | 4 ++-- libmultipath/devmapper.c | 5 +++-- libmultipath/structs.c | 38 +++++++++++++++++++++-------- ---- libmultipath/structs.h | 2 +- libmultipath/structs_vec.c | 1 + multipath/main.c | 9 +++++--- multipathd/main.c | 14 ++++++++---- 9 files changed, 49 insertions(+), 28 deletions(-)
For the series, except 7/8 "multipathd: unset mpp->hwe when removing map":
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