]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: support partition for rbd-nbd mapped raw block device. 12754/head
authorPan Liu <pan.liu@istuary.com>
Tue, 6 Dec 2016 13:04:03 +0000 (21:04 +0800)
committerAbhishek Varshney <abhishek.varshney@flipkart.com>
Wed, 8 Feb 2017 06:35:09 +0000 (12:05 +0530)
Fixes: http://tracker.ceph.com/issues/18115
Signed-off-by: Pan Liu pan.liu@istuary.com
(cherry picked from commit 42645a301869b08b4be860fcac491ae4189b313a)

Conflicts:
src/tools/rbd_nbd/rbd-nbd.cc
Removed exclusive option

src/tools/rbd_nbd/rbd-nbd.cc

index 49cbeecf19d1fbbb5ece0dc5ddcece199fbdd8e4..a5353c2b86c5f0147a863840096bd3db7483e984 100644 (file)
@@ -62,7 +62,8 @@ static void usage()
             << "Options:\n"
             << "  --device <device path>                    Specify nbd device path\n"
             << "  --read-only                               Map readonly\n"
-            << "  --nbds_max <limit>                        Override for module param\n"
+            << "  --nbds_max <limit>                        Override for module param nbds_max\n"
+            << "  --max_part <limit>                        Override for module param max_part\n"
             << std::endl;
   generic_server_usage();
 }
@@ -70,6 +71,7 @@ static void usage()
 static std::string devpath, poolname("rbd"), imgname, snapname;
 static bool readonly = false;
 static int nbds_max = 0;
+static int max_part = 255;
 
 #ifdef CEPH_BIG_ENDIAN
 #define ntohll(a) (a)
@@ -443,14 +445,15 @@ static int open_device(const char* path, bool try_load_moudle = false)
 {
   int nbd = open(path, O_RDWR);
   if (nbd < 0 && try_load_moudle && access("/sys/module/nbd", F_OK) != 0) {
+    ostringstream param;
     int r;
     if (nbds_max) {
-      ostringstream param;
       param << "nbds_max=" << nbds_max;
-      r = module_load("nbd", param.str().c_str());
-    } else {
-      r = module_load("nbd", NULL);
     }
+    if (max_part) {
+        param << " max_part=" << max_part;
+    }
+    r = module_load("nbd", param.str().c_str());
     if (r < 0) {
       cerr << "rbd-nbd: failed to load nbd kernel module: " << cpp_strerror(-r) << std::endl;
       return r;
@@ -755,6 +758,15 @@ static int rbd_nbd(int argc, const char *argv[])
         cerr << "rbd-nbd: Invalid argument for nbds_max!" << std::endl;
         return EXIT_FAILURE;
       }
+    } else if (ceph_argparse_witharg(args, i, &max_part, err, "--max_part", (char *)NULL)) {
+      if (!err.str().empty()) {
+        cerr << err.str() << std::endl;
+        return EXIT_FAILURE;
+      }
+      if ((max_part < 0) || (max_part > 255)) {
+        cerr << "rbd-nbd: Invalid argument for max_part(0~255)!" << std::endl;
+        return EXIT_FAILURE;
+      }
     } else if (ceph_argparse_flag(args, i, "--read-only", (char *)NULL)) {
       readonly = true;
     } else {