]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-nbd: sscanf return 0 mean not-match.
authorJianpeng Ma <jianpeng.ma@intel.com>
Fri, 19 Apr 2019 05:00:04 +0000 (13:00 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Fri, 19 Apr 2019 05:00:04 +0000 (13:00 +0800)
When exec:  rbd-nbd map rbd/image --device /dev/image
The error message is:
rbd-nbd: failed to open device: /dev/image.

In fact, it should print:
rbd-nbd: invalid device path: /dev/image (expected /dev/nbd{num})

Meantime change help which make more understand.

Fixes: http://tracker.ceph.com/issues/39269
Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/tools/rbd_nbd/rbd-nbd.cc

index 0e8fb16a8d285301d46c837018f6ff5f6a290766..5aa3ea1092d5af2ba79682812bf6a285480a5a07 100644 (file)
@@ -89,7 +89,7 @@ static void usage()
             << "               unmap <device|image-or-snap-spec>   Unmap nbd device\n"
             << "               [options] list-mapped               List mapped nbd devices\n"
             << "Map options:\n"
-            << "  --device <device path>  Specify nbd device path\n"
+            << "  --device <device path>  Specify nbd device path (/dev/nbd{num})\n"
             << "  --read-only             Map read-only\n"
             << "  --nbds_max <limit>      Override for module param nbds_max\n"
             << "  --max_part <limit>      Override for module param max_part\n"
@@ -782,7 +782,10 @@ static int do_map(int argc, const char *argv[], Config *cfg)
     }
   } else {
     r = sscanf(cfg->devpath.c_str(), "/dev/nbd%d", &index);
-    if (r < 0) {
+    if (r <= 0) {
+      // mean an early matching failure. But some cases need a negative value.
+      if (r == 0)
+       r = -EINVAL;
       cerr << "rbd-nbd: invalid device path: " << cfg->devpath
            << " (expected /dev/nbd{num})" << std::endl;
       goto close_fd;