From: Prasanna Kumar Kalever Date: Thu, 17 Jun 2021 13:35:20 +0000 (+0530) Subject: rbd-nbd: allow attach without --cookie for old kernel versions X-Git-Tag: v16.2.8~69^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=001b1e5ffcf7579a32474d2fbf2388b0ded116ec;p=ceph.git rbd-nbd: allow attach without --cookie for old kernel versions 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 (cherry picked from commit 833e71282ad82023237c5eb407b9fa4630280c15) --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 1870b67a982b..9d146ac806d6 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -2145,20 +2145,26 @@ static int parse_args(vector& 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]];