All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] zramctl: print all devices as a default action
@ 2014-08-03 14:17 Sami Kerola
  2014-08-03 14:17 ` [PATCH 2/7] docs: add details to zramctl --size option documentation Sami Kerola
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Sami Kerola @ 2014-08-03 14:17 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

This commit makes the command to display information about all zram
devices when the command is ran without any arguments.  Listing includes
the devices that are unused, which in this context means devices that
does not have --size specified, making them to be zero size.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/zramctl.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c
index a26cd8e..04744fd 100644
--- a/sys-utils/zramctl.c
+++ b/sys-utils/zramctl.c
@@ -193,18 +193,18 @@ static int zram_set_strparm(struct zram *z, const char *attr, const char *str)
 }
 
 
-static int zram_used(struct zram *z)
+static int zram_used(struct zram *z, int find_unused)
 {
 	uint64_t size;
 	struct sysfs_cxt *sysfs = zram_get_sysfs(z);
 
-	if (sysfs &&
-	    sysfs_read_u64(sysfs, "disksize", &size) == 0 &&
-	    size > 0) {
-
+	if (sysfs && sysfs_read_u64(sysfs, "disksize", &size) == 0) {
+		if (find_unused && size == 0)
+			goto unused;
 		DBG(fprintf(stderr, "%s used", z->devname));
 		return 1;
 	}
+ unused:
 	DBG(fprintf(stderr, "%s unused", z->devname));
 	return 0;
 }
@@ -220,7 +220,7 @@ static struct zram *find_free_zram(void)
 		zram_set_devname(z, NULL, i);
 		if (!zram_exist(z))
 			break;
-		isfree = !zram_used(z);
+		isfree = !zram_used(z, 1);
 	}
 	if (!isfree) {
 		free_zram(z);
@@ -344,12 +344,11 @@ static void status(struct zram *z)
 	else {
 		size_t i;			/* list all used devices */
 		z = new_zram(NULL);
-
 		for (i = 0; ; i++) {
 			zram_set_devname(z, NULL, i);
 			if (!zram_exist(z))
 				break;
-			if (zram_used(z))
+			if (zram_used(z, 0))
 				fill_table_row(tb, z);
 		}
 		free_zram(z);
@@ -511,10 +510,12 @@ int main(int argc, char **argv)
 			columns[ncolumns++] = COL_STREAMS;
 			columns[ncolumns++] = COL_MOUNTPOINT;
 		}
-		if (optind < argc)
+		if (optind < argc) {
 			zram = new_zram(argv[optind++]);
-		status(zram);
-		free_zram(zram);
+			status(zram);
+			free_zram(zram);
+		} else
+			status(NULL);
 		break;
 	case A_RESET:
 		if (optind == argc)
-- 
2.0.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-08-11 12:49 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-03 14:17 [PATCH 1/7] zramctl: print all devices as a default action Sami Kerola
2014-08-03 14:17 ` [PATCH 2/7] docs: add details to zramctl --size option documentation Sami Kerola
2014-08-03 14:17 ` [PATCH 3/7] zramctl: mark --reset mutually exclusive with --algorithm and --streams Sami Kerola
2014-08-03 14:17 ` [PATCH 4/7] zramctl: fail status printout when device does not exist Sami Kerola
2014-08-03 14:17 ` [PATCH 5/7] zramctl: improve error message Sami Kerola
2014-08-03 14:17 ` [PATCH 6/7] zramctl: fix mount point printout Sami Kerola
2014-08-04 12:15   ` Karel Zak
2014-08-05 23:03     ` Sami Kerola
2014-08-03 14:17 ` [PATCH 7/7] zramctl: add bash completion script Sami Kerola
2014-08-03 14:50 ` [PATCH 1/7] zramctl: print all devices as a default action Mike Frysinger
2014-08-03 20:50   ` Sami Kerola
2014-08-04  7:31     ` Mike Frysinger
2014-08-06  8:16       ` Karel Zak
2014-08-03 22:19 ` Bernhard Voelker
2014-08-04 12:02 ` Karel Zak
2014-08-05 22:38   ` Sami Kerola
2014-08-11 12:49 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.