multipath: add "count paths" multipathd command
Benjamin Marzinski
maintainerPATCH 1/1 multipath: add "count paths" multipathd command
This adds a new multipathd command, "count paths". which returns information in the format
Paths: <nr_of_paths>
Busy: <True|False>
where "Paths" is the number of monitored paths, and "Busy" is set when multipathd is currently handling uevents. With this, it is possible to quickly get the number of paths being monitored, as well as an idea if more paths may be showing up shortly.
--- libmultipath/uevent.c | 8 ++++++++ libmultipath/uevent.h | 1 + multipathd/cli.c | 2 ++ multipathd/cli.h | 2 ++ multipathd/cli_handlers.c | 33 +++++++++++++++++++++++++++++++++ multipathd/cli_handlers.h | 1 + multipathd/main.c | 1 + multipathd/multipathd.8 | 4 ++++ 8 files changed, 52 insertions(+)
libmultipath/uevent.c +8 -0
@@ -52,6 +52,12 @@ pthread_mutex_t uevc_lock, *uevc_lockp =pthread_cond_t uev_cond, *uev_condp = &uev_cond;uev_trigger *my_uev_trigger;void * my_trigger_data; +int servicing_uev; + +int is_uevent_busy (void ) +{ +return (uevqhp !=NULL || servicing_uev); +}static struct uevent *alloc_uevent (void ) {
@@ -96,7 +102,9 @@ uevq_thread(void * et)while (1 ) {pthread_mutex_lock (uevc_lockp); + servicing_uev =0 ;pthread_cond_wait (uev_condp, uevc_lockp); + servicing_uev =1 ;pthread_mutex_unlock (uevc_lockp);service_uevq ();
libmultipath/uevent.h +1 -0
@@ -17,3 +17,4 @@ struct uevent {int uevent_listen (int (*store_uev)(struct uevent *,void * trigger_data),void * trigger_data); +int is_uevent_busy (void );
multipathd/cli.c +2 -0
@@ -174,6 +174,7 @@ load_keys (void) r +=add_key (keys,"devices" ,DEVICES ,0 ); r +=add_key (keys,"format" ,FMT ,1 ); r +=add_key (keys,"wildcards" ,WILDCARDS ,0 ); + r +=add_key (keys,"count" ,COUNT ,0 ); r +=add_key (keys,"quit" ,QUIT ,0 ); r +=add_key (keys,"exit" ,QUIT ,0 );
@@ -443,6 +444,7 @@ cli_init (void) {add_handler (RESTOREQ +MAPS ,NULL );add_handler (REINSTATE +PATH ,NULL );add_handler (FAIL +PATH ,NULL ); +add_handler (COUNT +PATHS ,NULL );add_handler (QUIT ,NULL );return 0 ;
multipathd/cli_handlers.h +1 -0
@@ -25,5 +25,6 @@ int cli_restore_all_queueing(void * v, cint cli_suspend (void * v,char ** reply,int * len,void * data);int cli_resume (void * v,char ** reply,int * len,void * data);int cli_reinstate (void * v,char ** reply,int * len,void * data); +int cli_count_paths (void * v,char ** reply,int * len,void * data);int cli_fail (void * v,char ** reply,int * len,void * data);int cli_quit (void * v,char ** reply,int * len,void * data);
multipathd/main.c +1 -0
@@ -783,6 +783,7 @@ uxlsnrloop (void * ap)set_handler_callback (RESTOREQ +MAP , cli_restore_queueing);set_handler_callback (DISABLEQ +MAPS , cli_disable_all_queueing);set_handler_callback (RESTOREQ +MAPS , cli_restore_all_queueing); +set_handler_callback (COUNT +PATHS , cli_count_paths);set_handler_callback (QUIT , cli_quit);umask (077 );
multipathd/cli.h +2 -0
@@ -23,6 +23,7 @@ enum { __BLACKLIST, __DEVICES, __FMT, + __COUNT, __WILDCARDS, __QUIT, };
@@ -51,6 +52,7 @@ enum {#define BLACKLIST (1 << __BLACKLIST)#define DEVICES (1 << __DEVICES)#define FMT (1 << __FMT) +#define COUNT (1 << __COUNT)#define WILDCARDS (1 << __WILDCARDS)#define QUIT (1 << __QUIT)
multipathd/cli_handlers.c +33 -0
@@ -18,6 +18,29 @@#include "main.h" #include "cli.h" +#include "uevent.h" + +int +count_paths (char **r,int *l,struct vectors *vecs) +{ +int i, len; +struct path *pp; +char * reply; +unsigned int maxlen =INITIAL_REPLY_LEN ; +int monitored_count =0 ; + + reply =MALLOC (maxlen); +if (!reply) +return 1 ; + vector_foreach_slot(vecs->pathvec, pp, i) +if (pp->fd !=-1 ) + monitored_count++; + len =sprintf (reply,"Paths: %d\nBusy: %s\n" , monitored_count, +is_uevent_busy ()?"True" :"False" ); + *r = reply; + *l = len +1 ; +return 0 ; +}int show_paths (char ** r,int * len,struct vectors * vecs,char * style)
@@ -176,6 +199,16 @@ cli_list_config (void * v, char ** reply }int +cli_count_paths (void * v,char ** reply,int * len,void * data) +{ +struct vectors * vecs = (struct vectors *)data; + +condlog (3 ,"count paths (operator)" ); + +return count_paths (reply, len, vecs); +} + +int cli_list_paths (void * v,char ** reply,int * len,void * data) {struct vectors * vecs = (struct vectors *)data;
multipathd/multipathd.8 +4 -0
@@ -69,6 +69,10 @@ Add a path to the list of monitored path .B remove|del path $path Stop monitoring a path. $path is as listed in /sys/block (e.g. sda). .TP +.B count paths +Show the number of monitored paths, and whether multipathd is currently +handling a uevent. +.TP .B add map $map Add a multipath device to the list of monitored devices. $map can either be a device-mapper device as listed in /sys/block (e.g. dm-0) or it can be the alias for the multipath device (e.g. mpath1) or the uid of the multipath device (e.g. 36005076303ffc56200000000000010aa). .TP
Hi Ben,
Do you mind if I merge this output to the 'show status' command output ?
----- Message d'origine -----
Quoted 195 lines
This adds a new multipathd command, "count paths". which returns information in the format
Paths: <
nr_of_paths>
Busy: <True|False>where "Paths" is the number of monitored paths, and "Busy" is set when multipathd is currently handling uevents. With this, it is possible to quickly get the number of paths being monitored, as well as an idea if more paths may be showing up shortly.
Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/uevent.c | 8 ++++++++ libmultipath/uevent.h | 1 +
multipathd/cli.c | 2 ++ multipathd/cli.h | 2 ++multipathd/cli_handlers.c| 33 +++++++++++++++++++++++++++++++++multipathd/cli_handlers.h| 1 +
multipathd/main.c | 1 + multipathd/multipathd.8 | 4 ++++8 files changed, 52 insertions(+)Index:
multipath-tools-100510/libmultipath/uevent.c
===================================================================libmultipath/uevent.c +6
-0@@ -52,6 +52,12 @@ pthread_mutex_t uevc_lock, *uevc_lockp = pthread_cond_t uev_cond, *uev_condp = &uev_cond; uev_trigger *my_uev_trigger; void * my_trigger_data; +int servicing_uev; + +int is_uevent_busy (void ) +{ + return (uevqhp != NULL || servicing_uev); +}
static struct uevent *alloc_uevent(void)
{libmultipath/uevent.c +0
-0@@ -96,7 +102,9 @@ uevq_thread(void * et)
while (1) {pthread_mutex_lock(uevc_lockp);
+servicing_uev= 0;pthread_cond_wait(uev_condp, uevc_lockp); +servicing_uev= 1;pthread_mutex_unlock(uevc_lockp);
service_uevq();
Index:multipath-tools-100510/libmultipath/uevent.h
===================================================================libmultipath/uevent.h +0
-0@@ -17,3 +17,4 @@ struct uevent {
intuevent_listen(int (*store_uev)(struct uevent *, void * trigger_data), void * trigger_data);
+intis_uevent_busy(void);
Index:multipath-tools-100510/multipathd/cli.c
===================================================================multipathd/cli.c +1
-0@@ -174,6 +174,7 @@ load_keys (void) r += add_key(keys, "devices", DEVICES, 0); r += add_key(keys, "format", FMT, 1); r += add_key(keys, "wildcards", WILDCARDS, 0); + r += add_key(keys, "count", COUNT, 0); r += add_key(keys, "quit", QUIT, 0); r += add_key(keys, "exit", QUIT, 0);multipathd/cli.c +1
-0@@ -443,6 +444,7 @@ cli_init (void) { add_handler(RESTOREQ+MAPS, NULL); add_handler(REINSTATE+PATH, NULL); add_handler(FAIL+PATH, NULL); + add_handler(COUNT+PATHS, NULL); add_handler(QUIT, NULL);
return 0;
Index:multipath-tools-100510/multipathd/cli_handlers.h
===================================================================multipathd/cli_handlers.h +1
-0@@ -25,5 +25,6 @@ int cli_restore_all_queueing(void * v, c int cli_suspend(void * v, char ** reply, int * len, void * data); int cli_resume(void * v, char ** reply, int * len, void * data); int cli_reinstate(void * v, char ** reply, int * len, void * data); +int cli_count_paths (void * v,char ** reply,int * len,void * data); int cli_fail(void * v, char ** reply, int * len, void * data); int cli_quit(void * v, char ** reply, int * len, void * data);Index:
multipath-tools-100510/multipathd/main.c
===================================================================multipathd/main.c +1
-0@@ -783,6 +783,7 @@ uxlsnrloop (void * ap) set_handler_callback(RESTOREQ+MAP, cli_restore_queueing); set_handler_callback(DISABLEQ+MAPS, cli_disable_all_queueing); set_handler_callback(RESTOREQ+MAPS, cli_restore_all_queueing); + set_handler_callback(COUNT+PATHS, cli_count_paths); set_handler_callback(QUIT, cli_quit);
umask(077);
Index:multipath-tools-100510/multipathd/cli.h
===================================================================multipathd/cli.h +2
-0@@ -23,6 +23,7 @@ enum { __BLACKLIST, __DEVICES, __FMT, + __COUNT, __WILDCARDS, __QUIT, };@@ -51,6 +52,7 @@ enum { #define BLACKLIST (1 << __BLACKLIST) #define DEVICES (1 << __DEVICES) #define FMT (1 << __FMT) +#define COUNT (1 << __COUNT) #define WILDCARDS (1 << __WILDCARDS) #define QUIT (1 << __QUIT)
Index:multipath-tools-100510/multipathd/cli_handlers.c
===================================================================multipathd/cli_handlers.c +0
-0@@ -18,6 +18,29 @@
#include "main.h"
#include "cli.h"multipathd/cli_handlers.c +23
-0+#include "uevent.h" + +int +count_paths(char **r, int *l, struct vectors *vecs) +{ + int i, len; + struct path *pp; + char * reply; + unsigned int maxlen = INITIAL_REPLY_LEN; + int monitored_count = 0; + + reply = MALLOC(maxlen); + if (!reply) + return 1; + vector_foreach_slot(vecs->pathvec, pp, i) + if (pp->fd != -1) + monitored_count++; + len = sprintf(reply, "Paths: %d\nBusy: %s\n", monitored_count, + is_uevent_busy()? "True" : "False"); + *r = reply; + *l = len + 1; + return 0; +}
int
show_paths(char ** r, int * len, struct vectors * vecs, char * style)multipathd/cli_handlers.c +0
-0@@ -176,6 +199,16 @@ cli_list_config (void * v, char ** reply }
intmultipathd/cli_handlers.c +10
-0+cli_count_paths (void * v, char ** reply, int * len, void * data) +{ + struct vectors * vecs = (struct vectors *)data; + + condlog(3, "count paths (operator)"); + + return count_paths(reply, len, vecs); +} + +int
cli_list_paths(void * v, char ** reply, int * len, void * data) {
struct vectors * vecs = (struct vectors *)data;
Index: multipath-tools-100510/multipathd/multipathd.8
===================================================================multipathd/multipathd.8 +0
-0@@ -69,6 +69,10 @@ Add a path to the list of monitored path.B remove|del path $path
Stop monitoring a path. $path is as listed in/sys/block(e.g. sda). .TP
+.B count pathsmultipathd/multipathd.8 +3
-0+Show the number of monitored paths, and whether multipathd is currently +handling a uevent. +.TP.B add map $map
Add a multipath device to the list of monitored devices. $map can either be a device-mapper device as listed in/sys/block(e.g. dm-0) or it can be the alias for the multipath device (e.g. mpath1) or the uid of the multipath device (e.g. 36005076303ffc56200000000000010aa). .TP--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerQuoted 3 lines · Christophe Varoqui
Hi Ben,
Do you mind if I merge this output to the 'show status' command output ?
That's fine with me.
-Ben
Quoted 211 lines
----- Message d'origine ----- > This adds a new multipathd command, "count paths". which returns information in > the format > > Paths: <nr_of_paths> > Busy: <True|False> > > where "Paths" is the number of monitored paths, and "Busy" is set when > multipathd is currently handling uevents. With this, it is possible to quickly > get the number of paths being monitored, as well as an idea if more paths may > be showing up shortly. > > Signed-off-by: Benjamin Marzinski <[1][email protected]> > --- > libmultipath/uevent.c | 8 ++++++++ > libmultipath/uevent.h | 1 + > multipathd/cli.c | 2 ++ > multipathd/cli.h | 2 ++ > multipathd/cli_handlers.c | 33 +++++++++++++++++++++++++++++++++ > multipathd/cli_handlers.h | 1 + > multipathd/main.c | 1 + > multipathd/multipathd.8 | 4 ++++ > 8 files changed, 52 insertions(+) > > Index: multipath-tools-100510/libmultipath/uevent.c > =================================================================== > --- multipath-tools-100510.orig/libmultipath/uevent.c > +++ multipath-tools-100510/libmultipath/uevent.c > @@ -52,6 +52,12 @@ pthread_mutex_t uevc_lock, *uevc_lockp = > pthread_cond_t uev_cond, *uev_condp = &uev_cond; > uev_trigger *my_uev_trigger; > void * my_trigger_data; > +int servicing_uev; > + > +int is_uevent_busy(void) > +{ > + return (uevqhp != NULL || servicing_uev); > +} > > static struct uevent * alloc_uevent (void) > { > @@ -96,7 +102,9 @@ uevq_thread(void * et) > > while (1) { > pthread_mutex_lock(uevc_lockp); > + servicing_uev = 0; > pthread_cond_wait(uev_condp, uevc_lockp); > + servicing_uev = 1; > pthread_mutex_unlock(uevc_lockp); > > service_uevq(); > Index: multipath-tools-100510/libmultipath/uevent.h > =================================================================== > --- multipath-tools-100510.orig/libmultipath/uevent.h > +++ multipath-tools-100510/libmultipath/uevent.h > @@ -17,3 +17,4 @@ struct uevent { > > int uevent_listen(int (*store_uev)(struct uevent *, void * trigger_data), > void * trigger_data); > +int is_uevent_busy(void); > Index: multipath-tools-100510/multipathd/cli.c > =================================================================== > --- multipath-tools-100510.orig/multipathd/cli.c > +++ multipath-tools-100510/multipathd/cli.c > @@ -174,6 +174,7 @@ load_keys (void) > r += add_key(keys, "devices", DEVICES, 0); > r += add_key(keys, "format", FMT, 1); > r += add_key(keys, "wildcards", WILDCARDS, 0); > + r += add_key(keys, "count", COUNT, 0); > r += add_key(keys, "quit", QUIT, 0); > r += add_key(keys, "exit", QUIT, 0); > > @@ -443,6 +444,7 @@ cli_init (void) { > add_handler(RESTOREQ+MAPS, NULL); > add_handler(REINSTATE+PATH, NULL); > add_handler(FAIL+PATH, NULL); > + add_handler(COUNT+PATHS, NULL); > add_handler(QUIT, NULL); > > return 0; > Index: multipath-tools-100510/multipathd/cli_handlers.h > =================================================================== > --- multipath-tools-100510.orig/multipathd/cli_handlers.h > +++ multipath-tools-100510/multipathd/cli_handlers.h > @@ -25,5 +25,6 @@ int cli_restore_all_queueing(void * v, c > int cli_suspend(void * v, char ** reply, int * len, void * data); > int cli_resume(void * v, char ** reply, int * len, void * data); > int cli_reinstate(void * v, char ** reply, int * len, void * data); > +int cli_count_paths(void * v, char ** reply, int * len, void * data); > int cli_fail(void * v, char ** reply, int * len, void * data); > int cli_quit(void * v, char ** reply, int * len, void * data); > Index: multipath-tools-100510/multipathd/main.c > =================================================================== > --- multipath-tools-100510.orig/multipathd/main.c > +++ multipath-tools-100510/multipathd/main.c > @@ -783,6 +783,7 @@ uxlsnrloop (void * ap) > set_handler_callback(RESTOREQ+MAP, cli_restore_queueing); > set_handler_callback(DISABLEQ+MAPS, cli_disable_all_queueing); > set_handler_callback(RESTOREQ+MAPS, cli_restore_all_queueing); > + set_handler_callback(COUNT+PATHS, cli_count_paths); > set_handler_callback(QUIT, cli_quit); > > umask(077); > Index: multipath-tools-100510/multipathd/cli.h > =================================================================== > --- multipath-tools-100510.orig/multipathd/cli.h > +++ multipath-tools-100510/multipathd/cli.h > @@ -23,6 +23,7 @@ enum { > __BLACKLIST, > __DEVICES, > __FMT, > + __COUNT, > __WILDCARDS, > __QUIT, > }; > @@ -51,6 +52,7 @@ enum { > #define BLACKLIST (1 << __BLACKLIST) > #define DEVICES (1 << __DEVICES) > #define FMT (1 << __FMT) > +#define COUNT (1 << __COUNT) > #define WILDCARDS (1 << __WILDCARDS) > #define QUIT (1 << __QUIT) > > Index: multipath-tools-100510/multipathd/cli_handlers.c > =================================================================== > --- multipath-tools-100510.orig/multipathd/cli_handlers.c > +++ multipath-tools-100510/multipathd/cli_handlers.c > @@ -18,6 +18,29 @@ > > #include "main.h" > #include "cli.h" > +#include "uevent.h" > + > +int > +count_paths(char **r, int *l, struct vectors *vecs) > +{ > + int i, len; > + struct path *pp; > + char * reply; > + unsigned int maxlen = INITIAL_REPLY_LEN; > + int monitored_count = 0; > + > + reply = MALLOC(maxlen); > + if (!reply) > + return 1; > + vector_foreach_slot(vecs->pathvec, pp, i) > + if (pp->fd != -1) > + monitored_count++; > + len = sprintf(reply, "Paths: %d\nBusy: %s\n", monitored_count, > + is_uevent_busy()? "True" : "False"); > + *r = reply; > + *l = len + 1; > + return 0; > +} > > int > show_paths (char ** r, int * len, struct vectors * vecs, char * style) > @@ -176,6 +199,16 @@ cli_list_config (void * v, char ** reply > } > > int > +cli_count_paths (void * v, char ** reply, int * len, void * data) > +{ > + struct vectors * vecs = (struct vectors *)data; > + > + condlog(3, "count paths (operator)"); > + > + return count_paths(reply, len, vecs); > +} > + > +int > cli_list_paths (void * v, char ** reply, int * len, void * data) > { > struct vectors * vecs = (struct vectors *)data; > Index: multipath-tools-100510/multipathd/multipathd.8 > =================================================================== > --- multipath-tools-100510.orig/multipathd/multipathd.8 > +++ multipath-tools-100510/multipathd/multipathd.8 > @@ -69,6 +69,10 @@ Add a path to the list of monitored path > .B remove|del path $path > Stop monitoring a path. $path is as listed in /sys/block (e.g. sda). > .TP > +.B count paths > +Show the number of monitored paths, and whether multipathd is currently > +handling a uevent. > +.TP > .B add map $map > Add a multipath device to the list of monitored devices. $map can either be a > device-mapper device as listed in /sys/block (e.g. dm-0) or it can be the alias > for the multipath device (e.g. mpath1) or the uid of the multipath device (e.g. > 36005076303ffc56200000000000010aa). .TP > > -- > dm-devel mailing list > [2][email protected] > [3]https://www.redhat.com/mailman/listinfo/dm-develReferences
Visible links
1. mailto:[email protected]
2. mailto:[email protected]
3. https://www.redhat.com/mailman/listinfo/dm-devel