[multipathd] add "show wildcards" cli command
authorChristophe Varoqui <christophe.varoqui@free.fr>
Sun, 28 Sep 2008 23:37:02 +0000 (01:37 +0200)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Sun, 28 Sep 2008 23:37:02 +0000 (01:37 +0200)
The fact I had to look at the code to find the wildcards to use
in "show paths format ...", "show multipath format ..." and
"show pathgroup format ..." was a clear sign that more help was
necessary.

The "show wildcards" command outputs :

multipath format wildcards:
%n  name
%w  uuid
%d  sysfs
%F  failback
%Q  queueing
%N  paths
%r  write_prot
%t  dm-st
%S  size
%f  features
%h  hwhandler
%A  action
%0  path_faults
%1  switch_grp
%2  map_loads
%3  total_q_time
%4  q_timeouts
%s  vend/prod/rev

path format wildcards:
%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

pathgroup format wildcards:
%s  selector
%p  pri
%t  dm_st

And for example, "show paths format foo:%d:%S:%i", outs

foo:dev:size:hcil
foo:sda:149G:2:0:0:0

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

index 7411ccc..09b3579 100644 (file)
@@ -436,8 +436,29 @@ struct pathgroup_data pgd[] = {
        {'s', "selector",      0, snprint_pg_selector},
        {'p', "pri",           0, snprint_pg_pri},
        {'t', "dm_st",         0, snprint_pg_state},
+       {0, NULL, 0 , NULL}
 };
 
+int
+snprint_wildcards (char * buff, int len)
+{
+       int i, fwd = 0;
+
+       fwd += snprintf(buff + fwd, len - fwd, "multipath format wildcards:\n");
+       for (i = 0; mpd[i].header; i++)
+               fwd += snprintf(buff + fwd, len - fwd, "%%%c  %s\n",
+                               mpd[i].wildcard, mpd[i].header);
+       fwd += snprintf(buff + fwd, len - fwd, "\npath format wildcards:\n");
+       for (i = 0; pd[i].header; i++)
+               fwd += snprintf(buff + fwd, len - fwd, "%%%c  %s\n",
+                               pd[i].wildcard, pd[i].header);
+       fwd += snprintf(buff + fwd, len - fwd, "\npathgroup format wildcards:\n");
+       for (i = 0; pgd[i].header; i++)
+               fwd += snprintf(buff + fwd, len - fwd, "%%%c  %s\n",
+                               pgd[i].wildcard, pgd[i].header);
+       return fwd;
+}
+
 void
 get_path_layout (vector pathvec, int header)
 {
index 1718c94..a8be408 100644 (file)
@@ -44,6 +44,7 @@ int snprint_defaults (char *, int);
 int snprint_blacklist (char *, int);
 int snprint_blacklist_except (char *, int);
 int snprint_blacklist_report (char *, int);
+int snprint_wildcards (char *, int);
 int snprint_status (char *, int, struct vectors *);
 int snprint_devices (char *, int, struct vectors *);
 int snprint_hwtable (char *, int, vector);
index 051624a..34ae07c 100644 (file)
@@ -170,6 +170,7 @@ load_keys (void)
        r += add_key(keys, "blacklist", BLACKLIST, 0);
        r += add_key(keys, "devices", DEVICES, 0);
        r += add_key(keys, "format", FMT, 1);
+       r += add_key(keys, "wildcards", WILDCARDS, 0);
 
        if (r) {
                free_keys(keys);
@@ -416,6 +417,7 @@ cli_init (void) {
        add_handler(LIST+CONFIG, NULL);
        add_handler(LIST+BLACKLIST, NULL);
        add_handler(LIST+DEVICES, NULL);
+       add_handler(LIST+WILDCARDS, NULL);
        add_handler(ADD+PATH, NULL);
        add_handler(DEL+PATH, NULL);
        add_handler(ADD+MAP, NULL);
index 8c83eab..9932d96 100644 (file)
@@ -20,6 +20,7 @@ enum {
        __BLACKLIST,
        __DEVICES,
        __FMT,
+       __WILDCARDS,
 };
 
 #define LIST           (1 << __LIST)
@@ -43,6 +44,7 @@ enum {
 #define BLACKLIST      (1 << __BLACKLIST)
 #define DEVICES        (1 << __DEVICES)
 #define FMT            (1 << __FMT)
+#define WILDCARDS      (1 << __WILDCARDS)
 
 #define INITIAL_REPLY_LEN 1000
 
index 415f865..36a4968 100644 (file)
@@ -224,6 +224,23 @@ cli_list_maps_topology (void * v, char ** reply, int * len, void * data)
 }
 
 int
+cli_list_wildcards (void * v, char ** reply, int * len, void * data)
+{
+       char * c;
+
+       *reply = MALLOC(INITIAL_REPLY_LEN);
+
+       if (!reply)
+               return 1;
+
+       c = *reply;
+       c += snprint_wildcards(c, INITIAL_REPLY_LEN);
+
+       *len = INITIAL_REPLY_LEN;
+       return 0;
+}
+
+int
 show_status (char ** r, int *len, struct vectors * vecs)
 {
        char * c;
index cfc4b12..703a925 100644 (file)
@@ -9,6 +9,7 @@ int cli_list_maps_topology (void * v, char ** reply, int * len, void * data);
 int cli_list_config (void * v, char ** reply, int * len, void * data);
 int cli_list_blacklist (void * v, char ** reply, int * len, void * data);
 int cli_list_devices (void * v, char ** reply, int * len, void * data);
+int cli_list_wildcards (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 e57a3e4..84fb5c4 100644 (file)
@@ -703,6 +703,7 @@ uxlsnrloop (void * ap)
        set_handler_callback(LIST+CONFIG, cli_list_config);
        set_handler_callback(LIST+BLACKLIST, cli_list_blacklist);
        set_handler_callback(LIST+DEVICES, cli_list_devices);
+       set_handler_callback(LIST+WILDCARDS, cli_list_wildcards);
        set_handler_callback(ADD+PATH, cli_add_path);
        set_handler_callback(DEL+PATH, cli_del_path);
        set_handler_callback(ADD+MAP, cli_add_map);