multipath-tools: improve processing efficiency for addition and deletion of multipath devices
PATCH 1/1 multipath-tools: improve processing efficiency for addition and deletion of multipath devices
From: "tang.junhui" <[email protected]>
This patch used to improve processing efficiency for addition and deletion of multipath devices.
This patch is tested pass by ZTE multipath automatic testing system. The modification reduces the system consumption(such as CPU) and shortens the processing time obviously in scene of massive multipath devices addition or deletion.
The main processing flow of code is:
1) add uid_attrs configuration in the defaults section:
It is configured udev attribute which providing a unique path identifier for corresponding type of path devices. If this field is configured and matched with type of device, it would override any other methods providing for device unique identifier in config file, and it would activate merging uevents according to the identifier to promote effiecncy in processing uevents. Tt has no default value, so defaultly only uevents filtering works, and uevents merging does not works, if users want to identify path by udev attribute and to activate merging uevents for SCSI and DAS device, they can set it's value as:
"sd:ID_SERIAL dasd:ID_UID"
2) uevents accumulation in uevents burst scene:
wait one seconds for more uevents in uevent_listen() in uevents burst situations
3) uevents preparing, filtering and merging:
discard unuse uevents and fetch path idendifier from uevents; filter uevents;
merge uevents.
4) uevents proccessing:
proccess the merged uevents in uev->merge_node list without calling domap();
proccess the last uevents uev with calling domap().
--- libmultipath/config.c | 3 + libmultipath/config.h | 1 + libmultipath/dict.c | 3 + libmultipath/discovery.c | 5 +- libmultipath/discovery.h | 2 +- libmultipath/list.h | 41 ++++++ libmultipath/propsel.c | 7 + libmultipath/uevent.c | 320 +++++++++++++++++++++++++++++++++++++++++++-- libmultipath/uevent.h | 2 + libmultipath/util.c | 42 ++++++ libmultipath/util.h | 1 + multipath/multipath.conf.5 | 18 +++ multipathd/cli_handlers.c | 4 +- multipathd/main.c | 93 +++++-------- multipathd/main.h | 4 +- 15 files changed, 471 insertions(+), 75 deletions(-)
libmultipath/config.c +3 -0
@@ -488,6 +488,9 @@ free_config (struct config * conf)if (conf->uid_attribute)FREE (conf->uid_attribute); +if (conf->uid_attrs) +FREE (conf->uid_attrs); +if (conf->getuid)FREE (conf->getuid);
libmultipath/config.h +1 -0
@@ -153,6 +153,7 @@ struct config {char * multipath_dir;char * selector; +char * uid_attrs;char * uid_attribute;char * getuid;char * features;
libmultipath/dict.c +3 -0
@@ -249,6 +249,8 @@ declare_ovr_snprint(selector, print_str) declare_mp_handler(selector, set_str) declare_mp_snprint(selector, print_str) +declare_def_handler(uid_attrs, set_str) +declare_def_snprint(uid_attrs, print_str) declare_def_handler(uid_attribute, set_str) declare_def_snprint_defstr(uid_attribute, print_str, DEFAULT_UID_ATTRIBUTE)declare_ovr_handler (uid_attribute, set_str)
@@ -1367,6 +1369,7 @@ init_keywords(vector keywords)install_keyword ("multipath_dir" , &def_multipath_dir_handler, &snprint_def_multipath_dir);install_keyword ("path_selector" , &def_selector_handler, &snprint_def_selector);install_keyword ("path_grouping_policy" , &def_pgpolicy_handler, &snprint_def_pgpolicy); +install_keyword ("uid_attrs" , &def_uid_attrs_handler, &snprint_def_uid_attrs);install_keyword ("uid_attribute" , &def_uid_attribute_handler, &snprint_def_uid_attribute);install_keyword ("getuid_callout" , &def_getuid_handler, &snprint_def_getuid);install_keyword ("prio" , &def_prio_name_handler, &snprint_def_prio_name);
libmultipath/discovery.c +4 -1
@@ -33,7 +33,7 @@int alloc_path_with_pathinfo (struct config *conf,struct udev_device *udevice, -int flag,struct path **pp_ptr) +char *wwid,int flag,struct path **pp_ptr) {int err =PATHINFO_FAILED ;struct path * pp;
@@ -51,6 +51,9 @@ alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,if (!pp)return PATHINFO_FAILED ; +if (wwid) +strncpy (pp->wwid, wwid,sizeof (pp->wwid)); +if (safe_sprintf (pp->dev,"%s" , devname)) {condlog (0 ,"pp->dev too small" ); }else {
libmultipath/discovery.h +1 -1
@@ -37,7 +37,7 @@ int path_offline (struct path *);int get_state (struct path * pp,struct config * conf,int daemon);int pathinfo (struct path * pp,struct config * conf,int mask);int alloc_path_with_pathinfo (struct config *conf,struct udev_device *udevice, -int flag,struct path **pp_ptr); +char *wwid,int flag,struct path **pp_ptr);int store_pathinfo (vector pathvec,struct config *conf,struct udev_device *udevice,int flag,struct path **pp_ptr);
libmultipath/list.h +41 -0
45 lines not on this page · raw message
libmultipath/propsel.c +7 -0
@@ -18,6 +18,7 @@#include "prio.h" #include "discovery.h" #include "dict.h" +#include "util.h" #include "prioritizers/alua_rtpg.h" #include <inttypes.h>
@@ -339,6 +340,12 @@ int select_getuid(struct config *conf, struct path *pp) {char *origin; + pp->uid_attribute =parse_uid_attribute_by_attrs (conf->uid_attrs, pp->dev); +if (pp->uid_attribute) { + origin ="(setting: multipath.conf defaults section)" ; + goto out; + } +pp_set_ovr (getuid);pp_set_ovr (uid_attribute);pp_set_hwe (getuid);
libmultipath/uevent.c +309 -11
411 lines not on this page · raw message
libmultipath/uevent.h +2 -0
@@ -17,11 +17,13 @@ struct udev;struct uevent {struct list_head node; +struct list_head merge_node;struct udev_device *udev;char buffer[HOTPLUG_BUFFER_SIZE +OBJECT_SIZE ];char *devpath;char *action;char *kernel; +char *wwid;unsigned long seqnum;char *envp[HOTPLUG_NUM_ENVP ]; };
libmultipath/util.c +42 -0
48 lines not on this page · raw message
libmultipath/util.h +1 -0
@@ -12,6 +12,7 @@ size_t strlcat(char *dst, const char *src, size_t size);int devt2devname (char *,int ,char *);dev_t parse_devt (const char *dev_t);char *convert_dev (char *dev,int is_path_device); +char *parse_uid_attribute_by_attrs (char *uid_attrs,char *path_dev);void setup_thread_attr (pthread_attr_t *attr,size_t stacksize,int detached); #define safe_sprintf(var, format, args...) \
multipath/multipath.conf.5 +18 -0
@@ -209,6 +209,24 @@ The default is: \fBfailover\fR . . .TP +.B uid_attrs +The udev attribute providing a unique path identifier for corresponding +type of path devices. If this field is configured and matched with type +of device, it would override any other methods providing for device +unique identifier in config file, and it would activate merging uevents +according to the identifier to promote effiecncy in processing uevents. +Tt has no default value, if you want to identify path by udev attribute +and to activate merging uevents for SCSI and DAS device, you can set +it's value as: +.RS +.TP +\fBuid_attrs "sd:ID_SERIAL dasd:ID_UID"\fR +.TP +The default is: \fB<unset>\fR +.RE +. +. +.TP .B uid_attribute The udev attribute providing a unique path identifier. .RS
multipathd/cli_handlers.c +2 -2
@@ -670,7 +670,7 @@ cli_add_path (void * v, char ** reply, int * len, void * data) pp->checkint = conf->checkint; }put_multipath_config (conf); -return ev_add_path (pp, vecs); +return ev_add_path (pp, vecs,1 ); blacklisted: *reply =strdup ("blacklisted\n" ); *len =strlen (*reply) +1 ;
@@ -692,7 +692,7 @@ cli_del_path (void * v, char ** reply, int * len, void * data)condlog (0 ,"%s: path already removed" , param);return 1 ; } -return ev_remove_path (pp, vecs); +return ev_remove_path (pp, vecs,1 ); }int
multipathd/main.c +35 -58
206 lines not on this page · raw message
multipathd/main.h +2 -2
@@ -22,8 +22,8 @@ void exit_daemon(void);const char *daemon_status (void );int need_to_delay_reconfig (struct vectors *);int reconfigure (struct vectors *); -int ev_add_path (struct path *,struct vectors *); -int ev_remove_path (struct path *,struct vectors *); +int ev_add_path (struct path *,struct vectors *,int ); +int ev_remove_path (struct path *,struct vectors *,int );int ev_add_map (char *,char *,struct vectors *);int ev_remove_map (char *,char *,int ,struct vectors *);void sync_map_state (struct multipath *);
Signature · 1 line
2.8.1.windows.1
Benjamin Marzinski
maintainerQuoted 1 line · On Thu, Feb 16, 2017 at 02:54:01PM +0800, [email protected] wrote:
From: "tang.junhui" <[email protected]>
ACK
Thanks for all your work on this.
-Ben
Quoted 1,014 lines
Change-Id I3f81a55fff389f991f915927000b281d7e263cc5Signed-off-by tang.junhui <[email protected]>This patch used to improve processing efficiency for addition and deletion of multipath devices.
This patch is tested pass by ZTE multipath automatic testing system. The modification reduces the system consumption(such as CPU) and shortens the processing time obviously in scene of massive multipath devices addition or deletion.
The main processing flow of code is:
1) adduid_attrsconfiguration in the defaults section:
It is configured udev attribute which providing a unique path identifier for corresponding type of path devices. If this field is configured and matched with type of device, it would override any other methods providing for device unique identifier in config file, and it would activate merging uevents according to the identifier to promote effiecncy in processing uevents. Tt has no default value, so defaultly only uevents filtering works, and uevents merging does not works, if users want to identify path by udev attribute and to activate merging uevents for SCSI and DAS device, they can set it's value as:
"sd:ID_SERIAL dasd:ID_UID"
2) uevents accumulation in uevents burst scene:
wait one seconds for more uevents inuevent_listen()in uevents burst situations
3) uevents preparing, filtering and merging:discard unuse uevents and fetch path idendifier from uevents; filter uevents; merge uevents.4) uevents proccessing:
proccess the merged uevents inuev->merge_nodelist without callingdomap();
proccess the last uevents uev with callingdomap().--- libmultipath/config.c | 3 + libmultipath/config.h | 1 + libmultipath/dict.c | 3 + libmultipath/discovery.c | 5 +- libmultipath/discovery.h | 2 +- libmultipath/list.h | 41 ++++++ libmultipath/propsel.c | 7 + libmultipath/uevent.c | 320 +++++++++++++++++++++++++++++++++++++++++++-- libmultipath/uevent.h | 2 + libmultipath/util.c | 42 ++++++ libmultipath/util.h | 1 + multipath/multipath.conf.5 | 18 +++ multipathd/cli_handlers.c | 4 +- multipathd/main.c | 93 +++++-------- multipathd/main.h | 4 +- 15 files changed, 471 insertions(+), 75 deletions(-)libmultipath/config.c +3
-0@@ -488,6 +488,9 @@ free_config (struct config * conf)if (conf->uid_attribute)FREE (conf->uid_attribute); +if (conf->uid_attrs) +FREE (conf->uid_attrs); +if (conf->getuid)FREE (conf->getuid);libmultipath/config.h +1
-0@@ -153,6 +153,7 @@ struct config {char * multipath_dir;char * selector; +char * uid_attrs;char * uid_attribute;char * getuid;char * features;libmultipath/dict.c +3
-0@@ -249,6 +249,8 @@ declare_ovr_snprint(selector, print_str) declare_mp_handler(selector, set_str) declare_mp_snprint(selector, print_str) +declare_def_handler(uid_attrs, set_str) +declare_def_snprint(uid_attrs, print_str) declare_def_handler(uid_attribute, set_str) declare_def_snprint_defstr(uid_attribute, print_str, DEFAULT_UID_ATTRIBUTE)declare_ovr_handler (uid_attribute, set_str)@@ -1367,6 +1369,7 @@ init_keywords(vector keywords)install_keyword ("multipath_dir" , &def_multipath_dir_handler, &snprint_def_multipath_dir);install_keyword ("path_selector" , &def_selector_handler, &snprint_def_selector);install_keyword ("path_grouping_policy" , &def_pgpolicy_handler, &snprint_def_pgpolicy); +install_keyword ("uid_attrs" , &def_uid_attrs_handler, &snprint_def_uid_attrs);install_keyword ("uid_attribute" , &def_uid_attribute_handler, &snprint_def_uid_attribute);install_keyword ("getuid_callout" , &def_getuid_handler, &snprint_def_getuid);install_keyword ("prio" , &def_prio_name_handler, &snprint_def_prio_name);libmultipath/discovery.c +4
-1@@ -33,7 +33,7 @@int alloc_path_with_pathinfo (struct config *conf,struct udev_device *udevice, -int flag,struct path **pp_ptr) +char *wwid,int flag,struct path **pp_ptr) {int err =PATHINFO_FAILED ;struct path * pp;@@ -51,6 +51,9 @@ alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,if (!pp)return PATHINFO_FAILED ; +if (wwid) +strncpy (pp->wwid, wwid,sizeof (pp->wwid)); +if (safe_sprintf (pp->dev,"%s" , devname)) {condlog (0 ,"pp->dev too small" ); }else {libmultipath/discovery.h +1
-1@@ -37,7 +37,7 @@ int path_offline (struct path *);int get_state (struct path * pp,struct config * conf,int daemon);int pathinfo (struct path * pp,struct config * conf,int mask);int alloc_path_with_pathinfo (struct config *conf,struct udev_device *udevice, -int flag,struct path **pp_ptr); +char *wwid,int flag,struct path **pp_ptr);int store_pathinfo (vector pathvec,struct config *conf,struct udev_device *udevice,int flag,struct path **pp_ptr);libmultipath/list.h +41
-0@@ -317,4 +317,45 @@ static inline void list_splice_tail_init(struct list_head *list, &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) +/** +* list_for_each_entry_reverse_safe - iterate backwards over list of given type safe against removal of list entry +* @pos: the type * to use as a loop counter. +* @n: another type * to use as temporary storage +* @head: the head for your list. +* @member: the name of the list_struct within the struct. +*/ +#define list_for_each_entry_reverse_safe (pos, n, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member);\ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + +/** +* list_for_some_entry_safe - iterate list from the given begin node to the given end node safe against removal of list entry +* @pos: the type * to use as a loop counter. +* @n: another type * to use as temporary storage +* @from: the begin node of the iteration. +* @to: the end node of the iteration. +* @member: the name of the list_struct within the struct. +*/ +#define list_for_some_entry_safe (pos, n, from, to, member) \ + for (pos = list_entry((from)->next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (to); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** +* list_for_some_entry_reverse_safe - iterate backwards list from the given begin node to the given end node safe against removal of list entry +* @pos: the type * to use as a loop counter. +* @n: another type * to use as temporary storage +* @from: the begin node of the iteration. +* @to: the end node of the iteration. +* @member: the name of the list_struct within the struct. +*/ +#define list_for_some_entry_reverse_safe (pos, n, from, to, member) \ + for (pos = list_entry((from)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (to); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +#endif /* _LIST_H */ libmultipath/propsel.c +7
-0@@ -18,6 +18,7 @@#include "prio.h" #include "discovery.h" #include "dict.h" +#include "util.h" #include "prioritizers/alua_rtpg.h" #include <inttypes.h> @@ -339,6 +340,12 @@ int select_getuid(struct config *conf, struct path *pp) {char *origin; + pp->uid_attribute =parse_uid_attribute_by_attrs (conf->uid_attrs, pp->dev); +if (pp->uid_attribute) { + origin ="(setting: multipath.conf defaults section)" ; + goto out; + } +pp_set_ovr (getuid);pp_set_ovr (uid_attribute);pp_set_hwe (getuid);libmultipath/uevent.c +309
-11@@ -24,6 +24,7 @@#include <unistd.h> #include <stdio.h> +#include <stdbool.h> #include <errno.h> #include <stdlib.h> #include <stddef.h> @@ -38,6 +39,7 @@#include <linux/netlink.h> #include <pthread.h> #include <sys/mman.h> +#include <sys/time.h> #include <libudev.h> #include <errno.h> @@ -46,6 +48,14 @@#include "list.h" #include "uevent.h" #include "vector.h" +#include "structs.h" +#include "util.h" +#include "config.h" +#include "blacklist.h" + +#define MAX_ACCUMULATION_COUNT 2048 +#define MAX_ACCUMULATION_TIME 30*1000 +#define MIN_BURST_SPEED 10typedef int (uev_trigger )(struct uevent *,void * trigger_data);@@ -72,48 +82,301 @@ struct uevent * alloc_uevent (void) {struct uevent *uev =MALLOC (sizeof (struct uevent )); -if (uev) +if (uev) {INIT_LIST_HEAD (&uev->node); +INIT_LIST_HEAD (&uev->merge_node); + }return uev; }void -service_uevq (struct list_head *tmpq) +uevq_cleanup (struct list_head *tmpq) {struct uevent *uev, *tmp;list_for_each_entry_safe (uev, tmp, tmpq, node) {list_del_init (&uev->node); -if (my_uev_trigger &&my_uev_trigger (uev, my_trigger_data)) -condlog (0 ,"uevent trigger error" ); -if (uev->udev)udev_device_unref (uev->udev);FREE (uev); } } -static void uevent_cleanup (void *arg) +void +uevent_get_wwid (struct uevent *uev) { -struct udev *udev = arg; +int i; +char *uid_attribute; +struct config * conf; -condlog (3 ,"Releasing uevent_listen() resources" ); -udev_unref (udev); + conf =get_multipath_config (); + uid_attribute =parse_uid_attribute_by_attrs (conf->uid_attrs, uev->kernel); +put_multipath_config (conf); + +if (!uid_attribute) +return ; + +for (i =0 ; uev->envp[i] !=NULL ; i++) { +if (!strncmp (uev->envp[i], uid_attribute,strlen (uid_attribute)) && +strlen (uev->envp[i]) >strlen (uid_attribute) && + uev->envp[i][strlen (uid_attribute)] =='=' ) { + uev->wwid = uev->envp[i] +strlen (uid_attribute) +1 ; +break ; + } + } +free (uid_attribute); +} + +bool +uevent_need_merge (void ) +{ +struct config * conf; +bool need_merge = false; + + conf =get_multipath_config (); +if (conf->uid_attrs) + need_merge = true; +put_multipath_config (conf); + +return need_merge; +} + +bool +uevent_can_discard (struct uevent *uev) +{ +char *tmp; +char a[11 ], b[11 ]; +struct config * conf; + +/* +* keep only block devices, discard partitions +*/ + tmp =strstr (uev->devpath,"/block/" ); +if (tmp ==NULL ){ +condlog (4 ,"no /block/ in '%s'" , uev->devpath); +return true; + } +if (sscanf (tmp,"/block/%10s" , a) !=1 || +sscanf (tmp,"/block/%10[^/]/%10s" , a, b) ==2 ) { +condlog (4 ,"discard event on %s" , uev->devpath); +return true; + } + +/* +* do not filter dm devices by devnode +*/ +if (!strncmp (uev->kernel,"dm-" ,3 )) +return false; +/* +* filter paths devices by devnode +*/ + conf =get_multipath_config (); +if (filter_devnode (conf->blist_devnode, conf->elist_devnode, + uev->kernel) >0 ) { +put_multipath_config (conf); +return true; + } +put_multipath_config (conf); + +return false; +} + +bool +uevent_can_filter (struct uevent *earlier,struct uevent *later) +{ + +/* +* filter earlier uvents if path has removed later. Eg: +* "add path1 |chang path1 |add path2 |remove path1" +* can filter as: +* "add path2 |remove path1" +* uevents "add path1" and "chang path1" are filtered out +*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (later->action,"remove" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +/* +* filter change uvents if add uevents exist. Eg: +* "change path1| add path1 |add path2" +* can filter as: +* "add path1 |add path2" +* uevent "chang path1" is filtered out +*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (earlier->action,"change" ) && + !strcmp (later->action,"add" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +return false; +} + +bool +merge_need_stop (struct uevent *earlier,struct uevent *later) +{ +/* +* dm uevent do not try to merge with left uevents +*/ +if (!strncmp (later->kernel,"dm-" ,3 )) +return true; + +/* +* we can not make a jugement without wwid, +* so it is sensible to stop merging +*/ +if (!earlier->wwid || !later->wwid) +return true; +/* +* uevents merging stoped +* when we meet an opposite action uevent from the same LUN to AVOID +* "add path1 |remove path1 |add path2 |remove path2 |add path3" +* to merge as "remove path1, path2" and "add path1, path2, path3" +* OR +* "remove path1 |add path1 |remove path2 |add path2 |remove path3" +* to merge as "add path1, path2" and "remove path1, path2, path3" +* SO +* when we meet a non-change uevent from the same LUN +* with the same wwid and different action +* it would be better to stop merging. +*/ +if (!strcmp (earlier->wwid, later->wwid) && +strcmp (earlier->action, later->action) && +strcmp (earlier->action,"change" ) && +strcmp (later->action,"change" )) +return true; + +return false; +} + +bool +uevent_can_merge (struct uevent *earlier,struct uevent *later) +{ +/* merge paths uevents +* whose wwids exsit and are same +* and actions are same, +* and actions are addition or deletion +*/ +if (earlier->wwid && later->wwid && + !strcmp (earlier->wwid, later->wwid) && + !strcmp (earlier->action, later->action) && +strncmp (earlier->action,"change" ,6 ) && +strncmp (earlier->kernel,"dm-" ,3 )) { +return true; + } + +return false; }void -uevq_cleanup (struct list_head *tmpq) +uevent_prepare (struct list_head *tmpq) +{ +struct uevent *uev, *tmp; + +list_for_each_entry_reverse_safe (uev, tmp, tmpq, node) { +if (uevent_can_discard (uev)) { +list_del_init (&uev->node); +if (uev->udev) +udev_device_unref (uev->udev); +FREE (uev); +continue ; + } + +if (strncmp (uev->kernel,"dm-" ,3 ) && +uevent_need_merge ()) +uevent_get_wwid (uev); + } +} + +void +uevent_filter (struct uevent *later,struct list_head *tmpq) +{ +struct uevent *earlier, *tmp; + + list_for_some_entry_reverse_safe(earlier, tmp, &later->node, tmpq, node) { +/* +* filter unnessary earlier uevents +* by the later uevent +*/ +if (uevent_can_filter (earlier, later)) { +condlog (2 ,"uevent: %s-%s has filtered by uevent: %s-%s" , + earlier->kernel, earlier->action, + later->kernel, later->action); + +list_del_init (&earlier->node); +if (earlier->udev) +udev_device_unref (earlier->udev); +FREE (earlier); + } + } +} + +void +uevent_merge (struct uevent *later,struct list_head *tmpq) +{ +struct uevent *earlier, *tmp; + + list_for_some_entry_reverse_safe(earlier, tmp, &later->node, tmpq, node) { +if (merge_need_stop (earlier, later)) +break ; +/* +* merge earlier uevents to the later uevent +*/ +if (uevent_can_merge (earlier, later)) { +condlog (2 ,"merged uevent: %s-%s-%s with uevent: %s-%s-%s" , + earlier->action, earlier->kernel, earlier->wwid, + later->action, later->kernel, later->wwid); + +list_move (&earlier->node, &later->merge_node); + } + } +} + +void +merge_uevq (struct list_head *tmpq) +{ +struct uevent *later; + +uevent_prepare (tmpq); +list_for_each_entry_reverse (later, tmpq, node) { +uevent_filter (later, tmpq); +if (uevent_need_merge ()) +uevent_merge (later, tmpq); + } +} + +void +service_uevq (struct list_head *tmpq) {struct uevent *uev, *tmp;list_for_each_entry_safe (uev, tmp, tmpq, node) {list_del_init (&uev->node); + +if (my_uev_trigger &&my_uev_trigger (uev, my_trigger_data)) +condlog (0 ,"uevent trigger error" ); + +uevq_cleanup (&uev->merge_node); + +if (uev->udev) +udev_device_unref (uev->udev);FREE (uev); } } +static void uevent_cleanup (void *arg) +{ +struct udev *udev = arg; + +condlog (3 ,"Releasing uevent_listen() resources" ); +udev_unref (udev); +} +/* * Service the uevent queue. */ @@ -142,6 +405,7 @@ int uevent_dispatch(int (*uev_trigger)(struct uevent *, void * trigger_data),pthread_mutex_unlock (uevq_lockp);if (!my_uev_trigger)break ; +merge_uevq (&uevq_tmp);service_uevq (&uevq_tmp); }condlog (3 ,"Terminating uev service queue" );@@ -442,11 +706,43 @@ struct uevent *uevent_from_udev_device(struct udev_device *dev)return uev; } +bool uevent_burst (struct timeval *start_time,int events) +{ +struct timeval diff_time, end_time; +unsigned long speed; +unsigned long eclipse_ms; + +if (events >MAX_ACCUMULATION_COUNT ) { +condlog (2 ,"burst got %u uevents, too much uevents, stopped" , events); +return false; + } + +gettimeofday (&end_time,NULL ); +timersub (&end_time, start_time, &diff_time); + + eclipse_ms = diff_time.tv_sec *1000 + diff_time.tv_usec /1000 ; + +if (eclipse_ms ==0 ) +return true; + +if (eclipse_ms >MAX_ACCUMULATION_TIME ) { +condlog (2 ,"burst continued %lu ms, too long time, stopped" , eclipse_ms); +return false; + } + + speed = (events *1000 ) / eclipse_ms; +if (speed >MIN_BURST_SPEED ) +return true; + +return false; +} +int uevent_listen (struct udev *udev) {int err =2 ;struct udev_monitor *monitor =NULL ;int fd, socket_flags, events; +struct timeval start_time;int need_failback =1 ;int timeout =30 ;LIST_HEAD (uevlisten_tmp);@@ -500,6 +796,7 @@ int uevent_listen(struct udev *udev) } events =0 ; +gettimeofday (&start_time,NULL );while (1 ) {struct uevent *uev;struct udev_device *dev;@@ -514,7 +811,7 @@ int uevent_listen(struct udev *udev) errno =0 ; fdcount =poll (&ev_poll,1 , poll_timeout);if (fdcount && ev_poll.revents &POLLIN ) { - timeout =0 ; + timeout =uevent_burst (&start_time, events +1 ) ?1 :0 ; dev =udev_monitor_receive_device (monitor);if (!dev) {condlog (0 ,"failed getting udev device" );@@ -547,6 +844,7 @@ int uevent_listen(struct udev *udev)pthread_mutex_unlock (uevq_lockp); events =0 ; } +gettimeofday (&start_time,NULL ); timeout =30 ; } need_failback =0 ;libmultipath/uevent.h +2
-0@@ -17,11 +17,13 @@ struct udev;struct uevent {struct list_head node; +struct list_head merge_node;struct udev_device *udev;char buffer[HOTPLUG_BUFFER_SIZE +OBJECT_SIZE ];char *devpath;char *action;char *kernel; +char *wwid;unsigned long seqnum;char *envp[HOTPLUG_NUM_ENVP ]; };libmultipath/util.c +42
-0@@ -261,6 +261,48 @@ dev_t parse_devt(const char *dev_t)return makedev (maj, min); } +char *parse_uid_attribute_by_attrs (char *uid_attrs,char *path_dev) +{ +char *uid_attribute; +char *uid_attr_record; +char *dev; +char *attr; +char *tmp; +int count; + +if (!uid_attrs || !path_dev) +return NULL ; + + count =get_word (uid_attrs, &uid_attr_record); +while (uid_attr_record) { + tmp =strrchr (uid_attr_record,':' ); +if (!tmp) { +free (uid_attr_record); +if (!count) +break ; + uid_attrs += count; + count =get_word (uid_attrs, &uid_attr_record); +continue ; + } + dev = uid_attr_record; + attr = tmp +1 ; + *tmp ='\0' ; + +if (!strncmp (path_dev, dev,strlen (dev))) { + uid_attribute =STRDUP (attr); +free (uid_attr_record); +return uid_attribute; + } + +free (uid_attr_record); +if (!count) +break ; + uid_attrs += count; + count =get_word (uid_attrs, &uid_attr_record); + } +return NULL ; +} +void setup_thread_attr (pthread_attr_t *attr,size_t stacksize,int detached) {libmultipath/util.h +1
-0@@ -12,6 +12,7 @@ size_t strlcat(char *dst, const char *src, size_t size);int devt2devname (char *,int ,char *);dev_t parse_devt (const char *dev_t);char *convert_dev (char *dev,int is_path_device); +char *parse_uid_attribute_by_attrs (char *uid_attrs,char *path_dev);void setup_thread_attr (pthread_attr_t *attr,size_t stacksize,int detached); #define safe_sprintf(var, format, args...) \multipath/multipath.conf.5 +18
-0@@ -209,6 +209,24 @@ The default is: \fBfailover\fR . . .TP +.B uid_attrs +The udev attribute providing a unique path identifier for corresponding +type of path devices. If this field is configured and matched with type +of device, it would override any other methods providing for device +unique identifier in config file, and it would activate merging uevents +according to the identifier to promote effiecncy in processing uevents. +Tt has no default value, if you want to identify path by udev attribute +and to activate merging uevents for SCSI and DAS device, you can set +it's value as: +.RS +.TP +\fBuid_attrs "sd:ID_SERIAL dasd:ID_UID"\fR +.TP +The default is: \fB<unset>\fR +.RE +. +. +.TP .B uid_attribute The udev attribute providing a unique path identifier. .RSmultipathd/cli_handlers.c +2
-2@@ -670,7 +670,7 @@ cli_add_path (void * v, char ** reply, int * len, void * data) pp->checkint = conf->checkint; }put_multipath_config (conf); -return ev_add_path (pp, vecs); +return ev_add_path (pp, vecs,1 ); blacklisted: *reply =strdup ("blacklisted\n" ); *len =strlen (*reply) +1 ;@@ -692,7 +692,7 @@ cli_del_path (void * v, char ** reply, int * len, void * data)condlog (0 ,"%s: path already removed" , param);return 1 ; } -return ev_remove_path (pp, vecs); +return ev_remove_path (pp, vecs,1 ); }int multipathd/main.c +35
-58@@ -608,7 +608,7 @@ ev_remove_map (char * devname, char * alias, int minor, struct vectors * vecs) }static int -uev_add_path (struct uevent *uev,struct vectors * vecs) +uev_add_path (struct uevent *uev,struct vectors * vecs,int need_do_map) {struct path *pp;int ret =0 , i;@@ -641,7 +641,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs) DI_ALL | DI_BLACKLIST);put_multipath_config (conf);if (r ==PATHINFO_OK ) - ret =ev_add_path (pp, vecs); + ret =ev_add_path (pp, vecs, need_do_map);else if (r ==PATHINFO_SKIPPED ) {condlog (3 ,"%s: remove blacklisted path" , uev->kernel);@@ -665,7 +665,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)*/ conf =get_multipath_config (); ret =alloc_path_with_pathinfo (conf, uev->udev, -DI_ALL , &pp); + uev->wwid,DI_ALL , &pp);put_multipath_config (conf);if (!pp) {if (ret ==PATHINFO_SKIPPED )@@ -681,7 +681,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs) conf =get_multipath_config (); pp->checkint = conf->checkint;put_multipath_config (conf); - ret =ev_add_path (pp, vecs); + ret =ev_add_path (pp, vecs, need_do_map); }else { condlog(0, "%s: failed to store path info, " "dropping event",@@ -699,7 +699,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)* 1: error */ int -ev_add_path (struct path * pp,struct vectors * vecs) +ev_add_path (struct path * pp,struct vectors * vecs,int need_do_map) {struct multipath * mpp;char params[PARAMS_SIZE ] = {0 };@@ -767,6 +767,13 @@ rescan:/* persistent reservation check*/ mpath_pr_event_handle (pp); +if (!need_do_map) +return 0 ; + +if (!dm_map_present (mpp->alias)) { + mpp->action =ACT_CREATE ; + start_waiter =1 ; + }/* * push the map to the device-mapper */ @@ -833,7 +840,7 @@ fail: }static int -uev_remove_path (struct uevent *uev,struct vectors * vecs) +uev_remove_path (struct uevent *uev,struct vectors * vecs,int need_do_map) {struct path *pp;int ret;@@ -844,7 +851,7 @@ uev_remove_path (struct uevent *uev, struct vectors * vecs)pthread_testcancel (); pp =find_path_by_dev (vecs->pathvec, uev->kernel);if (pp) - ret =ev_remove_path (pp, vecs); + ret =ev_remove_path (pp, vecs, need_do_map);lock_cleanup_pop (vecs->lock);if (!pp) {/* Not an error; path might have been purged earlier */ @@ -855,7 +862,7 @@ uev_remove_path (struct uevent *uev, struct vectors * vecs) }int -ev_remove_path (struct path *pp,struct vectors * vecs) +ev_remove_path (struct path *pp,struct vectors * vecs,int need_do_map) {struct multipath * mpp;int i, retval =0 ;@@ -918,6 +925,8 @@ ev_remove_path (struct path *pp, struct vectors * vecs) goto out; } +if (!need_do_map) + goto out;/* * reload the map */ @@ -995,7 +1004,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) }if (pp->initialized ==INIT_REQUESTED_UDEV ) - retval =uev_add_path (uev, vecs); + retval =uev_add_path (uev, vecs,1 );else if (mpp && ro >=0 ) {condlog (2 ,"%s: update path write_protect to '%d' (uevent)" , uev->kernel, ro);@@ -1016,7 +1025,7 @@ out:int flag =DI_SYSFS |DI_WWID ; conf =get_multipath_config (); - retval =alloc_path_with_pathinfo (conf, uev->udev, flag,NULL ); + retval =alloc_path_with_pathinfo (conf, uev->udev, uev->wwid, flag,NULL );put_multipath_config (conf);if (retval ==PATHINFO_SKIPPED ) {@@ -1077,40 +1086,15 @@ uxsock_trigger (char * str, char ** reply, int * len, void * trigger_data)return r; } -static int -uev_discard (char * devpath) -{ -char *tmp; -char a[11 ], b[11 ]; - -/* -* keep only block devices, discard partitions -*/ - tmp =strstr (devpath,"/block/" ); -if (tmp ==NULL ){ -condlog (4 ,"no /block/ in '%s'" , devpath); -return 1 ; - } -if (sscanf (tmp,"/block/%10s" , a) !=1 || -sscanf (tmp,"/block/%10[^/]/%10s" , a, b) ==2 ) { -condlog (4 ,"discard event on %s" , devpath); -return 1 ; - } -return 0 ; -} -int uev_trigger (struct uevent * uev,void * trigger_data) {int r =0 ;struct vectors * vecs; -struct config *conf; +struct uevent *merge_uev, *tmp; vecs = (struct vectors *)trigger_data; -if (uev_discard (uev->devpath)) -return 0 ; -pthread_cleanup_push (config_cleanup,NULL );pthread_mutex_lock (&config_lock); if (running_state != DAEMON_IDLE &&@@ -1139,28 +1123,21 @@ uev_trigger (struct uevent * uev, void * trigger_data) }/* -* path add/remove event +* path add/remove/change event, add/remove maybe merged */ - conf =get_multipath_config (); -if (filter_devnode (conf->blist_devnode, conf->elist_devnode, - uev->kernel) >0 ) { -put_multipath_config (conf); - goto out; +list_for_each_entry_safe (merge_uev, tmp, &uev->merge_node, node) { +if (!strncmp (merge_uev->action,"add" ,3 )) + r +=uev_add_path (merge_uev, vecs,0 ); +if (!strncmp (merge_uev->action,"remove" ,6 )) + r +=uev_remove_path (merge_uev, vecs,0 ); } -put_multipath_config (conf); -if (!strncmp (uev->action,"add" ,3 )) { - r =uev_add_path (uev, vecs); - goto out; - } -if (!strncmp (uev->action,"remove" ,6 )) { - r =uev_remove_path (uev, vecs); - goto out; - } -if (!strncmp (uev->action,"change" ,6 )) { - r =uev_update_path (uev, vecs); - goto out; - } +if (!strncmp (uev->action,"add" ,3 )) + r +=uev_add_path (uev, vecs,1 ); +if (!strncmp (uev->action,"remove" ,6 )) + r +=uev_remove_path (uev, vecs,1 ); +if (!strncmp (uev->action,"change" ,6 )) + r +=uev_update_path (uev, vecs); out:return r;@@ -1570,7 +1547,7 @@ check_path (struct vectors * vecs, struct path * pp, int ticks) conf =get_multipath_config (); ret =pathinfo (pp, conf,DI_ALL |DI_BLACKLIST );if (ret ==PATHINFO_OK ) { -ev_add_path (pp, vecs); +ev_add_path (pp, vecs,1 ); pp->tick =1 ; }else if (ret ==PATHINFO_SKIPPED ) {put_multipath_config (conf);@@ -1686,7 +1663,7 @@ check_path (struct vectors * vecs, struct path * pp, int ticks) }if (!disable_reinstate &&reinstate_path (pp, add_active)) {condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs); +ev_add_path (pp, vecs,1 ); pp->tick =1 ;return 0 ; }@@ -1709,7 +1686,7 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)/* Clear IO errors */ if (reinstate_path (pp,0 )) {condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs); +ev_add_path (pp, vecs,1 ); pp->tick =1 ;return 0 ; }multipathd/main.h +2
-2@@ -22,8 +22,8 @@ void exit_daemon(void);const char *daemon_status (void );int need_to_delay_reconfig (struct vectors *);int reconfigure (struct vectors *); -int ev_add_path (struct path *,struct vectors *); -int ev_remove_path (struct path *,struct vectors *); +int ev_add_path (struct path *,struct vectors *,int ); +int ev_remove_path (struct path *,struct vectors *,int );int ev_add_map (char *,char *,struct vectors *);int ev_remove_map (char *,char *,int ,struct vectors *);void sync_map_state (struct multipath *);Signature · 1 line
2.8.1.windows.1
Hi Junhui,
It seems I did not receive the patch version Acked by Ben, Can you rebase and post please ?
Thanks.
Quoted 1,088 lines · Benjamin Marzinski
Quoted 1 line · On Thu, Feb 16, 2017 at 02:54:01PM +0800, [email protected] wrote:
From: "tang.junhui" <[email protected]>
ACK
Thanks for all your work on this.
-BenQuoted 5 lines
Change-Id I3f81a55fff389f991f915927000b281d7e263cc5Signed-off-by tang.junhui <[email protected]>This patch used to improve processing efficiency for addition and
deletion
Quoted 10 lines
of multipath devices.
This patch is tested pass by ZTE multipath automatic testing system. The modification reduces the system consumption(such as CPU) and shortens the processing time obviously in scene of massive multipath devices addition or deletion.
The main processing flow of code is:
1) adduid_attrsconfiguration in the defaults section:
It is configured udev attribute which providing a unique pathidentifier
Quoted 1 line
for corresponding type of path devices. If this field is configured
and
Quoted 1 line
matched with type of device, it would override any other methods
providing
Quoted 1 line
for device unique identifier in config file, and it would activate
merging
Quoted 3 lines
uevents according to the identifier to promote effiecncy in processing uevents. Tt has no default value, so defaultly only uevents filtering works, and uevents merging does not works, if users want to identify
path
Quoted 1 line
by udev attribute and to activate merging uevents for SCSI and DAS
device,
Quoted 13 lines
they can set it's value as:
"sd:ID_SERIAL dasd:ID_UID"
2) uevents accumulation in uevents burst scene:
wait one seconds for more uevents inuevent_listen()in uevents burst situations
3) uevents preparing, filtering and merging:discard unuse uevents and fetch path idendifier from uevents; filter uevents; merge uevents.4) uevents proccessing:
proccess the merged uevents inuev->merge_nodelist without callingdomap();
proccess the last uevents uev with callingdomap().Quoted 9 lines
--- libmultipath/config.c | 3 + libmultipath/config.h | 1 + libmultipath/dict.c | 3 + libmultipath/discovery.c | 5 +- libmultipath/discovery.h | 2 +- libmultipath/list.h | 41 ++++++ libmultipath/propsel.c | 7 + libmultipath/uevent.c | 320 +++++++++++++++++++++++++++++++++++++++++++--
Quoted 40 lines
libmultipath/uevent.h | 2 + libmultipath/util.c | 42 ++++++ libmultipath/util.h | 1 + multipath/multipath.conf.5 | 18 +++ multipathd/cli_handlers.c | 4 +- multipathd/main.c | 93 +++++-------- multipathd/main.h | 4 +- 15 files changed, 471 insertions(+), 75 deletions(-)libmultipath/config.c +3
-0@@ -488,6 +488,9 @@ free_config (struct config * conf)if (conf->uid_attribute)FREE (conf->uid_attribute); +if (conf->uid_attrs) +FREE (conf->uid_attrs); +if (conf->getuid)FREE (conf->getuid);libmultipath/config.h +1
-0@@ -153,6 +153,7 @@ struct config {char * multipath_dir;char * selector; +char * uid_attrs;char * uid_attribute;char * getuid;char * features;libmultipath/dict.c +0
-0libmultipath/dict.c declare_ovr_snprint(selector, print_str) · line 255
Quoted 7 lines
libmultipath/dict.c +2
-0@@ -249,6 +249,8 @@ declare_ovr_snprint(selector, print_str) declare_mp_handler(selector, set_str) declare_mp_snprint(selector, print_str) +declare_def_handler(uid_attrs, set_str) +declare_def_snprint(uid_attrs, print_str) declare_def_handler(uid_attribute, set_str) declare_def_snprint_defstr(uid_attribute, print_str,
DEFAULT_UID_ATTRIBUTE)libmultipath/dict.c init_keywords(vector keywords) · line 1369
Quoted 3 lines
libmultipath/dict.c +0
-0declare_ovr_handler (uid_attribute, set_str)@@ -1367,6 +1369,7 @@ init_keywords(vector keywords) install_keyword("multipath_dir", &def_multipath_dir_handler,
&snprint_def_multipath_dir);libmultipath/dict.c init_keywords(vector keywords) · line 1370
Quoted 1 line
libmultipath/dict.c +0
-0install_keyword("path_selector", &def_selector_handler,
&snprint_def_selector);libmultipath/dict.c init_keywords(vector keywords) · line 1371
Quoted 1 line
libmultipath/dict.c +0
-0install_keyword("path_grouping_policy", &def_pgpolicy_handler,
&snprint_def_pgpolicy);libmultipath/dict.c init_keywords(vector keywords) · line 1372
Quoted 1 line
libmultipath/dict.c +1
-0+ install_keyword("uid_attrs", &def_uid_attrs_handler,
&snprint_def_uid_attrs);libmultipath/dict.c init_keywords(vector keywords) · line 1373
Quoted 1 line
libmultipath/dict.c +0
-0install_keyword("uid_attribute", &def_uid_attribute_handler,
&snprint_def_uid_attribute);libmultipath/dict.c init_keywords(vector keywords) · line 1374
Quoted 1 line
libmultipath/dict.c +0
-0install_keyword("getuid_callout", &def_getuid_handler,
&snprint_def_getuid);libmultipath/dict.c init_keywords(vector keywords) · line 1375
Quoted 1 line
libmultipath/dict.c +0
-0install_keyword("prio", &def_prio_name_handler,
&snprint_def_prio_name);libmultipath/discovery.c line 35
Quoted 8 lines
libmultipath/discovery.c +0
-0@@ -33,7 +33,7 @@int alloc_path_with_pathinfo (struct config *conf, struct udev_device*udevice,
libmultipath/discovery.c alloc_path_with_pathinfo (struct config *conf, struct
Quoted 6 lines
libmultipath/discovery.c +1
-1- int flag, struct path **pp_ptr) + char *wwid, int flag, struct path **pp_ptr) { int err = PATHINFO_FAILED;struct path * pp;@@ -51,6 +51,9 @@ alloc_path_with_pathinfo (struct config *conf, struct
udev_device*udevice,Quoted 14 lines
libmultipath/discovery.c +3
-0if (!pp)return PATHINFO_FAILED ; +if (wwid) +strncpy (pp->wwid, wwid,sizeof (pp->wwid)); +if (safe_sprintf (pp->dev,"%s" , devname)) {condlog (0 ,"pp->dev too small" ); }else {libmultipath/discovery.h +0
-0libmultipath/discovery.h int path_offline (struct path *); · line 39
Quoted 3 lines
libmultipath/discovery.h +0
-0@@ -37,7 +37,7 @@ int path_offline (struct path *);int get_state (struct path * pp,struct config * conf,int daemon);int pathinfo (struct path * pp,struct config * conf,int mask); int alloc_path_with_pathinfo (struct config *conf, struct udev_device*udevice,
libmultipath/list.h static inline void list_splice_tail_init(struct
Quoted 10 lines
libmultipath/discovery.h +1
-1- int flag, struct path **pp_ptr); + char *wwid, int flag, struct path **pp_ptr);int store_pathinfo (vector pathvec,struct config *conf,struct udev_device *udevice,int flag,struct path **pp_ptr);libmultipath/list.h +0
-0@@ -317,4 +317,45 @@ static inline void list_splice_tail_init(struct
list_head*list,libmultipath/list.h static inline void list_splice_tail_init(struct list_head *list,
Quoted 5 lines
libmultipath/list.h +2
-0&pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) +/** +* list_for_each_entry_reverse_safe - iterate backwards over list of given type safe against removal of list entry
libmultipath/list.h static inline void list_splice_tail_init(struct list_head *list,
Quoted 6 lines
libmultipath/list.h +6
-0+* @pos: the type * to use as a loop counter. +* @n: another type * to use as temporary storage +* @head: the head for your list. +* @member: the name of the list_struct within the struct. +*/ +#define list_for_each_entry_reverse_safe (pos, n, head, member)\
libmultipath/list.h static inline void list_splice_tail_init(struct list_head *list,
Quoted 7 lines
libmultipath/list.h +7
-0+for (pos =list_entry ((head)->prev,typeof (*pos), member), \ + n =list_entry (pos->member.prev,typeof (*pos), member);\ + &pos->member != (head); \ + pos = n, n =list_entry (n->member.prev,typeof (*n), member)) + +/** +* list_for_some_entry_safe - iterate list from the given begin node to the given end node safe against removal of list entry
libmultipath/list.h static inline void list_splice_tail_init(struct list_head *list,
Quoted 7 lines
libmultipath/list.h +7
-0+* @pos: the type * to use as a loop counter. +* @n: another type * to use as temporary storage +* @from: the begin node of the iteration. +* @to: the end node of the iteration. +* @member: the name of the list_struct within the struct. +*/ +#define list_for_some_entry_safe (pos, n, from, to, member)\
libmultipath/list.h static inline void list_splice_tail_init(struct list_head *list,
Quoted 7 lines
libmultipath/list.h +7
-0+for (pos =list_entry ((from)->next,typeof (*pos), member), \ + n =list_entry (pos->member.next,typeof (*pos), member); \ + &pos->member != (to); \ + pos = n, n =list_entry (n->member.next,typeof (*n), member)) + +/** +* list_for_some_entry_reverse_safe - iterate backwards list from the given begin node to the given end node safe against removal of list entry
libmultipath/list.h static inline void list_splice_tail_init(struct list_head *list,
Quoted 7 lines
libmultipath/list.h +7
-0+* @pos: the type * to use as a loop counter. +* @n: another type * to use as temporary storage +* @from: the begin node of the iteration. +* @to: the end node of the iteration. +* @member: the name of the list_struct within the struct. +*/ +#define list_for_some_entry_reverse_safe (pos, n, from, to, member)\
libmultipath/propsel.c int select_getuid(struct config *conf, struct path
Quoted 19 lines
libmultipath/list.h +5
-0+for (pos =list_entry ((from)->prev,typeof (*pos), member), \ + n =list_entry (pos->member.prev,typeof (*pos), member); \ + &pos->member != (to); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +#endif /* _LIST_H */ libmultipath/propsel.c +1
-0@@ -18,6 +18,7 @@#include "prio.h" #include "discovery.h" #include "dict.h" +#include "util.h" #include "prioritizers/alua_rtpg.h" #include <inttypes.h> @@ -339,6 +340,12 @@ int select_getuid(struct config *conf, struct path*pp)
libmultipath/propsel.c int select_getuid(struct config *conf, struct path *pp)
Quoted 4 lines
libmultipath/propsel.c +1
-0{char *origin; + pp->uid_attribute = parse_uid_attribute_by_attrs(conf->uid_attrs,
pp->dev);Quoted 77 lines
libmultipath/propsel.c +5
-0+if (pp->uid_attribute) { + origin ="(setting: multipath.conf defaults section)" ; + goto out; + } +pp_set_ovr (getuid);pp_set_ovr (uid_attribute);pp_set_hwe (getuid);libmultipath/uevent.c +16
-6@@ -24,6 +24,7 @@#include <unistd.h> #include <stdio.h> +#include <stdbool.h> #include <errno.h> #include <stdlib.h> #include <stddef.h> @@ -38,6 +39,7 @@#include <linux/netlink.h> #include <pthread.h> #include <sys/mman.h> +#include <sys/time.h> #include <libudev.h> #include <errno.h> @@ -46,6 +48,14 @@#include "list.h" #include "uevent.h" #include "vector.h" +#include "structs.h" +#include "util.h" +#include "config.h" +#include "blacklist.h" + +#define MAX_ACCUMULATION_COUNT 2048 +#define MAX_ACCUMULATION_TIME 30*1000 +#define MIN_BURST_SPEED 10typedef int (uev_trigger )(struct uevent *,void * trigger_data);@@ -72,48 +82,301 @@ struct uevent * alloc_uevent (void) {struct uevent *uev =MALLOC (sizeof (struct uevent )); -if (uev) +if (uev) {INIT_LIST_HEAD (&uev->node); +INIT_LIST_HEAD (&uev->merge_node); + }return uev; }void -service_uevq (struct list_head *tmpq) +uevq_cleanup (struct list_head *tmpq) {struct uevent *uev, *tmp;list_for_each_entry_safe (uev, tmp, tmpq, node) {list_del_init (&uev->node); -if (my_uev_trigger &&my_uev_trigger (uev, my_trigger_data)) -condlog (0 ,"uevent trigger error" ); -if (uev->udev)udev_device_unref (uev->udev);FREE (uev); } } -static void uevent_cleanup (void *arg) +void +uevent_get_wwid (struct uevent *uev)libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 115
Quoted 10 lines
libmultipath/uevent.c +5
-3{ -struct udev *udev = arg; +int i; +char *uid_attribute; +struct config * conf; -condlog (3 ,"Releasing uevent_listen() resources" ); -udev_unref (udev); + conf =get_multipath_config (); + uid_attribute = parse_uid_attribute_by_attrs(conf->uid_attrs,
uev->kernel);libmultipath/uevent.c struct uevent * alloc_uevent (void)
Quoted 7 lines
libmultipath/uevent.c +7
-0+put_multipath_config (conf); + +if (!uid_attribute) +return ; + + for (i = 0; uev->envp[i] != NULL; i++) { + if (!strncmp(uev->envp[i], uid_attribute,
strlen(uid_attribute)) &&libmultipath/uevent.c struct uevent * alloc_uevent (void)
Quoted 3 lines
libmultipath/uevent.c +3
-0+ strlen(uev->envp[i]) > strlen(uid_attribute) && + uev->envp[i][strlen(uid_attribute)] == '=') { + uev->wwid = uev->envp[i] + strlen(uid_attribute) +1;
Quoted 102 lines
libmultipath/uevent.c +102
-0+break ; + } + } +free (uid_attribute); +} + +bool +uevent_need_merge (void ) +{ +struct config * conf; +bool need_merge = false; + + conf =get_multipath_config (); +if (conf->uid_attrs) + need_merge = true; +put_multipath_config (conf); + +return need_merge; +} + +bool +uevent_can_discard (struct uevent *uev) +{ +char *tmp; +char a[11 ], b[11 ]; +struct config * conf; + +/* +* keep only block devices, discard partitions +*/ + tmp =strstr (uev->devpath,"/block/" ); +if (tmp ==NULL ){ +condlog (4 ,"no /block/ in '%s'" , uev->devpath); +return true; + } +if (sscanf (tmp,"/block/%10s" , a) !=1 || +sscanf (tmp,"/block/%10[^/]/%10s" , a, b) ==2 ) { +condlog (4 ,"discard event on %s" , uev->devpath); +return true; + } + +/* +* do not filter dm devices by devnode +*/ +if (!strncmp (uev->kernel,"dm-" ,3 )) +return false; +/* +* filter paths devices by devnode +*/ + conf =get_multipath_config (); +if (filter_devnode (conf->blist_devnode, conf->elist_devnode, + uev->kernel) >0 ) { +put_multipath_config (conf); +return true; + } +put_multipath_config (conf); + +return false; +} + +bool +uevent_can_filter (struct uevent *earlier,struct uevent *later) +{ + +/* +* filter earlier uvents if path has removed later. Eg: +* "add path1 |chang path1 |add path2 |remove path1" +* can filter as: +* "add path2 |remove path1" +* uevents "add path1" and "chang path1" are filtered out +*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (later->action,"remove" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +/* +* filter change uvents if add uevents exist. Eg: +* "change path1| add path1 |add path2" +* can filter as: +* "add path1 |add path2" +* uevent "chang path1" is filtered out +*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (earlier->action,"change" ) && + !strcmp (later->action,"add" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +return false; +} + +bool +merge_need_stop (struct uevent *earlier,struct uevent *later) +{ +/* +* dm uevent do not try to merge with left uevents +*/ +if (!strncmp (later->kernel,"dm-" ,3 )) +return true;libmultipath/uevent.c struct uevent * alloc_uevent (void)
Quoted 10 lines
libmultipath/uevent.c +10
-0+ +/* +* we can not make a jugement without wwid, +* so it is sensible to stop merging +*/ +if (!earlier->wwid || !later->wwid) +return true; +/* +* uevents merging stoped +* when we meet an opposite action uevent from the same LUN to AVOID
Quoted 55 lines
libmultipath/uevent.c +51
-1+* "add path1 |remove path1 |add path2 |remove path2 |add path3" +* to merge as "remove path1, path2" and "add path1, path2, path3" +* OR +* "remove path1 |add path1 |remove path2 |add path2 |remove path3" +* to merge as "add path1, path2" and "remove path1, path2, path3" +* SO +* when we meet a non-change uevent from the same LUN +* with the same wwid and different action +* it would be better to stop merging. +*/ +if (!strcmp (earlier->wwid, later->wwid) && +strcmp (earlier->action, later->action) && +strcmp (earlier->action,"change" ) && +strcmp (later->action,"change" )) +return true; + +return false; +} + +bool +uevent_can_merge (struct uevent *earlier,struct uevent *later) +{ +/* merge paths uevents +* whose wwids exsit and are same +* and actions are same, +* and actions are addition or deletion +*/ +if (earlier->wwid && later->wwid && + !strcmp (earlier->wwid, later->wwid) && + !strcmp (earlier->action, later->action) && +strncmp (earlier->action,"change" ,6 ) && +strncmp (earlier->kernel,"dm-" ,3 )) { +return true; + } + +return false; }void -uevq_cleanup (struct list_head *tmpq) +uevent_prepare (struct list_head *tmpq) +{ +struct uevent *uev, *tmp; + +list_for_each_entry_reverse_safe (uev, tmp, tmpq, node) { +if (uevent_can_discard (uev)) { +list_del_init (&uev->node); +if (uev->udev) +udev_device_unref (uev->udev); +FREE (uev); +continue ; + } + +if (strncmp (uev->kernel,"dm-" ,3 ) && +uevent_need_merge ())libmultipath/uevent.c struct uevent * alloc_uevent (void)
Quoted 10 lines
libmultipath/uevent.c +10
-0+uevent_get_wwid (uev); + } +} + +void +uevent_filter (struct uevent *later,struct list_head *tmpq) +{ +struct uevent *earlier, *tmp; + + list_for_some_entry_reverse_safe(earlier, tmp, &later->node,tmpq, node) {
libmultipath/uevent.c struct uevent * alloc_uevent (void)
Quoted 6 lines
libmultipath/uevent.c +6
-0+/* +* filter unnessary earlier uevents +* by the later uevent +*/ +if (uevent_can_filter (earlier, later)) { + condlog(2, "uevent: %s-%s has filtered by uevent:%s-%s",
Quoted 7 lines
libmultipath/uevent.c +7
-0+ earlier->kernel, earlier->action, + later->kernel, later->action); + +list_del_init (&earlier->node); +if (earlier->udev) +udev_device_unref (earlier->udev); +FREE (earlier);libmultipath/uevent.c struct uevent * alloc_uevent (void)
Quoted 10 lines
libmultipath/uevent.c +10
-0+ } + } +} + +void +uevent_merge (struct uevent *later,struct list_head *tmpq) +{ +struct uevent *earlier, *tmp; + + list_for_some_entry_reverse_safe(earlier, tmp, &later->node,tmpq, node) {
libmultipath/uevent.c struct uevent * alloc_uevent (void)
Quoted 7 lines
libmultipath/uevent.c +7
-0+if (merge_need_stop (earlier, later)) +break ; +/* +* merge earlier uevents to the later uevent +*/ +if (uevent_can_merge (earlier, later)) { + condlog(2, "merged uevent: %s-%s-%s with uevent:%s-%s-%s",
libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 332
Quoted 1 line
libmultipath/uevent.c +1
-0+ earlier->action, earlier->kernel,
earlier->wwid,libmultipath/uevent.c int uevent_dispatch(int (*uev_trigger)(struct uevent
Quoted 51 lines
libmultipath/uevent.c +38
-0+ later->action, later->kernel, later->wwid); + +list_move (&earlier->node, &later->merge_node); + } + } +} + +void +merge_uevq (struct list_head *tmpq) +{ +struct uevent *later; + +uevent_prepare (tmpq); +list_for_each_entry_reverse (later, tmpq, node) { +uevent_filter (later, tmpq); +if (uevent_need_merge ()) +uevent_merge (later, tmpq); + } +} + +void +service_uevq (struct list_head *tmpq) {struct uevent *uev, *tmp;list_for_each_entry_safe (uev, tmp, tmpq, node) {list_del_init (&uev->node); + +if (my_uev_trigger &&my_uev_trigger (uev, my_trigger_data)) +condlog (0 ,"uevent trigger error" ); + +uevq_cleanup (&uev->merge_node); + +if (uev->udev) +udev_device_unref (uev->udev);FREE (uev); } } +static void uevent_cleanup (void *arg) +{ +struct udev *udev = arg; + +condlog (3 ,"Releasing uevent_listen() resources" ); +udev_unref (udev); +} +/* * Service the uevent queue. */ @@ -142,6 +405,7 @@ int uevent_dispatch(int (*uev_trigger)(struct uevent*, void *
trigger_data),libmultipath/uevent.c struct uevent *uevent_from_udev_device(struct
Quoted 8 lines
libmultipath/uevent.c +1
-0pthread_mutex_unlock (uevq_lockp);if (!my_uev_trigger)break ; +merge_uevq (&uevq_tmp);service_uevq (&uevq_tmp); }condlog (3 ,"Terminating uev service queue" );@@ -442,11 +706,43 @@ struct uevent *uevent_from_udev_device(struct
udev_device*dev)libmultipath/uevent.c struct uevent *uevent_from_udev_device(struct udev_device *dev)
Quoted 11 lines
libmultipath/uevent.c +8
-0return uev; } +bool uevent_burst (struct timeval *start_time,int events) +{ +struct timeval diff_time, end_time; +unsigned long speed; +unsigned long eclipse_ms; + +if (events >MAX_ACCUMULATION_COUNT ) { + condlog(2, "burst got %u uevents, too much uevents,stopped", events);
libmultipath/uevent.c struct uevent *uevent_from_udev_device(struct udev_device *dev)
Quoted 13 lines
libmultipath/uevent.c +13
-0+return false; + } + +gettimeofday (&end_time,NULL ); +timersub (&end_time, start_time, &diff_time); + + eclipse_ms = diff_time.tv_sec *1000 + diff_time.tv_usec /1000 ; + +if (eclipse_ms ==0 ) +return true; + +if (eclipse_ms >MAX_ACCUMULATION_TIME ) { + condlog(2, "burst continued %lu ms, too long time,stopped",
eclipse_ms);Quoted 28 lines
libmultipath/uevent.c +12
-0+return false; + } + + speed = (events *1000 ) / eclipse_ms; +if (speed >MIN_BURST_SPEED ) +return true; + +return false; +} +int uevent_listen (struct udev *udev) {int err =2 ;struct udev_monitor *monitor =NULL ;int fd, socket_flags, events; +struct timeval start_time;int need_failback =1 ;int timeout =30 ;LIST_HEAD (uevlisten_tmp);@@ -500,6 +796,7 @@ int uevent_listen(struct udev *udev) } events =0 ; +gettimeofday (&start_time,NULL );while (1 ) {struct uevent *uev;struct udev_device *dev;libmultipath/uevent.c int uevent_listen(struct udev *udev) · line 814
Quoted 5 lines
libmultipath/uevent.c +1
-1@@ -514,7 +811,7 @@ int uevent_listen(struct udev *udev) errno =0 ; fdcount =poll (&ev_poll,1 , poll_timeout);if (fdcount && ev_poll.revents &POLLIN ) { - timeout =0 ; + timeout = uevent_burst(&start_time, events + 1) ?1 : 0;
libmultipath/util.h size_t strlcat(char *dst, const char *src, size_t
Quoted 87 lines
libmultipath/uevent.c +1
-0dev =udev_monitor_receive_device (monitor);if (!dev) {condlog (0 ,"failed getting udev device" );@@ -547,6 +844,7 @@ int uevent_listen(struct udev *udev)pthread_mutex_unlock (uevq_lockp); events =0 ; } +gettimeofday (&start_time,NULL ); timeout =30 ; } need_failback =0 ;libmultipath/uevent.h +2
-0@@ -17,11 +17,13 @@ struct udev;struct uevent {struct list_head node; +struct list_head merge_node;struct udev_device *udev;char buffer[HOTPLUG_BUFFER_SIZE +OBJECT_SIZE ];char *devpath;char *action;char *kernel; +char *wwid;unsigned long seqnum;char *envp[HOTPLUG_NUM_ENVP ]; };libmultipath/util.c +42
-0@@ -261,6 +261,48 @@ dev_t parse_devt(const char *dev_t)return makedev (maj, min); } +char *parse_uid_attribute_by_attrs (char *uid_attrs,char *path_dev) +{ +char *uid_attribute; +char *uid_attr_record; +char *dev; +char *attr; +char *tmp; +int count; + +if (!uid_attrs || !path_dev) +return NULL ; + + count =get_word (uid_attrs, &uid_attr_record); +while (uid_attr_record) { + tmp =strrchr (uid_attr_record,':' ); +if (!tmp) { +free (uid_attr_record); +if (!count) +break ; + uid_attrs += count; + count =get_word (uid_attrs, &uid_attr_record); +continue ; + } + dev = uid_attr_record; + attr = tmp +1 ; + *tmp ='\0' ; + +if (!strncmp (path_dev, dev,strlen (dev))) { + uid_attribute =STRDUP (attr); +free (uid_attr_record); +return uid_attribute; + } + +free (uid_attr_record); +if (!count) +break ; + uid_attrs += count; + count =get_word (uid_attrs, &uid_attr_record); + } +return NULL ; +} +void setup_thread_attr (pthread_attr_t *attr,size_t stacksize,int detached) {libmultipath/util.h +0
-0@@ -12,6 +12,7 @@ size_t strlcat(char *dst, const char *src, size_tsize);
libmultipath/util.h size_t strlcat(char *dst, const char *src, size_t size);
Quoted 5 lines
libmultipath/util.h +1
-0int devt2devname (char *,int ,char *);dev_t parse_devt (const char *dev_t);char *convert_dev (char *dev,int is_path_device); +char *parse_uid_attribute_by_attrs (char *uid_attrs,char *path_dev); void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, intdetached);
multipathd/cli_handlers.c cli_add_path (void * v, char ** reply, int * len,
Quoted 36 lines
libmultipath/util.h +0
-0#define safe_sprintf(var, format, args...) \multipath/multipath.conf.5 +18
-0@@ -209,6 +209,24 @@ The default is: \fBfailover\fR . . .TP +.B uid_attrs +The udev attribute providing a unique path identifier for corresponding +type of path devices. If this field is configured and matched with type +of device, it would override any other methods providing for device +unique identifier in config file, and it would activate merging uevents +according to the identifier to promote effiecncy in processing uevents. +Tt has no default value, if you want to identify path by udev attribute +and to activate merging uevents for SCSI and DAS device, you can set +it's value as: +.RS +.TP +\fBuid_attrs "sd:ID_SERIAL dasd:ID_UID"\fR +.TP +The default is: \fB<unset>\fR +.RE +. +. +.TP .B uid_attribute The udev attribute providing a unique path identifier. .RSmultipathd/cli_handlers.c +0
-0@@ -670,7 +670,7 @@ cli_add_path (void * v, char ** reply, int * len,void * data)
multipathd/cli_handlers.c cli_del_path (void * v, char ** reply, int * len,
Quoted 9 lines
multipathd/cli_handlers.c +1
-1pp->checkint = conf->checkint; }put_multipath_config (conf); -return ev_add_path (pp, vecs); +return ev_add_path (pp, vecs,1 ); blacklisted: *reply =strdup ("blacklisted\n" ); *len =strlen (*reply) +1 ;@@ -692,7 +692,7 @@ cli_del_path (void * v, char ** reply, int * len,void * data)
multipathd/main.c ev_remove_map (char * devname, char * alias, int
Quoted 13 lines
multipathd/cli_handlers.c +1
-1condlog (0 ,"%s: path already removed" , param);return 1 ; } -return ev_remove_path (pp, vecs); +return ev_remove_path (pp, vecs,1 ); }int multipathd/main.c +0
-0@@ -608,7 +608,7 @@ ev_remove_map (char * devname, char * alias, intminor, struct vectors * vecs)
multipathd/main.c ev_remove_map (char * devname, char * alias, int minor, struct vectors * vecs)
Quoted 5 lines
multipathd/main.c +1
-1}static int -uev_add_path (struct uevent *uev,struct vectors * vecs) +uev_add_path (struct uevent *uev, struct vectors * vecs, int
need_do_map)multipathd/main.c uev_add_path (struct uevent *uev, struct vectors *
Quoted 4 lines
multipathd/main.c +0
-0{struct path *pp;int ret =0 , i;@@ -641,7 +641,7 @@ uev_add_path (struct uevent *uev, struct vectors *vecs)
multipathd/main.c uev_add_path (struct uevent *uev, struct vectors *
Quoted 9 lines
multipathd/main.c +1
-1DI_ALL | DI_BLACKLIST);put_multipath_config (conf);if (r ==PATHINFO_OK ) - ret =ev_add_path (pp, vecs); + ret =ev_add_path (pp, vecs, need_do_map);else if (r ==PATHINFO_SKIPPED ) {condlog (3 ,"%s: remove blacklisted path" , uev->kernel);@@ -665,7 +665,7 @@ uev_add_path (struct uevent *uev, struct vectors *vecs)
multipathd/main.c uev_add_path (struct uevent *uev, struct vectors *
Quoted 9 lines
multipathd/main.c +1
-1*/ conf =get_multipath_config (); ret =alloc_path_with_pathinfo (conf, uev->udev, -DI_ALL , &pp); + uev->wwid,DI_ALL , &pp);put_multipath_config (conf);if (!pp) {if (ret ==PATHINFO_SKIPPED )@@ -681,7 +681,7 @@ uev_add_path (struct uevent *uev, struct vectors *vecs)
multipathd/main.c uev_add_path (struct uevent *uev, struct vectors *
Quoted 9 lines
multipathd/main.c +1
-1conf =get_multipath_config (); pp->checkint = conf->checkint;put_multipath_config (conf); - ret =ev_add_path (pp, vecs); + ret =ev_add_path (pp, vecs, need_do_map); }else { condlog(0, "%s: failed to store path info, " "dropping event",@@ -699,7 +699,7 @@ uev_add_path (struct uevent *uev, struct vectors *vecs)
Quoted 23 lines
multipathd/main.c +8
-1* 1: error */ int -ev_add_path (struct path * pp,struct vectors * vecs) +ev_add_path (struct path * pp,struct vectors * vecs,int need_do_map) {struct multipath * mpp;char params[PARAMS_SIZE ] = {0 };@@ -767,6 +767,13 @@ rescan:/* persistent reservation check*/ mpath_pr_event_handle (pp); +if (!need_do_map) +return 0 ; + +if (!dm_map_present (mpp->alias)) { + mpp->action =ACT_CREATE ; + start_waiter =1 ; + }/* * push the map to the device-mapper */ multipathd/main.c fail: · line 843
Quoted 5 lines
multipathd/main.c +1
-1@@ -833,7 +840,7 @@ fail: }static int -uev_remove_path (struct uevent *uev,struct vectors * vecs) +uev_remove_path (struct uevent *uev, struct vectors * vecs, int
need_do_map)multipathd/main.c uev_remove_path (struct uevent *uev, struct vectors
Quoted 4 lines
multipathd/main.c +0
-0{struct path *pp;int ret;@@ -844,7 +851,7 @@ uev_remove_path (struct uevent *uev, struct vectors* vecs)
multipathd/main.c uev_remove_path (struct uevent *uev, struct vectors
Quoted 9 lines
multipathd/main.c +1
-1pthread_testcancel (); pp =find_path_by_dev (vecs->pathvec, uev->kernel);if (pp) - ret =ev_remove_path (pp, vecs); + ret =ev_remove_path (pp, vecs, need_do_map);lock_cleanup_pop (vecs->lock);if (!pp) {/* Not an error; path might have been purged earlier */ @@ -855,7 +862,7 @@ uev_remove_path (struct uevent *uev, struct vectors* vecs)
multipathd/main.c ev_remove_path (struct path *pp, struct vectors *
Quoted 9 lines
multipathd/main.c +1
-1}int -ev_remove_path (struct path *pp,struct vectors * vecs) +ev_remove_path (struct path *pp,struct vectors * vecs,int need_do_map) {struct multipath * mpp;int i, retval =0 ;@@ -918,6 +925,8 @@ ev_remove_path (struct path *pp, struct vectors *vecs)
multipathd/main.c uev_update_path (struct uevent *uev, struct vectors
Quoted 9 lines
multipathd/main.c +2
-0goto out; } +if (!need_do_map) + goto out;/* * reload the map */ @@ -995,7 +1004,7 @@ uev_update_path (struct uevent *uev, struct vectors* vecs)
multipathd/main.c uev_update_path (struct uevent *uev, struct vectors * vecs)
Quoted 7 lines
multipathd/main.c +1
-1}if (pp->initialized ==INIT_REQUESTED_UDEV ) - retval =uev_add_path (uev, vecs); + retval =uev_add_path (uev, vecs,1 );else if (mpp && ro >=0 ) { condlog(2, "%s: update path write_protect to '%d'(uevent)",
uev->kernel, ro);multipathd/main.c out: · line 1019
Quoted 6 lines
multipathd/main.c +0
-1@@ -1016,7 +1025,7 @@ out:int flag =DI_SYSFS |DI_WWID ; conf =get_multipath_config (); - retval = alloc_path_with_pathinfo(conf, uev->udev,flag, NULL);
multipathd/main.c out: · line 1028
Quoted 1 line
multipathd/main.c +1
-0+ retval = alloc_path_with_pathinfo(conf, uev->udev,
uev->wwid, flag, NULL);multipathd/main.c uxsock_trigger (char * str, char ** reply, int *
Quoted 4 lines
multipathd/main.c +0
-0put_multipath_config (conf);if (retval ==PATHINFO_SKIPPED ) {@@ -1077,40 +1086,15 @@ uxsock_trigger (char * str, char ** reply, int *len, void *
trigger_data)multipathd/main.c uev_trigger (struct uevent * uev, void *
Quoted 42 lines
multipathd/main.c +1
-26return r; } -static int -uev_discard (char * devpath) -{ -char *tmp; -char a[11 ], b[11 ]; - -/* -* keep only block devices, discard partitions -*/ - tmp =strstr (devpath,"/block/" ); -if (tmp ==NULL ){ -condlog (4 ,"no /block/ in '%s'" , devpath); -return 1 ; - } -if (sscanf (tmp,"/block/%10s" , a) !=1 || -sscanf (tmp,"/block/%10[^/]/%10s" , a, b) ==2 ) { -condlog (4 ,"discard event on %s" , devpath); -return 1 ; - } -return 0 ; -} -int uev_trigger (struct uevent * uev,void * trigger_data) {int r =0 ;struct vectors * vecs; -struct config *conf; +struct uevent *merge_uev, *tmp; vecs = (struct vectors *)trigger_data; -if (uev_discard (uev->devpath)) -return 0 ; -pthread_cleanup_push (config_cleanup,NULL );pthread_mutex_lock (&config_lock); if (running_state != DAEMON_IDLE &&@@ -1139,28 +1123,21 @@ uev_trigger (struct uevent * uev, void *
trigger_data)multipathd/main.c check_path (struct vectors * vecs, struct path *
Quoted 41 lines
multipathd/main.c +12
-19}/* -* path add/remove event +* path add/remove/change event, add/remove maybe merged */ - conf =get_multipath_config (); -if (filter_devnode (conf->blist_devnode, conf->elist_devnode, - uev->kernel) >0 ) { -put_multipath_config (conf); - goto out; +list_for_each_entry_safe (merge_uev, tmp, &uev->merge_node, node) { +if (!strncmp (merge_uev->action,"add" ,3 )) + r +=uev_add_path (merge_uev, vecs,0 ); +if (!strncmp (merge_uev->action,"remove" ,6 )) + r +=uev_remove_path (merge_uev, vecs,0 ); } -put_multipath_config (conf); -if (!strncmp (uev->action,"add" ,3 )) { - r =uev_add_path (uev, vecs); - goto out; - } -if (!strncmp (uev->action,"remove" ,6 )) { - r =uev_remove_path (uev, vecs); - goto out; - } -if (!strncmp (uev->action,"change" ,6 )) { - r =uev_update_path (uev, vecs); - goto out; - } +if (!strncmp (uev->action,"add" ,3 )) + r +=uev_add_path (uev, vecs,1 ); +if (!strncmp (uev->action,"remove" ,6 )) + r +=uev_remove_path (uev, vecs,1 ); +if (!strncmp (uev->action,"change" ,6 )) + r +=uev_update_path (uev, vecs); out:return r;@@ -1570,7 +1547,7 @@ check_path (struct vectors * vecs, struct path *pp, int ticks)
multipathd/main.c check_path (struct vectors * vecs, struct path *
Quoted 9 lines
multipathd/main.c +1
-1conf =get_multipath_config (); ret =pathinfo (pp, conf,DI_ALL |DI_BLACKLIST );if (ret ==PATHINFO_OK ) { -ev_add_path (pp, vecs); +ev_add_path (pp, vecs,1 ); pp->tick =1 ; }else if (ret ==PATHINFO_SKIPPED ) {put_multipath_config (conf);@@ -1686,7 +1663,7 @@ check_path (struct vectors * vecs, struct path *pp, int ticks)
multipathd/main.c check_path (struct vectors * vecs, struct path *
Quoted 9 lines
multipathd/main.c +1
-1}if (!disable_reinstate &&reinstate_path (pp, add_active)) {condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs); +ev_add_path (pp, vecs,1 ); pp->tick =1 ;return 0 ; }@@ -1709,7 +1686,7 @@ check_path (struct vectors * vecs, struct path *pp, int ticks)
Quoted 26 lines
multipathd/main.c +1
-1/* Clear IO errors */ if (reinstate_path (pp,0 )) {condlog (3 ,"%s: reload map" , pp->dev); -ev_add_path (pp, vecs); +ev_add_path (pp, vecs,1 ); pp->tick =1 ;return 0 ; }multipathd/main.h +2
-3@@ -22,8 +22,8 @@ void exit_daemon(void);const char *daemon_status (void );int need_to_delay_reconfig (struct vectors *);int reconfigure (struct vectors *); -int ev_add_path (struct path *,struct vectors *); -int ev_remove_path (struct path *,struct vectors *); +int ev_add_path (struct path *,struct vectors *,int ); +int ev_remove_path (struct path *,struct vectors *,int );int ev_add_map (char *,char *,struct vectors *);int ev_remove_map (char *,char *,int ,struct vectors *);void sync_map_state (struct multipath *); --2.8.1.windows.1
Hi Christophe,
OK, I'll post it later.
regards,
Tang Junhui
原始邮件
发件人: <[email protected]>
收件人: <[email protected]>
抄送人:唐文俊10144149唐军辉10074136张凯10072500 <[email protected]> <[email protected]> <[email protected]> 日 期 :2017年02月27日 14:22
主 题 :Re: [dm-devel] [PATCH] multipath-tools: improve processing efficiency for addition and deletion of multipath devices
Hi Junhui,
It seems I did not receive the patch version Acked by Ben,Can you rebase and post please ?
Thanks.
On Thu, Feb 16, 2017 at 5:27 PM, Benjamin Marzinski <[email protected]> wrote:
On Thu, Feb 16, 2017 at 02:54:01PM +0800, [email protected] wrote:
> From: "tang.junhui" <[email protected]>
ACK
Thanks for all your work on this.
-Ben
>
> Change-Id: I3f81a55fff389f991f915927000b281d7e263cc5
> Signed-off-by: tang.junhui <[email protected]>
>
> This patch used to improve processing efficiency for addition and deletion > of multipath devices.
>
> This patch is tested pass by ZTE multipath automatic testing system. > The modification reduces the system consumption(such as CPU) and shortens > the processing time obviously in scene of massive multipath devices > addition or deletion.
>
> The main processing flow of code is:
> 1) add uid_attrs configuration in the defaults section:
> It is configured udev attribute which providing a unique path identifier
> for corresponding type of path devices. If this field is configured and
> matched with type of device, it would override any other methods providing
> for device unique identifier in config file, and it would activate merging
> uevents according to the identifier to promote effiecncy in processing
> uevents. Tt has no default value, so defaultly only uevents filtering
> works, and uevents merging does not works, if users want to identify path
> by udev attribute and to activate merging uevents for SCSI and DAS device,
> they can set it's value as:
> "sd:ID_SERIAL dasd:ID_UID"
> 2) uevents accumulation in uevents burst scene:
> wait one seconds for more uevents in uevent_listen() in uevents burst
> situations
> 3) uevents preparing, filtering and merging:
> discard unuse uevents and fetch path idendifier from uevents
> filter uevents
> merge uevents.
> 4) uevents proccessing:
> proccess the merged uevents in uev->merge_node list without calling
> domap()
> proccess the last uevents uev with calling domap().
> ---
> libmultipath/config.c | 3 +
> libmultipath/config.h | 1 +
> libmultipath/dict.c | 3 +
> libmultipath/discovery.c | 5 +-
> libmultipath/discovery.h | 2 +-
> libmultipath/list.h | 41 ++++++
> libmultipath/propsel.c | 7 +
> libmultipath/uevent.c | 320 +++++++++++++++++++++++++++++++++++++++++++--
> libmultipath/uevent.h | 2 +
> libmultipath/util.c | 42 ++++++
> libmultipath/util.h | 1 +
> multipath/multipath.conf.5 | 18 +++
> multipathd/cli_handlers.c | 4 +-
> multipathd/main.c | 93 +++++--------
> multipathd/main.h | 4 +-
> 15 files changed, 471 insertions(+), 75 deletions(-)
>
> diff --git a/libmultipath/config.c b/libmultipath/config.c
> index 15ddbd8..765e91d 100644
> --- a/libmultipath/config.c
> +++ b/libmultipath/config.c
> @@ -488,6 +488,9 @@ free_config (struct config * conf)
> if (conf->uid_attribute)
> FREE(conf->uid_attribute)
>
> + if (conf->uid_attrs)
> + FREE(conf->uid_attrs)
> +
> if (conf->getuid)
> FREE(conf->getuid)
>
> diff --git a/libmultipath/config.h b/libmultipath/config.h
> index 9670020..ab85930 100644
> --- a/libmultipath/config.h
> +++ b/libmultipath/config.h
> @@ -153,6 +153,7 @@ struct config {
>
> char * multipath_dir
> char * selector
> + char * uid_attrs
> char * uid_attribute
> char * getuid
> char * features
> diff --git a/libmultipath/dict.c b/libmultipath/dict.c
> index dc21846..0a531d1 100644
> --- a/libmultipath/dict.c
> +++ b/libmultipath/dict.c
> @@ -249,6 +249,8 @@ declare_ovr_snprint(selector, print_str)
> declare_mp_handler(selector, set_str)
> declare_mp_snprint(selector, print_str)
>
> +declare_def_handler(uid_attrs, set_str)
> +declare_def_snprint(uid_attrs, print_str)
> declare_def_handler(uid_attribute, set_str)
> declare_def_snprint_defstr(uid_attribute, print_str, DEFAULT_UID_ATTRIBUTE)
> declare_ovr_handler(uid_attribute, set_str)
> @@ -1367,6 +1369,7 @@ init_keywords(vector keywords)
> install_keyword("multipath_dir", &def_multipath_dir_handler, &snprint_def_multipath_dir)
> install_keyword("path_selector", &def_selector_handler, &snprint_def_selector)
> install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_pgpolicy)
> + install_keyword("uid_attrs", &def_uid_attrs_handler, &snprint_def_uid_attrs)
> install_keyword("uid_attribute", &def_uid_attribute_handler, &snprint_def_uid_attribute)
> install_keyword("getuid_callout", &def_getuid_handler, &snprint_def_getuid)
> install_keyword("prio", &def_prio_name_handler, &snprint_def_prio_name)
> diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
> index d1aec31..14904f2 100644
> --- a/libmultipath/discovery.c
> +++ b/libmultipath/discovery.c
> @@ -33,7 +33,7 @@
>
> int
> alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
> - int flag, struct path **pp_ptr)
> + char *wwid, int flag, struct path **pp_ptr)
> {
> int err = PATHINFO_FAILED
> struct path * pp
> @@ -51,6 +51,9 @@ alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
> if (!pp)
> return PATHINFO_FAILED
>
> + if(wwid)
> + strncpy(pp->wwid, wwid, sizeof(pp->wwid))
> +
> if (safe_sprintf(pp->dev, "%s", devname)) {
> condlog(0, "pp->dev too small")
> } else {
> diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h
> index 3039268..d16a69a 100644
> --- a/libmultipath/discovery.h
> +++ b/libmultipath/discovery.h
> @@ -37,7 +37,7 @@ int path_offline (struct path *)
> int get_state (struct path * pp, struct config * conf, int daemon)
> int pathinfo (struct path * pp, struct config * conf, int mask)
> int alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
> - int flag, struct path **pp_ptr)
> + char *wwid, int flag, struct path **pp_ptr)
> int store_pathinfo (vector pathvec, struct config *conf,
> struct udev_device *udevice, int flag,
> struct path **pp_ptr)
> diff --git a/libmultipath/list.h b/libmultipath/list.h
> index ceaa381..2b1dcf3 100644
> --- a/libmultipath/list.h
> +++ b/libmultipath/list.h
> @@ -317,4 +317,45 @@ static inline void list_splice_tail_init(struct list_head *list,
> &pos->member != (head) \
> pos = n, n = list_entry(n->member.next, typeof(*n), member))
>
> +/**
> + * list_for_each_entry_reverse_safe - iterate backwards over list of given type safe against removal of list entry
> + * @pos: the type * to use as a loop counter.
> + * @n: another type * to use as temporary storage
> + * @head: the head for your list.
> + * @member: the name of the list_struct within the struct.
> + */
> +#define list_for_each_entry_reverse_safe(pos, n, head, member) \
> + for (pos = list_entry((head)->prev, typeof(*pos), member), \
> + n = list_entry(pos->member.prev, typeof(*pos), member)\
> + &pos->member != (head) \
> + pos = n, n = list_entry(n->member.prev, typeof(*n), member))
> +
> +/**
> + * list_for_some_entry_safe - iterate list from the given begin node to the given end node safe against removal of list entry
> + * @pos: the type * to use as a loop counter.
> + * @n: another type * to use as temporary storage
> + * @from: the begin node of the iteration.
> + * @to: the end node of the iteration.
> + * @member: the name of the list_struct within the struct.
> + */
> +#define list_for_some_entry_safe(pos, n, from, to, member) \
> + for (pos = list_entry((from)->next, typeof(*pos), member), \
> + n = list_entry(pos->member.next, typeof(*pos), member) \
> + &pos->member != (to) \
> + pos = n, n = list_entry(n->member.next, typeof(*n), member))
> +
> +/**
> + * list_for_some_entry_reverse_safe - iterate backwards list from the given begin node to the given end node safe against removal of list entry
> + * @pos: the type * to use as a loop counter.
> + * @n: another type * to use as temporary storage
> + * @from: the begin node of the iteration.
> + * @to: the end node of the iteration.
> + * @member: the name of the list_struct within the struct.
> + */
> +#define list_for_some_entry_reverse_safe(pos, n, from, to, member) \
> + for (pos = list_entry((from)->prev, typeof(*pos), member), \
> + n = list_entry(pos->member.prev, typeof(*pos), member) \
> + &pos->member != (to) \
> + pos = n, n = list_entry(n->member.prev, typeof(*n), member))
> +
> #endif /* _LIST_H */
> diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
> index c0bc616..c47bd08 100644
> --- a/libmultipath/propsel.c
> +++ b/libmultipath/propsel.c
> @@ -18,6 +18,7 @@
> #include "prio.h"
> #include "discovery.h"
> #include "dict.h"
> +#include "util.h"
> #include "prioritizers/alua_rtpg.h"
> #include <inttypes.h>
>
> @@ -339,6 +340,12 @@ int select_getuid(struct config *conf, struct path *pp)
> {
> char *origin
>
> + pp->uid_attribute = parse_uid_attribute_by_attrs(conf->uid_attrs, pp->dev)
> + if (pp->uid_attribute) {
> + origin = "(setting: multipath.conf defaults section)"
> + goto out
> + }
> +
> pp_set_ovr(getuid)
> pp_set_ovr(uid_attribute)
> pp_set_hwe(getuid)
> diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c
> index 7edcce1..6e2527b 100644
> --- a/libmultipath/uevent.c
> +++ b/libmultipath/uevent.c
> @@ -24,6 +24,7 @@
>
> #include <unistd.h>
> #include <stdio.h>
> +#include <stdbool.h>
> #include <errno.h>
> #include <stdlib.h>
> #include <stddef.h>
> @@ -38,6 +39,7 @@
> #include <linux/netlink.h>
> #include <pthread.h>
> #include <sys/mman.h>
> +#include <sys/time.h>
> #include <libudev.h>
> #include <errno.h>
>
> @@ -46,6 +48,14 @@
> #include "list.h"
> #include "uevent.h"
> #include "vector.h"
> +#include "structs.h"
> +#include "util.h"
> +#include "config.h"
> +#include "blacklist.h"
> +
> +#define MAX_ACCUMULATION_COUNT 2048
> +#define MAX_ACCUMULATION_TIME 30*1000
> +#define MIN_BURST_SPEED 10
>
> typedef int (uev_trigger)(struct uevent *, void * trigger_data)
>
> @@ -72,48 +82,301 @@ struct uevent * alloc_uevent (void)
> {
> struct uevent *uev = MALLOC(sizeof(struct uevent))
>
> - if (uev)
> + if (uev) {
> INIT_LIST_HEAD(&uev->node)
> + INIT_LIST_HEAD(&uev->merge_node)
> + }
>
> return uev
> }
>
> void
> -service_uevq(struct list_head *tmpq)
> +uevq_cleanup(struct list_head *tmpq)
> {
> struct uevent *uev, *tmp
>
> list_for_each_entry_safe(uev, tmp, tmpq, node) {
> list_del_init(&uev->node)
>
> - if (my_uev_trigger && my_uev_trigger(uev, my_trigger_data))
> - condlog(0, "uevent trigger error")
> -
> if (uev->udev)
> udev_device_unref(uev->udev)
> FREE(uev)
> }
> }
>
> -static void uevent_cleanup(void *arg)
> +void
> +uevent_get_wwid(struct uevent *uev)
> {
> - struct udev *udev = arg
> + int i
> + char *uid_attribute
> + struct config * conf
>
> - condlog(3, "Releasing uevent_listen() resources")
> - udev_unref(udev)
> + conf = get_multipath_config()
> + uid_attribute = parse_uid_attribute_by_attrs(conf->uid_attrs, uev->kernel)
> + put_multipath_config(conf)
> +
> + if (!uid_attribute)
> + return
> +
> + for (i = 0 uev->envp[i] != NULL i++) {
> + if (!strncmp(uev->envp[i], uid_attribute, strlen(uid_attribute)) &&
> + strlen(uev->envp[i]) > strlen(uid_attribute) &&
> + uev->envp[i][strlen(uid_attribute)] == '=') {
> + uev->wwid = uev->envp[i] + strlen(uid_attribute) + 1
> + break
> + }
> + }
> + free(uid_attribute)
> +}
> +
> +bool
> +uevent_need_merge(void)
> +{
> + struct config * conf
> + bool need_merge = false
> +
> + conf = get_multipath_config()
> + if (conf->uid_attrs)
> + need_merge = true
> + put_multipath_config(conf)
> +
> + return need_merge
> +}
> +
> +bool
> +uevent_can_discard(struct uevent *uev)
> +{
> + char *tmp
> + char a[11], b[11]
> + struct config * conf
> +
> + /*
> + * keep only block devices, discard partitions
> + */
> + tmp = strstr(uev->devpath, "/block/")
> + if (tmp == NULL){
> + condlog(4, "no /block/ in '%s'", uev->devpath)
> + return true
> + }
> + if (sscanf(tmp, "/block/%10s", a) != 1 ||
> + sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) {
> + condlog(4, "discard event on %s", uev->devpath)
> + return true
> + }
> +
> + /*
> + * do not filter dm devices by devnode
> + */
> + if (!strncmp(uev->kernel, "dm-", 3))
> + return false
> + /*
> + * filter paths devices by devnode
> + */
> + conf = get_multipath_config()
> + if (filter_devnode(conf->blist_devnode, conf->elist_devnode,
> + uev->kernel) > 0) {
> + put_multipath_config(conf)
> + return true
> + }
> + put_multipath_config(conf)
> +
> + return false
> +}
> +
> +bool
> +uevent_can_filter(struct uevent *earlier, struct uevent *later)
> +{
> +
> + /*
> + * filter earlier uvents if path has removed later. Eg:
> + * "add path1 |chang path1 |add path2 |remove path1"
> + * can filter as:
> + * "add path2 |remove path1"
> + * uevents "add path1" and "chang path1" are filtered out
> + */
> + if (!strcmp(earlier->kernel, later->kernel) &&
> + !strcmp(later->action, "remove") &&
> + strncmp(later->kernel, "dm-", 3)) {
> + return true
> + }
> +
> + /*
> + * filter change uvents if add uevents exist. Eg:
> + * "change path1| add path1 |add path2"
> + * can filter as:
> + * "add path1 |add path2"
> + * uevent "chang path1" is filtered out
> + */
> + if (!strcmp(earlier->kernel, later->kernel) &&
> + !strcmp(earlier->action, "change") &&
> + !strcmp(later->action, "add") &&
> + strncmp(later->kernel, "dm-", 3)) {
> + return true
> + }
> +
> + return false
> +}
> +
> +bool
> +merge_need_stop(struct uevent *earlier, struct uevent *later)
> +{
> + /*
> + * dm uevent do not try to merge with left uevents
> + */
> + if (!strncmp(later->kernel, "dm-", 3))
> + return true
> +
> + /*
> + * we can not make a jugement without wwid,
> + * so it is sensible to stop merging
> + */
> + if (!earlier->wwid || !later->wwid)
> + return true
> + /*
> + * uevents merging stoped
> + * when we meet an opposite action uevent from the same LUN to AVOID
> + * "add path1 |remove path1 |add path2 |remove path2 |add path3"
> + * to merge as "remove path1, path2" and "add path1, path2, path3"
> + * OR
> + * "remove path1 |add path1 |remove path2 |add path2 |remove path3"
> + * to merge as "add path1, path2" and "remove path1, path2, path3"
> + * SO
> + * when we meet a non-change uevent from the same LUN
> + * with the same wwid and different action
> + * it would be better to stop merging.
> + */
> + if (!strcmp(earlier->wwid, later->wwid) &&
> + strcmp(earlier->action, later->action) &&
> + strcmp(earlier->action, "change") &&
> + strcmp(later->action, "change"))
> + return true
> +
> + return false
> +}
> +
> +bool
> +uevent_can_merge(struct uevent *earlier, struct uevent *later)
> +{
> + /* merge paths uevents
> + * whose wwids exsit and are same
> + * and actions are same,
> + * and actions are addition or deletion
> + */
> + if (earlier->wwid && later->wwid &&
> + !strcmp(earlier->wwid, later->wwid) &&
> + !strcmp(earlier->action, later->action) &&
> + strncmp(earlier->action, "change", 6) &&
> + strncmp(earlier->kernel, "dm-", 3)) {
> + return true
> + }
> +
> + return false
> }
>
> void
> -uevq_cleanup(struct list_head *tmpq)
> +uevent_prepare(struct list_head *tmpq)
> +{
> + struct uevent *uev, *tmp
> +
> + list_for_each_entry_reverse_safe(uev, tmp, tmpq, node) {
> + if (uevent_can_discard(uev)) {
> + list_del_init(&uev->node)
> + if (uev->udev)
> + udev_device_unref(uev->udev)
> + FREE(uev)
> + continue
> + }
> +
> + if (strncmp(uev->kernel, "dm-", 3) &&
> + uevent_need_merge())
> + uevent_get_wwid(uev)
> + }
> +}
> +
> +void
> +uevent_filter(struct uevent *later, struct list_head *tmpq)
> +{
> + struct uevent *earlier, *tmp
> +
> + list_for_some_entry_reverse_safe(earlier, tmp, &later->node, tmpq, node) {
> + /*
> + * filter unnessary earlier uevents
> + * by the later uevent
> + */
> + if (uevent_can_filter(earlier, later)) {
> + condlog(2, "uevent: %s-%s has filtered by uevent: %s-%s",
> + earlier->kernel, earlier->action,
> + later->kernel, later->action)
> +
> + list_del_init(&earlier->node)
> + if (earlier->udev)
> + udev_device_unref(earlier->udev)
> + FREE(earlier)
> + }
> + }
> +}
> +
> +void
> +uevent_merge(struct uevent *later, struct list_head *tmpq)
> +{
> + struct uevent *earlier, *tmp
> +
> + list_for_some_entry_reverse_safe(earlier, tmp, &later->node, tmpq, node) {
> + if (merge_need_stop(earlier, later))
> + break
> + /*
> + * merge earlier uevents to the later uevent
> + */
> + if (uevent_can_merge(earlier, later)) {
> + condlog(2, "merged uevent: %s-%s-%s with uevent: %s-%s-%s",
> + earlier->action, earlier->kernel, earlier->wwid,
> + later->action, later->kernel, later->wwid)
> +
> + list_move(&earlier->node, &later->merge_node)
> + }
> + }
> +}
> +
> +void
> +merge_uevq(struct list_head *tmpq)
> +{
> + struct uevent *later
> +
> + uevent_prepare(tmpq)
> + list_for_each_entry_reverse(later, tmpq, node) {
> + uevent_filter(later, tmpq)
> + if(uevent_need_merge())
> + uevent_merge(later, tmpq)
> + }
> +}
> +
> +void
> +service_uevq(struct list_head *tmpq)
> {
> struct uevent *uev, *tmp
>
> list_for_each_entry_safe(uev, tmp, tmpq, node) {
> list_del_init(&uev->node)
> +
> + if (my_uev_trigger && my_uev_trigger(uev, my_trigger_data))
> + condlog(0, "uevent trigger error")
> +
> + uevq_cleanup(&uev->merge_node)
> +
> + if (uev->udev)
> + udev_device_unref(uev->udev)
> FREE(uev)
> }
> }
>
> +static void uevent_cleanup(void *arg)
> +{
> + struct udev *udev = arg
> +
> + condlog(3, "Releasing uevent_listen() resources")
> + udev_unref(udev)
> +}
> +
> /*
> * Service the uevent queue.
> */
> @@ -142,6 +405,7 @@ int uevent_dispatch(int (*uev_trigger)(struct uevent *, void * trigger_data),
> pthread_mutex_unlock(uevq_lockp)
> if (!my_uev_trigger)
> break
> + merge_uevq(&uevq_tmp)
> service_uevq(&uevq_tmp)
> }
> condlog(3, "Terminating uev service queue")
> @@ -442,11 +706,43 @@ struct uevent *uevent_from_udev_device(struct udev_device *dev)
> return uev
> }
>
> +bool uevent_burst(struct timeval *start_time, int events)
> +{
> + struct timeval diff_time, end_time
> + unsigned long speed
> + unsigned long eclipse_ms
> +
> + if(events > MAX_ACCUMULATION_COUNT) {
> + condlog(2, "burst got %u uevents, too much uevents, stopped", events)
> + return false
> + }
> +
> + gettimeofday(&end_time, NULL)
> + timersub(&end_time, start_time, &diff_time)
> +
> + eclipse_ms = diff_time.tv_sec * 1000 + diff_time.tv_usec / 1000
> +
> + if (eclipse_ms == 0)
> + return true
> +
> + if (eclipse_ms > MAX_ACCUMULATION_TIME) {
> + condlog(2, "burst continued %lu ms, too long time, stopped", eclipse_ms)
> + return false
> + }
> +
> + speed = (events * 1000) / eclipse_ms
> + if (speed > MIN_BURST_SPEED)
> + return true
> +
> + return false
> +}
> +
> int uevent_listen(struct udev *udev)
> {
> int err = 2
> struct udev_monitor *monitor = NULL
> int fd, socket_flags, events
> + struct timeval start_time
> int need_failback = 1
> int timeout = 30
> LIST_HEAD(uevlisten_tmp)
> @@ -500,6 +796,7 @@ int uevent_listen(struct udev *udev)
> }
>
> events = 0
> + gettimeofday(&start_time, NULL)
> while (1) {
> struct uevent *uev
> struct udev_device *dev
> @@ -514,7 +811,7 @@ int uevent_listen(struct udev *udev)
> errno = 0
> fdcount = poll(&ev_poll, 1, poll_timeout)
> if (fdcount && ev_poll.revents & POLLIN) {
> - timeout = 0
> + timeout = uevent_burst(&start_time, events + 1) ? 1 : 0
> dev = udev_monitor_receive_device(monitor)
> if (!dev) {
> condlog(0, "failed getting udev device")
> @@ -547,6 +844,7 @@ int uevent_listen(struct udev *udev)
> pthread_mutex_unlock(uevq_lockp)
> events = 0
> }
> + gettimeofday(&start_time, NULL)
> timeout = 30
> }
> need_failback = 0
> diff --git a/libmultipath/uevent.h b/libmultipath/uevent.h
> index 9d22dcd..61a4207 100644
> --- a/libmultipath/uevent.h
> +++ b/libmultipath/uevent.h
> @@ -17,11 +17,13 @@ struct udev
>
> struct uevent {
> struct list_head node
> + struct list_head merge_node
> struct udev_device *udev
> char buffer[HOTPLUG_BUFFER_SIZE + OBJECT_SIZE]
> char *devpath
> char *action
> char *kernel
> + char *wwid
> unsigned long seqnum
> char *envp[HOTPLUG_NUM_ENVP]
> }
> diff --git a/libmultipath/util.c b/libmultipath/util.c
> index 03a5738..e1e83cf 100644
> --- a/libmultipath/util.c
> +++ b/libmultipath/util.c
> @@ -261,6 +261,48 @@ dev_t parse_devt(const char *dev_t)
> return makedev(maj, min)
> }
>
> +char *parse_uid_attribute_by_attrs(char *uid_attrs, char *path_dev)
> +{
> + char *uid_attribute
> + char *uid_attr_record
> + char *dev
> + char *attr
> + char *tmp
> + int count
> +
> + if(!uid_attrs || !path_dev)
> + return NULL
> +
> + count = get_word(uid_attrs, &uid_attr_record)
> + while (uid_attr_record) {
> + tmp = strrchr(uid_attr_record, ':')
> + if (!tmp) {
> + free(uid_attr_record)
> + if (!count)
> + break
> + uid_attrs += count
> + count = get_word(uid_attrs, &uid_attr_record)
> + continue
> + }
> + dev = uid_attr_record
> + attr = tmp + 1
> + *tmp = '\0'
> +
> + if(!strncmp(path_dev, dev, strlen(dev))) {
> + uid_attribute = STRDUP(attr)
> + free(uid_attr_record)
> + return uid_attribute
> + }
> +
> + free(uid_attr_record)
> + if (!count)
> + break
> + uid_attrs += count
> + count = get_word(uid_attrs, &uid_attr_record)
> + }
> + return NULL
> +}
> +
> void
> setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached)
> {
> diff --git a/libmultipath/util.h b/libmultipath/util.h
> index f3b37ee..793f2b7 100644
> --- a/libmultipath/util.h
> +++ b/libmultipath/util.h
> @@ -12,6 +12,7 @@ size_t strlcat(char *dst, const char *src, size_t size)
> int devt2devname (char *, int, char *)
> dev_t parse_devt(const char *dev_t)
> char *convert_dev(char *dev, int is_path_device)
> +char *parse_uid_attribute_by_attrs(char *uid_attrs, char *path_dev)
> void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached)
>
> #define safe_sprintf(var, format, args...) \
> diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5
> index 36589f5..63c63c2 100644
> --- a/multipath/multipath.conf.5
> +++ b/multipath/multipath.conf.5
> @@ -209,6 +209,24 @@ The default is: \fBfailover\fR
> .
> .
> .TP
> +.B uid_attrs
> +The udev attribute providing a unique path identifier for corresponding
> +type of path devices. If this field is configured and matched with type
> +of device, it would override any other methods providing for device
> +unique identifier in config file, and it would activate merging uevents
> +according to the identifier to promote effiecncy in processing uevents.
> +Tt has no default value, if you want to identify path by udev attribute
> +and to activate merging uevents for SCSI and DAS device, you can set
> +it's value as:
> +.RS
> +.TP
> +\fBuid_attrs "sd:ID_SERIAL dasd:ID_UID"\fR
> +.TP
> +The default is: \fB<unset>\fR
> +.RE
> +.
> +.
> +.TP
> .B uid_attribute
> The udev attribute providing a unique path identifier.
> .RS
> diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
> index b0eeca6..12f85de 100644
> --- a/multipathd/cli_handlers.c
> +++ b/multipathd/cli_handlers.c
> @@ -670,7 +670,7 @@ cli_add_path (void * v, char ** reply, int * len, void * data)
> pp->checkint = conf->checkint
> }
> put_multipath_config(conf)
> - return ev_add_path(pp, vecs)
> + return ev_add_path(pp, vecs, 1)
> blacklisted:
> *reply = strdup("blacklisted\n")
> *len = strlen(*reply) + 1
> @@ -692,7 +692,7 @@ cli_del_path (void * v, char ** reply, int * len, void * data)
> condlog(0, "%s: path already removed", param)
> return 1
> }
> - return ev_remove_path(pp, vecs)
> + return ev_remove_path(pp, vecs, 1)
> }
>
> int
> diff --git a/multipathd/main.c b/multipathd/main.c
> index adc3258..e513f7d 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -608,7 +608,7 @@ ev_remove_map (char * devname, char * alias, int minor, struct vectors * vecs)
> }
>
> static int
> -uev_add_path (struct uevent *uev, struct vectors * vecs)
> +uev_add_path (struct uevent *uev, struct vectors * vecs, int need_do_map)
> {
> struct path *pp
> int ret = 0, i
> @@ -641,7 +641,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
> DI_ALL | DI_BLACKLIST)
> put_multipath_config(conf)
> if (r == PATHINFO_OK)
> - ret = ev_add_path(pp, vecs)
> + ret = ev_add_path(pp, vecs, need_do_map)
> else if (r == PATHINFO_SKIPPED) {
> condlog(3, "%s: remove blacklisted path",
> uev->kernel)
> @@ -665,7 +665,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
> */
> conf = get_multipath_config()
> ret = alloc_path_with_pathinfo(conf, uev->udev,
> - DI_ALL, &pp)
> + uev->wwid, DI_ALL, &pp)
> put_multipath_config(conf)
> if (!pp) {
> if (ret == PATHINFO_SKIPPED)
> @@ -681,7 +681,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
> conf = get_multipath_config()
> pp->checkint = conf->checkint
> put_multipath_config(conf)
> - ret = ev_add_path(pp, vecs)
> + ret = ev_add_path(pp, vecs, need_do_map)
> } else {
> condlog(0, "%s: failed to store path info, "
> "dropping event",
> @@ -699,7 +699,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
> * 1: error
> */
> int
> -ev_add_path (struct path * pp, struct vectors * vecs)
> +ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)
> {
> struct multipath * mpp
> char params[PARAMS_SIZE] = {0}
> @@ -767,6 +767,13 @@ rescan:
> /* persistent reservation check*/
> mpath_pr_event_handle(pp)
>
> + if (!need_do_map)
> + return 0
> +
> + if (!dm_map_present(mpp->alias)) {
> + mpp->action = ACT_CREATE
> + start_waiter = 1
> + }
> /*
> * push the map to the device-mapper
> */
> @@ -833,7 +840,7 @@ fail:
> }
>
> static int
> -uev_remove_path (struct uevent *uev, struct vectors * vecs)
> +uev_remove_path (struct uevent *uev, struct vectors * vecs, int need_do_map)
> {
> struct path *pp
> int ret
> @@ -844,7 +851,7 @@ uev_remove_path (struct uevent *uev, struct vectors * vecs)
> pthread_testcancel()
> pp = find_path_by_dev(vecs->pathvec, uev->kernel)
> if (pp)
> - ret = ev_remove_path(pp, vecs)
> + ret = ev_remove_path(pp, vecs, need_do_map)
> lock_cleanup_pop(vecs->lock)
> if (!pp) {
> /* Not an error path might have been purged earlier */
> @@ -855,7 +862,7 @@ uev_remove_path (struct uevent *uev, struct vectors * vecs)
> }
>
> int
> -ev_remove_path (struct path *pp, struct vectors * vecs)
> +ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map)
> {
> struct multipath * mpp
> int i, retval = 0
> @@ -918,6 +925,8 @@ ev_remove_path (struct path *pp, struct vectors * vecs)
> goto out
> }
>
> + if (!need_do_map)
> + goto out
> /*
> * reload the map
> */
> @@ -995,7 +1004,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
> }
>
> if (pp->initialized == INIT_REQUESTED_UDEV)
> - retval = uev_add_path(uev, vecs)
> + retval = uev_add_path(uev, vecs, 1)
> else if (mpp && ro >= 0) {
> condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro)
>
> @@ -1016,7 +1025,7 @@ out:
> int flag = DI_SYSFS | DI_WWID
>
> conf = get_multipath_config()
> - retval = alloc_path_with_pathinfo(conf, uev->udev, flag, NULL)
> + retval = alloc_path_with_pathinfo(conf, uev->udev, uev->wwid, flag, NULL)
> put_multipath_config(conf)
>
> if (retval == PATHINFO_SKIPPED) {
> @@ -1077,40 +1086,15 @@ uxsock_trigger (char * str, char ** reply, int * len, void * trigger_data)
> return r
> }
>
> -static int
> -uev_discard(char * devpath)
> -{
> - char *tmp
> - char a[11], b[11]
> -
> - /*
> - * keep only block devices, discard partitions
> - */
> - tmp = strstr(devpath, "/block/")
> - if (tmp == NULL){
> - condlog(4, "no /block/ in '%s'", devpath)
> - return 1
> - }
> - if (sscanf(tmp, "/block/%10s", a) != 1 ||
> - sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) {
> - condlog(4, "discard event on %s", devpath)
> - return 1
> - }
> - return 0
> -}
> -
> int
> uev_trigger (struct uevent * uev, void * trigger_data)
> {
> int r = 0
> struct vectors * vecs
> - struct config *conf
> + struct uevent *merge_uev, *tmp
>
> vecs = (struct vectors *)trigger_data
>
> - if (uev_discard(uev->devpath))
> - return 0
> -
> pthread_cleanup_push(config_cleanup, NULL)
> pthread_mutex_lock(&config_lock)
> if (running_state != DAEMON_IDLE &&
> @@ -1139,28 +1123,21 @@ uev_trigger (struct uevent * uev, void * trigger_data)
> }
>
> /*
> - * path add/remove event
> + * path add/remove/change event, add/remove maybe merged
> */
> - conf = get_multipath_config()
> - if (filter_devnode(conf->blist_devnode, conf->elist_devnode,
> - uev->kernel) > 0) {
> - put_multipath_config(conf)
> - goto out
> + list_for_each_entry_safe(merge_uev, tmp, &uev->merge_node, node) {
> + if (!strncmp(merge_uev->action, "add", 3))
> + r += uev_add_path(merge_uev, vecs, 0)
> + if (!strncmp(merge_uev->action, "remove", 6))
> + r += uev_remove_path(merge_uev, vecs, 0)
> }
> - put_multipath_config(conf)
>
> - if (!strncmp(uev->action, "add", 3)) {
> - r = uev_add_path(uev, vecs)
> - goto out
> - }
> - if (!strncmp(uev->action, "remove", 6)) {
> - r = uev_remove_path(uev, vecs)
> - goto out
> - }
> - if (!strncmp(uev->action, "change", 6)) {
> - r = uev_update_path(uev, vecs)
> - goto out
> - }
> + if (!strncmp(uev->action, "add", 3))
> + r += uev_add_path(uev, vecs, 1)
> + if (!strncmp(uev->action, "remove", 6))
> + r += uev_remove_path(uev, vecs, 1)
> + if (!strncmp(uev->action, "change", 6))
> + r += uev_update_path(uev, vecs)
>
> out:
> return r
> @@ -1570,7 +1547,7 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
> conf = get_multipath_config()
> ret = pathinfo(pp, conf, DI_ALL | DI_BLACKLIST)
> if (ret == PATHINFO_OK) {
> - ev_add_path(pp, vecs)
> + ev_add_path(pp, vecs, 1)
> pp->tick = 1
> } else if (ret == PATHINFO_SKIPPED) {
> put_multipath_config(conf)
> @@ -1686,7 +1663,7 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
> }
> if (!disable_reinstate && reinstate_path(pp, add_active)) {
> condlog(3, "%s: reload map", pp->dev)
> - ev_add_path(pp, vecs)
> + ev_add_path(pp, vecs, 1)
> pp->tick = 1
> return 0
> }
> @@ -1709,7 +1686,7 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
> /* Clear IO errors */
> if (reinstate_path(pp, 0)) {
> condlog(3, "%s: reload map", pp->dev)
> - ev_add_path(pp, vecs)
> + ev_add_path(pp, vecs, 1)
> pp->tick = 1
> return 0
> }
> diff --git a/multipathd/main.h b/multipathd/main.h
> index f72580d..094b04f 100644
> --- a/multipathd/main.h
> +++ b/multipathd/main.h
> @@ -22,8 +22,8 @@ void exit_daemon(void)
> const char * daemon_status(void)
> int need_to_delay_reconfig (struct vectors *)
> int reconfigure (struct vectors *)
> -int ev_add_path (struct path *, struct vectors *)
> -int ev_remove_path (struct path *, struct vectors *)
> +int ev_add_path (struct path *, struct vectors *, int)
> +int ev_remove_path (struct path *, struct vectors *, int)
> int ev_add_map (char *, char *, struct vectors *)
> int ev_remove_map (char *, char *, int, struct vectors *)
> void sync_map_state (struct multipath *) > --
> 2.8.1.windows.1
>
Hello Tang,
I'm sorry to reply so late. Thanks a lot for your work, I agree with Ben that the patch is in pretty good shape now. But I have some remarks left, please see below.
Quoted 10 lines
libmultipath/uevent.c +10
-0+bool +uevent_can_discard (struct uevent *uev) +{ +char *tmp; +char a[11 ], b[11 ]; +struct config * conf; + +/* +* keep only block devices, discard partitions +*/
libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 165
Quoted 10 lines
libmultipath/uevent.c +10
-0+ tmp =strstr (uev->devpath,"/block/" ); +if (tmp ==NULL ){ +condlog (4 ,"no /block/ in '%s'" , uev->devpath); +return true; + } +if (sscanf (tmp,"/block/%10s" , a) !=1 || + sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) { +condlog (4 ,"discard event on %s" , uev->devpath); +return true; + }
I'd like the following better for this check. It uses much less cycles.
static boolcan_discard_by_devpath(const char *devpath)
{
static const char BLOCK[] = "/block/";
const char *p;
p = strstr(pathstr, BLOCK);
if (p == NULL)
/* not a block device */
return true;
p += sizeof(BLOCK) - 1;
p = strchr(p, '/');
if (p == NULL)
/* exactly one path element after "/block/" */
return false;
/* If there are more path elements, it's a partition */
return true;
}Quoted 23 lines
libmultipath/uevent.c +23
-0+bool +uevent_can_filter (struct uevent *earlier,struct uevent *later) +{ + +/* +* filter earlier uvents if path has removed later. Eg: +* "add path1 |chang path1 |add path2 |remove path1" +* can filter as: +* "add path2 |remove path1" +* uevents "add path1" and "chang path1" are filtered out +*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (later->action,"remove" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +/* +* filter change uvents if add uevents exist. Eg: +* "change path1| add path1 |add path2" +* can filter as: +* "add path1 |add path2" +* uevent "chang path1" is filtered out
libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 218
Quoted 10 lines
libmultipath/uevent.c +10
-0+*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (earlier->action,"change" ) && + !strcmp (later->action,"add" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +return false; +}
This would be better readable and faster if you'd put the "kernel" tests first so that you need to check only "action" later:
if (!strncmp(later->kernel, "dm-", 3) || strcmp(earlier->kernel, later->kernel)) return false;
Quoted 32 lines
libmultipath/uevent.c +19
-0+ +bool +merge_need_stop (struct uevent *earlier,struct uevent *later) +{ +/* +* dm uevent do not try to merge with left uevents +*/ +if (!strncmp (later->kernel,"dm-" ,3 )) +return true; + +/* +* we can not make a jugement without wwid, +* so it is sensible to stop merging +*/ +if (!earlier->wwid || !later->wwid) +return true; +/* +* uevents merging stoped +* when we meet an opposite action uevent from the same LUN to AVOID
(quoted diff) +1
-0+ * "add path1 |remove path1 |add path2 |remove path2 |addpath3"
(quoted diff) +1
-0+ * to merge as "remove path1, path2" and "add path1, path2,path3"
(quoted diff) +2
-0+ * OR + * "remove path1 |add path1 |remove path2 |add path2 |removepath3"
(quoted diff) +1
-0+ * to merge as "add path1, path2" and "remove path1, path2,path3"
libmultipath/uevent.c +3
-0+ * SO + * when we meet a non-change uevent from the same LUN + * with the same wwid and different action
libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 255
Quoted 10 lines
libmultipath/uevent.c +10
-0+* it would be better to stop merging. +*/ +if (!strcmp (earlier->wwid, later->wwid) && + strcmp(earlier->action, later->action) && + strcmp(earlier->action, "change") && + strcmp(later->action, "change")) +return true; + +return false; +}
I know you discussed this with Ben before, but still have some trouble with it.
The first case should have been reduced to "remove path1 | remove path2 | add path3" by filtering beforehand. I suppose you want to avoid this sequence because it could leave us without paths temporarily, causing multipathd to destroy the map. But I don't understand what "stop merging" buys you here - if you process the events one-by-one, you may also have 0 paths at some point.
In the second case, we know all events in the sequence have the same WWID; in this case I think it would be safe to filter away "remove" events by subsequent "add" events, ending up with "add path1| add path2| remove path3". But I may be overlooking something here.
The dangerous thing if you have simultaneous remove and add events for the same LUN is that processing the "add" events is likely to fail in domap(). If you get "add path1 | remove path2", once you process "add path1", "path2" may not exist in the kernel any more, and "domap" will fail if you try to set up both; you may end up removing the map completely. IMHO the only safe way to process events in this situation is to merge the events into a single domap() call.
I know you want to avoid that in this patch, but I think it will be a logical further improvement.
Anyway, AFAICS your patch doesn't introduce a regression wrt the current code here; unless I'm overlooking something, my arguments would apply to sequential event processing as well.
Regards
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Hello Martin,
Thanks for your responsible,
> I'd like the following better for this check. It uses much less cycles.> static bool> can_discard_by_devpath(const char *devpath)
> This would be better readable and faster if you'd put the "kernel"> tests first so that you need to check only "action" later:> if (!strncmp(later->kernel, "dm-", 3) ||> strcmp(earlier->kernel, later->kernel))> return false
Yes, I think these codes can be reworked, but since they have no logical
effect, and this patch takes too long time, can you commit a new patch
to rework these codes?
> The first case should have been reduced to "remove path1 | remove path2
> | add path3" by filtering beforehand. I suppose you want to avoid this
> sequence because it could leave us without paths temporarily, causing
> multipathd to destroy the map. But I don't understand what "stop
> merging" buys you here - if you process the events one-by-one, you may
> also have 0 paths at some point.
>
> In the second case, we know all events in the sequence have the same
> WWID in this case I think it would be safe to filter away "remove"
> events by subsequent "add" events, ending up with "add path1| add
> path2| remove path3". But I may be overlooking something here.
> The dangerous thing if you have simultaneous remove and add events for
> the same LUN is that processing the "add" events is likely to fail in
> domap(). If you get "add path1 | remove path2", once you process "add
> path1", "path2" may not exist in the kernel any more, and "domap" will
> fail if you try to set up both you may end up removing the map
> completely. IMHO the only safe way to process events in this situation
> is to merge the events into a single domap() call.
"case 2: remove path1 |add path1 |remove path2 |add path2 |remove path3"
Since the mergering is starting from the latest to the eariest uevent, so the
uevent "remove path3" try to merger other uevents, if we do not stop mergering,
uevent "remove path3" would merge uevent "remove path2" and uevent
"remove path1". Uevent "add path2" would merge "add path1".
The result is that we get two merged uevents:
1) add path2, path1
2) remove path3, path2, path1
Then we process the merged uevents from the earlier to later, We try to ”add
path2 path1“, and we would create or reload a map device with path1 and path2.
Next we process ” remove path3, path2, path1“, so path1, path2 and path3 are
all removed from the map device, this is wrong, the correct result is that the path1
and path2 should be still in the map device.
Just as you say, this patch is just a shape, we need more testing, and maybe
more patches are needed to make it better.
Thank you,
Tang Junhui
原始邮件
发件人: <[email protected]>
收件人:唐军辉10074136 <[email protected]> <[email protected]> <[email protected]> <[email protected]> 抄送人:张凯10072500 <[email protected]>唐文俊10144149
日 期 :2017年02月17日 05:22
主 题 :Re: [dm-devel] [PATCH] multipath-tools: improve processing efficiency for addition and deletion of multipath devices
Hello Tang,
I'm sorry to reply so late. Thanks a lot for your work, I agree with Ben that the patch is in pretty good shape now. But I have some remarks left, please see below.
> +bool
> +uevent_can_discard(struct uevent *uev)
> +{
> + char *tmp > + char a[11], b[11] > + struct config * conf
> +
> + /*
> + * keep only block devices, discard partitions
> + */
> + tmp = strstr(uev->devpath, "/block/")
> + if (tmp == NULL){
> + condlog(4, "no /block/ in '%s'", uev->devpath)
> + return true
> + }
> + if (sscanf(tmp, "/block/%10s", a) != 1 ||
> + sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) {
> + condlog(4, "discard event on %s", uev->devpath)
> + return true> + }
I'd like the following better for this check. It uses much less cycles.
static boolcan_discard_by_devpath(const char *devpath)
{
static const char BLOCK[] = "/block/"
const char *p
p = strstr(pathstr, BLOCK)
if (p == NULL)
/* not a block device */
return true
p += sizeof(BLOCK) - 1
p = strchr(p, '/')
if (p == NULL)
/* exactly one path element after "/block/" */
return false
/* If there are more path elements, it's a partition */
return true
}> +bool
> +uevent_can_filter(struct uevent *earlier, struct uevent *later) > +{
> +
> + /*
> + * filter earlier uvents if path has removed later. Eg:
> + * "add path1 |chang path1 |add path2 |remove path1"
> + * can filter as:
> + * "add path2 |remove path1"
> + * uevents "add path1" and "chang path1" are filtered out
> + */
> + if (!strcmp(earlier->kernel, later->kernel) &&
> + !strcmp(later->action, "remove") &&
> + strncmp(later->kernel, "dm-", 3)) {
> + return true
> + }
> +
> + /*
> + * filter change uvents if add uevents exist. Eg:
> + * "change path1| add path1 |add path2"
> + * can filter as:
> + * "add path1 |add path2"
> + * uevent "chang path1" is filtered out
> + */
> + if (!strcmp(earlier->kernel, later->kernel) &&
> + !strcmp(earlier->action, "change") &&
> + !strcmp(later->action, "add") &&
> + strncmp(later->kernel, "dm-", 3)) {
> + return true> + }
> +
> + return false
> +}
This would be better readable and faster if you'd put the "kernel" tests first so that you need to check only "action" later:
if (!strncmp(later->kernel, "dm-", 3) ||
strcmp(earlier->kernel, later->kernel))
return false> +
> +bool
> +merge_need_stop(struct uevent *earlier, struct uevent *later) > +{
> + /*
> + * dm uevent do not try to merge with left uevents
> + */
> + if (!strncmp(later->kernel, "dm-", 3))
> + return true
> +
> + /*
> + * we can not make a jugement without wwid, > + * so it is sensible to stop merging > + */
> + if (!earlier->wwid || !later->wwid)
> + return true
> + /*
> + * uevents merging stoped
> + * when we meet an opposite action uevent from the same LUN
> to AVOID
> + * "add path1 |remove path1 |add path2 |remove path2 |add
> path3"
> + * to merge as "remove path1, path2" and "add path1, path2,
> path3"
> + * OR
> + * "remove path1 |add path1 |remove path2 |add path2 |remove
> path3"
> + * to merge as "add path1, path2" and "remove path1, path2,
> path3"
> + * SO > + * when we meet a non-change uevent from the same LUN > + * with the same wwid and different action > + * it would be better to stop merging. > + */ > + if (!strcmp(earlier->wwid, later->wwid) && > + strcmp(earlier->action, later->action) && > + strcmp(earlier->action, "change") && > + strcmp(later->action, "change")) > + return true
> +
> + return false
> +}
I know you discussed this with Ben before, but still have some trouble with it.
The first case should have been reduced to "remove path1 | remove path2 | add path3" by filtering beforehand. I suppose you want to avoid this sequence because it could leave us without paths temporarily, causing multipathd to destroy the map. But I don't understand what "stop merging" buys you here - if you process the events one-by-one, you may also have 0 paths at some point.
In the second case, we know all events in the sequence have the same WWID in this case I think it would be safe to filter away "remove" events by subsequent "add" events, ending up with "add path1| add path2| remove path3". But I may be overlooking something here.
The dangerous thing if you have simultaneous remove and add events for the same LUN is that processing the "add" events is likely to fail in domap(). If you get "add path1 | remove path2", once you process "add path1", "path2" may not exist in the kernel any more, and "domap" will fail if you try to set up both you may end up removing the map completely. IMHO the only safe way to process events in this situation is to merge the events into a single domap() call.
I know you want to avoid that in this patch, but I think it will be a logical further improvement.
Anyway, AFAICS your patch doesn't introduce a regression wrt the current code here unless I'm overlooking something, my arguments would apply to sequential event processing as well.
Regards
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerQuoted 88 lines · On Fri, Feb 17, 2017 at 11:24:10AM +0800, [email protected] wrote:
Hello Martin,
Thanks for your responsible,
> I'd like the following better for this check. It uses much less cycles.
> static bool
> can_discard_by_devpath(const char *devpath)> This would be better readable and faster if you'd put the "kernel" > tests first so that you need to check only "action" later:
> if (!strncmp(later->kernel, "dm-", 3) || >
strcmp(earlier->kernel, later->kernel)) > return false;Yes, I think these codes can be reworked, but since they have no logical
effect, and this patch takes too long time, can you commit a new patch
to rework these codes?
> The first case should have been reduced to "remove path1 | remove path2
> | add path3" by filtering beforehand. I suppose you want to avoid this
> sequence because it could leave us without paths temporarily, causing
> multipathd to destroy the map. But I don't understand what "stop
> merging" buys you here - if you process the events one-by-one, you may
> also have 0 paths at some point.
>
> In the second case, we know all events in the sequence have the same
> WWID; in this case I think it would be safe to filter away "remove"
> events by subsequent "add" events, ending up with "add path1| add
> path2| remove path3". But I may be overlooking something here.
> The dangerous thing if you have simultaneous remove and add events for
> the same LUN is that processing the "add" events is likely to fail in
>
domap(). If you get "add path1 | remove path2", once you process "add> path1", "path2" may not exist in the kernel any more, and "domap" will
> fail if you try to set up both; you may end up removing the map
> completely. IMHO the only safe way to process events in this situation
> is to merge the events into a single
domap()call."case 2: remove path1 |add path1 |remove path2 |add path2 |remove path3"
Since the mergering is starting from the latest to the eariest uevent, so the
uevent "remove path3" try to merger other uevents, if we do not stop mergering,
uevent "remove path3" would merge uevent "remove path2" and uevent
"remove path1". Uevent "add path2" would merge "add path1".
The result is that we get two merged uevents:
1) add path2, path1
2) remove path3, path2, path1
Then we process the merged uevents from the earlier to later, We try to ”add
path2 path1“, and we would create or reload a map device with path1 and path2.
Next we process ” remove path3, path2, path1“, so path1, path2 and path3 are
all removed from the map device, this is wrong, the correct result is that the path1
Quoted 6 lines
and path2 should be still in the map device.
Just as you say, this patch is just a shape, we need more testing, and maybe
more patches are needed to make it better.
But in theory, you could have one merged uevent where you
remove path1, add path1, remove path2, add path2, remove path3, and then call domap one time.
As long as you keep them in right order, I think you could just merge add and remove events. But what you have right now handles the common cases, which are bursts of add/chage events, and bursts of remove events.
-Ben
Quoted 182 lines
Thank you,
Tang Junhui
原始邮件
发件人: <[email protected]>;
收件人:唐军辉10074136; <[email protected]>;
<[email protected]>; <[email protected]>; <[email protected]>;
抄送人:张凯10072500; <[email protected]>;唐文俊10144149;
日 期 :2017年02月17日 05:22
主 题 :Re: [dm-devel] [PATCH] multipath-tools: improve processing
efficiency for addition and deletion of multipath devices
Hello Tang,
I'm sorry to reply so late. Thanks a lot for your work, I agree with
Ben that the patch is in pretty good shape now. But I have some
remarks left, please see below.
> +bool
> +uevent_can_discard(struct uevent *uev)
> +{
> + char *tmp;
> + char a[11], b[11];
> + struct config * conf;
> +
> + /*
> + * keep only block devices, discard partitions
> + */
> + tmp = strstr(uev->devpath, "/block/");
> + if (tmp == NULL){
> + condlog(4, "no /block/ in '%s'", uev->devpath);
> + return true;
> + }
> + if (sscanf(tmp, "/block/%10s", a) != 1 ||
> + sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) {
> + condlog(4, "discard event on %s", uev->devpath);
> + return true;
> + }
I'd like the following better for this check. It uses much less cycles.
static bool
can_discard_by_devpath(const char *devpath)
{
static const char BLOCK[] = "/block/";
const char *p;
p = strstr(pathstr, BLOCK);
if (p == NULL)
/* not a block device */
return true;
p += sizeof(BLOCK) - 1;
p = strchr(p, '/');
if (p == NULL)
/* exactly one path element after "/block/" */
return false;
/* If there are more path elements, it's a partition */
return true;
}
> +bool
> +uevent_can_filter(struct uevent *earlier, struct uevent *later)
> +{
> +
> + /*
> + * filter earlier uvents if path has removed later. Eg:
> + * "add path1 |chang path1 |add path2 |remove path1"
> + * can filter as:
> + * "add path2 |remove path1"
> + * uevents "add path1" and "chang path1" are filtered out
> + */
> + if (!strcmp(earlier->kernel, later->kernel) &&
> + !strcmp(later->action, "remove") &&
> + strncmp(later->kernel, "dm-", 3)) {
> + return true;
> + }
> +
> + /*
> + * filter change uvents if add uevents exist. Eg:
> + * "change path1| add path1 |add path2"
> + * can filter as:
> + * "add path1 |add path2"
> + * uevent "chang path1" is filtered out
> + */
> + if (!strcmp(earlier->kernel, later->kernel) &&
> + !strcmp(earlier->action, "change") &&
> + !strcmp(later->action, "add") &&
> + strncmp(later->kernel, "dm-", 3)) {
> + return true;
> + }
> +
> + return false;
> +}
This would be better readable and faster if you'd put the "kernel"
tests first so that you need to check only "action" later:
if (!strncmp(later->kernel, "dm-", 3) ||
strcmp(earlier->kernel, later->kernel))
return false;
> +
> +bool
> +merge_need_stop(struct uevent *earlier, struct uevent *later)
> +{
> + /*
> + * dm uevent do not try to merge with left uevents
> + */
> + if (!strncmp(later->kernel, "dm-", 3))
> + return true;
> +
> + /*
> + * we can not make a jugement without wwid,
> + * so it is sensible to stop merging
> + */
> + if (!earlier->wwid || !later->wwid)
> + return true;
> + /*
> + * uevents merging stoped
> + * when we meet an opposite action uevent from the same LUN
> to AVOID
> + * "add path1 |remove path1 |add path2 |remove path2 |add
> path3"
> + * to merge as "remove path1, path2" and "add path1, path2,
> path3"
> + * OR
> + * "remove path1 |add path1 |remove path2 |add path2 |remove
> path3"
> + * to merge as "add path1, path2" and "remove path1, path2,
> path3"
> + * SO
> + * when we meet a non-change uevent from the same LUN
> + * with the same wwid and different action
> + * it would be better to stop merging.
> + */
> + if (!strcmp(earlier->wwid, later->wwid) &&
> + strcmp(earlier->action, later->action) &&
> + strcmp(earlier->action, "change") &&
> + strcmp(later->action, "change"))
> + return true;
> +
> + return false;
> +}
I know you discussed this with Ben before, but still have some trouble
with it.
The first case should have been reduced to "remove path1 | remove path2
| add path3" by filtering beforehand. I suppose you want to avoid this
sequence because it could leave us without paths temporarily, causing
multipathd to destroy the map. But I don't understand what "stop
merging" buys you here - if you process the events one-by-one, you may
also have 0 paths at some point.
In the second case, we know all events in the sequence have the same
WWID; in this case I think it would be safe to filter away "remove"
events by subsequent "add" events, ending up with "add path1| add
path2| remove path3". But I may be overlooking something here.
The dangerous thing if you have simultaneous remove and add events for
the same LUN is that processing the "add" events is likely to fail in
domap(). If you get "add path1 | remove path2", once you process "add
path1", "path2" may not exist in the kernel any more, and "domap" will
fail if you try to set up both; you may end up removing the map
completely. IMHO the only safe way to process events in this situation
is to merge the events into a single domap() call.
I know you want to avoid that in this patch, but I think it will be a
logical further improvement.
Anyway, AFAICS your patch doesn't introduce a regression wrt the
current code here; unless I'm overlooking something, my arguments would
apply to sequential event processing as well.
Regards
Martin
-- Quoted 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 17 lines · On Fri, 2017-02-17 at 11:24 +0800, [email protected] wrote:
Hello Martin,
Thanks for your responsible,
> I'd like the following better for this check. It uses much less cyc les.
> static bool
> can_discard_by_devpath(const char *devpath)> This would be better readable and faster if you'd put the "kernel" > tests first so that you need to check only "action" later:
> if (!strncmp(later->kernel, "dm-", 3) ||
>strcmp(earlier->kernel, later->kernel))
> return false;
Quoted 5 lines
Yes, I think these codes can be reworked, but since they have no logical
effect, and this patch takes too long time, can you commit a new patch
to rework these codes?
Yes, I could do that.
Regards
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Hello Tang,
> In the second case, we know all events in the sequence have the
Quoted 30 lines
same
> WWID; in this case I think it would be safe to filter away "remove" > events by subsequent "add" events, ending up with "add path1| add > path2| remove path3". But I may be overlooking something here.> The dangerous thing if you have simultaneous remove and add events for
> the same LUN is that processing the "add" events is likely to fail in
>domap(). If you get "add path1 | remove path2", once you process "add
> path1", "path2" may not exist in the kernel any more, and "domap" will
> fail if you try to set up both; you may end up removing the map > completely. IMHO the only safe way to process events in this situation
> is to merge the events into a singledomap()call."case 2: remove path1 |add path1 |remove path2 |add path2 |remove path3"
Since the mergering is starting from the latest to the eariest uevent, so the
uevent "remove path3" try to merger other uevents, if we do not stop mergering,
uevent "remove path3" would merge uevent "remove path2" and uevent "remove path1". Uevent "add path2" would merge "add path1". The result is that we get two merged uevents:
1) add path2, path1
2) remove path3, path2, path1
Quoted 9 lines
Then we process the merged uevents from the earlier to later, We try to ”add
path2 path1“, and we would create or reload a map device with path1 and path2.
Next we process ” remove path3, path2, path1“, so path1, path2 and path3 are
all removed from the map device, this is wrong, the correct result is that the path1
and path2 should be still in the map device.
I don't understand that. This would mean that you'd re-order "remove path1 | add path1" into "add path1| remove path1", and the same for path2. That may obviously never happen. Your "stop merging" logic forbids it, and that's fine for me for now.
Regards
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Hello Martin,
This exmaple shows why we need to stop merging,
Yes, It's fine since we have "stop merging" in current code.
RegardsTang
原始邮件
发件人: <[email protected]>
收件人: <[email protected]>
日 期 :2017年02月20日 19:24
主 题 :Re: [dm-devel] 答复: Re: [PATCH] multipath-tools: improve processing efficiency for addition and deletion of multipath devices
Hello Tang,
> In the second case, we know all events in the sequence have the > same
> > WWID in this case I think it would be safe to filter away "remove" > > events by subsequent "add" events, ending up with "add path1| add > > path2| remove path3". But I may be overlooking something here. >
> > The dangerous thing if you have simultaneous remove and add events > for
> > the same LUN is that processing the "add" events is likely to fail > in
> > domap(). If you get "add path1 | remove path2", once you process > "add
> > path1", "path2" may not exist in the kernel any more, and "domap" > will
> > fail if you try to set up both you may end up removing the map > > completely. IMHO the only safe way to process events in this > situation
> > is to merge the events into a single domap() call.
>
> "case 2: remove path1 |add path1 |remove path2 |add path2 |remove > path3"
> Since the mergering is starting from the latest to the eariest > uevent, so the
> uevent "remove path3" try to merger other uevents, if we do not stop > mergering,
> uevent "remove path3" would merge uevent "remove path2" and uevent > "remove path1". Uevent "add path2" would merge "add path1". > The result is that we get two merged uevents:
> 1) add path2, path1
> 2) remove path3, path2, path1
> Then we process the merged uevents from the earlier to later, We try > to ”add
> path2 path1“, and we would create or reload a map device with path1 > and path2.
> Next we process ” remove path3, path2, path1“, so path1, path2 and > path3 are
> all removed from the map device, this is wrong, the correct result > is that the path1
> and path2 should be still in the map device.
I don't understand that. This would mean that you'd re-order "remove path1 | add path1" into "add path1| remove path1", and the same for path2. That may obviously never happen. Your "stop merging" logic forbids it, and that's fine for me for now.
Regards
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerQuoted 135 lines · Martin Wilck
Hello Tang,
I'm sorry to reply so late. Thanks a lot for your work, I agree with Ben that the patch is in pretty good shape now. But I have some remarks left, please see below.
Quoted 10 lines
libmultipath/uevent.c +10
-0+bool +uevent_can_discard (struct uevent *uev) +{ +char *tmp; +char a[11 ], b[11 ]; +struct config * conf; + +/* +* keep only block devices, discard partitions +*/ libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 165
Quoted 10 lines
libmultipath/uevent.c +10
-0+ tmp =strstr (uev->devpath,"/block/" ); +if (tmp ==NULL ){ +condlog (4 ,"no /block/ in '%s'" , uev->devpath); +return true; + } +if (sscanf (tmp,"/block/%10s" , a) !=1 || + sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) { +condlog (4 ,"discard event on %s" , uev->devpath); +return true; + }I'd like the following better for this check. It uses much less cycles.
static bool
can_discard_by_devpath(const char *devpath){ static const char BLOCK[] = "/block/"; const char *p; p = strstr(pathstr, BLOCK); if (p == NULL) /* not a block device */ return true; p += sizeof(BLOCK) - 1; p = strchr(p, '/'); if (p == NULL) /* exactly one path element after "/block/" */ return false; /* If there are more path elements, it's a partition */ return true; }Quoted 23 lines
libmultipath/uevent.c +23
-0+bool +uevent_can_filter (struct uevent *earlier,struct uevent *later) +{ + +/* +* filter earlier uvents if path has removed later. Eg: +* "add path1 |chang path1 |add path2 |remove path1" +* can filter as: +* "add path2 |remove path1" +* uevents "add path1" and "chang path1" are filtered out +*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (later->action,"remove" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +/* +* filter change uvents if add uevents exist. Eg: +* "change path1| add path1 |add path2" +* can filter as: +* "add path1 |add path2" +* uevent "chang path1" is filtered out libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 218
Quoted 10 lines
libmultipath/uevent.c +10
-0+*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (earlier->action,"change" ) && + !strcmp (later->action,"add" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +return false; +}This would be better readable and faster if you'd put the "kernel" tests first so that you need to check only "action" later:
if (!strncmp(later->kernel, "dm-", 3) || strcmp(earlier->kernel, later->kernel)) return false;Quoted 32 lines
libmultipath/uevent.c +19
-0+ +bool +merge_need_stop (struct uevent *earlier,struct uevent *later) +{ +/* +* dm uevent do not try to merge with left uevents +*/ +if (!strncmp (later->kernel,"dm-" ,3 )) +return true; + +/* +* we can not make a jugement without wwid, +* so it is sensible to stop merging +*/ +if (!earlier->wwid || !later->wwid) +return true; +/* +* uevents merging stoped +* when we meet an opposite action uevent from the same LUN to AVOID
(quoted diff) +1
-0+ * "add path1 |remove path1 |add path2 |remove path2 |addpath3"
(quoted diff) +1
-0+ * to merge as "remove path1, path2" and "add path1, path2,path3"
(quoted diff) +2
-0+ * OR + * "remove path1 |add path1 |remove path2 |add path2 |removepath3"
(quoted diff) +1
-0+ * to merge as "add path1, path2" and "remove path1, path2,path3"
libmultipath/uevent.c +3
-0+ * SO + * when we meet a non-change uevent from the same LUN + * with the same wwid and different actionlibmultipath/uevent.c struct uevent * alloc_uevent (void) · line 255
Quoted 10 lines
libmultipath/uevent.c +10
-0+* it would be better to stop merging. +*/ +if (!strcmp (earlier->wwid, later->wwid) && + strcmp(earlier->action, later->action) && + strcmp(earlier->action, "change") && + strcmp(later->action, "change")) +return true; + +return false; +}I know you discussed this with Ben before, but still have some trouble with it.
Quoted 6 lines
The first case should have been reduced to "remove path1 | remove path2 | add path3" by filtering beforehand. I suppose you want to avoid this sequence because it could leave us without paths temporarily, causing multipathd to destroy the map. But I don't understand what "stop merging" buys you here - if you process the events one-by-one, you may also have 0 paths at some point.
Well, because of the filtering , you will never actually stop merging in this case, like you mentioned.
Quoted 4 lines
In the second case, we know all events in the sequence have the same WWID; in this case I think it would be safe to filter away "remove" events by subsequent "add" events, ending up with "add path1| add path2| remove path3". But I may be overlooking something here.
We can't filter out the remove path events in this case. If you have
add sdb | remove sdb
You know that sdb in the remove event is referring to the same device as sdb in the add event. If you have
remove sdb | add sdb
There is no guarantee that sdb in the add event is referring to the same LUN as sdb in the remove event. Once the device gets removed that name can get reused for anything.
Quoted 23 lines
The dangerous thing if you have simultaneous remove and add events for the same LUN is that processing the "add" events is likely to fail in
domap(). If you get "add path1 | remove path2", once you process "add path1", "path2" may not exist in the kernel any more, and "domap" will fail if you try to set up both; you may end up removing the map completely. IMHO the only safe way to process events in this situation is to merge the events into a singledomap()call.I know you want to avoid that in this patch, but I think it will be a logical further improvement.
Anyway, AFAICS your patch doesn't introduce a regression wrt the current code here; unless I'm overlooking something, my arguments would apply to sequential event processing as well.
Regards
MartinSignature · 3 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)
Benjamin Marzinski
maintainerOn Thu, Feb 16, 2017 at 11:38:36PM -0600, Benjamin Marzinski wrote:
Quite possibly, I shouldn't try responding to email at 11:30 PM. It appears that my brain has already given up for the day.
Quoted 143 lines · Martin Wilck
Quoted 135 lines
Hello Tang,
I'm sorry to reply so late. Thanks a lot for your work, I agree with Ben that the patch is in pretty good shape now. But I have some remarks left, please see below.
Quoted 10 lines
libmultipath/uevent.c +10
-0+bool +uevent_can_discard (struct uevent *uev) +{ +char *tmp; +char a[11 ], b[11 ]; +struct config * conf; + +/* +* keep only block devices, discard partitions +*/ libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 165
Quoted 10 lines
libmultipath/uevent.c +10
-0+ tmp =strstr (uev->devpath,"/block/" ); +if (tmp ==NULL ){ +condlog (4 ,"no /block/ in '%s'" , uev->devpath); +return true; + } +if (sscanf (tmp,"/block/%10s" , a) !=1 || + sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) { +condlog (4 ,"discard event on %s" , uev->devpath); +return true; + }I'd like the following better for this check. It uses much less cycles.
static bool
can_discard_by_devpath(const char *devpath){ static const char BLOCK[] = "/block/"; const char *p; p = strstr(pathstr, BLOCK); if (p == NULL) /* not a block device */ return true; p += sizeof(BLOCK) - 1; p = strchr(p, '/'); if (p == NULL) /* exactly one path element after "/block/" */ return false; /* If there are more path elements, it's a partition */ return true; }Quoted 23 lines
libmultipath/uevent.c +23
-0+bool +uevent_can_filter (struct uevent *earlier,struct uevent *later) +{ + +/* +* filter earlier uvents if path has removed later. Eg: +* "add path1 |chang path1 |add path2 |remove path1" +* can filter as: +* "add path2 |remove path1" +* uevents "add path1" and "chang path1" are filtered out +*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (later->action,"remove" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +/* +* filter change uvents if add uevents exist. Eg: +* "change path1| add path1 |add path2" +* can filter as: +* "add path1 |add path2" +* uevent "chang path1" is filtered out libmultipath/uevent.c struct uevent * alloc_uevent (void) · line 218
Quoted 10 lines
libmultipath/uevent.c +10
-0+*/ +if (!strcmp (earlier->kernel, later->kernel) && + !strcmp (earlier->action,"change" ) && + !strcmp (later->action,"add" ) && +strncmp (later->kernel,"dm-" ,3 )) { +return true; + } + +return false; +}This would be better readable and faster if you'd put the "kernel" tests first so that you need to check only "action" later:
if (!strncmp(later->kernel, "dm-", 3) || strcmp(earlier->kernel, later->kernel)) return false;Quoted 32 lines
libmultipath/uevent.c +19
-0+ +bool +merge_need_stop (struct uevent *earlier,struct uevent *later) +{ +/* +* dm uevent do not try to merge with left uevents +*/ +if (!strncmp (later->kernel,"dm-" ,3 )) +return true; + +/* +* we can not make a jugement without wwid, +* so it is sensible to stop merging +*/ +if (!earlier->wwid || !later->wwid) +return true; +/* +* uevents merging stoped +* when we meet an opposite action uevent from the same LUN to AVOID
(quoted diff) +1
-0+ * "add path1 |remove path1 |add path2 |remove path2 |addpath3"
(quoted diff) +1
-0+ * to merge as "remove path1, path2" and "add path1, path2,path3"
(quoted diff) +2
-0+ * OR + * "remove path1 |add path1 |remove path2 |add path2 |removepath3"
(quoted diff) +1
-0+ * to merge as "add path1, path2" and "remove path1, path2,path3"
libmultipath/uevent.c +3
-0+ * SO + * when we meet a non-change uevent from the same LUN + * with the same wwid and different actionlibmultipath/uevent.c struct uevent * alloc_uevent (void) · line 255
Quoted 10 lines
libmultipath/uevent.c +10
-0+* it would be better to stop merging. +*/ +if (!strcmp (earlier->wwid, later->wwid) && + strcmp(earlier->action, later->action) && + strcmp(earlier->action, "change") && + strcmp(later->action, "change")) +return true; + +return false; +}I know you discussed this with Ben before, but still have some trouble with it.
Quoted 6 lines
The first case should have been reduced to "remove path1 | remove path2 | add path3" by filtering beforehand. I suppose you want to avoid this sequence because it could leave us without paths temporarily, causing multipathd to destroy the map. But I don't understand what "stop merging" buys you here - if you process the events one-by-one, you may also have 0 paths at some point.
Quoted 2 lines
Well, because of the filtering , you will never actually stop merging in this case, like you mentioned.
Or, if I actually read better, I would see that you will stop merging. I can't think of any problems in theory with merging adds after removes in the simple case at least.
Quoted 9 lines
Quoted 4 lines
In the second case, we know all events in the sequence have the same WWID; in this case I think it would be safe to filter away "remove" events by subsequent "add" events, ending up with "add path1| add path2| remove path3". But I may be overlooking something here.
We can't filter out the remove path events in this case. If you have
add sdb | remove sdb
Quoted 8 lines
You know that sdb in the remove event is referring to the same device as sdb in the add event. If you have
remove sdb | add sdb
There is no guarantee that sdb in the add event is referring to the same LUN as sdb in the remove event. Once the device gets removed that name can get reused for anything.
Or you could change the filtering code to verify that the wwids matched. However, while the device would be for the same LUN, it might be a different I_T Nexus, so you still don't want to filter the remove of that specific device.
-Ben
Quoted 28 lines
Quoted 12 lines
The dangerous thing if you have simultaneous remove and add events for the same LUN is that processing the "add" events is likely to fail in
domap(). If you get "add path1 | remove path2", once you process "add path1", "path2" may not exist in the kernel any more, and "domap" will fail if you try to set up both; you may end up removing the map completely. IMHO the only safe way to process events in this situation is to merge the events into a singledomap()call.I know you want to avoid that in this patch, but I think it will be a logical further improvement.
Quoted 11 lines
Anyway, AFAICS your patch doesn't introduce a regression wrt the current code here; unless I'm overlooking something, my arguments would apply to sequential event processing as well.
Regards
MartinSignature · 3 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Hello Ben,
It's too later now, I think you'd better go bed, haha.
> > > The first case should have been reduced to "remove path1 | remove path2
> > > | add path3" by filtering beforehand. I suppose you want to avoid this
> > > sequence because it could leave us without paths temporarily, causing
> > > multipathd to destroy the map. But I don't understand what "stop
> > > merging" buys you here - if you process the events one-by-one, you may
> > > also have 0 paths at some point.
> >
> > Well, because of the filtering , you will never actually stop merging
> > in this case, like you mentioned.
>
> Or, if I actually read better, I would see that you will stop merging.
> I can't think of any problems in theory with merging adds after removes
> in the simple case at least.
Maybe we can merger more uevents without stopping mergering(Like even
merge "add uevent" and "remove uevent" ), but what I have right now handles
the common cases, which are bursts of add/chage events, and bursts of remove
events. So when we meet the complex scene, we'd better stop mergering,
and just let them be processed one by one. It can reduce abnormal situation,
and enhance the reliability of the code.
> > sdb in the add event. If you have
> >
> > remove sdb | add sdb
> >
> > There is no guarantee that sdb in the add event is referring to the same
> > LUN as sdb in the remove event. Once the device gets removed that name
> > can get reused for anything.
>
> Or you could change the filtering code to verify that the wwids matched.
> However, while the device would be for the same LUN, it might be a
> different I_T Nexus, so you still don't want to filter the remove of that
> specific device.
We didn't filter such uevent "remove sdb" in current codes, as you know, they
are quite possibly not the same LUN.
Regards,
Tang Junhui
原始邮件
发件人: <[email protected]>
收件人: <[email protected]>
抄送人:张凯10072500 <[email protected]>唐军辉10074136唐文俊10144149 <[email protected]>
日 期 :2017年02月17日 14:27
主 题 :Re: [dm-devel] [PATCH] multipath-tools: improve processing efficiency for addition and deletion of multipath devices
On Thu, Feb 16, 2017 at 11:38:36PM -0600, Benjamin Marzinski wrote:
Quite possibly, I shouldn't try responding to email at 11:30 PM. It appears that my brain has already given up for the day.
> On Thu, Feb 16, 2017 at 10:17:35PM +0100, Martin Wilck wrote:
> > Hello Tang,
> >
> > I'm sorry to reply so late. Thanks a lot for your work, I agree with > > Ben that the patch is in pretty good shape now. But I have some > > remarks left, please see below.
> >
> > > +bool
> > > +uevent_can_discard(struct uevent *uev)
> > > +{
> > > + char *tmp > > > + char a[11], b[11] > > > + struct config * conf
> > > +
> > > + /*
> > > + * keep only block devices, discard partitions
> > > + */
> > > + tmp = strstr(uev->devpath, "/block/")
> > > + if (tmp == NULL){
> > > + condlog(4, "no /block/ in '%s'", uev->devpath)
> > > + return true
> > > + }
> > > + if (sscanf(tmp, "/block/%10s", a) != 1 ||
> > > + sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) {
> > > + condlog(4, "discard event on %s", uev->devpath)
> > > + return true> > > + }
> >
> > I'd like the following better for this check. It uses much less cycles. > >
> > static bool
> > can_discard_by_devpath(const char *devpath)
> > {
> > static const char BLOCK[] = "/block/"
> > const char *p
> >
> > p = strstr(pathstr, BLOCK)
> > if (p == NULL)
> > /* not a block device */
> > return true
> > p += sizeof(BLOCK) - 1 > > p = strchr(p, '/') > > if (p == NULL)
> > /* exactly one path element after "/block/" */
> > return false
> > /* If there are more path elements, it's a partition */
> > return true
> > }
> >
> > > +bool
> > > +uevent_can_filter(struct uevent *earlier, struct uevent *later) > > > +{
> > > +
> > > + /*
> > > + * filter earlier uvents if path has removed later. Eg:
> > > + * "add path1 |chang path1 |add path2 |remove path1"
> > > + * can filter as:
> > > + * "add path2 |remove path1"
> > > + * uevents "add path1" and "chang path1" are filtered out
> > > + */
> > > + if (!strcmp(earlier->kernel, later->kernel) &&
> > > + !strcmp(later->action, "remove") &&
> > > + strncmp(later->kernel, "dm-", 3)) {
> > > + return true
> > > + }
> > > +
> > > + /*
> > > + * filter change uvents if add uevents exist. Eg:
> > > + * "change path1| add path1 |add path2"
> > > + * can filter as:
> > > + * "add path1 |add path2"
> > > + * uevent "chang path1" is filtered out
> > > + */
> > > + if (!strcmp(earlier->kernel, later->kernel) &&
> > > + !strcmp(earlier->action, "change") &&
> > > + !strcmp(later->action, "add") &&
> > > + strncmp(later->kernel, "dm-", 3)) {
> > > + return true> > > + }
> > > +
> > > + return false
> > > +}
> >
> > This would be better readable and faster if you'd put the "kernel" > > tests first so that you need to check only "action" later:
> >
> > if (!strncmp(later->kernel, "dm-", 3) ||
> > strcmp(earlier->kernel, later->kernel))
> > return false
> >
> > > +
> > > +bool
> > > +merge_need_stop(struct uevent *earlier, struct uevent *later) > > > +{
> > > + /*
> > > + * dm uevent do not try to merge with left uevents
> > > + */
> > > + if (!strncmp(later->kernel, "dm-", 3))
> > > + return true
> > > +
> > > + /*
> > > + * we can not make a jugement without wwid, > > > + * so it is sensible to stop merging > > > + */
> > > + if (!earlier->wwid || !later->wwid)
> > > + return true
> > > + /*
> > > + * uevents merging stoped
> > > + * when we meet an opposite action uevent from the same LUN
> > > to AVOID
> > > + * "add path1 |remove path1 |add path2 |remove path2 |add
> > > path3"
> > > + * to merge as "remove path1, path2" and "add path1, path2,
> > > path3"
> > > + * OR
> > > + * "remove path1 |add path1 |remove path2 |add path2 |remove
> > > path3"
> > > + * to merge as "add path1, path2" and "remove path1, path2,
> > > path3"
> > > + * SO > > > + * when we meet a non-change uevent from the same LUN > > > + * with the same wwid and different action > > > + * it would be better to stop merging. > > > + */ > > > + if (!strcmp(earlier->wwid, later->wwid) && > > > + strcmp(earlier->action, later->action) && > > > + strcmp(earlier->action, "change") && > > > + strcmp(later->action, "change")) > > > + return true
> > > +
> > > + return false
> > > +}
> >
> > I know you discussed this with Ben before, but still have some trouble > > with it.
> >
> > The first case should have been reduced to "remove path1 | remove path2 > > | add path3" by filtering beforehand. I suppose you want to avoid this > > sequence because it could leave us without paths temporarily, causing > > multipathd to destroy the map. But I don't understand what "stop > > merging" buys you here - if you process the events one-by-one, you may > > also have 0 paths at some point.
>
> Well, because of the filtering , you will never actually stop merging > in this case, like you mentioned.
Or, if I actually read better, I would see that you will stop merging. I can't think of any problems in theory with merging adds after removes in the simple case at least.
> > In the second case, we know all events in the sequence have the same > > WWID in this case I think it would be safe to filter away "remove" > > events by subsequent "add" events, ending up with "add path1| add > > path2| remove path3". But I may be overlooking something here. >
> We can't filter out the remove path events in this case. If you have >
> add sdb | remove sdb
>
> You know that sdb in the remove event is referring to the same device as > sdb in the add event. If you have
>
> remove sdb | add sdb
>
> There is no guarantee that sdb in the add event is referring to the same > LUN as sdb in the remove event. Once the device gets removed that name > can get reused for anything.
Or you could change the filtering code to verify that the wwids matched. However, while the device would be for the same LUN, it might be a different I_T Nexus, so you still don't want to filter the remove of that specific device.
-Ben
> >
> > The dangerous thing if you have simultaneous remove and add events for > > the same LUN is that processing the "add" events is likely to fail in > > domap(). If you get "add path1 | remove path2", once you process "add > > path1", "path2" may not exist in the kernel any more, and "domap" will > > fail if you try to set up both you may end up removing the map > > completely. IMHO the only safe way to process events in this situation > > is to merge the events into a single domap() call.
> >
> > I know you want to avoid that in this patch, but I think it will be a > > logical further improvement.
> >
> > Anyway, AFAICS your patch doesn't introduce a regression wrt the > > current code here unless I'm overlooking something, my arguments would > > apply to sequential event processing as well.
> >
> > Regards
> > Martin
> >
> > --
> > Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 > > SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton > > HRB 21284 (AG Nürnberg)
>
> --
> dm-devel mailing list
> [email protected]
> https://www.redhat.com/mailman/listinfo/dm-devel
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 29 lines · On Fri, 2017-02-17 at 15:41 +0800, [email protected] wrote:
Hello Ben,
It's too later now, I think you'd better go bed, haha.
> > > The first case should have been reduced to "remove path1 | remove path2
> > > | add path3" by filtering beforehand. I suppose you want to avoid this
> > > sequence because it could leave us without paths temporarily, causing
> > > multipathd to destroy the map. But I don't understand what "stop
> > > merging" buys you here - if you process the events one-by-one, you may
> > > also have 0 paths at some point.
> >
> > Well, because of the filtering , you will never actually stop merging
> > in this case, like you mentioned.
>
> Or, if I actually read better, I would see that you will stop merging.
> I can't think of any problems in theory with merging adds after removes
> in the simple case at least.
Maybe we can merger more uevents without stopping mergering(Like even
merge "add uevent" and "remove uevent" ), but what I have right now
Quoted 8 lines
handles
the common cases, which are bursts of add/chage events, and bursts of remove
events. So when we meet the complex scene, we'd better stop mergering,
and just let them be processed one by one. It can reduce abnormal situation,
and enhance the reliability of the code.
As I wrote in my previous mail, I am not sure if one-by-one processing is really safer. We are considering a situation where paths for one WWID are rapidly coming and going at the same time. In that situation it's inevitable that the kernel and multipathd get out of sync, and care needs to be taken not to destroy the multipath device prematurely.
Because uevents are unreliable and relatively slow, it may actually be a good idea to pause processing them altogether.
But again, I'm not expecting you to fix this in this patch set. It's just something we should keep in mind. And it's a good thing that you're trying not to break stuff :-)
Regards
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 93 lines · Benjamin Marzinski
Quoted 64 lines · Benjamin Marzinski
Quoted 57 lines
Quoted 37 lines
libmultipath/uevent.c +19
-0+ +bool +merge_need_stop (struct uevent *earlier,struct uevent *later) +{ +/* +* dm uevent do not try to merge with left uevents +*/ +if (!strncmp (later->kernel,"dm-" ,3 )) +return true; + +/* +* we can not make a jugement without wwid, +* so it is sensible to stop merging +*/ +if (!earlier->wwid || !later->wwid) +return true; +/* +* uevents merging stoped +* when we meet an opposite action uevent from the same LUN
to AVOID(quoted diff) +1
-0+ * "add path1 |remove path1 |add path2 |remove path2|add
path3"(quoted diff) +1
-0+ * to merge as "remove path1, path2" and "add path1,path2,
path3"(quoted diff) +2
-0+ * OR + * "remove path1 |add path1 |remove path2 |add path2|remove
path3"(quoted diff) +1
-0+ * to merge as "add path1, path2" and "remove path1,path2,
path3"libmultipath/uevent.c +3
-0+ * SO + * when we meet a non-change uevent from the same LUN + * with the same wwid and different actionlibmultipath/uevent.c struct uevent * alloc_uevent (void) · line 255
Quoted 10 lines
libmultipath/uevent.c +10
-0+* it would be better to stop merging. +*/ +if (!strcmp (earlier->wwid, later->wwid) && + strcmp(earlier->action, later->action) && + strcmp(earlier->action, "change") && + strcmp(later->action, "change")) +return true; + +return false; +}I know you discussed this with Ben before, but still have some trouble
with it.The first case should have been reduced to "remove path1 | remove path2
Quoted 2 lines
add path3" by filtering beforehand. I suppose you want to avoid this
Quoted 6 lines
sequence because it could leave us without paths temporarily, causing
multipathd to destroy the map. But I don't understand what "stop merging" buys you here - if you process the events one-by-one, you may
also have 0 paths at some point.Quoted 3 lines
Well, because of the filtering , you will never actually stop merging
in this case, like you mentioned.Or, if I actually read better, I would see that you will stop merging.
I can't think of any problems in theory with merging adds after removes
in the simple case at least.Quoted 18 lines
Quoted 6 lines
In the second case, we know all events in the sequence have the same
WWID; in this case I think it would be safe to filter away "remove"
events by subsequent "add" events, ending up with "add path1| add path2| remove path3". But I may be overlooking something here.We can't filter out the remove path events in this case. If you have
add sdb | remove sdb
You know that sdb in the remove event is referring to the same device as
sdb in the add event. If you haveremove sdb | add sdb
Quoted 8 lines
Quoted 5 lines
There is no guarantee that sdb in the add event is referring to the same
LUN as sdb in the remove event. Once the device gets removed that name
can get reused for anything.Or you could change the filtering code to verify that the wwids matched.
AFAICS this is already the case in this code path. merge_needs_stop() is run after determining the WWID, and will only ever act on devices with the same WWID.
Quoted 4 lines
However, while the device would be for the same LUN, it might be a different
I_TNexus, so you still don't want to filter the remove of that
specific device.
I figure this could be handled in uev_add_path() by not simply returning if an add event for an already existing device was encountered. But I agree that would be another, separate, patch.
Regards
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerQuoted 100 lines · Martin Wilck
Quoted 99 lines · Benjamin Marzinski
Quoted 64 lines · Benjamin Marzinski
Quoted 57 lines
Quoted 37 lines
libmultipath/uevent.c +19
-0+ +bool +merge_need_stop (struct uevent *earlier,struct uevent *later) +{ +/* +* dm uevent do not try to merge with left uevents +*/ +if (!strncmp (later->kernel,"dm-" ,3 )) +return true; + +/* +* we can not make a jugement without wwid, +* so it is sensible to stop merging +*/ +if (!earlier->wwid || !later->wwid) +return true; +/* +* uevents merging stoped +* when we meet an opposite action uevent from the same LUN
to AVOID(quoted diff) +1
-0+ * "add path1 |remove path1 |add path2 |remove path2|add
path3"(quoted diff) +1
-0+ * to merge as "remove path1, path2" and "add path1,path2,
path3"(quoted diff) +2
-0+ * OR + * "remove path1 |add path1 |remove path2 |add path2|remove
path3"(quoted diff) +1
-0+ * to merge as "add path1, path2" and "remove path1,path2,
path3"libmultipath/uevent.c +3
-0+ * SO + * when we meet a non-change uevent from the same LUN + * with the same wwid and different actionlibmultipath/uevent.c struct uevent * alloc_uevent (void) · line 255
Quoted 10 lines
libmultipath/uevent.c +10
-0+* it would be better to stop merging. +*/ +if (!strcmp (earlier->wwid, later->wwid) && + strcmp(earlier->action, later->action) && + strcmp(earlier->action, "change") && + strcmp(later->action, "change")) +return true; + +return false; +}I know you discussed this with Ben before, but still have some trouble
with it.The first case should have been reduced to "remove path1 | remove path2
Quoted 2 lines
add path3" by filtering beforehand. I suppose you want to avoid this
Quoted 6 lines
sequence because it could leave us without paths temporarily, causing
multipathd to destroy the map. But I don't understand what "stop merging" buys you here - if you process the events one-by-one, you may
also have 0 paths at some point.Quoted 3 lines
Well, because of the filtering , you will never actually stop merging
in this case, like you mentioned.Or, if I actually read better, I would see that you will stop merging.
I can't think of any problems in theory with merging adds after removes
in the simple case at least.Quoted 23 lines
Quoted 6 lines
In the second case, we know all events in the sequence have the same
WWID; in this case I think it would be safe to filter away "remove"
events by subsequent "add" events, ending up with "add path1| add path2| remove path3". But I may be overlooking something here.We can't filter out the remove path events in this case. If you have
add sdb | remove sdb
You know that sdb in the remove event is referring to the same device as
sdb in the add event. If you haveremove sdb | add sdb
There is no guarantee that sdb in the add event is referring to the same
LUN as sdb in the remove event. Once the device gets removed that name
can get reused for anything.
Quoted 7 lines
Quoted 2 lines
Or you could change the filtering code to verify that the wwids matched.
AFAICS this is already the case in this code path.
merge_needs_stop()is run after determining the WWID, and will only ever act on devices with the same WWID.
I was talking about filtering out the remove events. The filtering code simply looks at kernel names, which is fine if you don't filter out removes.
Quoted 9 lines
Quoted 4 lines
However, while the device would be for the same LUN, it might be a different
I_TNexus, so you still don't want to filter the remove of that
specific device.I figure this could be handled in
uev_add_path()by not simply returning if an add event for an already existing device was encountered. But I agree that would be another, separate, patch.
Assume a device like this (except not a scsi debug one).
mpathi (353333330000007d0) dm-10 Linux ,scsi_debug
size=1.0G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active | `- 10:0:0:0 sdh 8:112 active ready running |-+- policy='service-time 0' prio=1 status=enabled | `- 11:0:0:0 sdi 8:128 active ready running |-+- policy='service-time 0' prio=1 status=enabled | `- 13:0:0:0 sdk 8:160 active ready running
`-+- policy='service-time 0' prio=1 status=enabled
`- 12:0:0:0 sdj 8:144 active ready running
Now imagine that path sdk (13:0:0:0) had already gone away. After this you get a string of events that look liek
remove sdj | add sdj
Except the sdj that got removed was (12:0:0:0) and the one the got added was (13:0:0:0). In this case, skipping the completely and not adding the new device could get you a bad configuration, since (12:0:0:0) might have a different priority than (13:0:0:0). Skipping the remove and also adding the new device is also wrong because then you still have (12:0:0:0) in the multipath device, when it doesn't really exist.
I'm pretty sure that we can't ever filter out remove events.
-Ben
Quoted 7 lines
Regards
MartinSignature · 3 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)