182 lines
5.1 KiB
Diff
182 lines
5.1 KiB
Diff
From db77d1b3cdb14ca0e32132ff7ad360e3d48f62ee Mon Sep 17 00:00:00 2001
|
|
From: Martin Wilck <mwilck@suse.com>
|
|
Date: Tue, 7 Sep 2021 22:41:46 +0200
|
|
Subject: [PATCH] multipathd: add and set cli_handlers in a single step
|
|
|
|
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. Assigning the same handler multiple
|
|
times would be a bug which is tested with assert().
|
|
|
|
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
---
|
|
multipathd/cli.c | 96 ++++++++----------------------------------------
|
|
multipathd/cli.h | 7 ++--
|
|
2 files changed, 20 insertions(+), 83 deletions(-)
|
|
|
|
diff --git a/multipathd/cli.c b/multipathd/cli.c
|
|
index 4d6c37c..ddeb5fc 100644
|
|
--- a/multipathd/cli.c
|
|
+++ b/multipathd/cli.c
|
|
@@ -4,6 +4,7 @@
|
|
#include <sys/time.h>
|
|
#include <errno.h>
|
|
#include <pthread.h>
|
|
+#include <assert.h>
|
|
#include "memory.h"
|
|
#include "vector.h"
|
|
#include "structs.h"
|
|
@@ -64,26 +65,27 @@ out:
|
|
return 1;
|
|
}
|
|
|
|
-int
|
|
-add_handler (uint64_t fp, int (*fn)(void *, char **, int *, void *))
|
|
+
|
|
+static struct handler *add_handler (uint64_t fp, int (*fn)(void *, char **, int *, void *), bool locked)
|
|
{
|
|
struct handler * h;
|
|
|
|
h = alloc_handler();
|
|
|
|
- if (!h)
|
|
- return 1;
|
|
+ if (h == NULL)
|
|
+ return NULL;
|
|
|
|
if (!vector_alloc_slot(handlers)) {
|
|
FREE(h);
|
|
- return 1;
|
|
+ return NULL;
|
|
}
|
|
|
|
vector_set_slot(handlers, h);
|
|
h->fingerprint = fp;
|
|
h->fn = fn;
|
|
+ h->locked = locked;
|
|
|
|
- return 0;
|
|
+ return h;
|
|
}
|
|
|
|
static struct handler *
|
|
@@ -100,26 +102,17 @@ find_handler (uint64_t fp)
|
|
}
|
|
|
|
int
|
|
-set_handler_callback (uint64_t fp, int (*fn)(void *, char **, int *, void *))
|
|
+__set_handler_callback (uint64_t fp, int (*fn)(void *, char **, int *, void *), bool locked)
|
|
{
|
|
- struct handler * h = find_handler(fp);
|
|
-
|
|
- if (!h)
|
|
- return 1;
|
|
- h->fn = fn;
|
|
- h->locked = 1;
|
|
- return 0;
|
|
-}
|
|
-
|
|
-int
|
|
-set_unlocked_handler_callback (uint64_t fp,int (*fn)(void *, char **, int *, void *))
|
|
-{
|
|
- struct handler * h = find_handler(fp);
|
|
+ struct handler *h;
|
|
|
|
- if (!h)
|
|
+ assert(find_handler(fp) == NULL);
|
|
+ h = add_handler(fp, fn, locked);
|
|
+ if (!h) {
|
|
+ condlog(0, "%s: failed to set handler for code %"PRIu64,
|
|
+ __func__, fp);
|
|
return 1;
|
|
- h->fn = fn;
|
|
- h->locked = 0;
|
|
+ }
|
|
return 0;
|
|
}
|
|
|
|
@@ -513,63 +506,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 fdfb9ae..a6704b1 100644
|
|
--- a/multipathd/cli.h
|
|
+++ b/multipathd/cli.h
|
|
@@ -131,9 +131,10 @@ struct handler {
|
|
};
|
|
|
|
int alloc_handlers (void);
|
|
-int add_handler (uint64_t fp, int (*fn)(void *, char **, int *, void *));
|
|
-int set_handler_callback (uint64_t fp, int (*fn)(void *, char **, int *, void *));
|
|
-int set_unlocked_handler_callback (uint64_t fp, int (*fn)(void *, char **, int *, void *));
|
|
+int __set_handler_callback (uint64_t fp, int (*fn)(void *, char **, int *, void *), 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
|