From 4d7db9e86a246bf77e8545d0d4e220d90f48ac29 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Mon, 17 May 2021 15:10:45 +0530 Subject: [PATCH] rbd: improve conditional compilation specific checks Signed-off-by: Prasanna Kumar Kalever --- src/tools/rbd/action/Ggate.cc | 21 ++++++++++++++++++--- src/tools/rbd/action/Kernel.cc | 10 ++++++++++ src/tools/rbd/action/Nbd.cc | 19 +++++++++++++------ src/tools/rbd/action/Wnbd.cc | 27 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/tools/rbd/action/Ggate.cc b/src/tools/rbd/action/Ggate.cc index 4ff02d4874819..24699b43ff8d7 100644 --- a/src/tools/rbd/action/Ggate.cc +++ b/src/tools/rbd/action/Ggate.cc @@ -25,6 +25,7 @@ namespace ggate { namespace at = argument_types; namespace po = boost::program_options; +#if defined(__FreeBSD__) static int call_ggate_cmd(const po::variables_map &vm, const std::vector &args, const std::vector &ceph_global_args) { @@ -103,13 +104,14 @@ int parse_options(const std::vector &options, return 0; } +#endif int execute_list(const po::variables_map &vm, const std::vector &ceph_global_init_args) { #if !defined(__FreeBSD__) std::cerr << "rbd: ggate is only supported on FreeBSD" << std::endl; return -EOPNOTSUPP; -#endif +#else std::vector args; args.push_back("list"); @@ -123,6 +125,7 @@ int execute_list(const po::variables_map &vm, } return call_ggate_cmd(vm, args, ceph_global_init_args); +#endif } int execute_map(const po::variables_map &vm, @@ -130,7 +133,7 @@ int execute_map(const po::variables_map &vm, #if !defined(__FreeBSD__) std::cerr << "rbd: ggate is only supported on FreeBSD" << std::endl; return -EOPNOTSUPP; -#endif +#else std::vector args; args.push_back("map"); @@ -165,6 +168,7 @@ int execute_map(const po::variables_map &vm, } return call_ggate_cmd(vm, args, ceph_global_init_args); +#endif } int execute_unmap(const po::variables_map &vm, @@ -172,7 +176,7 @@ int execute_unmap(const po::variables_map &vm, #if !defined(__FreeBSD__) std::cerr << "rbd: ggate is only supported on FreeBSD" << std::endl; return -EOPNOTSUPP; -#endif +#else std::string device_name = utils::get_positional_argument(vm, 0); if (!boost::starts_with(device_name, "/dev/")) { device_name.clear(); @@ -205,15 +209,26 @@ int execute_unmap(const po::variables_map &vm, } return call_ggate_cmd(vm, args, ceph_global_init_args); +#endif } int execute_attach(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if !defined(__FreeBSD__) + std::cerr << "rbd: ggate is only supported on FreeBSD" << std::endl; +#else + std::cerr << "rbd: ggate attach command not supported" << std::endl; +#endif return -EOPNOTSUPP; } int execute_detach(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if !defined(__FreeBSD__) + std::cerr << "rbd: ggate is only supported on FreeBSD" << std::endl; +#else + std::cerr << "rbd: ggate detach command not supported" << std::endl; +#endif return -EOPNOTSUPP; } diff --git a/src/tools/rbd/action/Kernel.cc b/src/tools/rbd/action/Kernel.cc index c1167a88ae348..51e9975867e8d 100644 --- a/src/tools/rbd/action/Kernel.cc +++ b/src/tools/rbd/action/Kernel.cc @@ -635,11 +635,21 @@ int execute_unmap(const po::variables_map &vm, int execute_attach(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if defined(WITH_KRBD) + std::cerr << "rbd: krbd does not support attach" << std::endl; +#else + std::cerr << "rbd: kernel device is not supported" << std::endl; +#endif return -EOPNOTSUPP; } int execute_detach(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if defined(WITH_KRBD) + std::cerr << "rbd: krbd does not support detach" << std::endl; +#else + std::cerr << "rbd: kernel device is not supported" << std::endl; +#endif return -EOPNOTSUPP; } diff --git a/src/tools/rbd/action/Nbd.cc b/src/tools/rbd/action/Nbd.cc index 557842e8477f8..117a2592dd1e8 100644 --- a/src/tools/rbd/action/Nbd.cc +++ b/src/tools/rbd/action/Nbd.cc @@ -21,7 +21,7 @@ namespace po = boost::program_options; static int call_nbd_cmd(const po::variables_map &vm, const std::vector &args, const std::vector &ceph_global_init_args) { - #ifdef _WIN32 + #if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; #else @@ -60,6 +60,7 @@ static int call_nbd_cmd(const po::variables_map &vm, #endif } +#if !defined(__FreeBSD__) && !defined(_WIN32) int get_image_or_snap_spec(const po::variables_map &vm, std::string *spec) { size_t arg_index = 0; std::string pool_name; @@ -112,13 +113,14 @@ int parse_options(const std::vector &options, return 0; } +#endif int execute_list(const po::variables_map &vm, const std::vector &ceph_global_init_args) { #if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; -#endif +#else std::vector args; args.push_back("list-mapped"); @@ -132,6 +134,7 @@ int execute_list(const po::variables_map &vm, } return call_nbd_cmd(vm, args, ceph_global_init_args); +#endif } int execute_attach(const po::variables_map &vm, @@ -139,7 +142,7 @@ int execute_attach(const po::variables_map &vm, #if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; -#endif +#else std::vector args; std::string device_path; @@ -192,6 +195,7 @@ int execute_attach(const po::variables_map &vm, } return call_nbd_cmd(vm, args, ceph_global_init_args); +#endif } int execute_detach(const po::variables_map &vm, @@ -199,7 +203,7 @@ int execute_detach(const po::variables_map &vm, #if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; -#endif +#else std::string device_name = utils::get_positional_argument(vm, 0); if (!boost::starts_with(device_name, "/dev/")) { device_name.clear(); @@ -232,6 +236,7 @@ int execute_detach(const po::variables_map &vm, } return call_nbd_cmd(vm, args, ceph_global_init_args); +#endif } int execute_map(const po::variables_map &vm, @@ -239,7 +244,7 @@ int execute_map(const po::variables_map &vm, #if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; -#endif +#else std::vector args; args.push_back("map"); @@ -275,6 +280,7 @@ int execute_map(const po::variables_map &vm, } return call_nbd_cmd(vm, args, ceph_global_init_args); +#endif } int execute_unmap(const po::variables_map &vm, @@ -282,7 +288,7 @@ int execute_unmap(const po::variables_map &vm, #if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; -#endif +#else std::string device_name = utils::get_positional_argument(vm, 0); if (!boost::starts_with(device_name, "/dev/")) { device_name.clear(); @@ -315,6 +321,7 @@ int execute_unmap(const po::variables_map &vm, } return call_nbd_cmd(vm, args, ceph_global_init_args); +#endif } void get_list_arguments_deprecated(po::options_description *positional, diff --git a/src/tools/rbd/action/Wnbd.cc b/src/tools/rbd/action/Wnbd.cc index 5c52404522446..4da6be33b5d54 100644 --- a/src/tools/rbd/action/Wnbd.cc +++ b/src/tools/rbd/action/Wnbd.cc @@ -18,6 +18,7 @@ namespace wnbd { namespace at = argument_types; namespace po = boost::program_options; +#if defined(_WIN32) static int call_wnbd_cmd(const po::variables_map &vm, const std::vector &args, const std::vector &ceph_global_init_args) { @@ -106,9 +107,14 @@ int parse_options(const std::vector &options, return 0; } +#endif int execute_list(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if !defined(_WIN32) + std::cerr << "rbd: wnbd is only supported on Windows" << std::endl; + return -EOPNOTSUPP; +#else std::vector args; args.push_back("list"); @@ -122,10 +128,15 @@ int execute_list(const po::variables_map &vm, } return call_wnbd_cmd(vm, args, ceph_global_init_args); +#endif } int execute_map(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if !defined(_WIN32) + std::cerr << "rbd: wnbd is only supported on Windows" << std::endl; + return -EOPNOTSUPP; +#else std::vector args; args.push_back("map"); @@ -152,10 +163,15 @@ int execute_map(const po::variables_map &vm, } return call_wnbd_cmd(vm, args, ceph_global_init_args); +#endif } int execute_unmap(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if !defined(_WIN32) + std::cerr << "rbd: wnbd is only supported on Windows" << std::endl; + return -EOPNOTSUPP; +#else std::string device_name = utils::get_positional_argument(vm, 0); std::string image_name; @@ -185,15 +201,26 @@ int execute_unmap(const po::variables_map &vm, } return call_wnbd_cmd(vm, args, ceph_global_init_args); +#endif } int execute_attach(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if !defined(_WIN32) + std::cerr << "rbd: wnbd is only supported on Windows" << std::endl; +#else + std::cerr << "rbd: wnbd attach command not supported" << std::endl; +#endif return -EOPNOTSUPP; } int execute_detach(const po::variables_map &vm, const std::vector &ceph_global_init_args) { +#if !defined(_WIN32) + std::cerr << "rbd: wnbd is only supported on Windows" << std::endl; +#else + std::cerr << "rbd: wnbd detach command not supported" << std::endl; +#endif return -EOPNOTSUPP; } -- 2.39.5