]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: support optionally setting device timeout 19436/head
authorMykola Golub <to.my.trociny@gmail.com>
Mon, 11 Dec 2017 17:29:00 +0000 (19:29 +0200)
committerMykola Golub <to.my.trociny@gmail.com>
Tue, 12 Dec 2017 09:10:54 +0000 (11:10 +0200)
Fixes: http://tracker.ceph.com/issues/22333
Signed-off-by: Mykola Golub <to.my.trociny@gmail.com>
src/test/cli/rbd/help.t
src/tools/rbd/action/Nbd.cc
src/tools/rbd_nbd/rbd-nbd.cc

index dfbfbe71d543b969d063adc12a134d3a4579f7ba..876aa88aa3ac9b35407b828865526aa5bb32786e 100644 (file)
@@ -1148,6 +1148,7 @@ Skip test on FreeBSD as it generates different output there.
   usage: rbd nbd map [--pool <pool>] [--image <image>] [--snap <snap>] 
                      [--read-only] [--exclusive] [--device <device>] 
                      [--nbds_max <nbds_max>] [--max_part <max_part>] 
+                     [--timeout <timeout>] 
                      <image-or-snap-spec> 
   
   Map image to a nbd device.
@@ -1165,6 +1166,7 @@ Skip test on FreeBSD as it generates different output there.
     --device arg          specify nbd device
     --nbds_max arg        override module param nbds_max
     --max_part arg        override module param max_part
+    --timeout arg         set nbd request timeout (seconds)
   
   rbd help nbd unmap
   usage: rbd nbd unmap 
index d612fef1930ced4e6c0c3e5671d82f338fa434b1..0a586353d5efb5cc2674fc1997bb713f14ded3c2 100644 (file)
@@ -103,7 +103,8 @@ void get_map_arguments(po::options_description *positional,
     ("exclusive", po::bool_switch(), "forbid writes by other clients")
     ("device", po::value<std::string>(), "specify nbd device")
     ("nbds_max", po::value<std::string>(), "override module param nbds_max")
-    ("max_part", po::value<std::string>(), "override module param max_part");
+    ("max_part", po::value<std::string>(), "override module param max_part")
+    ("timeout", po::value<std::string>(), "set nbd request timeout (seconds)");
 }
 
 int execute_map(const po::variables_map &vm)
@@ -151,6 +152,10 @@ int execute_map(const po::variables_map &vm)
     args.push_back("--max_part");
     args.push_back(vm["max_part"].as<std::string>().c_str());
   }
+  if (vm.count("timeout")) {
+    args.push_back("--timeout");
+    args.push_back(vm["timeout"].as<std::string>().c_str());
+  }
 
   return call_nbd_cmd(vm, args);
 }
index 78e4239aaaea74a892c840e3a6d5b981000a2ec7..bf133c13dd2dc32a66d2eb5ef69f113fcaf7b69b 100644 (file)
@@ -63,6 +63,7 @@
 struct Config {
   int nbds_max = 0;
   int max_part = 255;
+  int timeout = -1;
 
   bool exclusive = false;
   bool readonly = false;
@@ -85,6 +86,7 @@ static void usage()
             << "  --nbds_max <limit>      Override for module param nbds_max\n"
             << "  --max_part <limit>      Override for module param max_part\n"
             << "  --exclusive             Forbid writes by other clients\n"
+            << "  --timeout <seconds>     Set nbd request timeout\n"
             << std::endl;
   generic_server_usage();
 }
@@ -745,6 +747,16 @@ static int do_map(int argc, const char *argv[], Config *cfg)
     goto close_nbd;
   }
 
+  if (cfg->timeout >= 0) {
+    r = ioctl(nbd, NBD_SET_TIMEOUT, (unsigned long)cfg->timeout);
+    if (r < 0) {
+      r = -errno;
+      cerr << "rbd-nbd: failed to set timeout: " << cpp_strerror(r)
+           << std::endl;
+      goto close_nbd;
+    }
+  }
+
   {
     uint64_t handle;
 
@@ -989,6 +1001,16 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg, Config *
       cfg->readonly = true;
     } else if (ceph_argparse_flag(args, i, "--exclusive", (char *)NULL)) {
       cfg->exclusive = true;
+    } else if (ceph_argparse_witharg(args, i, &cfg->timeout, err, "--timeout",
+                                     (char *)NULL)) {
+      if (!err.str().empty()) {
+        *err_msg << "rbd-nbd: " << err.str();
+        return -EINVAL;
+      }
+      if (cfg->timeout < 0) {
+        *err_msg << "rbd-nbd: Invalid argument for timeout!";
+        return -EINVAL;
+      }
     } else {
       ++i;
     }