]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
format: rescan after format for character device linux-nvme #709
authorSteven Seungcheol Lee <sc108.lee@samsung.com>
Mon, 13 Jul 2020 10:33:33 +0000 (19:33 +0900)
committerKeith Busch <kbusch@kernel.org>
Mon, 13 Jul 2020 15:51:11 +0000 (08:51 -0700)
re-read partition table is only vaild for block device
so do namespaces rescan for character device

Signed-off-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 98c6c87f7aaa5df295c6f16e0ed1a7402a23dd5a..6d160ed100e2d8910d6ade5fdeba0cf3e509fe89 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -2923,12 +2923,21 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
                nvme_show_status(err);
        else {
                printf("Success formatting namespace:%x\n", cfg.namespace_id);
-               if (cfg.lbaf != prev_lbaf && ioctl(fd, BLKRRPART) < 0) {
-                       fprintf(stderr, "failed to re-read partition table\n");
-                       err = -errno;
-                       goto close_fd;
+               if (cfg.lbaf != prev_lbaf){
+                       if (S_ISCHR(nvme_stat.st_mode)) {
+                               if(ioctl(fd, NVME_IOCTL_RESCAN) < 0){
+                                       fprintf(stderr, "failed to rescan namespaces\n");
+                                       err = -errno;
+                                       goto close_fd;
+                               }
+                       } else {
+                               if(ioctl(fd, BLKRRPART) < 0) {
+                                       fprintf(stderr, "failed to re-read partition table\n");
+                                       err = -errno;
+                                       goto close_fd;
+                               }
+                       }
                }
-
                if (cfg.reset && S_ISCHR(nvme_stat.st_mode))
                        nvme_reset_controller(fd);
        }