multipathd: avoid unnecessary read-only reloads
Benjamin Marzinski
maintainercover 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.
Benjamin Marzinski (3):
libmultipath: keep existing dm_info if you fail to get a new one
multipathd: update dm_info on multipath change events
multipathd: avoid unnecessary path read-only reloads
libmultipath/devmapper.c | 24 ++++++++++++++---------- libmultipath/libmultipath.version | 1 + libmultipath/sysfs.c | 22 ++++++++++++++++++++++ libmultipath/sysfs.h | 1 + multipathd/main.c | 27 ++++++++++++++++++++++++++- 5 files changed, 64 insertions(+), 11 deletions(-)
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH 1/3 libmultipath: keep existing dm_info if you fail to get a new one
There are reasons that dm_get_info() can fail other than the multipath device not existing. If there is an existing dm_info structure and the call fails, don't free it.
--- libmultipath/devmapper.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
libmultipath/devmapper.c +14 -10
@@ -1590,22 +1590,26 @@ alloc_dminfo (void) }int -dm_get_info (const char * mapname,struct dm_info ** dmi) +dm_get_info (const char * mapname,struct dm_info ** dmi_p) { +struct dm_info *dmi =NULL ; +if (!mapname)return 1 ; -if (!*dmi) - *dmi =alloc_dminfo (); - -if (!*dmi) -return 1 ; +if (!*dmi_p) { + dmi =alloc_dminfo (); +if (!dmi) +return 1 ; + }else + dmi = *dmi_p; -if (do_get_info (mapname, *dmi) !=0 ) { -free (*dmi); - *dmi =NULL ; +if (do_get_info (mapname, dmi) !=0 ) { +if (!*dmi_p) +free (dmi);return 1 ; - } + }else if (!*dmi_p) + *dmi_p = dmi;return 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 1/3] libmultipath: keep existing dm_info if you fail to get a new one
Quoted 7 lines · Benjamin Marzinski
There are reasons that
dm_get_info()can fail other than the multipath
device not existing. If there is an existingdm_infostructure and the
call fails, don't free it.Signed-off-by Benjamin Marzinski <[email protected]>
This is ok, but I think it'd be better to simply embed the dmi struct in struct multipath and thus avoid having allocate and free it separately. Either that, or just use a struct dm_info on stack in dm_get_info() and just copy the properties we actually look at, i.e. read_only, major, minor, suspended, to respective fields in struct multipath. I'd prefer embedding the complete dmi, as it's not that large and contains other interesting fields, too (for example, we might be able to leverage the event_nr field to avoid duplicate work between uevent and dmevent handlers).
We would need to be able to figure out if the dmi is valid, but that's rather easy, we could simply set major = minor = 0.
Regards
Martin
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerRe: [dm-devel] [PATCH 1/3] libmultipath: keep existing dm_info if you fail to get a new one
Quoted 19 lines · Martin Wilck
Quoted 7 lines · Benjamin Marzinski
There are reasons that
dm_get_info()can fail other than the multipath
device not existing. If there is an existingdm_infostructure and the
call fails, don't free it.Signed-off-by Benjamin Marzinski <[email protected]>This is ok, but I think it'd be better to simply embed the dmi struct in struct multipath and thus avoid having allocate and free it separately. Either that, or just use a struct
dm_infoon stack indm_get_info()and just copy the properties we actually look at, i.e.read_only, major, minor, suspended, to respective fields in struct multipath. I'd prefer embedding the complete dmi, as it's not that large and contains other interesting fields, too (for example, we might be able to leverage theevent_nrfield to avoid duplicate work between uevent and dmevent handlers).
Quoted 2 lines
We would need to be able to figure out if the dmi is valid, but that's rather easy, we could simply set major = minor = 0.
Makes sense. I can change this.
-Ben
Quoted 3 lines
Regards
Martin
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH 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
Re: [dm-devel] [PATCH 2/3] multipathd: update dm_info on multipath change events
Quoted 21 lines · Benjamin Marzinski
When multipathd gets a change event for a multipath device, the dm info
may have changed, so update it.Signed-off-by Benjamin Marzinski <[email protected]>---
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;
Quoted 1 line
if (
get_delayed_reconfig()&&
Note for future development: I just realized that dm_get_info() would also get called in the dmevent handler. We currently do some duplicate work in both handlers.
In theory at least, we could look at the event_nr field and see whether this event has already been handled by ourselves. If the dmevent handler sees that uevent kicked in first, it wouldn't need to do anything. The uevent handler would only need to look at properties that udev might have added, but wouldn't need to do a full setup_multipath() any more.
Regards,
Martin
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH 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.
--- libmultipath/libmultipath.version | 1 + libmultipath/sysfs.c | 22 ++++++++++++++++++++++ libmultipath/sysfs.h | 1 + multipathd/main.c | 26 +++++++++++++++++++++++++- 4 files changed, 49 insertions(+), 1 deletion(-)
libmultipath/libmultipath.version +1 -0
@@ -205,6 +205,7 @@ global: strlcpy; sync_map_state; sysfs_attr_set_value; + sysfs_get_ro; sysfs_get_size; sysfs_is_multipathed; timespeccmp;
libmultipath/sysfs.c +22 -0
@@ -236,6 +236,28 @@ sysfs_get_size (struct path *pp, unsigned long long * size)return 0 ; } +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; +} +int sysfs_check_holders (char * check_devt,char * new_devt) {unsigned int major, new_minor, table_minor;
libmultipath/sysfs.h +1 -0
@@ -13,6 +13,7 @@ ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,ssize_t sysfs_bin_attr_get_value (struct udev_device *dev,const char *attr_name,unsigned char * value,size_t value_len);int sysfs_get_size (struct path *pp,unsigned long long * size); +int sysfs_get_ro (struct path *pp);int sysfs_check_holders (char * check_devt,char * new_devt);bool sysfs_is_multipathed (struct path *pp,bool set_wwid);#endif
multipathd/main.c +25 -1
@@ -1440,6 +1440,30 @@ finish_path_init(struct path *pp, struct vectors * vecs)return -1 ; } +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 (!mpp->dmi) +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 +1536,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