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

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