Blame SOURCES/0143-lsmem-make-split-optional-follow-output-by-default.patch

304038
From 66d819dc82080e9dba609b3bfff45c14d7c3ba3c Mon Sep 17 00:00:00 2001
304038
From: Karel Zak <kzak@redhat.com>
304038
Date: Fri, 3 Nov 2017 10:58:33 +0100
304038
Subject: [PATCH] lsmem: make --split optional, follow output by default
304038
304038
Let's keep lsmem backwardly compatible (<=v2.30) and create ranges
304038
according to the output columns by default. This default behavior may
304038
be modified by --split command line option.
304038
304038
Upstream: http://github.com/karelzak/util-linux/commit/96cbe362c034305e5f12a912b4247b3321420ee7
304038
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1496421
304038
Signed-off-by: Karel Zak <kzak@redhat.com>
304038
---
304038
 sys-utils/lsmem.1 | 14 ++++++--------
304038
 sys-utils/lsmem.c | 49 ++++++++++++++++++++++++++++++-------------------
304038
 2 files changed, 36 insertions(+), 27 deletions(-)
304038
304038
diff --git a/sys-utils/lsmem.1 b/sys-utils/lsmem.1
304038
index 3f5cd7d4b..bfe312bfc 100644
304038
--- a/sys-utils/lsmem.1
304038
+++ b/sys-utils/lsmem.1
304038
@@ -16,14 +16,12 @@ Always explicitly define expected columns by using the \fB\-\-output\fR option
304038
 together with a columns list in environments where a stable output is required.
304038
 
304038
 The \fBlsmem\fP command lists a new memory range always when the current memory
304038
-block distinguish from the previous block by STATE, REMOVABLE, NODE or ZONES
304038
-attribute.  This default behavior is possible to override by the
304038
-\fB\-\-split\fR option (e.g. \fBlsmem \-\-split=STATE,ZONES\fR).  The special
304038
-word "none" may be used to ignore all differences between memory blocks and to
304038
-create as large as possible continuous ranges.  The opposite semantic is
304038
-\fB\-\-all\fR to list individual memory blocks.  The default split policy is
304038
-subject to change.  Always explicitly use \fB\-\-split\fR in environments where
304038
-a stable output is required.
304038
+block distinguish from the previous block by some output column.  This default
304038
+behavior is possible to override by the \fB\-\-split\fR option (e.g. \fBlsmem
304038
+\-\-split=ZONES\fR).  The special word "none" may be used to ignore all
304038
+differences between memory blocks and to create as large as possible continuous
304038
+ranges.  The opposite semantic is \fB\-\-all\fR to list individual memory
304038
+blocks.
304038
 
304038
 Note that some output columns may provide inaccurate information if a split policy
304038
 forces \fBlsmem\fP to ignore diffrences in some attributes. For example if you
304038
diff --git a/sys-utils/lsmem.c b/sys-utils/lsmem.c
304038
index 34a2847af..aaf7374fc 100644
304038
--- a/sys-utils/lsmem.c
304038
+++ b/sys-utils/lsmem.c
304038
@@ -202,6 +202,32 @@ static inline void reset_split_policy(struct lsmem *l, int enable)
304038
 	l->split_by_zones = enable;
304038
 }
304038
 
304038
+static void set_split_policy(struct lsmem *l, int cols[], size_t ncols)
304038
+{
304038
+	size_t i;
304038
+
304038
+	reset_split_policy(l, 0);
304038
+
304038
+	for (i = 0; i < ncols; i++) {
304038
+		switch (cols[i]) {
304038
+		case COL_STATE:
304038
+			l->split_by_state = 1;
304038
+			break;
304038
+		case COL_NODE:
304038
+			l->split_by_node = 1;
304038
+			break;
304038
+		case COL_REMOVABLE:
304038
+			l->split_by_removable = 1;
304038
+			break;
304038
+		case COL_ZONES:
304038
+			l->split_by_zones = 1;
304038
+			break;
304038
+		default:
304038
+			break;
304038
+		}
304038
+	}
304038
+}
304038
+
304038
 static void add_scols_line(struct lsmem *lsmem, struct memory_block *blk)
304038
 {
304038
 	size_t i;
304038
@@ -638,32 +664,17 @@ int main(int argc, char **argv)
304038
 		int split[ARRAY_SIZE(coldescs)] = { 0 };
304038
 		static size_t nsplits = 0;
304038
 
304038
-		reset_split_policy(lsmem, 0);	/* disable all */
304038
-
304038
 		if (strcasecmp(splitarg, "none") == 0)
304038
 			;
304038
 		else if (string_add_to_idarray(splitarg, split, ARRAY_SIZE(split),
304038
 					(int *) &nsplits, column_name_to_id) < 0)
304038
 			return EXIT_FAILURE;
304038
 
304038
-		for (i = 0; i < nsplits; i++) {
304038
-			switch (split[i]) {
304038
-			case COL_STATE:
304038
-				lsmem->split_by_state = 1;
304038
-				break;
304038
-			case COL_NODE:
304038
-				lsmem->split_by_node = 1;
304038
-				break;
304038
-			case COL_REMOVABLE:
304038
-				lsmem->split_by_removable = 1;
304038
-				break;
304038
-			case COL_ZONES:
304038
-				lsmem->split_by_zones = 1;
304038
-				break;
304038
-			}
304038
-		}
304038
+		set_split_policy(lsmem, split, nsplits);
304038
+
304038
 	} else
304038
-		reset_split_policy(lsmem, 1); /* enable all */
304038
+		/* follow output columns */
304038
+		set_split_policy(lsmem, columns, ncolumns);
304038
 
304038
 	/*
304038
 	 * Read data and print output
304038
-- 
304038
2.13.6
304038