dcavalca / rpms / util-linux

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