Skip to content

Commit

Permalink
librbd/Utils: add ioctx cration for external clusters
Browse files Browse the repository at this point in the history
This commit adds a new utility function for creating an IoCtx for external cluster access.

Signed-off-by: Or Ozeri <[email protected]>
  • Loading branch information
orozery committed Jan 5, 2022
1 parent 0247bbd commit 1b4ff8d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/librbd/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,20 @@ int create_ioctx(librados::IoCtx& src_io_ctx, const std::string& pool_desc,
int64_t pool_id,
const std::optional<std::string>& pool_namespace,
librados::IoCtx* dst_io_ctx) {
auto cct = (CephContext *)src_io_ctx.cct();

librados::Rados rados(src_io_ctx);
return create_ioctx2(
rados, (CephContext *)src_io_ctx.cct(), pool_desc, pool_id,
pool_namespace ? pool_namespace :
std::make_optional(src_io_ctx.get_namespace()),
src_io_ctx.get_pool_full_try(),
dst_io_ctx);
}

int create_ioctx2(librados::Rados& rados, CephContext* cct,
const std::string& pool_desc, int64_t pool_id,
const std::optional<std::string>& pool_namespace,
bool pool_full_try,
librados::IoCtx* dst_io_ctx) {
int r = rados.ioctx_create2(pool_id, *dst_io_ctx);
if (r == -ENOENT) {
ldout(cct, 1) << pool_desc << " pool " << pool_id << " no longer exists"
Expand All @@ -152,9 +163,10 @@ int create_ioctx(librados::IoCtx& src_io_ctx, const std::string& pool_desc,
return r;
}

dst_io_ctx->set_namespace(
pool_namespace ? *pool_namespace : src_io_ctx.get_namespace());
if (src_io_ctx.get_pool_full_try()) {
if (pool_namespace) {
dst_io_ctx->set_namespace(*pool_namespace);
}
if (pool_full_try) {
dst_io_ctx->set_pool_full_try();
}
return 0;
Expand Down
6 changes: 6 additions & 0 deletions src/librbd/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ int create_ioctx(librados::IoCtx& src_io_ctx, const std::string& pool_desc,
int64_t pool_id,
const std::optional<std::string>& pool_namespace,
librados::IoCtx* dst_io_ctx);
int create_ioctx2(librados::Rados& rados, CephContext* cct,
const std::string& pool_desc,
int64_t pool_id,
const std::optional<std::string>& pool_namespace,
bool pool_full_try,
librados::IoCtx* dst_io_ctx);

int snap_create_flags_api_to_internal(CephContext *cct, uint32_t api_flags,
uint64_t *internal_flags);
Expand Down

0 comments on commit 1b4ff8d

Please sign in to comment.