]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
format: check BLKRRPART failure
authorMinwoo Im <minwoo.im.dev@gmail.com>
Sun, 21 Jul 2019 11:53:02 +0000 (20:53 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Sun, 21 Jul 2019 12:00:46 +0000 (21:00 +0900)
ioctl might be failed in case that user gave a nvmeX controller device
node which is a character device.

Issue: #521
Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 6fe99ebf29677b1785a575bf4ebde6ebe4668fec..7604c33a4fa0816e46f7621059c511f5b9e50467 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -3360,7 +3360,12 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
                show_nvme_status(err);
        else {
                printf("Success formatting namespace:%x\n", cfg.namespace_id);
-               ioctl(fd, BLKRRPART);
+               if (S_ISBLK(nvme_stat.st_mode) && 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);
        }