]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: allow attach without --cookie for old kernel versions
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Thu, 17 Jun 2021 13:35:20 +0000 (19:05 +0530)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Tue, 26 Oct 2021 13:54:13 +0000 (19:24 +0530)
For backward compatibility allow attach without --cookie option:

[root@linux-vm1]# rbd-nbd attach rbd-pool/image0 --device /dev/nbd0
/dev/nbd0

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
src/tools/rbd_nbd/rbd-nbd.cc

index f8c24397542c2ae6cc3b1a69d61a2e870b0973f4..5a9492daa3081855717909f3e2e2a1e4b36dc918 100644 (file)
@@ -2144,20 +2144,26 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg,
     return -EINVAL;
   }
 
+  std::string cookie;
   switch (cmd) {
     case Attach:
       if (cfg->devpath.empty()) {
         *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";
+      // Allowing attach without --cookie option for kernel without
+      // NBD_ATTR_BACKEND_IDENTIFIER support for compatibility
+      cookie = get_cookie(cfg->devpath);
+      if (!cookie.empty()) {
+        if (cfg->cookie.empty()) {
+          *err_msg << "rbd-nbd: must specify cookie to attach";
+          return -EINVAL;
+       } else if (cookie != cfg->cookie) {
+          *err_msg << "rbd-nbd: cookie mismatch";
+          return -EINVAL;
+        }
+      } else if (!cfg->cookie.empty()) {
+        *err_msg << "rbd-nbd: kernel does not have cookie support";
         return -EINVAL;
       }
       [[fallthrough]];