[multitpathd] add "show paths format" cli command
authorChristophe Varoqui <christophe.varoqui@free.fr>
Thu, 12 Jun 2008 21:36:08 +0000 (23:36 +0200)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Thu, 12 Jun 2008 21:36:08 +0000 (23:36 +0200)
to let users extract custom reports from the daemon data stractures.
format is printf fmt-like with :

%w uuid
%i hcil
%d dev
%D dev_t
%t dm_st
%T chk_st
%s vend/prod/rev
%C next_check
%p pri
%S size

example:
$ mutlipathd -k'show paths format "/dev/%d is a path to %w"'

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

index d786eef..7eaac73 100644 (file)
@@ -3,6 +3,7 @@
  */
 #include <memory.h>
 #include <vector.h>
+#include <parser.h>
 #include <util.h>
 #include <version.h>
 #include <readline/readline.h>
@@ -168,6 +169,7 @@ load_keys (void)
        r += add_key(keys, "config", CONFIG, 0);
        r += add_key(keys, "blacklist", BLACKLIST, 0);
        r += add_key(keys, "devices", DEVICES, 0);
+       r += add_key(keys, "format", FMT, 1);
 
        if (r) {
                free_keys(keys);
@@ -210,13 +212,17 @@ find_key (const char * str)
 static int
 get_cmdvec (char * cmd, vector *v)
 {
-       int fwd = 1;
+       int i;
        int r = 0;
-       char * p = cmd;
+       int get_param = 0;
        char * buff;
        struct key * kw = NULL;
        struct key * cmdkw = NULL;
-       vector cmdvec;
+       vector cmdvec, strvec;
+
+       strvec = alloc_strvec(cmd);
+       if (!strvec)
+               return 0;
 
        cmdvec = vector_alloc();
        *v = cmdvec;
@@ -224,21 +230,20 @@ get_cmdvec (char * cmd, vector *v)
        if (!cmdvec)
                return E_NOMEM;
 
-       while (fwd) {
-               fwd = get_word(p, &buff);
-
-               if (!buff)
-                       break;
-
-               p += fwd;
+       vector_foreach_slot(strvec, buff, i) {
+               if (*buff == '"')
+                       continue;
+               if (get_param) {
+                       get_param = 0;
+                       cmdkw->param = strdup(buff);
+                       continue;
+               }
                kw = find_key(buff);
-               FREE(buff);
-
-               if (!kw)
-                       return E_SYNTAX;
-
+               if (!kw) {
+                       r = E_SYNTAX;
+                       goto out;
+               }
                cmdkw = alloc_key();
-
                if (!cmdkw) {
                        r = E_NOMEM;
                        goto out;
@@ -251,23 +256,17 @@ get_cmdvec (char * cmd, vector *v)
                vector_set_slot(cmdvec, cmdkw);
                cmdkw->code = kw->code;
                cmdkw->has_param = kw->has_param;
-               
-               if (kw->has_param) {
-                       if (*p == '\0')
-                               goto out;
-
-                       fwd = get_word(p, &buff);
-
-                       if (!buff)
-                               return E_NOPARM;
-
-                       p += fwd;
-                       cmdkw->param = buff;
-               }
+               if (kw->has_param)
+                       get_param = 1;
+       }
+       if (get_param) {
+               r = E_NOPARM;
+               goto out;
        }
        return 0;
 
 out:
+       free_strvec(strvec);
        free_keys(cmdvec);
        *v = NULL;
        return r;
@@ -406,6 +405,7 @@ cli_init (void) {
                return 1;
 
        add_handler(LIST+PATHS, NULL);
+       add_handler(LIST+PATHS+FMT, NULL);
        add_handler(LIST+MAPS, NULL);
        add_handler(LIST+MAPS+STATUS, NULL);
        add_handler(LIST+MAPS+STATS, NULL);
index a2397df..8c83eab 100644 (file)
@@ -19,6 +19,7 @@ enum {
        __CONFIG,
        __BLACKLIST,
        __DEVICES,
+       __FMT,
 };
 
 #define LIST           (1 << __LIST)
@@ -41,6 +42,7 @@ enum {
 #define CONFIG         (1 << __CONFIG)
 #define BLACKLIST      (1 << __BLACKLIST)
 #define DEVICES        (1 << __DEVICES)
+#define FMT            (1 << __FMT)
 
 #define INITIAL_REPLY_LEN 1000
 
index 540a330..c84805a 100644 (file)
@@ -185,6 +185,17 @@ cli_list_paths (void * v, char ** reply, int * len, void * data)
 }
 
 int
+cli_list_paths_fmt (void * v, char ** reply, int * len, void * data)
+{
+       struct vectors * vecs = (struct vectors *)data;
+       char * fmt = get_keyparam(v, FMT);
+
+       condlog(3, "list paths (operator)");
+
+       return show_paths(reply, len, vecs, fmt);
+}
+
+int
 cli_list_map_topology (void * v, char ** reply, int * len, void * data)
 {
        struct multipath * mpp;
index 863694b..a688481 100644 (file)
@@ -1,4 +1,5 @@
 int cli_list_paths (void * v, char ** reply, int * len, void * data);
+int cli_list_paths_fmt (void * v, char ** reply, int * len, void * data);
 int cli_list_maps (void * v, char ** reply, int * len, void * data);
 int cli_list_maps_status (void * v, char ** reply, int * len, void * data);
 int cli_list_maps_stats (void * v, char ** reply, int * len, void * data);
index f68dc41..d406a4b 100644 (file)
@@ -691,6 +691,7 @@ uxlsnrloop (void * ap)
                return NULL;
 
        set_handler_callback(LIST+PATHS, cli_list_paths);
+       set_handler_callback(LIST+PATHS+FMT, cli_list_paths_fmt);
        set_handler_callback(LIST+MAPS, cli_list_maps);
        set_handler_callback(LIST+MAPS+STATUS, cli_list_maps_status);
        set_handler_callback(LIST+MAPS+STATS, cli_list_maps_stats);