]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/tools/rbd_nbd/rbd-nbd.cc
update sources to v12.1.1
[ceph.git] / ceph / src / tools / rbd_nbd / rbd-nbd.cc
index 84fd0e476a85e9e5e42e9b88919f53e2b6dbb4f0..5e7f98dcaa4d0b1bc775a50d73853f6832af9e01 100644 (file)
@@ -46,6 +46,7 @@
 #include "common/TextTable.h"
 #include "common/ceph_argparse.h"
 #include "common/Preforker.h"
+#include "common/version.h"
 #include "global/global_init.h"
 #include "global/signal_handler.h"
 
@@ -99,6 +100,9 @@ static enum {
 
 #define RBD_NBD_BLKSIZE 512UL
 
+#define HELP_INFO 1
+#define VERSION_INFO 2
+
 #ifdef CEPH_BIG_ENDIAN
 #define ntohll(a) (a)
 #elif defined(CEPH_LITTLE_ENDIAN)
@@ -931,7 +935,9 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg, Config *
 
   for (i = args.begin(); i != args.end(); ) {
     if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
-      return -ENODATA;
+      return HELP_INFO;
+    } else if (ceph_argparse_flag(args, i, "-v", "--version", (char*)NULL)) {
+      return VERSION_INFO;
     } else if (ceph_argparse_witharg(args, i, &cfg->devpath, "--device", (char *)NULL)) {
     } else if (ceph_argparse_witharg(args, i, &cfg->nbds_max, err, "--nbds_max", (char *)NULL)) {
       if (!err.str().empty()) {
@@ -1020,10 +1026,14 @@ static int rbd_nbd(int argc, const char *argv[])
 
   std::ostringstream err_msg;
   r = parse_args(args, &err_msg, &cfg);
-  if (r == -ENODATA) {
+  if (r == HELP_INFO) {
     usage();
     return 0;
-  } else if (r < 0) {
+  } else if (r == VERSION_INFO) {
+    std::cout << pretty_version_to_str() << std::endl;
+    return 0;
+  }
+  else if (r < 0) {
     cerr << err_msg.str() << std::endl;
     return r;
   }