using util::create_async_context_callback;
template <typename I>
-CloneRequest<I>::CloneRequest(I *p_imctx, IoCtx &c_ioctx, const std::string &c_name,
+CloneRequest<I>::CloneRequest(I *p_imctx, IoCtx &c_ioctx,
+ const std::string &c_name,
+ const std::string &c_id,
ImageOptions c_options,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
ContextWQ *op_work_queue, Context *on_finish)
- : m_p_imctx(p_imctx), m_ioctx(c_ioctx), m_name(c_name), m_opts(c_options),
+ : m_p_imctx(p_imctx), m_ioctx(c_ioctx), m_name(c_name), m_id(c_id),
+ m_opts(c_options),
m_pspec(m_p_imctx->md_ctx.get_id(), m_p_imctx->id, m_p_imctx->snap_id),
m_non_primary_global_image_id(non_primary_global_image_id),
m_primary_mirror_uuid(primary_mirror_uuid),
Context *ctx = create_context_callback<klass, &klass::handle_create>(this);
RWLock::RLocker snap_locker(m_p_imctx->snap_lock);
- m_id = librbd::util::generate_image_id(m_ioctx);
CreateRequest<I> *req = CreateRequest<I>::create(
m_ioctx, m_name, m_id, m_size, m_opts, m_non_primary_global_image_id,
m_primary_mirror_uuid, true, m_op_work_queue, ctx);
class CloneRequest {
public:
static CloneRequest *create(ImageCtxT *p_imctx, IoCtx &c_ioctx, const std::string &c_name,
- ImageOptions c_options,
+ const std::string &c_id, ImageOptions c_options,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
ContextWQ *op_work_queue, Context *on_finish) {
- return new CloneRequest(p_imctx, c_ioctx, c_name, c_options,
+ return new CloneRequest(p_imctx, c_ioctx, c_name, c_id, c_options,
non_primary_global_image_id, primary_mirror_uuid,
op_work_queue, on_finish);
}
*/
CloneRequest(ImageCtxT *p_imctx, IoCtx &c_ioctx, const std::string &c_name,
+ const std::string &c_id,
ImageOptions c_options,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
int r = opts.set(RBD_IMAGE_OPTION_ORDER, order_);
assert(r == 0);
- r = create(io_ctx, imgname, size, opts, "", "", false);
+ r = create(io_ctx, imgname, "", size, opts, "", "", false);
int r1 = opts.get(RBD_IMAGE_OPTION_ORDER, &order_);
assert(r1 == 0);
r = opts.set(RBD_IMAGE_OPTION_STRIPE_COUNT, stripe_count);
assert(r == 0);
- r = create(io_ctx, imgname, size, opts, "", "", false);
+ r = create(io_ctx, imgname, "", size, opts, "", "", false);
int r1 = opts.get(RBD_IMAGE_OPTION_ORDER, &order_);
assert(r1 == 0);
return r;
}
- int create(IoCtx& io_ctx, const char *imgname, uint64_t size,
+ int create(IoCtx& io_ctx, const std::string &image_name,
+ const std::string &image_id, uint64_t size,
ImageOptions& opts,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
bool skip_mirror_enable)
{
+ std::string id(image_id);
+ if (id.empty()) {
+ id = util::generate_image_id(io_ctx);
+ }
+
CephContext *cct = (CephContext *)io_ctx.cct();
- ldout(cct, 10) << __func__ << " name=" << imgname << ", "
- << "size=" << size << ", opts=" << opts << dendl;
+ ldout(cct, 10) << __func__ << " name=" << image_name << ", "
+ << "id= " << id << ", "
+ << "size=" << size << ", opts=" << opts << dendl;
uint64_t format;
if (opts.get(RBD_IMAGE_OPTION_FORMAT, &format) != 0)
format = cct->_conf->rbd_default_format;
bool old_format = format == 1;
-
// make sure it doesn't already exist, in either format
- int r = detect_format(io_ctx, imgname, NULL, NULL);
+ int r = detect_format(io_ctx, image_name, NULL, NULL);
if (r != -ENOENT) {
if (r) {
- lderr(cct) << "Could not tell if " << imgname << " already exists" << dendl;
+ lderr(cct) << "Could not tell if " << image_name << " already exists"
+ << dendl;
return r;
}
- lderr(cct) << "rbd image " << imgname << " already exists" << dendl;
+ lderr(cct) << "rbd image " << image_name << " already exists" << dendl;
return -EEXIST;
}
}
if (old_format) {
- r = create_v1(io_ctx, imgname, size, order);
+ r = create_v1(io_ctx, image_name.c_str(), size, order);
} else {
ThreadPool *thread_pool;
ContextWQ *op_work_queue;
ImageCtx::get_thread_pool_instance(cct, &thread_pool, &op_work_queue);
C_SaferCond cond;
- std::string id = util::generate_image_id(io_ctx);
image::CreateRequest<> *req = image::CreateRequest<>::create(
- io_ctx, imgname, id, size, opts, non_primary_global_image_id,
+ io_ctx, image_name, id, size, opts, non_primary_global_image_id,
primary_mirror_uuid, skip_mirror_enable, op_work_queue, &cond);
req->send();
return r;
}
- r = clone(p_imctx, c_ioctx, c_name, c_opts, "", "");
+ r = clone(p_imctx, c_ioctx, c_name, "", c_opts, "", "");
int close_r = p_imctx->state->close();
if (r == 0 && close_r < 0) {
return 0;
}
- int clone(ImageCtx *p_imctx, IoCtx& c_ioctx, const char *c_name,
- ImageOptions& c_opts,
+ int clone(ImageCtx *p_imctx, IoCtx& c_ioctx, const std::string &c_name,
+ const std::string &c_id, ImageOptions& c_opts,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid)
{
+ std::string id(c_id);
+ if (id.empty()) {
+ id = util::generate_image_id(c_ioctx);
+ }
+
CephContext *cct = (CephContext *)c_ioctx.cct();
+ ldout(cct, 10) << __func__ << " "
+ << "c_name=" << c_name << ", "
+ << "c_id= " << c_id << ", "
+ << "c_opts=" << c_opts << dendl;
ThreadPool *thread_pool;
ContextWQ *op_work_queue;
C_SaferCond cond;
auto *req = image::CloneRequest<>::create(
- p_imctx, c_ioctx, std::string(c_name), c_opts, non_primary_global_image_id,
- primary_mirror_uuid, op_work_queue, &cond);
+ p_imctx, c_ioctx, c_name, id, c_opts,
+ non_primary_global_image_id, primary_mirror_uuid, op_work_queue, &cond);
req->send();
return cond.wait();
return -ENOSYS;
}
- int r = create(dest_md_ctx, destname, src_size, opts, "", "", false);
+ int r = create(dest_md_ctx, destname, "", src_size, opts, "", "", false);
if (r < 0) {
lderr(cct) << "header creation failed" << dendl;
return r;
int create(librados::IoCtx& io_ctx, const char *imgname, uint64_t size,
bool old_format, uint64_t features, int *order,
uint64_t stripe_unit, uint64_t stripe_count);
- int create(IoCtx& io_ctx, const char *imgname, uint64_t size,
- ImageOptions& opts,
+ int create(IoCtx& io_ctx, const std::string &image_name,
+ const std::string &image_id, uint64_t size, ImageOptions& opts,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
bool skip_mirror_enable);
uint64_t stripe_unit, int stripe_count);
int clone(IoCtx& p_ioctx, const char *p_name, const char *p_snap_name,
IoCtx& c_ioctx, const char *c_name, ImageOptions& c_opts);
- int clone(ImageCtx *p_imctx, IoCtx& c_ioctx, const char *c_name,
- ImageOptions& c_opts,
+ int clone(ImageCtx *p_imctx, IoCtx& c_ioctx, const std::string &c_name,
+ const std::string &c_id, ImageOptions& c_opts,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid);
int rename(librados::IoCtx& io_ctx, const char *srcname, const char *dstname);
{
TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
tracepoint(librbd, create4_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name, size, opts.opts);
- int r = librbd::create(io_ctx, name, size, opts, "", "", false);
+ int r = librbd::create(io_ctx, name, "", size, opts, "", "", false);
tracepoint(librbd, create4_exit, r);
return r;
}
TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
tracepoint(librbd, create4_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name, size, opts);
librbd::ImageOptions opts_(opts);
- int r = librbd::create(io_ctx, name, size, opts_, "", "", false);
+ int r = librbd::create(io_ctx, name, "", size, opts_, "", "", false);
tracepoint(librbd, create4_exit, r);
return r;
}
static CloneRequest *create(librbd::MockTestImageCtx *p_imctx,
IoCtx &c_ioctx, const std::string &c_name,
- ImageOptions c_options,
+ const std::string &c_id, ImageOptions c_options,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
MockContextWQ *op_work_queue, Context *on_finish) {
opts.set(RBD_IMAGE_OPTION_STRIPE_UNIT, m_remote_image_ctx->stripe_unit);
opts.set(RBD_IMAGE_OPTION_STRIPE_COUNT, m_remote_image_ctx->stripe_count);
+ std::string id = librbd::util::generate_image_id(m_local_io_ctx);
+
using klass = CreateImageRequest<I>;
Context *ctx = create_context_callback<klass, &klass::handle_clone_image>(this);
librbd::image::CloneRequest<I> *req = librbd::image::CloneRequest<I>::create(
- m_local_parent_image_ctx, m_local_io_ctx, m_local_image_name, opts,
+ m_local_parent_image_ctx, m_local_io_ctx, m_local_image_name, id, opts,
m_global_image_id, m_remote_mirror_uuid,
m_remote_image_ctx->op_work_queue, ctx);
req->send();