From: Jianpeng Ma Date: Fri, 19 Apr 2019 05:00:04 +0000 (+0800) Subject: rbd-nbd: sscanf return 0 mean not-match. X-Git-Tag: v14.2.3~104^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0d1523c7ad39bc596ef87a7e53ff34791e385ce8;p=ceph.git 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 (cherry picked from commit 5b5c21be7138dc29f190887061f3a1de457a2e24) --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 0e8fb16a8d28..5aa3ea1092d5 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;