util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: zhenwei pi <pizhenwei@bytedance.com>
To: kzak@redhat.com
Cc: util-linux@vger.kernel.org, zhenwei pi <pizhenwei@bytedance.com>
Subject: [PATCH 3/5] lsblk: add -v/--virtio
Date: Fri,  3 Jun 2022 20:24:00 +0800	[thread overview]
Message-ID: <20220603122402.3274789-4-pizhenwei@bytedance.com> (raw)
In-Reply-To: <20220603122402.3274789-1-pizhenwei@bytedance.com>

Add -v/--virtio to filter the virtio block devices.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 bash-completion/lsblk   |  1 +
 misc-utils/lsblk.8.adoc |  3 +++
 misc-utils/lsblk.c      | 23 ++++++++++++++++++++++-
 misc-utils/lsblk.h      |  1 +
 4 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/bash-completion/lsblk b/bash-completion/lsblk
index 011af41c2..697dd23d2 100644
--- a/bash-completion/lsblk
+++ b/bash-completion/lsblk
@@ -80,6 +80,7 @@ _lsblk_module()
 				--topology
 				--scsi
 				--nvme
+				--virtio
 				--sort
 				--width
 				--help
diff --git a/misc-utils/lsblk.8.adoc b/misc-utils/lsblk.8.adoc
index 8c6d50f79..6a9770ef2 100644
--- a/misc-utils/lsblk.8.adoc
+++ b/misc-utils/lsblk.8.adoc
@@ -75,6 +75,9 @@ Output info about device owner, group and mode. This option is equivalent to *-o
 *-N*, *--nvme*::
 Output info about NVMe devices only.
 
+*-v*, *--virtio*::
+Output info about virtio devices only.
+
 *-n*, *--noheadings*::
 Do not print a header line.
 
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index dfa317970..64d7edad6 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -1361,6 +1361,16 @@ static int initialize_device(struct lsblk_device *dev,
 		}
 	}
 
+	/* ignore non-virtio devices */
+	if (lsblk->virtio) {
+		char *transport = get_transport(dev);
+
+		if (!transport || strcmp(transport, "virtio")) {
+			DBG(DEV, ul_debugobj(dev, "non-virtio device -- ignore"));
+			return -1;
+		}
+	}
+
 	DBG(DEV, ul_debugobj(dev, "%s: context successfully initialized", dev->name));
 	return 0;
 }
@@ -1938,6 +1948,7 @@ static void __attribute__((__noreturn__)) usage(void)
 	fputs(_(" -P, --pairs          use key=\"value\" output format\n"), out);
 	fputs(_(" -S, --scsi           output info about SCSI devices\n"), out);
 	fputs(_(" -N, --nvme           output info about NVMe devices\n"), out);
+	fputs(_(" -v, --virtio         output info about virtio devices\n"), out);
 	fputs(_(" -T, --tree[=<column>] use tree format output\n"), out);
 	fputs(_(" -a, --all            print all devices\n"), out);
 	fputs(_(" -b, --bytes          print SIZE in bytes rather than in human readable format\n"), out);
@@ -2024,6 +2035,7 @@ int main(int argc, char *argv[])
 		{ "pairs",      no_argument,       NULL, 'P' },
 		{ "scsi",       no_argument,       NULL, 'S' },
 		{ "nvme",       no_argument,       NULL, 'N' },
+		{ "virtio",     no_argument,       NULL, 'v' },
 		{ "sort",	required_argument, NULL, 'x' },
 		{ "sysroot",    required_argument, NULL, OPT_SYSROOT },
 		{ "shell",      no_argument,       NULL, 'y' },
@@ -2057,7 +2069,7 @@ int main(int argc, char *argv[])
 	lsblk_init_debug();
 
 	while((c = getopt_long(argc, argv,
-				"AabdDzE:e:fhJlNnMmo:OpPiI:rstVST::w:x:y",
+				"AabdDzE:e:fhJlNnMmo:OpPiI:rstVvST::w:x:y",
 				longopts, NULL)) != -1) {
 
 		err_exclusive_options(c, longopts, excl, excl_st);
@@ -2189,6 +2201,15 @@ int main(int argc, char *argv[])
 			add_uniq_column(COL_TRANSPORT);
 			add_uniq_column(COL_RQ_SIZE);
 			break;
+		case 'v':
+			lsblk->nodeps = 1;
+			lsblk->virtio = 1;
+			add_uniq_column(COL_NAME);
+			add_uniq_column(COL_TYPE);
+			add_uniq_column(COL_TRANSPORT);
+			add_uniq_column(COL_SIZE);
+			add_uniq_column(COL_RQ_SIZE);
+			break;
 		case 'T':
 			force_tree = 1;
 			if (optarg) {
diff --git a/misc-utils/lsblk.h b/misc-utils/lsblk.h
index 536120a9c..31c9ecad5 100644
--- a/misc-utils/lsblk.h
+++ b/misc-utils/lsblk.h
@@ -52,6 +52,7 @@ struct lsblk {
 	unsigned int nodeps:1;		/* don't print slaves/holders */
 	unsigned int scsi:1;		/* print only device with HCTL (SCSI) */
 	unsigned int nvme:1;		/* print NVMe device only */
+	unsigned int virtio:1;		/* print virtio device only */
 	unsigned int paths:1;		/* print devnames with "/dev" prefix */
 	unsigned int sort_hidden:1;	/* sort column not between output columns */
 	unsigned int dedup_hidden :1;	/* deduplication column not between output columns */
-- 
2.20.1


  parent reply	other threads:[~2022-06-03 12:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03 12:23 [PATCH 0/5] Support --nvme/--virtio and MQ zhenwei pi
2022-06-03 12:23 ` [PATCH 1/5] lsblk: add -N/--nvme zhenwei pi
2022-06-03 12:23 ` [PATCH 2/5] lsblk: support virtio block zhenwei pi
2022-06-03 12:24 ` zhenwei pi [this message]
2022-06-03 12:24 ` [PATCH 4/5] lsblk: introduce 'MQ' column zhenwei pi
2022-06-06 10:41   ` Karel Zak
2022-06-06 10:45     ` zhenwei pi
2022-06-03 12:24 ` [PATCH 5/5] lsblk: enable 'MQ' for NVMe/virtio by default zhenwei pi
2022-06-06 10:37 ` [PATCH 0/5] Support --nvme/--virtio and MQ Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220603122402.3274789-4-pizhenwei@bytedance.com \
    --to=pizhenwei@bytedance.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).