[libmultipath] printing enhancements and fixes
authorChristophe Varoqui <root@xa-s05.(none)>
Mon, 24 Oct 2005 13:35:54 +0000 (15:35 +0200)
committerChristophe Varoqui <root@xa-s05.(none)>
Mon, 24 Oct 2005 13:35:54 +0000 (15:35 +0200)
- [enh] align path uuid
- [fix] PAD() macro could overflow
- [enh] add line header for paths (print.c:snprint_path_header)
- [enh] align pathvec dumps in 'multipath -v3' and print header
- [enh] remove heading and trailing white line in multipathd cli output
- [enh] print header in cli's 'show paths' mode

libmultipath/print.c
libmultipath/print.h
multipath/main.c
multipathd/cli.c
multipathd/main.c
multipathd/uxclnt.c

index 63d6163..d5fe8c2 100644 (file)
 
 #define MAX_FIELD_LEN 64
 
-#define MAX(x,y) (x > y) ? x : y;
+#define MAX(x,y) (x > y) ? x : y
 
 void
 get_path_layout (struct path_layout * pl, vector pathvec)
 {
        int i;
-       int hbtl_len, dev_len, dev_t_len, prio_len;
+       int uuid_len, hbtl_len, dev_len, dev_t_len, prio_len;
        char buff[MAX_FIELD_LEN];
        struct path * pp;
 
        /* reset max col lengths */
+       pl->uuid_len = 0;
        pl->hbtl_len = 0;
        pl->dev_len = 0;
        pl->dev_t_len = 0;
        pl->prio_len = 0;
 
        vector_foreach_slot (pathvec, pp, i) {
+               uuid_len = strlen(pp->wwid);
                hbtl_len = snprintf(buff, MAX_FIELD_LEN, "%i:%i:%i:%i",
                                        pp->sg_id.host_no,
                                        pp->sg_id.channel,
@@ -37,6 +39,7 @@ get_path_layout (struct path_layout * pl, vector pathvec)
                dev_t_len = strlen(pp->dev_t);
                prio_len = 1 + (int)log10(pp->priority);
 
+               pl->uuid_len = MAX(uuid_len, pl->uuid_len);
                pl->hbtl_len = MAX(hbtl_len, pl->hbtl_len);
                pl->dev_len = MAX(dev_len, pl->dev_len);
                pl->dev_t_len = MAX(dev_t_len, pl->dev_t_len);
@@ -70,7 +73,8 @@ get_map_layout (struct map_layout * ml, vector mpvec)
 }
 
 #define TAIL   (line + len - 1 - c)
-#define PAD(x) while ((int)(c - s) < (x)) *c++ = ' '; s = c
+#define PAD(x) while ((int)(c - s) < (x) && (c < (line + len - 1))) \
+                       *c++ = ' '; s = c
 #define NOPAD  s = c
 #define PRINT(var, size, format, args...)      \
                fwd = snprintf(var, size, format, ##args); \
@@ -140,6 +144,76 @@ snprint_map (char * line, int len, char * format,
 }
 
 int
+snprint_path_header (char * line, int len, char * format,
+                    struct path_layout * pl)
+{
+       char * c = line;   /* line cursor */
+       char * s = line;   /* for padding */
+       char * f = format; /* format string cursor */
+       int fwd;
+
+       do {
+               if (!TAIL)
+                       break;
+
+               if (*f != '%') {
+                       *c++ = *f;
+                       NOPAD;
+                       continue;
+               }
+               f++;
+               switch (*f) {
+               case 'w':
+                       PRINT(c, TAIL, "uuid");
+                       PAD(pl->uuid_len);
+                       break;
+               case 'i':
+                       PRINT(c, TAIL, "hcil");
+                       PAD(pl->hbtl_len);
+                       break;
+               case 'd':
+                       PRINT(c, TAIL, "dev");
+                       pl->dev_len = MAX(pl->dev_len, 3);
+                       PAD(pl->dev_len);
+                       break;
+               case 'D':
+                       PRINT(c, TAIL, "dev_t");
+                       pl->dev_t_len = MAX(pl->dev_t_len, 5);
+                       PAD(pl->dev_t_len);
+                       break;
+               case 'T':
+                       PRINT(c, TAIL, "chk-st");
+                       PAD(8);
+                       break;
+               case 't':
+                       PRINT(c, TAIL, "dm-st");
+                       PAD(8);
+                       break;
+               case 's':
+                       PRINT(c, TAIL, "vendor/product/rev");
+                       NOPAD;
+                       break;
+               case 'C':
+                       PRINT(c, TAIL, "next-check");
+                       NOPAD;
+                       break;
+               case 'p':
+                       PRINT(c, TAIL, "prio");
+                       pl->prio_len = MAX(pl->prio_len, 4);
+                       PAD(pl->prio_len);
+                       break;
+               default:
+                       break;
+               }
+       } while (*f++);
+
+       line[c - line - 1] = '\n';
+       line[c - line] = '\0';
+
+       return (c - line);
+}
+
+int
 snprint_path (char * line, int len, char * format, struct path * pp,
            struct path_layout * pl)
 {
@@ -161,8 +235,8 @@ snprint_path (char * line, int len, char * format, struct path * pp,
                f++;
                switch (*f) {
                case 'w':       
-                       PRINT(c, TAIL, "%s ", pp->wwid);
-                       PAD(WWID_SIZE);
+                       PRINT(c, TAIL, "%s", pp->wwid);
+                       PAD(pl->uuid_len);
                        break;
                case 'i':
                        if (pp->sg_id.host_no < 0) {
index a0eb9cb..84ce40e 100644 (file)
@@ -25,6 +25,7 @@
 #define MAX_LINE_LEN 80
 
 struct path_layout {
+       int uuid_len;
        int hbtl_len;
        int dev_len;
        int dev_t_len;
@@ -39,5 +40,6 @@ struct map_layout {
 
 void get_path_layout (struct path_layout * pl, vector pathvec);
 void get_map_layout (struct map_layout * pl, vector mpvec);
+int snprint_path_header (char *, int, char *, struct path_layout *);
 int snprint_path (char *, int, char *, struct path *, struct path_layout *);
 int snprint_map (char *, int, char *,struct multipath *, struct map_layout *);
index 61b53ed..e5b8101 100644 (file)
@@ -154,10 +154,10 @@ get_refwwid (vector pathvec)
 static void
 print_path (struct path * pp, char * style)
 {
-       char buff[MAX_LINE_LEN];
+       char line[MAX_LINE_LEN];
 
-       snprint_path(&buff[0], MAX_LINE_LEN, style, pp, &pl);
-       printf("%s", buff);
+       snprint_path(&line[0], MAX_LINE_LEN, style, pp, &pl);
+       printf("%s", line);
 }
 
 static void
@@ -174,6 +174,11 @@ print_all_paths (vector pathvec)
 {
        int i;
        struct path * pp;
+       char line[MAX_LINE_LEN];
+
+       get_path_layout(&pl, pathvec);
+       snprint_path_header(line, MAX_LINE_LEN, PRINT_PATH_LONG, &pl);
+       fprintf(stdout, "%s", line);
 
        vector_foreach_slot (pathvec, pp, i)
                print_path(pp, PRINT_PATH_LONG);
@@ -982,7 +987,7 @@ configure (void)
        cache_load(pathvec);
 
        if (conf->verbosity > 2) {
-               fprintf(stdout, "#\n# all paths in cache :\n#\n");
+               fprintf(stdout, "===== all paths in cache =====\n");
                print_all_paths(pathvec);
        }
 
@@ -1006,7 +1011,7 @@ configure (void)
                goto out;
 
        if (conf->verbosity > 2) {
-               fprintf(stdout, "#\n# all paths :\n#\n");
+               fprintf(stdout, "===== all paths discovered =====\n");
                print_all_paths(pathvec);
        }
 
index 8ad7dc5..78deee6 100644 (file)
@@ -282,7 +282,6 @@ genhelp_handler (void)
                return NULL;
 
        p = reply;
-       p += sprintf(p, "\n");
 
        vector_foreach_slot (handlers, h, i) {
                fp = h->fingerprint;
index 2051432..7835721 100644 (file)
@@ -817,7 +817,8 @@ show_paths (char ** r, int * len, struct vectors * vecs)
                return 1;
 
        c = reply;
-       c += sprintf(c, "\n");
+       c += snprint_path_header(c, reply + MAX_REPLY_LEN - c,
+                                PRINT_PATH_CHECKER, &pl);
 
        vector_foreach_slot(vecs->pathvec, pp, i)
                c += snprint_path(c, reply + MAX_REPLY_LEN - c,
@@ -844,7 +845,6 @@ show_maps (char ** r, int *len, struct vectors * vecs)
                return 1;
 
        c = reply;
-       c += sprintf(c, "\n");
 
        vector_foreach_slot(vecs->mpvec, mpp, i)
                c += snprint_map(c, reply + MAX_REPLY_LEN - c,
index 6fd8afb..bb08a8a 100644 (file)
@@ -29,7 +29,7 @@ static void process(int fd)
                if (send_packet(fd, line, strlen(line) + 1) != 0) break;
                if (recv_packet(fd, &reply, &len) != 0) break;
 
-               printf("%s\n", reply);
+               printf("%s", reply);
 
                if (line && *line)
                        add_history(line);
@@ -47,7 +47,7 @@ static void process_req(int fd, char * inbuf)
        send_packet(fd, inbuf, strlen(inbuf) + 1);
        recv_packet(fd, &reply, &len);
 
-       printf("%s\n", reply);
+       printf("%s", reply);
        FREE(reply);
 }