multipathd: avoid unnecessary read-only reloads
Benjamin Marzinski
maintainerv2 cover multipathd: avoid unnecessary read-only reloads
This patchset is an expanded version of my single patch "multipathd: avoid unnecessary path read-only reloads" That also makes some changes to how the multipath dm_info is handled.
changes from v1, (suggested by Martin Wilck):
0001: This has been completely rewritten to embed the dmi structure in
the multipath structure. This will require a major version bump for libmultipath, which I've not included.
0003: sysfs_get_ro() has been moved to mutlipathd, and needs_ro_update()
has been changed to work with the embedded dmi structure.
Benjamin Marzinski (3):
libmultipath: embed dm_info in multipath structure
multipathd: update dm_info on multipath change events
multipathd: avoid unnecessary path read-only reloads
libmultipath/configure.c | 7 +++-- libmultipath/devmapper.c | 51 +++++++++++-------------------- libmultipath/devmapper.h | 3 +- libmultipath/libmultipath.version | 1 + libmultipath/print.c | 12 +++++--- libmultipath/structs.c | 10 ++---- libmultipath/structs.h | 3 +- multipathd/main.c | 51 +++++++++++++++++++++++++++++-- 8 files changed, 85 insertions(+), 53 deletions(-)
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH v2 1/3 libmultipath: embed dm_info in multipath structure
Instead of having multipath allocate its dm_info structure, it should just embed it to save on the extra allocations. This also lets us have only one function that all callers use to fill a dm_info structure.
--- libmultipath/configure.c | 7 +++-- libmultipath/devmapper.c | 51 +++++++++++-------------------- libmultipath/devmapper.h | 3 +- libmultipath/libmultipath.version | 1 + libmultipath/print.c | 12 +++++--- libmultipath/structs.c | 10 ++---- libmultipath/structs.h | 3 +- multipathd/main.c | 2 +- 8 files changed, 37 insertions(+), 52 deletions(-)
libmultipath/configure.c +4 -3
@@ -450,12 +450,12 @@ get_udev_for_mpp(const struct multipath *mpp)dev_t devnum;struct udev_device *udd; -if (!mpp || !mpp->dmi) { +if (!mpp || !has_dm_info (mpp)) {condlog (1 ,"%s called with empty mpp" , __func__);return NULL ; } - devnum =makedev (mpp->dmi->major, mpp->dmi->minor); + devnum =makedev (mpp->dmi.major, mpp->dmi.minor); udd =udev_device_new_from_devnum (udev,'b' , devnum);if (!udd) {condlog (1 ,"failed to get udev device for %s" , mpp->alias);
@@ -574,7 +574,8 @@ sysfs_set_max_sectors_kb(struct multipath *mpp, int is_reload)return 0 ; max_sectors_kb = mpp->max_sectors_kb;if (is_reload) { -if (!mpp->dmi &&dm_get_info (mpp->alias, &mpp->dmi) !=0 ) { +if (!has_dm_info (mpp) && +dm_get_info (mpp->alias, &mpp->dmi) !=0 ) {condlog (1 ,"failed to get dm info for %s" , mpp->alias);return 1 ; }
libmultipath/devmapper.c +17 -34
103 lines not on this page · raw message
libmultipath/devmapper.h +2 -1
@@ -70,7 +70,8 @@ char * dm_mapname(int major, int minor);int dm_remove_partmaps (const char * mapname,int need_sync,int deferred_remove);int dm_get_uuid (const char *name,char *uuid,int uuid_len); -int dm_get_info (const char * mapname,struct dm_info ** dmi); +bool has_dm_info (const struct multipath *mpp); +int dm_get_info (const char * mapname,struct dm_info *dmi);int dm_rename (const char * old,char * new,char * delim,int skip_kpartx);int dm_reassign (const char * mapname);int dm_reassign_table (const char *name,char *old,char *new);
libmultipath/libmultipath.version +1 -0
@@ -121,6 +121,7 @@ global: get_used_hwes; get_vpd_sgio; group_by_prio; + has_dm_info; init_checkers; init_config; init_foreign;
libmultipath/print.c +7 -5
@@ -171,8 +171,8 @@ snprint_name (struct strbuf *buff, const struct multipath * mpp)static int snprint_sysfs (struct strbuf *buff,const struct multipath * mpp) { -if (mpp->dmi) -return print_strbuf (buff,"dm-%i" , mpp->dmi->minor); +if (has_dm_info (mpp)) +return print_strbuf (buff,"dm-%i" , mpp->dmi.minor);else return append_strbuf_str (buff,"undef" ); }
@@ -180,9 +180,9 @@ snprint_sysfs (struct strbuf *buff, const struct multipath * mpp)static int snprint_ro (struct strbuf *buff,const struct multipath * mpp) { -if (!mpp->dmi) +if (!has_dm_info (mpp))return append_strbuf_str (buff,"undef" ); -if (mpp->dmi->read_only) +if (mpp->dmi.read_only)return append_strbuf_str (buff,"ro" );else return append_strbuf_str (buff,"rw" );
@@ -256,7 +256,9 @@ snprint_nb_paths (struct strbuf *buff, const struct multipath * mpp)static int snprint_dm_map_state (struct strbuf *buff,const struct multipath * mpp) { -if (mpp->dmi && mpp->dmi->suspended) +if (!has_dm_info (mpp)) +return append_strbuf_str (buff,"undef" ); +else if (mpp->dmi.suspended)return append_strbuf_str (buff,"suspend" );else return append_strbuf_str (buff,"active" );
libmultipath/structs.c +3 -7
@@ -18,6 +18,7 @@#include "prio.h" #include "prioritizers/alua_spc3.h" #include "dm-generic.h" +#include "devmapper.h" struct adapter_group *alloc_adaptergroup (void )
@@ -278,11 +279,6 @@ free_multipath (struct multipath * mpp, enum free_path_mode free_paths) mpp->alias =NULL ; } -if (mpp->dmi) { -free (mpp->dmi); - mpp->dmi =NULL ; - } -if (!free_paths && mpp->pg) {struct pathgroup *pgp;struct path *pp;
@@ -407,10 +403,10 @@ find_mp_by_minor (const struct _vector *mpvec, unsigned int minor)return NULL ; vector_foreach_slot (mpvec, mpp, i) { -if (!mpp->dmi) +if (!has_dm_info (mpp))continue ; -if (mpp->dmi->minor == minor) +if (mpp->dmi.minor == minor)return mpp; }return NULL ;
libmultipath/structs.h +2 -1
@@ -4,6 +4,7 @@#include <sys/types.h> #include <inttypes.h> #include <stdbool.h> +#include <libdevmapper.h> #include "prio.h" #include "byteorder.h"
@@ -386,7 +387,7 @@ struct multipath {unsigned long long size;vector paths;vector pg; -struct dm_info * dmi; +struct dm_info dmi;/* configlet pointers */ char * alias;
multipathd/main.c +1 -1
@@ -908,7 +908,7 @@ ev_remove_map (char * devname, char * alias, int minor, struct vectors * vecs) }if (strcmp (mpp->alias, alias)) {condlog (2 ,"%s: minor number mismatch (map %d, event %d)" , - mpp->alias, mpp->dmi->minor, minor); + mpp->alias, mpp->dmi.minor, minor);return 1 ; }return flush_map (mpp, vecs,0 );
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Re: [dm-devel] [PATCH v2 1/3] libmultipath: embed dm_info in multipath structure
Quoted 6 lines · Benjamin Marzinski
Instead of having multipath allocate its
dm_infostructure, it should just embed it to save on the extra allocations. This also lets us have
only one function that all callers use to fill adm_infostructure.Signed-off-by Benjamin Marzinski <[email protected]>
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH v2 2/3 multipathd: update dm_info on multipath change events
In reply to Benjamin MarzinskiWhen multipathd gets a change event for a multipath device, the dm info may have changed, so update it.
--- multipathd/main.c | 1 + 1 file changed, 1 insertion(+)
multipathd/main.c +1 -0
@@ -818,6 +818,7 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs) conf =get_multipath_config (); reassign_maps = conf->reassign_maps;put_multipath_config (conf); +dm_get_info (mpp->alias, &mpp->dmi);if (mpp->wait_for_udev) { mpp->wait_for_udev =0 ; if (get_delayed_reconfig() &&
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH v2 3/3 multipathd: avoid unnecessary path read-only reloads
In reply to Benjamin MarzinskiA mulitpath device can only be reloaded read/write when all paths are read/write. Also, whenever a read-only scsi device is rescanned, the scsi subsystem will first unconditionally issue a uevent with DISK_RO=0 before checking the read-only status, and if it the device is still read-only, issuing another uevent with DISK_RO=1. These uevents cause pointless reloads when read-only paths are rescanned. To avoid this, first check if the path is being changed to the existing multipath read-only state. If the state is the same, do nothing. If it's different, check to see if all paths are read/write before changing a multipath device from read-only to read/write. If the multipath device read-only state is unknown, assume that it needs to be reloaded.
--- multipathd/main.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
multipathd/main.c +47 -1
@@ -1440,6 +1440,52 @@ finish_path_init(struct path *pp, struct vectors * vecs)return -1 ; } +static int +sysfs_get_ro (struct path *pp) +{ +int ro; +char buff[3 ];/* Either "0\n\0" or "1\n\0" */ + +if (!pp->udev) +return -1 ; + +if (sysfs_attr_get_value (pp->udev,"ro" , buff,sizeof (buff)) <=0 ) { +condlog (3 ,"%s: Cannot read ro attribute in sysfs" , pp->dev); +return -1 ; + } + +if (sscanf (buff,"%d\n" , &ro) !=1 || ro <0 || ro >1 ) { +condlog (3 ,"%s: Cannot parse ro attribute" , pp->dev); +return -1 ; + } + +return ro; +} + +static bool +needs_ro_update (struct multipath *mpp,int ro) +{ +struct pathgroup * pgp; +struct path * pp; +unsigned int i, j; + +if (!mpp || ro <0 ) +return false; +if (!has_dm_info (mpp)) +return true; +if (mpp->dmi.read_only == ro) +return false; +if (ro ==1 ) +return true; + vector_foreach_slot (mpp->pg, pgp, i) { + vector_foreach_slot (pgp->paths, pp, j) { +if (sysfs_get_ro (pp) ==1 ) +return false; + } + } +return true; +} +static int uev_update_path (struct uevent *uev,struct vectors * vecs) {
@@ -1512,7 +1558,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) } ro =uevent_get_disk_ro (uev); -if (mpp && ro >=0 ) { +if (needs_ro_update (mpp, ro)) {condlog (2 ,"%s: update path write_protect to '%d' (uevent)" , uev->kernel, ro);if (mpp->wait_for_udev)
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Re: [dm-devel] [PATCH v2 3/3] multipathd: avoid unnecessary path read-only reloads
Quoted 14 lines · Benjamin Marzinski
A mulitpath device can only be reloaded read/write when all paths are read/write. Also, whenever a read-only scsi device is rescanned, the scsi subsystem will first unconditionally issue a uevent with DISK_RO=0
before checking the read-only status, and if it the device is still read-only, issuing another uevent with DISK_RO=1. These uevents cause pointless reloads when read-only paths are rescanned. To avoid this, first check if the path is being changed to the existing multipath read-only state. If the state is the same, do nothing. If it's different, check to see if all paths are read/write before changing a multipath device from read-only to read/write. If the multipath device
read-only state is unknown, assume that it needs to be reloaded.
Quoted 1 line
Signed-off-by Benjamin Marzinski <[email protected]>
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel