[dm-devel] [PATCH] danymical blacklist addition

Gechangwei ge.changwei at h3c.com
Wed May 25 06:46:35 UTC 2016


Hi,

It is inconvenient to add blacklist exception to conf without restart multipath service or perform reconfigure command.
Suffering storage path failure, either performing reconfigure or restarting multipathd daemon will flush the map with path failure.

With this patch, blacklist exception will be added dynamically without restarting multipathd daemon, hence, no map will be flushed.



From: gechangwei <ge.changwei at h3c.com>
Date: Tue, 17 May 2016 14:13:25 +0800
Subject: [PATCH] Dynamic blacklist exception addition

Signed-off-by: gechangwei <ge.changwei at h3c.com>
---
multipath-tools-0.5.0/libmultipath/structs.c    |  20 +++++
multipath-tools-0.5.0/libmultipath/structs.h    |   1 +
multipath-tools-0.5.0/multipathd/cli.c          |   6 ++
multipath-tools-0.5.0/multipathd/cli.h          |   9 +-
multipath-tools-0.5.0/multipathd/cli_handlers.c | 105 ++++++++++++++++++++++++
multipath-tools-0.5.0/multipathd/cli_handlers.h |   4 +
multipath-tools-0.5.0/multipathd/main.c         |   3 +
7 files changed, 147 insertions(+), 1 deletion(-)

