]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: mandate device cookie for attach command
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Thu, 13 May 2021 08:22:25 +0000 (13:52 +0530)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 23 Mar 2022 12:31:59 +0000 (13:31 +0100)
[root@linux-vm1]# rbd-nbd attach rbd-pool/image0 --device /dev/nbd0 \
                          --cookie c704cb91-c6cf-466e-a335-0e935c0d5e47
/dev/nbd0

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
(cherry picked from commit 6ca70ee4f078aba86a6edd013bd8d95f690a46a1)

src/tools/rbd_nbd/rbd-nbd.cc

index 51abe3763a21ac26a4d4ff2eee6b824eb395af7d..fa6eb9851295c5b8b7916c162301ad7120bb9937 100644 (file)
@@ -163,6 +163,7 @@ static void usage()
             << "                                (default: " << Config().reattach_timeout << ")\n"
             << "  --try-netlink                 Use the nbd netlink interface\n"
             << "  --show-cookie                 Show device cookie\n"
+            << "  --cookie                      Specify device cookie for attach\n"
             << "\n"
             << "List options:\n"
             << "  --format plain|json|xml Output format (default: plain)\n"
@@ -2094,6 +2095,7 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg,
       cfg->try_netlink = true;
     } else if (ceph_argparse_flag(args, i, "--show-cookie", (char *)NULL)) {
       cfg->show_cookie = true;
+    } else if (ceph_argparse_witharg(args, i, &cfg->cookie, "--cookie", (char *)NULL)) {
     } else if (ceph_argparse_witharg(args, i, &arg_value,
                                      "--encryption-format", (char *)NULL)) {
       if (arg_value == "luks1") {
@@ -2145,6 +2147,16 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg,
         *err_msg << "rbd-nbd: must specify device to attach";
         return -EINVAL;
       }
+      /* FIXME: Should we allow attach for kernel versions that doesn't
+       * support NBD_ATTR_BACKEND_IDENTIFIER (danger!) ?
+       * 1. If we allow attach for lower kernel versions then, we should
+       *    also provide a way to skip cookie check here
+       * 2. If we do not want to allow, then add kernel version check here
+       */
+      if (cfg->cookie.empty()) {
+        *err_msg << "rbd-nbd: must specify cookie to attach";
+        return -EINVAL;
+      }
       [[fallthrough]];
     case Map:
       if (args.begin() == args.end()) {