[multipathd] show maps/paths to grow its output buffer
authorChristophe Varoqui <root@xa-s05.(none)>
Wed, 16 Nov 2005 09:14:58 +0000 (10:14 +0100)
committerChristophe Varoqui <root@xa-s05.(none)>
Wed, 16 Nov 2005 09:14:58 +0000 (10:14 +0100)
Thus adapt to large setups needs : Up to or greater than a 8,500 byte
buffer to handle 140 paths spread over 35 maps.

Edward Goggin, EMC

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

index 39265ec..f8cecd5 100644 (file)
@@ -283,7 +283,7 @@ genhelp_handler (void)
        char * reply;
        char * p;
 
-       reply = MALLOC(MAX_REPLY_LEN);
+       reply = MALLOC(INITIAL_REPLY_LEN);
 
        if (!reply)
                return NULL;
index d0ad850..814af15 100644 (file)
@@ -34,7 +34,7 @@ enum {
 #define PATHVEC                (1 << __PATHVEC)
 #define RECONFIGURE    (1 << __RECONFIGURE)
 
-#define MAX_REPLY_LEN 1000
+#define INITIAL_REPLY_LEN 1000
 
 struct key {
        char * str;
index 2cbc814..af3fabc 100644 (file)
@@ -809,23 +809,32 @@ show_paths (char ** r, int * len, struct vectors * vecs)
        char * c;
        char * reply;
        struct path_layout pl;
+       int maxlen = INITIAL_REPLY_LEN;
+       int again = 1;
 
        get_path_layout(&pl, vecs->pathvec);
-       reply = MALLOC(MAX_REPLY_LEN);
+       reply = MALLOC(maxlen);
 
-       if (!reply)
-               return 1;
+       while (again) {
+               if (!reply)
+                       return 1;
 
-       c = reply;
+               c = reply;
 
-       if (VECTOR_SIZE(vecs->pathvec) > 0)
-               c += snprint_path_header(c, reply + MAX_REPLY_LEN - c,
-                                        PRINT_PATH_CHECKER, &pl);
+               if (VECTOR_SIZE(vecs->pathvec) > 0)
+                       c += snprint_path_header(c, reply + maxlen - c,
+                                                PRINT_PATH_CHECKER, &pl);
 
-       vector_foreach_slot(vecs->pathvec, pp, i)
-               c += snprint_path(c, reply + MAX_REPLY_LEN - c,
-                                 PRINT_PATH_CHECKER, pp, &pl);
+               vector_foreach_slot(vecs->pathvec, pp, i)
+                       c += snprint_path(c, reply + maxlen - c,
+                                         PRINT_PATH_CHECKER, pp, &pl);
 
+               again = ((c - reply) == (maxlen - 1));
+
+               if (again)
+                       reply = REALLOC(reply, maxlen *= 2);
+
+       }
        *r = reply;
        *len = (int)(c - reply + 1);
        return 0;
@@ -839,22 +848,30 @@ show_maps (char ** r, int *len, struct vectors * vecs)
        char * c;
        char * reply;
        struct map_layout ml;
+       int maxlen = INITIAL_REPLY_LEN;
+       int again = 1;
 
        get_map_layout(&ml, vecs->mpvec);
-       reply = MALLOC(MAX_REPLY_LEN);
+       reply = MALLOC(maxlen);
 
-       if (!reply)
-               return 1;
+       while (again) {
+               if (!reply)
+                       return 1;
 
-       c = reply;
-       if (VECTOR_SIZE(vecs->mpvec) > 0)
-               c += snprint_map_header(c, reply + MAX_REPLY_LEN - c,
-                                       PRINT_MAP_FAILBACK, &ml);
+               c = reply;
+               if (VECTOR_SIZE(vecs->mpvec) > 0)
+                       c += snprint_map_header(c, reply + maxlen - c,
+                                               PRINT_MAP_FAILBACK, &ml);
 
-       vector_foreach_slot(vecs->mpvec, mpp, i)
-               c += snprint_map(c, reply + MAX_REPLY_LEN - c,
-                                PRINT_MAP_FAILBACK, mpp, &ml);
+               vector_foreach_slot(vecs->mpvec, mpp, i)
+                       c += snprint_map(c, reply + maxlen - c,
+                                        PRINT_MAP_FAILBACK, mpp, &ml);
 
+               again = ((c - reply) == (maxlen - 1));
+
+               if (again)
+                       reply = REALLOC(reply, maxlen *= 2);
+       }
        *r = reply;
        *len = (int)(c - reply + 1);
        return 0;