Blame SOURCES/0146-UPBZ-1299651-raw-output.patch

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