[lib] printing readability enhancements
authorChristophe Varoqui <christophe.varoqui@free.fr>
Tue, 18 Nov 2008 23:05:21 +0000 (00:05 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Tue, 18 Nov 2008 23:05:21 +0000 (00:05 +0100)
o use the ascii-mode pstree branching representation
o discard the bracketing around status informations

libmultipath/print.c
libmultipath/print.h

index a3f22f4..9243cfa 100644 (file)
@@ -94,14 +94,14 @@ snprint_sysfs (char * buff, size_t len, struct multipath * mpp)
        if (mpp->dmi)
                return snprintf(buff, len, "dm-%i", mpp->dmi->minor);
        else
-               return snprintf(buff, len, "n/a");
+               return snprintf(buff, len, "undef");
 }
 
 static int
 snprint_ro (char * buff, size_t len, struct multipath * mpp)
 {
        if (!mpp->dmi)
-               return snprintf(buff, len, "n/a");
+               return snprintf(buff, len, "undef");
        if (mpp->dmi->read_only)
                return snprintf(buff, len, "ro");
        else
@@ -318,15 +318,15 @@ snprint_chk_state (char * buff, size_t len, struct path * pp)
 {
        switch (pp->state) {
        case PATH_UP:
-               return snprintf(buff, len, "[ready]");
+               return snprintf(buff, len, "ready");
        case PATH_DOWN:
-               return snprintf(buff, len, "[faulty]");
+               return snprintf(buff, len, "faulty");
        case PATH_SHAKY:
-               return snprintf(buff, len, "[shaky]");
+               return snprintf(buff, len, "shaky");
        case PATH_GHOST:
-               return snprintf(buff, len, "[ghost]");
+               return snprintf(buff, len, "ghost");
        default:
-               return snprintf(buff, len, "[undef]");
+               return snprintf(buff, len, "undef");
        }
 }
 
@@ -335,11 +335,11 @@ snprint_dm_path_state (char * buff, size_t len, struct path * pp)
 {
        switch (pp->dmstate) {
        case PSTATE_ACTIVE:
-               return snprintf(buff, len, "[active]");
+               return snprintf(buff, len, "active");
        case PSTATE_FAILED:
-               return snprintf(buff, len, "[failed]");
+               return snprintf(buff, len, "failed");
        default:
-               return snprintf(buff, len, "[undef]");
+               return snprintf(buff, len, "undef");
        }
 }
 
@@ -354,7 +354,7 @@ static int
 snprint_next_check (char * buff, size_t len, struct path * pp)
 {
        if (!pp->mpp)
-               return snprintf(buff, len, "[orphan]");
+               return snprintf(buff, len, "orphan");
 
        return snprint_progress(buff, len, pp->tick, pp->checkint);
 }
@@ -389,13 +389,13 @@ snprint_pg_state (char * buff, size_t len, struct pathgroup * pgp)
 {
        switch (pgp->status) {
        case PGSTATE_ENABLED:
-               return snprintf(buff, len, "[enabled]");
+               return snprintf(buff, len, "enabled");
        case PGSTATE_DISABLED:
-               return snprintf(buff, len, "[disabled]");
+               return snprintf(buff, len, "disabled");
        case PGSTATE_ACTIVE:
-               return snprintf(buff, len, "[active]");
+               return snprintf(buff, len, "active");
        default:
-               return snprintf(buff, len, "[undef]");
+               return snprintf(buff, len, "undef");
        }
 }
 
@@ -554,6 +554,8 @@ snprint_multipath_header (char * line, int len, char * format)
        int fwd;
        struct multipath_data * data;
 
+       memset(line, 0, len);
+
        do {
                if (!TAIL)
                        break;
@@ -587,6 +589,8 @@ snprint_multipath (char * line, int len, char * format,
        struct multipath_data * data;
        char buff[MAX_FIELD_LEN] = {};
 
+       memset(line, 0, len);
+
        do {
                if (!TAIL)
                        break;
@@ -620,6 +624,8 @@ snprint_path_header (char * line, int len, char * format)
        int fwd;
        struct path_data * data;
 
+       memset(line, 0, len);
+
        do {
                if (!TAIL)
                        break;
@@ -653,6 +659,8 @@ snprint_path (char * line, int len, char * format,
        struct path_data * data;
        char buff[MAX_FIELD_LEN];
 
+       memset(line, 0, len);
+
        do {
                if (!TAIL)
                        break;
@@ -687,6 +695,8 @@ snprint_pathgroup (char * line, int len, char * format,
        struct pathgroup_data * data;
        char buff[MAX_FIELD_LEN];
 
+       memset(line, 0, len);
+
        do {
                if (!TAIL)
                        break;
@@ -729,6 +739,8 @@ snprint_multipath_topology (char * buff, int len, struct multipath * mpp,
        struct pathgroup * pgp = NULL;
        char style[64];
        char * c = style;
+       char fmt[64];
+       char * f;
 
        if (verbosity <= 0)
                return fwd;
@@ -751,8 +763,7 @@ snprint_multipath_topology (char * buff, int len, struct multipath * mpp,
        fwd += snprint_multipath(buff + fwd, len - fwd, style, mpp);
        if (fwd > len)
                return len;
-       fwd += snprint_multipath(buff + fwd, len - fwd,
-                                "[size=%S][features=%f][hwhandler=%h][%r]", mpp);
+       fwd += snprint_multipath(buff + fwd, len - fwd, PRINT_MAP_PROPS, mpp);
        if (fwd > len)
                return len;
 
@@ -760,15 +771,26 @@ snprint_multipath_topology (char * buff, int len, struct multipath * mpp,
                return fwd;
 
        vector_foreach_slot (mpp->pg, pgp, j) {
+               f=fmt;
                pgp->selector = mpp->selector; /* hack */
-               fwd += snprint_pathgroup(buff + fwd, len - fwd,
-                                        PRINT_PG_INDENT, pgp);
+               if (j + 1 < VECTOR_SIZE(mpp->pg)) {
+                       strcpy(f, "|-+- " PRINT_PG_INDENT);
+               } else
+                       strcpy(f, "`-+- " PRINT_PG_INDENT);
+               fwd += snprint_pathgroup(buff + fwd, len - fwd, fmt, pgp);
                if (fwd > len)
                        return len;
 
                vector_foreach_slot (pgp->paths, pp, i) {
-                       fwd += snprint_path(buff + fwd, len - fwd,
-                                           PRINT_PATH_INDENT, pp);
+                       f=fmt;
+                       if (*f != '|')
+                               *f=' ';
+                       f++;
+                       if (i + 1 < VECTOR_SIZE(pgp->paths))
+                               strcpy(f, " |- " PRINT_PATH_INDENT);
+                       else
+                               strcpy(f, " `- " PRINT_PATH_INDENT);
+                       fwd += snprint_path(buff + fwd, len - fwd, fmt, pp);
                        if (fwd > len)
                                return len;
                }
index ea9160f..47f4257 100644 (file)
@@ -1,10 +1,11 @@
-#define PRINT_PATH_LONG      "%w %i %d %D %p %t%T %s %o"
-#define PRINT_PATH_INDENT    " \\_ %i %d %D %t%T %o"
-#define PRINT_PATH_CHECKER   "%i %d %D %p %t%T %o %C"
+#define PRINT_PATH_LONG      "%w %i %d %D %p %t %T %s %o"
+#define PRINT_PATH_INDENT    "%i %d %D %t %T %o"
+#define PRINT_PATH_CHECKER   "%i %d %D %p %t %T %o %C"
 #define PRINT_MAP_STATUS     "%n %F %Q %N %t %r"
 #define PRINT_MAP_STATS      "%n %0 %1 %2 %3 %4"
 #define PRINT_MAP_NAMES      "%n %d %w"
-#define PRINT_PG_INDENT      "\\_ %s [prio=%p]%t"
+#define PRINT_MAP_PROPS      "size=%S features='%f' hwhandler='%h' wp=%r"
+#define PRINT_PG_INDENT      "policy='%s' prio=%p status=%t"
 
 #define MAX_LINE_LEN  80
 #define MAX_LINES     64