From 6ca70ee4f078aba86a6edd013bd8d95f690a46a1 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 13 May 2021 13:52:25 +0530 Subject: [PATCH] rbd-nbd: mandate device cookie for attach command [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 --- src/tools/rbd_nbd/rbd-nbd.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index ccf9b0d2d421d..0ac0e23e3a82e 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -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& 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& 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()) { -- 2.39.5