]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: support optionally setting device timeout
authorMykola Golub <to.my.trociny@gmail.com>
Mon, 11 Dec 2017 17:29:00 +0000 (19:29 +0200)
committerJason Dillaman <dillaman@redhat.com>
Thu, 10 Oct 2019 22:54:40 +0000 (18:54 -0400)
Fixes: http://tracker.ceph.com/issues/22333
Signed-off-by: Mykola Golub <to.my.trociny@gmail.com>
(cherry picked from commit bad51ffe7fbfe8c2e33eb0db2ef7acb89a03bd1d)

src/test/cli/rbd/help.t
src/tools/rbd/action/Nbd.cc
src/tools/rbd_nbd/rbd-nbd.cc

index f9a7a6f84a6605f5180c2bcdbb82a7fbd1274854..ee63e52a44d6495957a65c34e9688e387c9c8f82 100644 (file)
@@ -1032,6 +1032,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.
@@ -1049,6 +1050,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 [--pool <pool>] [--image <image>] [--snap <snap>] 
index 266d368fb7f7aa215b7dccdcb1101b0c08ac23f6..43f547704e5fea40db58a17040f52ea3fb450f90 100644 (file)
@@ -127,7 +127,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)
@@ -160,6 +161,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 faca9a564a5a163ab800dab524553cb6fccfb4b9..e59f95435a542430fdee17ae87595ccbde4b208a 100644 (file)
@@ -64,6 +64,7 @@
 struct Config {
   int nbds_max = 0;
   int max_part = 255;
+  int timeout = -1;
 
   bool exclusive = false;
   bool readonly = false;
@@ -86,6 +87,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();
 }
@@ -826,6 +828,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;
 
@@ -1021,6 +1033,16 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg,
       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;
     }