Message ID | 20210910114120.13665-13-mwilck@suse.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Delegated to: | christophe varoqui |
Headers | show |
Series | multipathd: uxlsnr overhaul | expand |
On Fri, Sep 10, 2021 at 01:40:57PM +0200, mwilck@suse.com wrote: > From: Martin Wilck <mwilck@suse.com> > > Modify set_handler_callback() such that a missing slot is created > if no matching slot is found. This way, we can skip the initialization > with NULL handlers on startup. > > Signed-off-by: Martin Wilck <mwilck@suse.com> > --- > multipathd/cli.c | 85 +++++++----------------------------------------- > multipathd/cli.h | 6 ++-- > 2 files changed, 15 insertions(+), 76 deletions(-) > > diff --git a/multipathd/cli.c b/multipathd/cli.c > index 5213813..7020d2b 100644 > --- a/multipathd/cli.c > +++ b/multipathd/cli.c > @@ -100,26 +100,20 @@ find_handler (uint64_t fp) > } > > int > -set_handler_callback (uint64_t fp, cli_handler *fn) > +__set_handler_callback (uint64_t fp, cli_handler *fn, bool locked) > { > - struct handler * h = find_handler(fp); > + struct handler *h = find_handler(fp); > Wouldn't it be a bug if we reset the handler? Is this really something we need to check for? Also, if add_handler() just returned a pointer to the handler, we wouldn't need to call fail_handler() immediately after creating it. -Ben > - if (!h) > + if (!h) { > + add_handler(fp, fn); > + h = find_handler(fp); > + } > + if (!h) { > + condlog(0, "%s: failed to set handler for code %"PRIu64, > + __func__, fp); > return 1; > - h->fn = fn; > - h->locked = 1; > - return 0; > -} > - > -int > -set_unlocked_handler_callback (uint64_t fp, cli_handler *fn) > -{ > - struct handler * h = find_handler(fp); > - > - if (!h) > - return 1; > - h->fn = fn; > - h->locked = 0; > + } > + h->locked = locked; > return 0; > } > > @@ -513,63 +507,6 @@ cli_init (void) { > if (alloc_handlers()) > return 1; > > - add_handler(LIST+PATHS, NULL); > - add_handler(LIST+PATHS+FMT, NULL); > - add_handler(LIST+PATHS+RAW+FMT, NULL); > - add_handler(LIST+PATH, NULL); > - add_handler(LIST+STATUS, NULL); > - add_handler(LIST+DAEMON, NULL); > - add_handler(LIST+MAPS, NULL); > - add_handler(LIST+MAPS+STATUS, NULL); > - add_handler(LIST+MAPS+STATS, NULL); > - add_handler(LIST+MAPS+FMT, NULL); > - add_handler(LIST+MAPS+RAW+FMT, NULL); > - add_handler(LIST+MAPS+TOPOLOGY, NULL); > - add_handler(LIST+MAPS+JSON, NULL); > - add_handler(LIST+TOPOLOGY, NULL); > - add_handler(LIST+MAP+TOPOLOGY, NULL); > - add_handler(LIST+MAP+JSON, NULL); > - add_handler(LIST+MAP+FMT, NULL); > - add_handler(LIST+MAP+RAW+FMT, NULL); > - add_handler(LIST+CONFIG, NULL); > - add_handler(LIST+CONFIG+LOCAL, NULL); > - add_handler(LIST+BLACKLIST, NULL); > - add_handler(LIST+DEVICES, NULL); > - add_handler(LIST+WILDCARDS, NULL); > - add_handler(RESET+MAPS+STATS, NULL); > - add_handler(RESET+MAP+STATS, NULL); > - add_handler(ADD+PATH, NULL); > - add_handler(DEL+PATH, NULL); > - add_handler(ADD+MAP, NULL); > - add_handler(DEL+MAP, NULL); > - add_handler(DEL+MAPS, NULL); > - add_handler(SWITCH+MAP+GROUP, NULL); > - add_handler(RECONFIGURE, NULL); > - add_handler(SUSPEND+MAP, NULL); > - add_handler(RESUME+MAP, NULL); > - add_handler(RESIZE+MAP, NULL); > - add_handler(RESET+MAP, NULL); > - add_handler(RELOAD+MAP, NULL); > - add_handler(DISABLEQ+MAP, NULL); > - add_handler(RESTOREQ+MAP, NULL); > - add_handler(DISABLEQ+MAPS, NULL); > - add_handler(RESTOREQ+MAPS, NULL); > - add_handler(REINSTATE+PATH, NULL); > - add_handler(FAIL+PATH, NULL); > - add_handler(QUIT, NULL); > - add_handler(SHUTDOWN, NULL); > - add_handler(GETPRSTATUS+MAP, NULL); > - add_handler(SETPRSTATUS+MAP, NULL); > - add_handler(UNSETPRSTATUS+MAP, NULL); > - add_handler(GETPRKEY+MAP, NULL); > - add_handler(SETPRKEY+MAP+KEY, NULL); > - add_handler(UNSETPRKEY+MAP, NULL); > - add_handler(FORCEQ+DAEMON, NULL); > - add_handler(RESTOREQ+DAEMON, NULL); > - add_handler(SETMARGINAL+PATH, NULL); > - add_handler(UNSETMARGINAL+PATH, NULL); > - add_handler(UNSETMARGINAL+MAP, NULL); > - > return 0; > } > > diff --git a/multipathd/cli.h b/multipathd/cli.h > index 3dac1b4..dbb75be 100644 > --- a/multipathd/cli.h > +++ b/multipathd/cli.h > @@ -134,8 +134,10 @@ struct handler { > > int alloc_handlers (void); > int add_handler (uint64_t fp, cli_handler *fn); > -int set_handler_callback (uint64_t fp, cli_handler *fn); > -int set_unlocked_handler_callback (uint64_t fp, cli_handler *fn); > +int __set_handler_callback (uint64_t fp, cli_handler *fn, bool locked); > +#define set_handler_callback(fp, fn) __set_handler_callback(fp, fn, true) > +#define set_unlocked_handler_callback(fp, fn) __set_handler_callback(fp, fn, false) > + > int parse_cmd (char * cmd, char ** reply, int * len, void *, int); > int load_keys (void); > char * get_keyparam (vector v, uint64_t code); > -- > 2.33.0 -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
On Wed, 2021-09-15 at 19:01 -0500, Benjamin Marzinski wrote: > On Fri, Sep 10, 2021 at 01:40:57PM +0200, mwilck@suse.com wrote: > > From: Martin Wilck <mwilck@suse.com> > > > > Modify set_handler_callback() such that a missing slot is created > > if no matching slot is found. This way, we can skip the > > initialization > > with NULL handlers on startup. > > > > Signed-off-by: Martin Wilck <mwilck@suse.com> > > --- > > multipathd/cli.c | 85 +++++++------------------------------------- > > ---- > > multipathd/cli.h | 6 ++-- > > 2 files changed, 15 insertions(+), 76 deletions(-) > > > > diff --git a/multipathd/cli.c b/multipathd/cli.c > > index 5213813..7020d2b 100644 > > --- a/multipathd/cli.c > > +++ b/multipathd/cli.c > > @@ -100,26 +100,20 @@ find_handler (uint64_t fp) > > } > > > > int > > -set_handler_callback (uint64_t fp, cli_handler *fn) > > +__set_handler_callback (uint64_t fp, cli_handler *fn, bool locked) > > { > > - struct handler * h = find_handler(fp); > > + struct handler *h = find_handler(fp); > > > > Wouldn't it be a bug if we reset the handler? Is this really > something > we need to check for? Also, if add_handler() just returned a pointer > to > the handler, we wouldn't need to call fail_handler() immediately > after > creating it. That makes sense. I'll resubmit. Regards, Martin > > -Ben > > > - if (!h) > > + if (!h) { > > + add_handler(fp, fn); > > + h = find_handler(fp); > > + } > > + if (!h) { > > + condlog(0, "%s: failed to set handler for code > > %"PRIu64, > > + __func__, fp); > > return 1; > > - h->fn = fn; > > - h->locked = 1; > > - return 0; > > -} > > - > > -int > > -set_unlocked_handler_callback (uint64_t fp, cli_handler *fn) > > -{ > > - struct handler * h = find_handler(fp); > > - > > - if (!h) > > - return 1; > > - h->fn = fn; > > - h->locked = 0; > > + } > > + h->locked = locked; > > return 0; > > } > > > > @@ -513,63 +507,6 @@ cli_init (void) { > > if (alloc_handlers()) > > return 1; > > > > - add_handler(LIST+PATHS, NULL); > > - add_handler(LIST+PATHS+FMT, NULL); > > - add_handler(LIST+PATHS+RAW+FMT, NULL); > > - add_handler(LIST+PATH, NULL); > > - add_handler(LIST+STATUS, NULL); > > - add_handler(LIST+DAEMON, NULL); > > - add_handler(LIST+MAPS, NULL); > > - add_handler(LIST+MAPS+STATUS, NULL); > > - add_handler(LIST+MAPS+STATS, NULL); > > - add_handler(LIST+MAPS+FMT, NULL); > > - add_handler(LIST+MAPS+RAW+FMT, NULL); > > - add_handler(LIST+MAPS+TOPOLOGY, NULL); > > - add_handler(LIST+MAPS+JSON, NULL); > > - add_handler(LIST+TOPOLOGY, NULL); > > - add_handler(LIST+MAP+TOPOLOGY, NULL); > > - add_handler(LIST+MAP+JSON, NULL); > > - add_handler(LIST+MAP+FMT, NULL); > > - add_handler(LIST+MAP+RAW+FMT, NULL); > > - add_handler(LIST+CONFIG, NULL); > > - add_handler(LIST+CONFIG+LOCAL, NULL); > > - add_handler(LIST+BLACKLIST, NULL); > > - add_handler(LIST+DEVICES, NULL); > > - add_handler(LIST+WILDCARDS, NULL); > > - add_handler(RESET+MAPS+STATS, NULL); > > - add_handler(RESET+MAP+STATS, NULL); > > - add_handler(ADD+PATH, NULL); > > - add_handler(DEL+PATH, NULL); > > - add_handler(ADD+MAP, NULL); > > - add_handler(DEL+MAP, NULL); > > - add_handler(DEL+MAPS, NULL); > > - add_handler(SWITCH+MAP+GROUP, NULL); > > - add_handler(RECONFIGURE, NULL); > > - add_handler(SUSPEND+MAP, NULL); > > - add_handler(RESUME+MAP, NULL); > > - add_handler(RESIZE+MAP, NULL); > > - add_handler(RESET+MAP, NULL); > > - add_handler(RELOAD+MAP, NULL); > > - add_handler(DISABLEQ+MAP, NULL); > > - add_handler(RESTOREQ+MAP, NULL); > > - add_handler(DISABLEQ+MAPS, NULL); > > - add_handler(RESTOREQ+MAPS, NULL); > > - add_handler(REINSTATE+PATH, NULL); > > - add_handler(FAIL+PATH, NULL); > > - add_handler(QUIT, NULL); > > - add_handler(SHUTDOWN, NULL); > > - add_handler(GETPRSTATUS+MAP, NULL); > > - add_handler(SETPRSTATUS+MAP, NULL); > > - add_handler(UNSETPRSTATUS+MAP, NULL); > > - add_handler(GETPRKEY+MAP, NULL); > > - add_handler(SETPRKEY+MAP+KEY, NULL); > > - add_handler(UNSETPRKEY+MAP, NULL); > > - add_handler(FORCEQ+DAEMON, NULL); > > - add_handler(RESTOREQ+DAEMON, NULL); > > - add_handler(SETMARGINAL+PATH, NULL); > > - add_handler(UNSETMARGINAL+PATH, NULL); > > - add_handler(UNSETMARGINAL+MAP, NULL); > > - > > return 0; > > } > > > > diff --git a/multipathd/cli.h b/multipathd/cli.h > > index 3dac1b4..dbb75be 100644 > > --- a/multipathd/cli.h > > +++ b/multipathd/cli.h > > @@ -134,8 +134,10 @@ struct handler { > > > > int alloc_handlers (void); > > int add_handler (uint64_t fp, cli_handler *fn); > > -int set_handler_callback (uint64_t fp, cli_handler *fn); > > -int set_unlocked_handler_callback (uint64_t fp, cli_handler *fn); > > +int __set_handler_callback (uint64_t fp, cli_handler *fn, bool > > locked); > > +#define set_handler_callback(fp, fn) __set_handler_callback(fp, > > fn, true) > > +#define set_unlocked_handler_callback(fp, fn) > > __set_handler_callback(fp, fn, false) > > + > > int parse_cmd (char * cmd, char ** reply, int * len, void *, int); > > int load_keys (void); > > char * get_keyparam (vector v, uint64_t code); > > -- > > 2.33.0 > > -- > dm-devel mailing list > dm-devel@redhat.com > https://listman.redhat.com/mailman/listinfo/dm-devel > -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
On Wed, 2021-09-15 at 19:01 -0500, Benjamin Marzinski wrote: > On Fri, Sep 10, 2021 at 01:40:57PM +0200, mwilck@suse.com wrote: > > From: Martin Wilck <mwilck@suse.com> > > > > Modify set_handler_callback() such that a missing slot is created > > if no matching slot is found. This way, we can skip the > > initialization > > with NULL handlers on startup. > > > > Signed-off-by: Martin Wilck <mwilck@suse.com> > > --- > > multipathd/cli.c | 85 +++++++------------------------------------- > > ---- > > multipathd/cli.h | 6 ++-- > > 2 files changed, 15 insertions(+), 76 deletions(-) > > > > diff --git a/multipathd/cli.c b/multipathd/cli.c > > index 5213813..7020d2b 100644 > > --- a/multipathd/cli.c > > +++ b/multipathd/cli.c > > @@ -100,26 +100,20 @@ find_handler (uint64_t fp) > > } > > > > int > > -set_handler_callback (uint64_t fp, cli_handler *fn) > > +__set_handler_callback (uint64_t fp, cli_handler *fn, bool locked) > > { > > - struct handler * h = find_handler(fp); > > + struct handler *h = find_handler(fp); > > > > Wouldn't it be a bug if we reset the handler? Is this really > something > we need to check for? Also, if add_handler() just returned a pointer > to > the handler, we wouldn't need to call fail_handler() immediately > after > creating it. I'll fix this in an add-on patch in v2. Regards Martin -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
diff --git a/multipathd/cli.c b/multipathd/cli.c index 5213813..7020d2b 100644 --- a/multipathd/cli.c +++ b/multipathd/cli.c @@ -100,26 +100,20 @@ find_handler (uint64_t fp) } int -set_handler_callback (uint64_t fp, cli_handler *fn) +__set_handler_callback (uint64_t fp, cli_handler *fn, bool locked) { - struct handler * h = find_handler(fp); + struct handler *h = find_handler(fp); - if (!h) + if (!h) { + add_handler(fp, fn); + h = find_handler(fp); + } + if (!h) { + condlog(0, "%s: failed to set handler for code %"PRIu64, + __func__, fp); return 1; - h->fn = fn; - h->locked = 1; - return 0; -} - -int -set_unlocked_handler_callback (uint64_t fp, cli_handler *fn) -{ - struct handler * h = find_handler(fp); - - if (!h) - return 1; - h->fn = fn; - h->locked = 0; + } + h->locked = locked; return 0; } @@ -513,63 +507,6 @@ cli_init (void) { if (alloc_handlers()) return 1; - add_handler(LIST+PATHS, NULL); - add_handler(LIST+PATHS+FMT, NULL); - add_handler(LIST+PATHS+RAW+FMT, NULL); - add_handler(LIST+PATH, NULL); - add_handler(LIST+STATUS, NULL); - add_handler(LIST+DAEMON, NULL); - add_handler(LIST+MAPS, NULL); - add_handler(LIST+MAPS+STATUS, NULL); - add_handler(LIST+MAPS+STATS, NULL); - add_handler(LIST+MAPS+FMT, NULL); - add_handler(LIST+MAPS+RAW+FMT, NULL); - add_handler(LIST+MAPS+TOPOLOGY, NULL); - add_handler(LIST+MAPS+JSON, NULL); - add_handler(LIST+TOPOLOGY, NULL); - add_handler(LIST+MAP+TOPOLOGY, NULL); - add_handler(LIST+MAP+JSON, NULL); - add_handler(LIST+MAP+FMT, NULL); - add_handler(LIST+MAP+RAW+FMT, NULL); - add_handler(LIST+CONFIG, NULL); - add_handler(LIST+CONFIG+LOCAL, NULL); - add_handler(LIST+BLACKLIST, NULL); - add_handler(LIST+DEVICES, NULL); - add_handler(LIST+WILDCARDS, NULL); - add_handler(RESET+MAPS+STATS, NULL); - add_handler(RESET+MAP+STATS, NULL); - add_handler(ADD+PATH, NULL); - add_handler(DEL+PATH, NULL); - add_handler(ADD+MAP, NULL); - add_handler(DEL+MAP, NULL); - add_handler(DEL+MAPS, NULL); - add_handler(SWITCH+MAP+GROUP, NULL); - add_handler(RECONFIGURE, NULL); - add_handler(SUSPEND+MAP, NULL); - add_handler(RESUME+MAP, NULL); - add_handler(RESIZE+MAP, NULL); - add_handler(RESET+MAP, NULL); - add_handler(RELOAD+MAP, NULL); - add_handler(DISABLEQ+MAP, NULL); - add_handler(RESTOREQ+MAP, NULL); - add_handler(DISABLEQ+MAPS, NULL); - add_handler(RESTOREQ+MAPS, NULL); - add_handler(REINSTATE+PATH, NULL); - add_handler(FAIL+PATH, NULL); - add_handler(QUIT, NULL); - add_handler(SHUTDOWN, NULL); - add_handler(GETPRSTATUS+MAP, NULL); - add_handler(SETPRSTATUS+MAP, NULL); - add_handler(UNSETPRSTATUS+MAP, NULL); - add_handler(GETPRKEY+MAP, NULL); - add_handler(SETPRKEY+MAP+KEY, NULL); - add_handler(UNSETPRKEY+MAP, NULL); - add_handler(FORCEQ+DAEMON, NULL); - add_handler(RESTOREQ+DAEMON, NULL); - add_handler(SETMARGINAL+PATH, NULL); - add_handler(UNSETMARGINAL+PATH, NULL); - add_handler(UNSETMARGINAL+MAP, NULL); - return 0; } diff --git a/multipathd/cli.h b/multipathd/cli.h index 3dac1b4..dbb75be 100644 --- a/multipathd/cli.h +++ b/multipathd/cli.h @@ -134,8 +134,10 @@ struct handler { int alloc_handlers (void); int add_handler (uint64_t fp, cli_handler *fn); -int set_handler_callback (uint64_t fp, cli_handler *fn); -int set_unlocked_handler_callback (uint64_t fp, cli_handler *fn); +int __set_handler_callback (uint64_t fp, cli_handler *fn, bool locked); +#define set_handler_callback(fp, fn) __set_handler_callback(fp, fn, true) +#define set_unlocked_handler_callback(fp, fn) __set_handler_callback(fp, fn, false) + int parse_cmd (char * cmd, char ** reply, int * len, void *, int); int load_keys (void); char * get_keyparam (vector v, uint64_t code);