You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.9 KiB

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