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

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