]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: add -N/--nvme
authorzhenwei pi <pizhenwei@bytedance.com>
Fri, 3 Jun 2022 12:23:58 +0000 (20:23 +0800)
committerKarel Zak <kzak@redhat.com>
Mon, 6 Jun 2022 10:31:56 +0000 (12:31 +0200)
Add -N/--nvme to filter NVMe device only, NVMe usually has a larger
I/O depth, also show COL_RQ_SIZE by default.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
bash-completion/lsblk
misc-utils/lsblk.8.adoc
misc-utils/lsblk.c
misc-utils/lsblk.h

index ca0ad39d73457cafabd5b83e152472596adf0bd1..011af41c243e8bdd8cff179e70d59c1789a0cf16 100644 (file)
@@ -79,6 +79,7 @@ _lsblk_module()
                                --inverse
                                --topology
                                --scsi
+                               --nvme
                                --sort
                                --width
                                --help
index 8ffc2cd796873d3250e15c8ee377ce4c84a3f6a5..8c6d50f79c95b0032657ff88e6b80ae4eba23736 100644 (file)
@@ -72,6 +72,9 @@ Group parents of sub-trees to provide more readable output for RAIDs and Multi-p
 *-m*, *--perms*::
 Output info about device owner, group and mode. This option is equivalent to *-o NAME,SIZE,OWNER,GROUP,MODE*.
 
+*-N*, *--nvme*::
+Output info about NVMe devices only.
+
 *-n*, *--noheadings*::
 Do not print a header line.
 
index fbaa1797f3dc696425fd9eee1ec7db8e97b62bce..047f744bed7cde2633bca4faf7d2b847198271de 100644 (file)
@@ -1349,6 +1349,16 @@ static int initialize_device(struct lsblk_device *dev,
                return -1;
        }
 
+       /* ignore non-NVMe devices */
+       if (lsblk->nvme) {
+               char *transport = get_transport(dev);
+
+               if (!transport || strcmp(transport, "nvme")) {
+                       DBG(DEV, ul_debugobj(dev, "non-nvme device -- ignore"));
+                       return -1;
+               }
+       }
+
        DBG(DEV, ul_debugobj(dev, "%s: context successfully initialized", dev->name));
        return 0;
 }
@@ -1925,6 +1935,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -O, --output-all     output all columns\n"), out);
        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(_(" -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);
@@ -2010,6 +2021,7 @@ int main(int argc, char *argv[])
                { "paths",      no_argument,       NULL, 'p' },
                { "pairs",      no_argument,       NULL, 'P' },
                { "scsi",       no_argument,       NULL, 'S' },
+               { "nvme",       no_argument,       NULL, 'N' },
                { "sort",       required_argument, NULL, 'x' },
                { "sysroot",    required_argument, NULL, OPT_SYSROOT },
                { "shell",      no_argument,       NULL, 'y' },
@@ -2043,7 +2055,7 @@ int main(int argc, char *argv[])
        lsblk_init_debug();
 
        while((c = getopt_long(argc, argv,
-                               "AabdDzE:e:fhJlnMmo:OpPiI:rstVST::w:x:y",
+                               "AabdDzE:e:fhJlNnMmo:OpPiI:rstVST::w:x:y",
                                longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
@@ -2165,6 +2177,16 @@ int main(int argc, char *argv[])
                        add_uniq_column(COL_SERIAL);
                        add_uniq_column(COL_TRANSPORT);
                        break;
+               case 'N':
+                       lsblk->nodeps = 1;
+                       lsblk->nvme = 1;
+                       add_uniq_column(COL_NAME);
+                       add_uniq_column(COL_TYPE);
+                       add_uniq_column(COL_MODEL);
+                       add_uniq_column(COL_SERIAL);
+                       add_uniq_column(COL_TRANSPORT);
+                       add_uniq_column(COL_RQ_SIZE);
+                       break;
                case 'T':
                        force_tree = 1;
                        if (optarg) {
index b20aa6be9887c613dbf8bde362048e419f1edee5..536120a9cc927bbdb57ae99e093b2edb51a24079 100644 (file)
@@ -51,6 +51,7 @@ struct lsblk {
        unsigned int merge:1;           /* merge sub-trees */
        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 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 */