]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: add flush command chardev handle error message
authorTokunori Ikegami <ikegami.t@gmail.com>
Sun, 19 Jan 2025 05:36:22 +0000 (14:36 +0900)
committerDaniel Wagner <wagi@monom.org>
Mon, 20 Jan 2025 16:20:41 +0000 (17:20 +0100)
Since IO commands rejected by the chardev if more than one namespace.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 25e9f005860f444ec8aa386390e2e9085be1bdaa..a65873b2416ca469a460737a896436b488d2f244 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -7435,6 +7435,23 @@ static int copy_cmd(int argc, char **argv, struct command *cmd, struct plugin *p
        return err;
 }
 
+static void io_cmd_show_error(struct nvme_dev *dev, int err, const char *cmd)
+{
+       if (err > 0) {
+               nvme_show_status(err);
+               return;
+       }
+
+       nvme_show_init();
+
+       nvme_show_error("%s: %s", cmd, nvme_strerror(errno));
+
+       if (is_chardev(dev))
+               nvme_show_result("char device provided but blkdev is needed, e.g. /dev/nvme0n1");
+
+       nvme_show_finish();
+}
+
 static int flush_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
        const char *desc = "Commit data and metadata associated with\n"
@@ -7470,10 +7487,8 @@ static int flush_cmd(int argc, char **argv, struct command *cmd, struct plugin *
        }
 
        err = nvme_flush(dev_fd(dev), cfg.namespace_id);
-       if (err < 0)
-               nvme_show_error("flush: %s", nvme_strerror(errno));
-       else if (err != 0)
-               nvme_show_status(err);
+       if (err)
+               io_cmd_show_error(dev, err, "flush");
        else
                printf("NVMe Flush: success\n");