diff --git a/multipath-tools-0.5.0/libmultipath/structs.c b/multipath-tools-0.5.0/libmultipath/structs.c
index 0538327..2750ef9 100644
--- a/multipath-tools-0.5.0/libmultipath/structs.c
+++ b/multipath-tools-0.5.0/libmultipath/structs.c
@@ -424,6 +424,26 @@ find_path_by_devt (vector pathvec, char * dev_t)
       return NULL;
}
+struct blentry *
+find_wwid_in_elist (vector wwid_vector, char * wwid)
+{
+       int i;
+       struct blentry *ele = NULL;
+
+       if (!wwid_vector)
+       {
+                condlog(0, "wwid vector is NULL while finding wwid");
+                return NULL;
+       }
+
+       vector_foreach_slot (wwid_vector, ele, i)
+                if (!strcmp(ele->str, wwid))
+                          return ele;
+
+       condlog(3, "not found in wwid vecotr");
+       return NULL;
+}
+
extern int
pathcountgr (struct pathgroup * pgp, int state)
{
diff --git a/multipath-tools-0.5.0/libmultipath/structs.h b/multipath-tools-0.5.0/libmultipath/structs.h
index ab7dc25..75a39cd 100644
--- a/multipath-tools-0.5.0/libmultipath/structs.h
+++ b/multipath-tools-0.5.0/libmultipath/structs.h
@@ -332,6 +332,7 @@ struct multipath * find_mp_by_minor (vector mp, int minor);
struct path * find_path_by_devt (vector pathvec, char * devt);
struct path * find_path_by_dev (vector pathvec, char * dev);
struct path * first_path (struct multipath * mpp);
+struct blentry * find_wwid_in_elist (vector wwid_vector, char * wwid);
 int pathcountgr (struct pathgroup *, int);
int pathcount (struct multipath *, int);
diff --git a/multipath-tools-0.5.0/multipathd/cli.c b/multipath-tools-0.5.0/multipathd/cli.c
index 6a5c6db..0c2e026 100644
--- a/multipath-tools-0.5.0/multipathd/cli.c
+++ b/multipath-tools-0.5.0/multipathd/cli.c
@@ -188,6 +188,9 @@ load_keys (void)
       r += add_key(keys, "getprstatus", GETPRSTATUS, 0);
       r += add_key(keys, "setprstatus", SETPRSTATUS, 0);
       r += add_key(keys, "unsetprstatus", UNSETPRSTATUS, 0);
+       r += add_key(keys, "elist", ELIST, 1);
+       r += add_key(keys, "discover", DISCOVER, 0);
+       r += add_key(keys, "newpath", NEWPATH, 0);
       r += add_key(keys, "format", FMT, 1);
        if (r) {
@@ -504,6 +507,9 @@ cli_init (void) {
       add_handler(UNSETPRSTATUS+MAP, NULL);
       add_handler(FORCEQ+DAEMON, NULL);
       add_handler(RESTOREQ+DAEMON, NULL);
+       add_handler(ADD+ELIST, NULL);
+       add_handler(DEL+ELIST, NULL);
+       add_handler(DISCOVER+NEWPATH, NULL);
        return 0;
}
diff --git a/multipath-tools-0.5.0/multipathd/cli.h b/multipath-tools-0.5.0/multipathd/cli.h
index f6d2726..c410ed4 100644
--- a/multipath-tools-0.5.0/multipathd/cli.h
+++ b/multipath-tools-0.5.0/multipathd/cli.h
@@ -33,6 +33,10 @@ enum {
       __GETPRSTATUS,
       __SETPRSTATUS,
       __UNSETPRSTATUS,
+       __ELIST,
+       __DISCOVER,
+       __NEWPATH,
+       __MAPPATH,
       __FMT,
};
@@ -71,7 +75,10 @@ enum {
#define GETPRSTATUS   (1UL << __GETPRSTATUS)
#define SETPRSTATUS    (1UL << __SETPRSTATUS)
#define UNSETPRSTATUS       (1UL << __UNSETPRSTATUS)
-#define FMT             (1UL << __FMT)
+#define ELIST       (1UL << __ELIST)
+#define DISCOVER    (1UL << __DISCOVER)
+#define NEWPATH     (1UL << __NEWPATH)
+#define FMT                (1UL << __FMT)
 #define INITIAL_REPLY_LEN 1200
diff --git a/multipath-tools-0.5.0/multipathd/cli_handlers.c b/multipath-tools-0.5.0/multipathd/cli_handlers.c
index 3d39acf..4b2db06 100644
--- a/multipath-tools-0.5.0/multipathd/cli_handlers.c
+++ b/multipath-tools-0.5.0/multipathd/cli_handlers.c
@@ -517,6 +517,111 @@ cli_del_path (void * v, char ** reply, int * len, void * data)
}
 int
+cli_add_elist(void * v, char ** reply, int * len, void * data)
+{
+       char *param         = get_keyparam(v, ELIST);
+       struct blentry *ele = NULL;
+       char *elist_wwid    = NULL;
+
+       condlog(2, "%s: add elist (operator)", param);
+
+       if(find_wwid_in_elist(conf->elist_wwid, param))
+       {
+                condlog(0, "elist already contains wwid(%s)", param);
+                goto out;
+       }
+
+       elist_wwid = MALLOC(WWID_SIZE);
+       if (!elist_wwid)
+       {
+                condlog(0, "malloc temporary wwid space failed.");
+                goto out;
+       }
+
+       strncpy(elist_wwid, param, WWID_SIZE);
+       elist_wwid[WWID_SIZE - 1] = '\0';
+
+       ele = MALLOC(sizeof(struct blentry));
+       if (!ele)
+       {
+                condlog(0, "malloc black list exception entry failed.");
+                goto out;
+       }
+
+       if (regcomp(&ele->regex, param, REG_EXTENDED|REG_NOSUB))
+       {
+                goto out;
+       }
+       ele->origin = ORIGIN_CONFIG;
+       ele->str    = elist_wwid;
+
+       if (!vector_alloc_slot(conf->elist_wwid))
+       {
+                condlog(0, "malloc black list exception entry failed.");
+                goto out;
+       }
+       vector_set_slot(conf->elist_wwid, ele);
+       return 0;;
+out:
+       *len = 0;
+       FREE(elist_wwid);
+       FREE(ele);
+       return 1;
+}
+
+int
+cli_del_elist(void * v, char ** reply, int * len, void * data)
+{
+       int i;
+       struct blentry *ele = NULL;
+       char *param = get_keyparam(v, ELIST);
+
+       *len = 0;
+
+       condlog(2, "%s: del elist (operator)", param);
+
+       vector_foreach_slot (conf->elist_wwid, ele, i)
+       {
+                if (ele->str && !strcmp(ele->str, param))
+                {
+                          vector_del_slot(conf->elist_wwid, i);
+                          FREE(ele->str);
+                          FREE(ele);
+                          return 0;
+                }
+       }
+       condlog(0, "specific wwid(%s) is not found!", param);
+       return 1;
+}
+
+int
+cli_discover_new_path(void * v, char ** reply, int * len, void * data)
+{
+       int ret = 0;
+       struct vectors *vecs = (struct vectors *)data;
+       vector pathvec = vecs->pathvec;
+
+       condlog(2, "discover new paths, this could update current paths' state (operator)");
+       if (path_discovery(pathvec, conf, DI_ALL) < 0)
+       {
+                condlog(0, "discover new paths failed.");
+                ret = 1;
+       }
+
+       struct path *pp;
+       int i;
+
+       vector_foreach_slot(pathvec, pp, i)
+       {
+                if(0 == pp->checkint)
+                          pp->checkint = conf->checkint;
+       }
+
+       *len = 0;
+       return ret;
+}
+
+int
cli_add_map (void * v, char ** reply, int * len, void * data)
{
       struct vectors * vecs = (struct vectors *)data;
diff --git a/multipath-tools-0.5.0/multipathd/cli_handlers.h b/multipath-tools-0.5.0/multipathd/cli_handlers.h
index 799f8da..2bf8b60 100644
--- a/multipath-tools-0.5.0/multipathd/cli_handlers.h
+++ b/multipath-tools-0.5.0/multipathd/cli_handlers.h
@@ -39,4 +39,8 @@ int cli_reassign (void * v, char ** reply, int * len, void * data);
int cli_getprstatus(void * v, char ** reply, int * len, void * data);
int cli_setprstatus(void * v, char ** reply, int * len, void * data);
int cli_unsetprstatus(void * v, char ** reply, int * len, void * data);
+int cli_add_elist(void * v, char ** reply, int * len, void * data);
+int cli_del_elist(void * v, char ** reply, int * len, void * data);
+int cli_discover_new_path(void * v, char ** reply, int * len, void * data);
+
diff --git a/multipath-tools-0.5.0/multipathd/main.c b/multipath-tools-0.5.0/multipathd/main.c
index 626f703..566c920 100644
--- a/multipath-tools-0.5.0/multipathd/main.c
+++ b/multipath-tools-0.5.0/multipathd/main.c
@@ -1013,6 +1013,9 @@ uxlsnrloop (void * ap)
       set_handler_callback(UNSETPRSTATUS+MAP, cli_unsetprstatus);
       set_handler_callback(FORCEQ+DAEMON, cli_force_no_daemon_q);
       set_handler_callback(RESTOREQ+DAEMON, cli_restore_no_daemon_q);
+       set_handler_callback(ADD+ELIST, cli_add_elist);
+       set_handler_callback(DEL+ELIST, cli_del_elist);
+       set_handler_callback(DISCOVER+NEWPATH, cli_discover_new_path);
        umask(077);
       uxsock_listen(&uxsock_trigger, ap);
--
2.7.2.windows.1

-------------------------------------------------------------------------------------------------------------------------------------
本邮件及其附件含有杭州华三通信技术有限公司的保密信息,仅限于发送给上面地址中列出
的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、
或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本
邮件!
This e-mail and its attachments contain confidential information from H3C, which is
intended only for the person or entity whose address is listed above. Any use of the
information contained herein in any way (including, but not limited to, total or partial
disclosure, reproduction, or dissemination) by persons other than the intended
recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender
by phone or email immediately and delete it!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/dm-devel/attachments/20160525/3f9295bd/attachment.htm>


More information about the dm-devel mailing list