]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
fabrics: Fix disconnect_by_device from disconnecting instance 0 on error
authorLogan Gunthorpe <logang@deltatee.com>
Tue, 28 Mar 2017 19:26:41 +0000 (13:26 -0600)
committerLogan Gunthorpe <logang@deltatee.com>
Tue, 28 Mar 2017 19:32:02 +0000 (13:32 -0600)
I was a bit surprised that running:

nvme disconnect -d /dev/nvme1

actually disconnected nvme0 and I could never disconnect nvme1. Turns
out the code was not expecting a full path and silently used instance
zero if it failed to parse any arguments.

This patch fixes it so that it ignores any path component and fails if
sscanf doesn't match any items.

fabrics.c

index d93cfe7ab004f02d7685c3ad708a4970795a11f4..cd671c7aa4e0f5300e94220ceb9b78af24858056 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -31,6 +31,7 @@
 #include <asm/byteorder.h>
 #include <inttypes.h>
 #include <linux/types.h>
+#include <libgen.h>
 
 #include "parser.h"
 #include "nvme-ioctl.h"
@@ -899,9 +900,12 @@ static int disconnect_by_device(char *device)
        int instance;
        int ret;
 
+       device = basename(device);
        ret = sscanf(device, "nvme%d", &instance);
        if (ret < 0)
                return ret;
+       if (!ret)
+               return -1;
 
        return remove_ctrl(instance);
 }