[multipathd] add "show map $map topo" CLI command
authorChristophe Varoqui <root@xa-s05.(none)>
Sun, 18 Dec 2005 10:46:43 +0000 (11:46 +0100)
committerChristophe Varoqui <root@xa-s05.(none)>
Sun, 18 Dec 2005 10:46:43 +0000 (11:46 +0100)
multipathd> sho map dm-1 topo
mpath0 (149455400000000000000000000000000d00600000b000000)
[size=67 GB][features=1 queue_if_no_path][hwhandler=0]
\_ round-robin 0 [prio=10][enabled]
 \_ 3:0:0:1 sdb 8:16 [active][ready]
\_ round-robin 0 [prio=6][enabled]
 \_ 4:0:0:1 sde 8:64 [active][ready]

and :

multipathd> sho map mpath0 topo
mpath0 (149455400000000000000000000000000d00600000b000000)
[size=67 GB][features=1 queue_if_no_path][hwhandler=0]
\_ round-robin 0 [prio=0][enabled]
 \_ 3:0:0:1 sdb 8:16 [active][ready]
\_ round-robin 0 [prio=0][enabled]
 \_ 4:0:0:1 sde 8:64 [active][ready]

libmultipath/structs.c
libmultipath/structs.h
multipathd/cli_handlers.c
multipathd/main.c

index 75d40d9..a70a89b 100644 (file)
@@ -291,6 +291,17 @@ find_mp_by_alias (vector mpvec, char * alias)
        return NULL;
 }
 
+struct multipath *
+find_mp_by_str (vector mpvec, char * str)
+{
+       int minor;
+
+       if (sscanf(str, "dm-%d", &minor) == 1)
+               return find_mp_by_minor(mpvec, minor);
+       else
+               return find_mp_by_alias(mpvec, str);
+}
+
 struct path *
 find_path_by_dev (vector pathvec, char * dev)
 {
index 3ebd54f..e4c5623 100644 (file)
@@ -179,6 +179,7 @@ int store_pathgroup (vector pgvec, struct pathgroup * pgp);
 
 struct multipath * find_mp_by_alias (vector mp, char * alias);
 struct multipath * find_mp_by_wwid (vector mp, char * wwid);
+struct multipath * find_mp_by_str (vector mp, char * wwid);
 struct multipath * find_mp_by_minor (vector mp, int minor);
        
 struct path * find_path_by_devt (vector pathvec, char * devt);
index db025b7..cdd4a20 100644 (file)
@@ -55,6 +55,34 @@ show_paths (char ** r, int * len, struct vectors * vecs, char * style)
 }
 
 int
+show_map_topology (char ** r, int * len, 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;
+
+               c += snprint_multipath_topology( 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
 show_maps_topology (char ** r, int * len, struct vectors * vecs)
 {
        int i;
@@ -98,6 +126,23 @@ cli_list_paths (void * v, char ** reply, int * len, void * data)
 }
 
 int
+cli_list_map_topology (void * v, char ** reply, int * len, void * data)
+{
+       struct multipath * mpp;
+       struct vectors * vecs = (struct vectors *)data;
+       char * param = get_keyparam(v, MAP);
+       
+       mpp = find_mp_by_str(vecs->mpvec, param);
+
+       if (!mpp)
+               return 1;
+
+       condlog(3, "list multipath %s (operator)", param);
+
+       return show_map_topology(reply, len, mpp);
+}
+
+int
 cli_list_maps_topology (void * v, char ** reply, int * len, void * data)
 {
        struct vectors * vecs = (struct vectors *)data;
index 0770386..343b8b1 100644 (file)
@@ -591,13 +591,9 @@ uev_remove_map (char * devname, struct vectors * vecs)
 int
 ev_remove_map (char * devname, struct vectors * vecs)
 {
-       int minor;
        struct multipath * mpp;
 
-       if (sscanf(devname, "dm-%d", &minor) == 1)
-               mpp = find_mp_by_minor(vecs->mpvec, minor);
-       else
-               mpp = find_mp_by_alias(vecs->mpvec, devname);
+       mpp = find_mp_by_str(vecs->mpvec, devname);
 
        if (!mpp) {
                condlog(3, "%s: devmap not registered, can't remove",
@@ -999,6 +995,7 @@ uxlsnrloop (void * ap)
        add_handler(LIST+MAPS, cli_list_maps);
        add_handler(LIST+MAPS+STATS, cli_list_maps_stats);
        add_handler(LIST+MAPS+TOPOLOGY, cli_list_maps_topology);
+       add_handler(LIST+MAP+TOPOLOGY, cli_list_map_topology);
        add_handler(ADD+PATH, cli_add_path);
        add_handler(DEL+PATH, cli_del_path);
        add_handler(ADD+MAP, cli_add_map);