[multipathd] add "show multipaths" CLI command
authorChristophe Varoqui <root@xa-s05.(none)>
Fri, 9 Dec 2005 15:40:53 +0000 (16:40 +0100)
committerChristophe Varoqui <root@xa-s05.(none)>
Fri, 9 Dec 2005 15:40:53 +0000 (16:40 +0100)
Mimics the 'multipath -ll' output in the CLI.

multipathd/cli.c
multipathd/cli.h
multipathd/cli_handlers.c
multipathd/cli_handlers.h
multipathd/main.c

index d680349..e3d7e34 100644 (file)
@@ -135,6 +135,7 @@ load_keys (void)
        r += add_key(keys, "group", GROUP, 1);
        r += add_key(keys, "reconfigure", RECONFIGURE, 0);
        r += add_key(keys, "stats", STATS, 0);
+       r += add_key(keys, "multipaths", MULTIPATHS, 0);
 
        if (r) {
                free_keys(keys);
index 659d1ea..3bd7771 100644 (file)
@@ -14,6 +14,7 @@ enum {
        __GROUP,
        __RECONFIGURE,
        __STATS,
+       __MULTIPATHS,
 };
 
 #define LIST           (1 << __LIST)
@@ -31,6 +32,7 @@ enum {
 #define GROUP          (1 << __GROUP)
 #define RECONFIGURE    (1 << __RECONFIGURE)
 #define STATS          (1 << __STATS)
+#define MULTIPATHS     (1 << __MULTIPATHS)
 
 #define INITIAL_REPLY_LEN 1000
 
index 1b2b789..262caea 100644 (file)
@@ -55,6 +55,39 @@ show_paths (char ** r, int * len, struct vectors * vecs, char * style)
 }
 
 int
+show_multipaths (char ** r, int * len, struct vectors * vecs)
+{
+       int i;
+       struct multipath * mpp;
+       char * c;
+       char * reply;
+       int maxlen = INITIAL_REPLY_LEN;
+       int again = 1;
+
+       reply = MALLOC(maxlen);
+
+       while (again) {
+               if (!reply)
+                       return 1;
+
+               c = reply;
+
+               vector_foreach_slot(vecs->mpvec, mpp, i)
+                       c += snprint_mp(c, reply + maxlen - c,
+                                         mpp, 2);
+
+               again = ((c - reply) == (maxlen - 1));
+
+               if (again)
+                       reply = REALLOC(reply, maxlen *= 2);
+
+       }
+       *r = reply;
+       *len = (int)(c - reply + 1);
+       return 0;
+}
+
+int
 cli_list_paths (void * v, char ** reply, int * len, void * data)
 {
        struct vectors * vecs = (struct vectors *)data;
@@ -65,6 +98,16 @@ cli_list_paths (void * v, char ** reply, int * len, void * data)
 }
 
 int
+cli_list_multipaths (void * v, char ** reply, int * len, void * data)
+{
+       struct vectors * vecs = (struct vectors *)data;
+
+       condlog(3, "list multipaths (operator)");
+
+       return show_multipaths(reply, len, vecs);
+}
+
+int
 show_maps (char ** r, int *len, struct vectors * vecs, char * style)
 {
        int i;
index fbfbeda..5fbf022 100644 (file)
@@ -1,6 +1,8 @@
 int cli_list_paths (void * v, char ** reply, int * len, void * data);
 int cli_list_maps (void * v, char ** reply, int * len, void * data);
 int cli_list_maps_stats (void * v, char ** reply, int * len, void * data);
+int cli_list_multipath (void * v, char ** reply, int * len, void * data);
+int cli_list_multipaths (void * v, char ** reply, int * len, void * data);
 int cli_add_path (void * v, char ** reply, int * len, void * data);
 int cli_del_path (void * v, char ** reply, int * len, void * data);
 int cli_add_map (void * v, char ** reply, int * len, void * data);
index eee6556..318428c 100644 (file)
@@ -998,6 +998,7 @@ uxlsnrloop (void * ap)
        add_handler(LIST+PATHS, cli_list_paths);
        add_handler(LIST+MAPS, cli_list_maps);
        add_handler(LIST+MAPS+STATS, cli_list_maps_stats);
+       add_handler(LIST+MULTIPATHS, cli_list_multipaths);
        add_handler(ADD+PATH, cli_add_path);
        add_handler(DEL+PATH, cli_del_path);
        add_handler(ADD+MAP, cli_add_map);