]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Register read fix for kernel 4.0
authorKeith Busch <keith.busch@intel.com>
Mon, 6 Apr 2015 20:31:09 +0000 (14:31 -0600)
committerKeith Busch <keith.busch@intel.com>
Mon, 6 Apr 2015 20:31:09 +0000 (14:31 -0600)
The nvme sysfs path was moved in kernel 4.0 to a new class type, so just
opening that one first before falling back to the previous location.

This also is printing an error if the user requested an invalid command.

Signed-off-by: Keith Busch <keith.busch@intel.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 7210a1a75e429f6e64bb96dc46ceda6904e257bc..87e87beca251529519f4d4d177798f50d3038299 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -778,8 +778,13 @@ static void get_registers(struct nvme_bar *bar, unsigned char_only)
        }
 
        base = nvme_char_from_block(basename(devicename));
-       sprintf(path, "/sys/class/misc/%s/device/resource0", base);
+
+       sprintf(path, "/sys/class/nvme/%s/device/resource0", base);
        pci_fd = open(path, O_RDONLY);
+       if (pci_fd < 0) {
+               sprintf(path, "/sys/class/misc/%s/device/resource0", base);
+               pci_fd = open(path, O_RDONLY);
+       }
        if (pci_fd < 0) {
                fprintf(stderr, "%s did not find a pci resource\n", devicename);
                exit(ENODEV);
@@ -2382,6 +2387,9 @@ static void handle_internal_command(int argc, char **argv)
                        continue;
                exit(cmd->fn(argc, argv));
        }
+       fprintf(stderr, "unknown command '%s'\n", argv[0]);
+       help(1, NULL);
+       exit(1);
 }
 
 int main(int argc, char **argv)