From 0a037ef15dae9774d9a5032bf376d634c7797ed5 Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Thu, 16 Aug 2018 18:53:36 +0200 Subject: [PATCH] krbd: support for images within namespaces Signed-off-by: Ilya Dryomov --- src/include/krbd.h | 24 +++- src/krbd.cc | 93 +++++++++++--- src/test/cli-integration/rbd/unmap.t | 184 +++++++++++++-------------- src/test/librbd/fsx.cc | 2 +- src/tools/rbd/action/Kernel.cc | 43 ++++--- 5 files changed, 214 insertions(+), 132 deletions(-) diff --git a/src/include/krbd.h b/src/include/krbd.h index eb753f5b684d7..2c63bc7ea54aa 100644 --- a/src/include/krbd.h +++ b/src/include/krbd.h @@ -24,15 +24,27 @@ struct krbd_ctx; int krbd_create_from_context(rados_config_t cct, struct krbd_ctx **pctx); void krbd_destroy(struct krbd_ctx *ctx); -int krbd_map(struct krbd_ctx *ctx, const char *pool, const char *image, - const char *snap, const char *options, char **pdevnode); -int krbd_is_mapped(struct krbd_ctx *ctx, const char *pool, const char *image, - const char *snap, char **pdevnode); +int krbd_map(struct krbd_ctx *ctx, + const char *pool_name, + const char *nspace_name, + const char *image_name, + const char *snap_name, + const char *options, + char **pdevnode); +int krbd_is_mapped(struct krbd_ctx *ctx, + const char *pool_name, + const char *nspace_name, + const char *image_name, + const char *snap_name, + char **pdevnode); int krbd_unmap(struct krbd_ctx *ctx, const char *devnode, const char *options); -int krbd_unmap_by_spec(struct krbd_ctx *ctx, const char *pool, - const char *image, const char *snap, +int krbd_unmap_by_spec(struct krbd_ctx *ctx, + const char *pool_name, + const char *nspace_name, + const char *image_name, + const char *snap_name, const char *options); #ifdef __cplusplus diff --git a/src/krbd.cc b/src/krbd.cc index d3875f79f6ed8..74163c7edddb1 100644 --- a/src/krbd.cc +++ b/src/krbd.cc @@ -53,17 +53,20 @@ static const std::string SNAP_HEAD_NAME("-"); struct krbd_spec { std::string pool_name; + std::string nspace_name; std::string image_name; std::string snap_name; - krbd_spec(const char *pool_name, const char *image_name, - const char *snap_name) + krbd_spec(const char *pool_name, const char *nspace_name, + const char *image_name, const char *snap_name) : pool_name(pool_name), + nspace_name(nspace_name), image_name(image_name), snap_name(*snap_name ? snap_name : SNAP_HEAD_NAME) { } bool operator==(const krbd_spec& rhs) const { return pool_name == rhs.pool_name && + nspace_name == rhs.nspace_name && image_name == rhs.image_name && snap_name == rhs.snap_name; } @@ -71,6 +74,8 @@ struct krbd_spec { std::ostream& operator<<(std::ostream& os, const krbd_spec& spec) { os << spec.pool_name << "/"; + if (!spec.nspace_name.empty()) + os << spec.nspace_name << "/"; os << spec.image_name; if (spec.snap_name != SNAP_HEAD_NAME) os << "@" << spec.snap_name; @@ -79,6 +84,7 @@ std::ostream& operator<<(std::ostream& os, const krbd_spec& spec) { std::optional spec_from_dev(udev_device *dev) { const char *pool_name = udev_device_get_sysattr_value(dev, "pool"); + const char *nspace_name = udev_device_get_sysattr_value(dev, "pool_ns"); const char *image_name = udev_device_get_sysattr_value(dev, "name"); const char *snap_name = udev_device_get_sysattr_value(dev, "current_snap"); @@ -86,7 +92,7 @@ std::optional spec_from_dev(udev_device *dev) { return std::nullopt; return std::make_optional( - pool_name, image_name, snap_name); + pool_name, nspace_name ?: "", image_name, snap_name); } static string get_kernel_rbd_name(const char *id) @@ -212,6 +218,8 @@ static int build_map_buf(CephContext *cct, const krbd_spec& spec, if (strcmp(options, "") != 0) oss << "," << options; + if (!spec.nspace_name.empty()) + oss << ",_pool_ns=" << spec.nspace_name; oss << " " << spec.pool_name << " " << spec.image_name << " " << spec.snap_name; @@ -410,8 +418,8 @@ out_enm: return r; } -static int enumerate_devices(struct udev *udev, const krbd_spec& spec, - struct udev_enumerate **penm) +static int __enumerate_devices(struct udev *udev, const krbd_spec& spec, + bool match_nspace, struct udev_enumerate **penm) { struct udev_enumerate *enm; int r; @@ -428,6 +436,19 @@ static int enumerate_devices(struct udev *udev, const krbd_spec& spec, if (r < 0) goto out_enm; + if (match_nspace) { + r = udev_enumerate_add_match_sysattr(enm, "pool_ns", + spec.nspace_name.c_str()); + } else { + /* + * Match _only_ devices that don't have pool_ns attribute. + * If the kernel supports namespaces, the result will be empty. + */ + r = udev_enumerate_add_nomatch_sysattr(enm, "pool_ns", nullptr); + } + if (r < 0) + goto out_enm; + r = udev_enumerate_add_match_sysattr(enm, "name", spec.image_name.c_str()); if (r < 0) goto out_enm; @@ -449,6 +470,32 @@ out_enm: return r; } +static int enumerate_devices(struct udev *udev, const krbd_spec& spec, + struct udev_enumerate **penm) +{ + struct udev_enumerate *enm; + int r; + + r = __enumerate_devices(udev, spec, true, &enm); + if (r < 0) + return r; + + /* + * If no namespace is set, try again with match_nspace=false to + * handle older kernels. On a newer kernel the result will remain + * the same (i.e. empty). + */ + if (!udev_enumerate_get_list_entry(enm) && spec.nspace_name.empty()) { + udev_enumerate_unref(enm); + r = __enumerate_devices(udev, spec, false, &enm); + if (r < 0) + return r; + } + + *penm = enm; + return 0; +} + static int spec_to_devno_and_krbd_id(struct udev *udev, const krbd_spec& spec, dev_t *pdevno, string *pid) { @@ -673,13 +720,14 @@ static bool dump_one_image(Formatter *f, TextTable *tbl, f->open_object_section("device"); f->dump_string("id", id); f->dump_string("pool", spec->pool_name); + f->dump_string("namespace", spec->nspace_name); f->dump_string("name", spec->image_name); f->dump_string("snap", spec->snap_name); f->dump_string("device", kname); f->close_section(); } else { - *tbl << id << spec->pool_name << spec->image_name << spec->snap_name << kname - << TextTable::endrow; + *tbl << id << spec->pool_name << spec->nspace_name << spec->image_name + << spec->snap_name << kname << TextTable::endrow; } return true; @@ -730,6 +778,7 @@ int dump_images(struct krbd_ctx *ctx, Formatter *f) } else { tbl.define_column("id", TextTable::LEFT, TextTable::LEFT); tbl.define_column("pool", TextTable::LEFT, TextTable::LEFT); + tbl.define_column("namespace", TextTable::LEFT, TextTable::LEFT); tbl.define_column("image", TextTable::LEFT, TextTable::LEFT); tbl.define_column("snap", TextTable::LEFT, TextTable::LEFT); tbl.define_column("device", TextTable::LEFT, TextTable::LEFT); @@ -807,11 +856,15 @@ extern "C" void krbd_destroy(struct krbd_ctx *ctx) delete ctx; } -extern "C" int krbd_map(struct krbd_ctx *ctx, const char *pool, - const char *image, const char *snap, - const char *options, char **pdevnode) +extern "C" int krbd_map(struct krbd_ctx *ctx, + const char *pool_name, + const char *nspace_name, + const char *image_name, + const char *snap_name, + const char *options, + char **pdevnode) { - krbd_spec spec(pool, image, snap); + krbd_spec spec(pool_name, nspace_name, image_name, snap_name); string name; char *devnode; int r; @@ -834,11 +887,14 @@ extern "C" int krbd_unmap(struct krbd_ctx *ctx, const char *devnode, return unmap_image(ctx, devnode, options); } -extern "C" int krbd_unmap_by_spec(struct krbd_ctx *ctx, const char *pool, - const char *image, const char *snap, +extern "C" int krbd_unmap_by_spec(struct krbd_ctx *ctx, + const char *pool_name, + const char *nspace_name, + const char *image_name, + const char *snap_name, const char *options) { - krbd_spec spec(pool, image, snap); + krbd_spec spec(pool_name, nspace_name, image_name, snap_name); return unmap_image(ctx, spec, options); } @@ -847,11 +903,14 @@ int krbd_showmapped(struct krbd_ctx *ctx, Formatter *f) return dump_images(ctx, f); } -extern "C" int krbd_is_mapped(struct krbd_ctx *ctx, const char *pool, - const char *image, const char *snap, +extern "C" int krbd_is_mapped(struct krbd_ctx *ctx, + const char *pool_name, + const char *nspace_name, + const char *image_name, + const char *snap_name, char **pdevnode) { - krbd_spec spec(pool, image, snap); + krbd_spec spec(pool_name, nspace_name, image_name, snap_name); string name; char *devnode; int r; diff --git a/src/test/cli-integration/rbd/unmap.t b/src/test/cli-integration/rbd/unmap.t index 8f6d6242656d0..6712abf2494ee 100644 --- a/src/test/cli-integration/rbd/unmap.t +++ b/src/test/cli-integration/rbd/unmap.t @@ -30,8 +30,8 @@ Unmap by device Unmap by device (img is already mapped): $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) $ sudo rbd device unmap $DEV $ rbd device list @@ -39,15 +39,15 @@ Unmap by device partition: $ DEV=$(sudo rbd device map img) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) $ sudo rbd device unmap ${DEV}p1 $ rbd device list $ DEV=$(sudo rbd device map img) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) $ sudo rbd device unmap ${DEV}p5 $ rbd device list @@ -84,16 +84,16 @@ img: $ sudo rbd device map img /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) $ sudo rbd device unmap img $ rbd device list $ sudo rbd device map img /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) $ sudo rbd --image img device unmap $ rbd device list @@ -102,24 +102,24 @@ img@snap: $ sudo rbd device map img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap img@snap $ rbd device list $ sudo rbd device map img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd --snap snap device unmap img $ rbd device list $ sudo rbd device map img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd --image img --snap snap device unmap $ rbd device list @@ -128,32 +128,32 @@ pool/img@snap, default pool: $ sudo rbd device map rbd/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap rbd/img@snap $ rbd device list $ sudo rbd device map rbd/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd --pool rbd device unmap img@snap $ rbd device list $ sudo rbd device map rbd/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd --pool rbd --snap snap device unmap img $ rbd device list $ sudo rbd device map rbd/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd --pool rbd --image img --snap snap device unmap $ rbd device list @@ -162,32 +162,32 @@ pool/img@snap, custom pool: $ sudo rbd device map custom/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) $ sudo rbd device unmap custom/img@snap $ rbd device list $ sudo rbd device map custom/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) $ sudo rbd --pool custom device unmap img@snap $ rbd device list $ sudo rbd device map custom/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) $ sudo rbd --pool custom --snap snap device unmap img $ rbd device list $ sudo rbd device map custom/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) $ sudo rbd --pool custom --image img --snap snap device unmap $ rbd device list @@ -238,13 +238,13 @@ Unmap img first: $ sudo rbd device map anotherimg /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) - ? rbd anotherimg - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) + ? rbd anotherimg - /dev/rbd? (glob) $ sudo rbd device unmap img $ rbd device list - id pool image snap device - ? rbd anotherimg - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd anotherimg - /dev/rbd? (glob) $ sudo rbd device unmap anotherimg $ rbd device list @@ -255,13 +255,13 @@ Unmap anotherimg first: $ sudo rbd device map anotherimg /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) - ? rbd anotherimg - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) + ? rbd anotherimg - /dev/rbd? (glob) $ sudo rbd device unmap anotherimg $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) $ sudo rbd device unmap img $ rbd device list @@ -276,13 +276,13 @@ Unmap the image first: $ sudo rbd device map img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap img $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap img@snap $ rbd device list @@ -293,13 +293,13 @@ Unmap the snap first: $ sudo rbd device map img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap img@snap $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) $ sudo rbd device unmap img $ rbd device list @@ -314,13 +314,13 @@ Unmap snap first: $ sudo rbd device map custom/img@anothersnap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) - ? custom img anothersnap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) + ? custom img anothersnap /dev/rbd? (glob) $ sudo rbd device unmap custom/img@snap $ rbd device list - id pool image snap device - ? custom img anothersnap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img anothersnap /dev/rbd? (glob) $ sudo rbd device unmap custom/img@anothersnap $ rbd device list @@ -331,13 +331,13 @@ Unmap anothersnap first: $ sudo rbd device map custom/img@anothersnap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) - ? custom img anothersnap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) + ? custom img anothersnap /dev/rbd? (glob) $ sudo rbd device unmap custom/img@anothersnap $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) $ sudo rbd device unmap custom/img@snap $ rbd device list @@ -352,13 +352,13 @@ img: $ sudo rbd device map custom/img /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) - ? custom img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) + ? custom img - /dev/rbd? (glob) $ sudo rbd device unmap img $ rbd device list - id pool image snap device - ? custom img - /dev/rbd? (glob) + id pool namespace image snap device + ? custom img - /dev/rbd? (glob) $ sudo rbd device unmap custom/img $ rbd device list @@ -369,13 +369,13 @@ img@snap: $ sudo rbd device map custom/img@snap /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) - ? custom img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) + ? custom img snap /dev/rbd? (glob) $ sudo rbd device unmap custom/img@snap $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap img@snap $ rbd device list @@ -391,14 +391,14 @@ img: rbd: warning: image already mapped as /dev/rbd? (glob) /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) + ? rbd img - /dev/rbd? (glob) $ sudo rbd device unmap img rbd: rbd/img: mapped more than once, unmapping /dev/rbd? only (glob) $ rbd device list - id pool image snap device - ? rbd img - /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img - /dev/rbd? (glob) $ sudo rbd device unmap img $ rbd device list @@ -410,14 +410,14 @@ img@snap: rbd: warning: image already mapped as /dev/rbd? (glob) /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap img@snap rbd: rbd/img@snap: mapped more than once, unmapping /dev/rbd? only (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap img@snap $ rbd device list @@ -429,14 +429,14 @@ pool/img@snap, default pool: rbd: warning: image already mapped as /dev/rbd? (glob) /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap rbd/img@snap rbd: rbd/img@snap: mapped more than once, unmapping /dev/rbd? only (glob) $ rbd device list - id pool image snap device - ? rbd img snap /dev/rbd? (glob) + id pool namespace image snap device + ? rbd img snap /dev/rbd? (glob) $ sudo rbd device unmap rbd/img@snap $ rbd device list @@ -448,14 +448,14 @@ pool/img@snap, custom pool: rbd: warning: image already mapped as /dev/rbd? (glob) /dev/rbd? (glob) $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) - ? custom img snap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) + ? custom img snap /dev/rbd? (glob) $ sudo rbd device unmap custom/img@snap rbd: custom/img@snap: mapped more than once, unmapping /dev/rbd? only (glob) $ rbd device list - id pool image snap device - ? custom img snap /dev/rbd? (glob) + id pool namespace image snap device + ? custom img snap /dev/rbd? (glob) $ sudo rbd device unmap custom/img@snap $ rbd device list diff --git a/src/test/librbd/fsx.cc b/src/test/librbd/fsx.cc index b0863e42aca21..37fce7575fb8c 100644 --- a/src/test/librbd/fsx.cc +++ b/src/test/librbd/fsx.cc @@ -968,7 +968,7 @@ krbd_open(const char *name, struct rbd_ctx *ctx) if (ret < 0) return ret; - ret = krbd_map(krbd, pool, name, "", "", &devnode); + ret = krbd_map(krbd, pool, "", name, "", "", &devnode); if (ret < 0) { prt("krbd_map(%s) failed\n", name); return ret; diff --git a/src/tools/rbd/action/Kernel.cc b/src/tools/rbd/action/Kernel.cc index 91715e329fc0c..2695fb16f3cbe 100644 --- a/src/tools/rbd/action/Kernel.cc +++ b/src/tools/rbd/action/Kernel.cc @@ -234,8 +234,11 @@ static int get_unsupported_features(librbd::Image &image, * based on errno return by krbd_map(). also note that even if some librbd calls * fail, we at least dump the "try dmesg..." message to aid debugging. */ -static void print_error_description(const char *poolname, const char *imgname, - const char *snapname, int maperrno) +static void print_error_description(const char *poolname, + const char *nspace_name, + const char *imgname, + const char *snapname, + int maperrno) { int r; uint8_t oldformat; @@ -246,7 +249,7 @@ static void print_error_description(const char *poolname, const char *imgname, if (maperrno == -ENOENT) goto done; - r = utils::init_and_open_image(poolname, "", imgname, "", snapname, + r = utils::init_and_open_image(poolname, nspace_name, imgname, "", snapname, true, &rados, &ioctx, &image); if (r < 0) goto done; @@ -276,10 +279,12 @@ static void print_error_description(const char *poolname, const char *imgname, } else { std::cout << "You can disable features unsupported by the kernel " << "with \"rbd feature disable "; - - if (poolname != utils::get_default_pool_name()) { + if (poolname != utils::get_default_pool_name() || *nspace_name) { std::cout << poolname << "/"; } + if (*nspace_name) { + std::cout << nspace_name << "/"; + } std::cout << imgname; } } else { @@ -301,8 +306,8 @@ static void print_error_description(const char *poolname, const char *imgname, std::cout << "In some cases useful info is found in syslog - try \"dmesg | tail\"." << std::endl; } -static int do_kernel_map(const char *poolname, const char *imgname, - const char *snapname) +static int do_kernel_map(const char *poolname, const char *nspace_name, + const char *imgname, const char *snapname) { #if defined(WITH_KRBD) struct krbd_ctx *krbd; @@ -329,7 +334,7 @@ static int do_kernel_map(const char *poolname, const char *imgname, } } - r = krbd_is_mapped(krbd, poolname, imgname, snapname, &devnode); + r = krbd_is_mapped(krbd, poolname, nspace_name, imgname, snapname, &devnode); if (r < 0) { std::cerr << "rbd: warning: can't get image map information: " << cpp_strerror(r) << std::endl; @@ -339,9 +344,10 @@ static int do_kernel_map(const char *poolname, const char *imgname, free(devnode); } - r = krbd_map(krbd, poolname, imgname, snapname, oss.str().c_str(), &devnode); + r = krbd_map(krbd, poolname, nspace_name, imgname, snapname, + oss.str().c_str(), &devnode); if (r < 0) { - print_error_description(poolname, imgname, snapname, r); + print_error_description(poolname, nspace_name, imgname, snapname, r); goto out; } @@ -358,7 +364,8 @@ out: } static int do_kernel_unmap(const char *dev, const char *poolname, - const char *imgname, const char *snapname) + const char *nspace_name, const char *imgname, + const char *snapname) { #if defined(WITH_KRBD) struct krbd_ctx *krbd; @@ -378,7 +385,7 @@ static int do_kernel_unmap(const char *dev, const char *poolname, if (dev) r = krbd_unmap(krbd, dev, oss.str().c_str()); else - r = krbd_unmap_by_spec(krbd, poolname, imgname, snapname, + r = krbd_unmap_by_spec(krbd, poolname, nspace_name, imgname, snapname, oss.str().c_str()); krbd_destroy(krbd); @@ -411,10 +418,11 @@ int execute_map(const po::variables_map &vm, const std::vector &ceph_global_init_args) { size_t arg_index = 0; std::string pool_name; + std::string nspace_name; std::string image_name; std::string snap_name; int r = utils::get_pool_image_snapshot_names( - vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, nullptr, + vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &nspace_name, &image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_PERMITTED, utils::SPEC_VALIDATION_NONE); if (r < 0) { @@ -448,7 +456,8 @@ int execute_map(const po::variables_map &vm, utils::init_context(); - r = do_kernel_map(pool_name.c_str(), image_name.c_str(), snap_name.c_str()); + r = do_kernel_map(pool_name.c_str(), nspace_name.c_str(), image_name.c_str(), + snap_name.c_str()); if (r < 0) { std::cerr << "rbd: map failed: " << cpp_strerror(r) << std::endl; return r; @@ -466,12 +475,13 @@ int execute_unmap(const po::variables_map &vm, size_t arg_index = 0; std::string pool_name; + std::string nspace_name; std::string image_name; std::string snap_name; int r; if (device_name.empty()) { r = utils::get_pool_image_snapshot_names( - vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, nullptr, + vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &nspace_name, &image_name, &snap_name, false, utils::SNAPSHOT_PRESENCE_PERMITTED, utils::SPEC_VALIDATION_NONE); if (r < 0) { @@ -498,7 +508,8 @@ int execute_unmap(const po::variables_map &vm, utils::init_context(); r = do_kernel_unmap(device_name.empty() ? nullptr : device_name.c_str(), - pool_name.c_str(), image_name.c_str(), snap_name.c_str()); + pool_name.c_str(), nspace_name.c_str(), + image_name.c_str(), snap_name.c_str()); if (r < 0) { std::cerr << "rbd: unmap failed: " << cpp_strerror(r) << std::endl; return r; -- 2.39.5