You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

394 lines
12 KiB

---
libmultipath/print.c | 42 ++++++++++++++++++++++++----------------
libmultipath/print.h | 4 +--
multipathd/cli.c | 5 +++-
multipathd/cli.h | 6 +++--
multipathd/cli_handlers.c | 48 ++++++++++++++++++++++++++++++++++------------
multipathd/cli_handlers.h | 2 +
multipathd/main.c | 2 +
7 files changed, 76 insertions(+), 33 deletions(-)
Index: multipath-tools-130222/libmultipath/print.c
===================================================================
--- multipath-tools-130222.orig/libmultipath/print.c
+++ multipath-tools-130222/libmultipath/print.c
@@ -32,14 +32,21 @@
#define MAX(x,y) (x > y) ? x : y
#define TAIL (line + len - 1 - c)
#define NOPAD s = c
-#define PAD(x) while ((int)(c - s) < (x) && (c < (line + len - 1))) \
- *c++ = ' '; s = c
+#define PAD(x) \
+do { \
+ while ((int)(c - s) < (x) && (c < (line + len - 1))) \
+ *c++ = ' '; \
+ s = c; \
+} while (0)
+
#define ENDLINE \
if (c > line) \
line[c - line - 1] = '\n'
-#define PRINT(var, size, format, args...) \
- fwd = snprintf(var, size, format, ##args); \
- c += (fwd >= size) ? size : fwd;
+#define PRINT(var, size, format, args...) \
+do { \
+ fwd = snprintf(var, size, format, ##args); \
+ c += (fwd >= size) ? size : fwd; \
+} while (0)
/*
* information printing helpers
@@ -720,7 +727,7 @@ snprint_multipath_header (char * line, i
int
snprint_multipath (char * line, int len, char * format,
- struct multipath * mpp)
+ struct multipath * mpp, int pad)
{
char * c = line; /* line cursor */
char * s = line; /* for padding */
@@ -747,7 +754,8 @@ snprint_multipath (char * line, int len,
data->snprint(buff, MAX_FIELD_LEN, mpp);
PRINT(c, TAIL, "%s", buff);
- PAD(data->width);
+ if (pad)
+ PAD(data->width);
buff[0] = '\0';
} while (*f++);
@@ -790,7 +798,7 @@ snprint_path_header (char * line, int le
int
snprint_path (char * line, int len, char * format,
- struct path * pp)
+ struct path * pp, int pad)
{
char * c = line; /* line cursor */
char * s = line; /* for padding */
@@ -817,7 +825,8 @@ snprint_path (char * line, int len, char
data->snprint(buff, MAX_FIELD_LEN, pp);
PRINT(c, TAIL, "%s", buff);
- PAD(data->width);
+ if (pad)
+ PAD(data->width);
} while (*f++);
ENDLINE;
@@ -909,7 +918,7 @@ snprint_multipath_topology (char * buff,
reset_multipath_layout();
if (verbosity == 1)
- return snprint_multipath(buff, len, "%n", mpp);
+ return snprint_multipath(buff, len, "%n", mpp, 1);
if(isatty(1))
c += sprintf(c, "%c[%dm", 0x1B, 1); /* bold on */
@@ -928,10 +937,11 @@ snprint_multipath_topology (char * buff,
if(isatty(1))
c += sprintf(c, "%c[%dm", 0x1B, 0); /* bold off */
- fwd += snprint_multipath(buff + fwd, len - fwd, style, mpp);
+ fwd += snprint_multipath(buff + fwd, len - fwd, style, mpp, 1);
if (fwd > len)
return len;
- fwd += snprint_multipath(buff + fwd, len - fwd, PRINT_MAP_PROPS, mpp);
+ fwd += snprint_multipath(buff + fwd, len - fwd, PRINT_MAP_PROPS, mpp,
+ 1);
if (fwd > len)
return len;
@@ -958,7 +968,7 @@ snprint_multipath_topology (char * buff,
strcpy(f, " |- " PRINT_PATH_INDENT);
else
strcpy(f, " `- " PRINT_PATH_INDENT);
- fwd += snprint_path(buff + fwd, len - fwd, fmt, pp);
+ fwd += snprint_path(buff + fwd, len - fwd, fmt, pp, 1);
if (fwd > len)
return len;
}
@@ -1425,7 +1435,7 @@ snprint_devices (char * buff, int len, s
if (r > 0)
fwd += snprintf(buff + fwd, len - fwd,
" devnode blacklisted, unmonitored");
- else if (r < 0)
+ else if (r <= 0)
fwd += snprintf(buff + fwd, len - fwd,
" devnode whitelisted, unmonitored");
} else
@@ -1455,7 +1465,7 @@ print_path (struct path * pp, char * sty
char line[MAX_LINE_LEN];
memset(&line[0], 0, MAX_LINE_LEN);
- snprint_path(&line[0], MAX_LINE_LEN, style, pp);
+ snprint_path(&line[0], MAX_LINE_LEN, style, pp, 1);
printf("%s", line);
}
@@ -1465,7 +1475,7 @@ print_multipath (struct multipath * mpp,
char line[MAX_LINE_LEN];
memset(&line[0], 0, MAX_LINE_LEN);
- snprint_multipath(&line[0], MAX_LINE_LEN, style, mpp);
+ snprint_multipath(&line[0], MAX_LINE_LEN, style, mpp, 1);
printf("%s", line);
}
Index: multipath-tools-130222/libmultipath/print.h
===================================================================
--- multipath-tools-130222.orig/libmultipath/print.h
+++ multipath-tools-130222/libmultipath/print.h
@@ -37,8 +37,8 @@ void get_path_layout (vector pathvec, in
void get_multipath_layout (vector mpvec, int header);
int snprint_path_header (char *, int, char *);
int snprint_multipath_header (char *, int, char *);
-int snprint_path (char *, int, char *, struct path *);
-int snprint_multipath (char *, int, char *, struct multipath *);
+int snprint_path (char *, int, char *, struct path *, int);
+int snprint_multipath (char *, int, char *, struct multipath *, int);
int snprint_multipath_topology (char *, int, struct multipath * mpp,
int verbosity);
int snprint_defaults (char *, int);
Index: multipath-tools-130222/multipathd/cli.c
===================================================================
--- multipath-tools-130222.orig/multipathd/cli.c
+++ multipath-tools-130222/multipathd/cli.c
@@ -180,7 +180,7 @@ load_keys (void)
r += add_key(keys, "config", CONFIG, 0);
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, "raw", RAW, 0);
r += add_key(keys, "wildcards", WILDCARDS, 0);
r += add_key(keys, "quit", QUIT, 0);
r += add_key(keys, "exit", QUIT, 0);
@@ -188,6 +188,7 @@ load_keys (void)
r += add_key(keys, "getprstatus", GETPRSTATUS, 0);
r += add_key(keys, "setprstatus", SETPRSTATUS, 0);
r += add_key(keys, "unsetprstatus", UNSETPRSTATUS, 0);
+ r += add_key(keys, "format", FMT, 1);
if (r) {
free_keys(keys);
@@ -463,12 +464,14 @@ cli_init (void) {
add_handler(LIST+PATHS, NULL);
add_handler(LIST+PATHS+FMT, NULL);
+ add_handler(LIST+PATHS+RAW+FMT, NULL);
add_handler(LIST+STATUS, NULL);
add_handler(LIST+DAEMON, NULL);
add_handler(LIST+MAPS, NULL);
add_handler(LIST+MAPS+STATUS, NULL);
add_handler(LIST+MAPS+STATS, NULL);
add_handler(LIST+MAPS+FMT, NULL);
+ add_handler(LIST+MAPS+RAW+FMT, NULL);
add_handler(LIST+MAPS+TOPOLOGY, NULL);
add_handler(LIST+TOPOLOGY, NULL);
add_handler(LIST+MAP+TOPOLOGY, NULL);
Index: multipath-tools-130222/multipathd/cli.h
===================================================================
--- multipath-tools-130222.orig/multipathd/cli.h
+++ multipath-tools-130222/multipathd/cli.h
@@ -26,13 +26,14 @@ enum {
__CONFIG,
__BLACKLIST,
__DEVICES,
- __FMT,
+ __RAW,
__WILDCARDS,
__QUIT,
__SHUTDOWN,
__GETPRSTATUS,
__SETPRSTATUS,
__UNSETPRSTATUS,
+ __FMT,
};
#define LIST (1 << __LIST)
@@ -62,7 +63,7 @@ enum {
#define CONFIG (1 << __CONFIG)
#define BLACKLIST (1 << __BLACKLIST)
#define DEVICES (1 << __DEVICES)
-#define FMT (1 << __FMT)
+#define RAW (1 << __RAW)
#define COUNT (1 << __COUNT)
#define WILDCARDS (1 << __WILDCARDS)
#define QUIT (1 << __QUIT)
@@ -70,6 +71,7 @@ enum {
#define GETPRSTATUS (1UL << __GETPRSTATUS)
#define SETPRSTATUS (1UL << __SETPRSTATUS)
#define UNSETPRSTATUS (1UL << __UNSETPRSTATUS)
+#define FMT (1UL << __FMT)
#define INITIAL_REPLY_LEN 1200
Index: multipath-tools-130222/multipathd/cli_handlers.c
===================================================================
--- multipath-tools-130222.orig/multipathd/cli_handlers.c
+++ multipath-tools-130222/multipathd/cli_handlers.c
@@ -24,7 +24,8 @@
#include "uevent.h"
int
-show_paths (char ** r, int * len, struct vectors * vecs, char * style)
+show_paths (char ** r, int * len, struct vectors * vecs, char * style,
+ int pretty)
{
int i;
struct path * pp;
@@ -42,13 +43,13 @@ show_paths (char ** r, int * len, struct
c = reply;
- if (VECTOR_SIZE(vecs->pathvec) > 0)
+ if (pretty && VECTOR_SIZE(vecs->pathvec) > 0)
c += snprint_path_header(c, reply + maxlen - c,
style);
vector_foreach_slot(vecs->pathvec, pp, i)
c += snprint_path(c, reply + maxlen - c,
- style, pp);
+ style, pp, pretty);
again = ((c - reply) == (maxlen - 1));
@@ -183,7 +184,7 @@ cli_list_paths (void * v, char ** reply,
condlog(3, "list paths (operator)");
- return show_paths(reply, len, vecs, PRINT_PATH_CHECKER);
+ return show_paths(reply, len, vecs, PRINT_PATH_CHECKER, 1);
}
int
@@ -194,7 +195,18 @@ cli_list_paths_fmt (void * v, char ** re
condlog(3, "list paths (operator)");
- return show_paths(reply, len, vecs, fmt);
+ return show_paths(reply, len, vecs, fmt, 1);
+}
+
+int
+cli_list_paths_raw (void * v, char ** reply, int * len, void * data)
+{
+ struct vectors * vecs = (struct vectors *)data;
+ char * fmt = get_keyparam(v, FMT);
+
+ condlog(3, "list paths (operator)");
+
+ return show_paths(reply, len, vecs, fmt, 0);
}
int
@@ -285,7 +297,8 @@ show_daemon (char ** r, int *len)
}
int
-show_maps (char ** r, int *len, struct vectors * vecs, char * style)
+show_maps (char ** r, int *len, struct vectors * vecs, char * style,
+ int pretty)
{
int i;
struct multipath * mpp;
@@ -302,13 +315,13 @@ show_maps (char ** r, int *len, struct v
return 1;
c = reply;
- if (VECTOR_SIZE(vecs->mpvec) > 0)
+ if (pretty && VECTOR_SIZE(vecs->mpvec) > 0)
c += snprint_multipath_header(c, reply + maxlen - c,
style);
vector_foreach_slot(vecs->mpvec, mpp, i)
c += snprint_multipath(c, reply + maxlen - c,
- style, mpp);
+ style, mpp, pretty);
again = ((c - reply) == (maxlen - 1));
@@ -327,7 +340,18 @@ cli_list_maps_fmt (void * v, char ** rep
condlog(3, "list maps (operator)");
- return show_maps(reply, len, vecs, fmt);
+ return show_maps(reply, len, vecs, fmt, 1);
+}
+
+int
+cli_list_maps_raw (void * v, char ** reply, int * len, void * data)
+{
+ struct vectors * vecs = (struct vectors *)data;
+ char * fmt = get_keyparam(v, FMT);
+
+ condlog(3, "list maps (operator)");
+
+ return show_maps(reply, len, vecs, fmt, 0);
}
int
@@ -337,7 +361,7 @@ cli_list_maps (void * v, char ** reply,
condlog(3, "list maps (operator)");
- return show_maps(reply, len, vecs, PRINT_MAP_NAMES);
+ return show_maps(reply, len, vecs, PRINT_MAP_NAMES, 1);
}
int
@@ -357,7 +381,7 @@ cli_list_maps_status (void * v, char **
condlog(3, "list maps status (operator)");
- return show_maps(reply, len, vecs, PRINT_MAP_STATUS);
+ return show_maps(reply, len, vecs, PRINT_MAP_STATUS, 1);
}
int
@@ -367,7 +391,7 @@ cli_list_maps_stats (void * v, char ** r
condlog(3, "list maps stats (operator)");
- return show_maps(reply, len, vecs, PRINT_MAP_STATS);
+ return show_maps(reply, len, vecs, PRINT_MAP_STATS, 1);
}
int
Index: multipath-tools-130222/multipathd/cli_handlers.h
===================================================================
--- multipath-tools-130222.orig/multipathd/cli_handlers.h
+++ multipath-tools-130222/multipathd/cli_handlers.h
@@ -1,9 +1,11 @@
int cli_list_paths (void * v, char ** reply, int * len, void * data);
int cli_list_paths_fmt (void * v, char ** reply, int * len, void * data);
+int cli_list_paths_raw (void * v, char ** reply, int * len, void * data);
int cli_list_status (void * v, char ** reply, int * len, void * data);
int cli_list_daemon (void * v, char ** reply, int * len, void * data);
int cli_list_maps (void * v, char ** reply, int * len, void * data);
int cli_list_maps_fmt (void * v, char ** reply, int * len, void * data);
+int cli_list_maps_raw (void * v, char ** reply, int * len, void * data);
int cli_list_maps_status (void * v, char ** reply, int * len, void * data);
int cli_list_maps_stats (void * v, char ** reply, int * len, void * data);
int cli_list_map_topology (void * v, char ** reply, int * len, void * data);
Index: multipath-tools-130222/multipathd/main.c
===================================================================
--- multipath-tools-130222.orig/multipathd/main.c
+++ multipath-tools-130222/multipathd/main.c
@@ -967,12 +967,14 @@ uxlsnrloop (void * ap)
set_handler_callback(LIST+PATHS, cli_list_paths);
set_handler_callback(LIST+PATHS+FMT, cli_list_paths_fmt);
+ set_handler_callback(LIST+PATHS+RAW+FMT, cli_list_paths_raw);
set_handler_callback(LIST+MAPS, cli_list_maps);
set_handler_callback(LIST+STATUS, cli_list_status);
set_handler_callback(LIST+DAEMON, cli_list_daemon);
set_handler_callback(LIST+MAPS+STATUS, cli_list_maps_status);
set_handler_callback(LIST+MAPS+STATS, cli_list_maps_stats);
set_handler_callback(LIST+MAPS+FMT, cli_list_maps_fmt);
+ set_handler_callback(LIST+MAPS+RAW+FMT, cli_list_maps_raw);
set_handler_callback(LIST+MAPS+TOPOLOGY, cli_list_maps_topology);
set_handler_callback(LIST+TOPOLOGY, cli_list_maps_topology);
set_handler_callback(LIST+MAP+TOPOLOGY, cli_list_map_topology);