Signed-off-by: Oleksandr Natalenko <oleksandr(a)redhat.com>
---
dev.c | 27 +++++++++++++++++++--------
help.c | 1 +
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/dev.c b/dev.c
index e46081e..3db898a 100644
--- a/dev.c
+++ b/dev.c
@@ -31,7 +31,7 @@ static const char *pci_strclass (uint, char *);
static const char *pci_strvendor(uint, char *);
static const char *pci_strdev(uint, uint, char *);
-static void diskio_option(void);
+static void diskio_option(ulong flags);
static struct dev_table {
ulong flags;
@@ -42,6 +42,9 @@ struct dev_table *dt = &dev_table;
#define DEV_INIT 0x1
#define DISKIO_INIT 0x2
+#define DIOF_ALL 1 << 0
+#define DIOF_NONZERO 1 << 1
+
void
dev_init(void)
{
@@ -93,11 +96,15 @@ cmd_dev(void)
flags = 0;
- while ((c = getopt(argcnt, args, "dpi")) != EOF) {
+ while ((c = getopt(argcnt, args, "dDpi")) != EOF) {
switch(c)
{
case 'd':
- diskio_option();
+ diskio_option(DIOF_ALL);
+ return;
+
+ case 'D':
+ diskio_option(DIOF_NONZERO);
return;
case 'i':
@@ -4002,7 +4009,7 @@ init_iter(struct iter *i)
}
static void
-display_one_diskio(struct iter *i, unsigned long gendisk)
+display_one_diskio(struct iter *i, unsigned long gendisk, ulong flags)
{
char disk_name[BUFSIZE + 1];
char buf0[BUFSIZE];
@@ -4028,6 +4035,10 @@ display_one_diskio(struct iter *i, unsigned long gendisk)
"gen_disk.major", FAULT_ON_ERROR);
i->get_diskio(queue_addr, &io);
+ if ((flags & DIOF_NONZERO)
+ && (io.read + io.write == 0))
+ return;
+
fprintf(fp, "%s%s%s %s%s%s%s %s%5d%s%s%s%s%s",
mkstring(buf0, 5, RJUST|INT_DEC, (char *)(unsigned long)major),
space(MINSPACE),
@@ -4055,7 +4066,7 @@ display_one_diskio(struct iter *i, unsigned long gendisk)
}
static void
-display_all_diskio(void)
+display_all_diskio(ulong flags)
{
struct iter i;
unsigned long gendisk;
@@ -4089,7 +4100,7 @@ display_all_diskio(void)
mkstring(buf5, 5, RJUST, "DRV"));
while ((gendisk = i.next_disk(&i)) != 0)
- display_one_diskio(&i, gendisk);
+ display_one_diskio(&i, gendisk, flags);
}
static
@@ -4149,8 +4160,8 @@ void diskio_init(void)
}
static void
-diskio_option(void)
+diskio_option(ulong flags)
{
diskio_init();
- display_all_diskio();
+ display_all_diskio(flags);
}
diff --git a/help.c b/help.c
index f7f61a1..a8d2a19 100644
--- a/help.c
+++ b/help.c
@@ -2736,6 +2736,7 @@ char *help_dev[] = {
" DRV: I/O requests that are in-flight in the device driver.",
" If the device driver uses blk-mq interface, this field",
" shows N/A(MQ).",
+" -D same as -d, but filter out disks with no in-progress I/O requests",
"\nEXAMPLES",
" Display character and block device data:\n",
" %s> dev",
--
2.15.0