diff options
Diffstat (limited to '')
-rw-r--r-- | src/tools/rbd/action/Children.cc | 21 | ||||
-rw-r--r-- | src/tools/rbd_nbd/rbd-nbd.cc | 30 |
2 files changed, 36 insertions, 15 deletions
diff --git a/src/tools/rbd/action/Children.cc b/src/tools/rbd/action/Children.cc index 58e861b69..6881989ab 100644 --- a/src/tools/rbd/action/Children.cc +++ b/src/tools/rbd/action/Children.cc @@ -84,6 +84,7 @@ void get_arguments(po::options_description *positional, po::options_description *options) { at::add_image_or_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE); + at::add_image_id_option(options); at::add_snap_id_option(options); options->add_options() ("all,a", po::bool_switch(), "list all children (include trash)"); @@ -104,14 +105,26 @@ int execute(const po::variables_map &vm, std::string namespace_name; std::string image_name; std::string snap_name; + std::string image_id; + + if (vm.count(at::IMAGE_ID)) { + image_id = vm[at::IMAGE_ID].as<std::string>(); + } + int r = utils::get_pool_image_snapshot_names( vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name, - &image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_PERMITTED, - utils::SPEC_VALIDATION_NONE); + &image_name, &snap_name, image_id.empty(), + utils::SNAPSHOT_PRESENCE_PERMITTED, utils::SPEC_VALIDATION_NONE); if (r < 0) { return r; } + if (!image_id.empty() && !image_name.empty()) { + std::cerr << "rbd: trying to access image using both name and id." + << std::endl; + return -EINVAL; + } + if (snap_id != LIBRADOS_SNAP_HEAD && !snap_name.empty()) { std::cerr << "rbd: trying to access snapshot using both name and id." << std::endl; @@ -127,8 +140,8 @@ int execute(const po::variables_map &vm, librados::Rados rados; librados::IoCtx io_ctx; librbd::Image image; - r = utils::init_and_open_image(pool_name, namespace_name, image_name, "", "", - true, &rados, &io_ctx, &image); + r = utils::init_and_open_image(pool_name, namespace_name, image_name, + image_id, "", true, &rados, &io_ctx, &image); if (r < 0) { return r; } diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index e348bd8fe..f2dfa1f66 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -194,7 +194,8 @@ static EventSocket terminate_event_sock; static int parse_args(vector<const char*>& args, std::ostream *err_msg, Config *cfg); static int netlink_disconnect(int index); -static int netlink_resize(int nbd_index, uint64_t size); +static int netlink_resize(int nbd_index, const std::string& cookie, + uint64_t size); static int run_quiesce_hook(const std::string &quiesce_hook, const std::string &devpath, @@ -744,6 +745,7 @@ private: ceph::mutex lock = ceph::make_mutex("NBDWatchCtx::Locker"); bool notify = false; bool terminated = false; + std::string cookie; bool wait_notify() { dout(10) << __func__ << dendl; @@ -779,11 +781,11 @@ private: << dendl; } if (use_netlink) { - ret = netlink_resize(nbd_index, new_size); + ret = netlink_resize(nbd_index, cookie, new_size); } else { ret = ioctl(fd, NBD_SET_SIZE, new_size); if (ret < 0) { - derr << "resize failed: " << cpp_strerror(errno) << dendl; + derr << "ioctl resize failed: " << cpp_strerror(errno) << dendl; } } if (!ret) { @@ -805,13 +807,15 @@ public: bool _use_netlink, librados::IoCtx &_io_ctx, librbd::Image &_image, - unsigned long _size) + unsigned long _size, + std::string _cookie) : fd(_fd) , nbd_index(_nbd_index) , use_netlink(_use_netlink) , io_ctx(_io_ctx) , image(_image) , size(_size) + , cookie(std::move(_cookie)) { handle_notify_thread = make_named_thread("rbd_handle_notify", &NBDWatchCtx::handle_notify_entry, @@ -1319,7 +1323,8 @@ static int netlink_disconnect_by_path(const std::string& devpath) return netlink_disconnect(index); } -static int netlink_resize(int nbd_index, uint64_t size) +static int netlink_resize(int nbd_index, const std::string& cookie, + uint64_t size) { struct nl_sock *sock; struct nl_msg *msg; @@ -1327,30 +1332,33 @@ static int netlink_resize(int nbd_index, uint64_t size) sock = netlink_init(&nl_id); if (!sock) { - cerr << "rbd-nbd: Netlink interface not supported." << std::endl; - return 1; + derr << __func__ << ": netlink interface not supported" << dendl; + return -EINVAL; } nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, genl_handle_msg, NULL); msg = nlmsg_alloc(); if (!msg) { - cerr << "rbd-nbd: Could not allocate netlink message." << std::endl; + derr << __func__ << ": could not allocate netlink message" << dendl; goto free_sock; } if (!genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, nl_id, 0, 0, NBD_CMD_RECONFIGURE, 0)) { - cerr << "rbd-nbd: Could not setup message." << std::endl; + derr << __func__ << ": could not setup netlink message" << dendl; goto free_msg; } NLA_PUT_U32(msg, NBD_ATTR_INDEX, nbd_index); NLA_PUT_U64(msg, NBD_ATTR_SIZE_BYTES, size); + if (!cookie.empty()) + NLA_PUT_STRING(msg, NBD_ATTR_BACKEND_IDENTIFIER, cookie.c_str()); ret = nl_send_sync(sock, msg); if (ret < 0) { - cerr << "rbd-nbd: netlink resize failed: " << nl_geterror(ret) << std::endl; + derr << __func__ << ": netlink resize failed: " << nl_geterror(ret) + << dendl; goto free_sock; } @@ -1896,7 +1904,7 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect) uint64_t handle; NBDWatchCtx watch_ctx(nbd, nbd_index, use_netlink, io_ctx, image, - info.size); + info.size, cfg->cookie); r = image.update_watch(&watch_ctx, &handle); if (r < 0) goto close_nbd; |