]> 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)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Tue, 26 Oct 2021 13:54:13 +0000 (19:24 +0530)
[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>
src/tools/rbd_nbd/rbd-nbd.cc

index ccf9b0d2d421d5f2f7bc64ab8c7e8ccafa791f60..0ac0e23e3a82e89c42d7b6f291068697dace510c 100644 (file)
@@ -167,6 +167,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"
@@ -2093,6 +2094,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") {
@@ -2144,6 +2146,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()) {