journal_policy = new journal::StandardPolicy<ImageCtx>(this);
}
+ ImageCtx::ImageCtx(const string &image_name, const string &image_id,
+ uint64_t snap_id, IoCtx& p, bool ro)
+ : ImageCtx(image_name, image_id, "", p, ro) {
+ open_snap_id = snap_id;
+ }
+
ImageCtx::~ImageCtx() {
assert(image_watcher == NULL);
assert(exclusive_lock == NULL);
// a format librados can understand
std::map<librados::snap_t, SnapInfo> snap_info;
std::map<std::pair<cls::rbd::SnapshotNamespace, std::string>, librados::snap_t> snap_ids;
+ uint64_t open_snap_id = CEPH_NOSNAP;
uint64_t snap_id;
bool snap_exists; // false if our snap_id was deleted
// whether the image was opened read-only. cannot be changed after opening
const char *snap, IoCtx& p, bool read_only) {
return new ImageCtx(image_name, image_id, snap, p, read_only);
}
+ static ImageCtx* create(const std::string &image_name,
+ const std::string &image_id,
+ librados::snap_t snap_id, IoCtx& p,
+ bool read_only) {
+ return new ImageCtx(image_name, image_id, snap_id, p, read_only);
+ }
void destroy() {
delete this;
}
*/
ImageCtx(const std::string &image_name, const std::string &image_id,
const char *snap, IoCtx& p, bool read_only);
+ ImageCtx(const std::string &image_name, const std::string &image_id,
+ librados::snap_t snap_id, IoCtx& p, bool read_only);
~ImageCtx();
void init();
void shutdown();
}
opts.set(RBD_IMAGE_OPTION_ORDER, static_cast<uint64_t>(order));
- ImageCtx *dest = new librbd::ImageCtx(destname, "", NULL,
+ ImageCtx *dest = new librbd::ImageCtx(destname, "", nullptr,
dest_md_ctx, false);
r = dest->state->open(0);
if (r < 0) {
void CloneRequest<I>::open_child() {
ldout(m_cct, 20) << dendl;
- m_imctx = I::create(m_name, "", NULL, m_ioctx, false);
+ m_imctx = I::create(m_name, "", nullptr, m_ioctx, false);
using klass = CloneRequest<I>;
Context *ctx = create_context_callback<
template <typename I>
Context *OpenRequest<I>::send_set_snap(int *result) {
- if (m_image_ctx->snap_name.empty()) {
+ if (m_image_ctx->snap_name.empty() &&
+ m_image_ctx->open_snap_id == CEPH_NOSNAP) {
*result = 0;
return m_on_finish;
}
ldout(cct, 10) << this << " " << __func__ << dendl;
uint64_t snap_id = CEPH_NOSNAP;
- {
+ std::swap(m_image_ctx->open_snap_id, snap_id);
+ if (snap_id == CEPH_NOSNAP) {
RWLock::RLocker snap_locker(m_image_ctx->snap_lock);
snap_id = m_image_ctx->get_snap_id(m_image_ctx->snap_namespace,
m_image_ctx->snap_name);
ioctx.set_namespace(ictx->md_ctx.get_namespace());
for (auto &id_it : info.second) {
- ImageCtx *imctx = new ImageCtx("", id_it, NULL, ioctx, false);
+ ImageCtx *imctx = new ImageCtx("", id_it, nullptr, ioctx, false);
int r = imctx->state->open(0);
if (r < 0) {
lderr(cct) << "error opening image: "
}
opts.set(RBD_IMAGE_OPTION_ORDER, static_cast<uint64_t>(order));
- ImageCtx *dest = new librbd::ImageCtx(destname, "", NULL,
- dest_md_ctx, false);
+ ImageCtx *dest = new librbd::ImageCtx(destname, "", nullptr, dest_md_ctx,
+ false);
r = dest->state->open(0);
if (r < 0) {
lderr(cct) << "failed to read newly created header" << dendl;
int TestFixture::open_image(const std::string &image_name,
librbd::ImageCtx **ictx) {
- *ictx = new librbd::ImageCtx(image_name.c_str(), "", NULL, m_ioctx, false);
+ *ictx = new librbd::ImageCtx(image_name.c_str(), "", nullptr, m_ioctx, false);
m_ictxs.insert(*ictx);
return (*ictx)->state->open(false);
int TestFixture::open_image(librados::IoCtx &io_ctx,
const std::string &image_name,
librbd::ImageCtx **image_ctx) {
- *image_ctx = new librbd::ImageCtx(image_name.c_str(), "", NULL, io_ctx,
+ *image_ctx = new librbd::ImageCtx(image_name.c_str(), "", nullptr, io_ctx,
false);
m_image_ctxs.insert(*image_ctx);
return (*image_ctx)->state->open(false);