From 5b5c21be7138dc29f190887061f3a1de457a2e24 Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Fri, 19 Apr 2019 13:00:04 +0800 Subject: [PATCH] rbd-nbd: sscanf return 0 mean not-match. 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 --- src/tools/rbd_nbd/rbd-nbd.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 0e8fb16a8d2..5aa3ea1092d 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -89,7 +89,7 @@ static void usage() << " unmap Unmap nbd device\n" << " [options] list-mapped List mapped nbd devices\n" << "Map options:\n" - << " --device Specify nbd device path\n" + << " --device Specify nbd device path (/dev/nbd{num})\n" << " --read-only Map read-only\n" << " --nbds_max Override for module param nbds_max\n" << " --max_part 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; -- 2.47.3