#include "librbd/ImageState.h"
#include "librbd/internal.h"
#include "librbd/Operations.h"
+#include "librbd/Utils.h"
#include "librbd/api/Config.h"
#include "librbd/api/DiffIterate.h"
#include "librbd/api/Group.h"
#include "librbd/api/Image.h"
+#include "librbd/api/Io.h"
#include "librbd/api/Migration.h"
#include "librbd/api/Mirror.h"
#include "librbd/api/Namespace.h"
#include "librbd/api/Snapshot.h"
#include "librbd/api/Trash.h"
#include "librbd/io/AioCompletion.h"
-#include "librbd/io/ImageRequestWQ.h"
#include "librbd/io/ReadResult.h"
#include <algorithm>
#include <string>
}
void finish(int r) override {
- ldout(cct, 20) << "C_AioComplete::finish: r=" << r << dendl;
+ ldout(cct, 20) << "C_AioCompletion::finish: r=" << r << dendl;
if (r < 0) {
aio_comp->fail(r);
} else {
ictx(ictx), ictxp(ictxp) {
}
void finish(int r) override {
- ldout(ictx->cct, 20) << "C_OpenComplete::finish: r=" << r << dendl;
+ ldout(cct, 20) << "C_OpenComplete::finish: r=" << r << dendl;
if (r < 0) {
*ictxp = nullptr;
} else {
void finish(int r) override {
ldout(ictx->cct, 20) << "C_OpenAfterCloseComplete::finish: r=" << r
<< dendl;
- delete reinterpret_cast<librbd::ImageCtx*>(*ictxp);
*ictxp = nullptr;
ictx->state->open(0, new C_OpenComplete(ictx, comp, ictxp));
}
};
+struct C_QuiesceWatchCB : public librbd::QuiesceWatchCtx {
+ rbd_update_callback_t quiesce_cb;
+ rbd_update_callback_t unquiesce_cb;
+ void *arg;
+ uint64_t handle = 0;
+
+ C_QuiesceWatchCB(rbd_update_callback_t quiesce_cb,
+ rbd_update_callback_t unquiesce_cb, void *arg) :
+ quiesce_cb(quiesce_cb), unquiesce_cb(unquiesce_cb), arg(arg) {
+ }
+ void handle_quiesce() override {
+ quiesce_cb(arg);
+ }
+ void handle_unquiesce() override {
+ unquiesce_cb(arg);
+ }
+};
+
void group_image_status_cpp_to_c(const librbd::group_image_info_t &cpp_info,
rbd_group_image_info_t *c_info) {
c_info->name = strdup(cpp_info.name.c_str());
tracepoint(librbd, trash_undelete_enter, io_ctx.get_pool_name().c_str(),
io_ctx.get_id(), id, name);
int r = librbd::api::Trash<>::restore(
- io_ctx, librbd::api::Trash<>::RESTORE_SOURCE_WHITELIST, id, name);
+ io_ctx, librbd::api::Trash<>::ALLOWED_RESTORE_SOURCES, id, name);
tracepoint(librbd, trash_undelete_exit, r);
return r;
}
return r;
}
+ int RBD::migration_prepare_import(const char *source_spec, IoCtx& dest_io_ctx,
+ const char *dest_image_name,
+ ImageOptions& opts) {
+ return librbd::api::Migration<>::prepare_import(source_spec, dest_io_ctx,
+ dest_image_name, opts);
+ }
+
int RBD::migration_execute(IoCtx& io_ctx, const char *image_name)
{
TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
group_ioctx.get_pool_name().c_str(),
group_ioctx.get_id(), group_name, snap_name);
int r = librbd::api::Group<>::snap_create(group_ioctx, group_name,
- snap_name);
+ snap_name, 0);
+ tracepoint(librbd, group_snap_create_exit, r);
+ return r;
+ }
+
+ int RBD::group_snap_create2(IoCtx& group_ioctx, const char *group_name,
+ const char *snap_name, uint32_t flags) {
+ TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
+ tracepoint(librbd, group_snap_create_enter,
+ group_ioctx.get_pool_name().c_str(),
+ group_ioctx.get_id(), group_name, snap_name);
+ int r = librbd::api::Group<>::snap_create(group_ioctx, group_name,
+ snap_name, flags);
tracepoint(librbd, group_snap_create_exit, r);
return r;
}
return r;
}
+ int Image::get_migration_source_spec(std::string* source_spec)
+ {
+ auto ictx = reinterpret_cast<ImageCtx*>(ctx);
+ return librbd::api::Migration<>::get_source_spec(ictx, source_spec);
+ }
+
int Image::get_flags(uint64_t *flags)
{
ImageCtx *ictx = (ImageCtx *)ctx;
return r;
}
+ int Image::encryption_format(encryption_format_t format,
+ encryption_options_t opts,
+ size_t opts_size)
+ {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ return librbd::api::Image<>::encryption_format(
+ ictx, format, opts, opts_size, false);
+ }
+
+ int Image::encryption_load(encryption_format_t format,
+ encryption_options_t opts,
+ size_t opts_size)
+ {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ return librbd::api::Image<>::encryption_load(
+ ictx, format, opts, opts_size, false);
+ }
+
int Image::flatten()
{
ImageCtx *ictx = (ImageCtx *)ctx;
{
ImageCtx *ictx = (ImageCtx *)ctx;
tracepoint(librbd, snap_create_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, snap_name);
- int r = ictx->operations->snap_create(cls::rbd::UserSnapshotNamespace(),
- snap_name);
+ auto flags = librbd::util::get_default_snap_create_flags(ictx);
+ librbd::NoOpProgressContext prog_ctx;
+ int r = librbd::api::Snapshot<>::create(ictx, snap_name, flags, prog_ctx);
+ tracepoint(librbd, snap_create_exit, r);
+ return r;
+ }
+
+ int Image::snap_create2(const char *snap_name, uint32_t flags,
+ ProgressContext& prog_ctx)
+ {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ tracepoint(librbd, snap_create_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, snap_name);
+ int r = librbd::api::Snapshot<>::create(ictx, snap_name, flags, prog_ctx);
tracepoint(librbd, snap_create_exit, r);
return r;
}
tracepoint(librbd, read_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, ofs, len);
bufferptr ptr(len);
bl.push_back(std::move(ptr));
-
- int r = ictx->io_work_queue->read(ofs, len, io::ReadResult{&bl}, 0);
+
+ int r = api::Io<>::read(*ictx, ofs, len, io::ReadResult{&bl}, 0);
tracepoint(librbd, read_exit, r);
return r;
}
ictx->read_only, ofs, len, op_flags);
bufferptr ptr(len);
bl.push_back(std::move(ptr));
-
- int r = ictx->io_work_queue->read(ofs, len, io::ReadResult{&bl}, op_flags);
+
+ int r = api::Io<>::read(*ictx, ofs, len, io::ReadResult{&bl}, op_flags);
tracepoint(librbd, read_exit, r);
return r;
}
{
ImageCtx *ictx = (ImageCtx *)ctx;
tracepoint(librbd, read_iterate_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, ofs, len);
-
+
int64_t r = librbd::read_iterate(ictx, ofs, len, cb, arg);
tracepoint(librbd, read_iterate_exit, r);
return r;
{
ImageCtx *ictx = (ImageCtx *)ctx;
tracepoint(librbd, read_iterate2_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, ofs, len);
-
+
int64_t r = librbd::read_iterate(ictx, ofs, len, cb, arg);
if (r > 0)
r = 0;
return -EINVAL;
}
- int r = ictx->io_work_queue->write(ofs, len, bufferlist{bl}, 0);
+ int r = api::Io<>::write(*ictx, ofs, len, bufferlist{bl}, 0);
tracepoint(librbd, write_exit, r);
return r;
}
return -EINVAL;
}
- int r = ictx->io_work_queue->write(ofs, len, bufferlist{bl}, op_flags);
+ int r = api::Io<>::write(*ictx, ofs, len, bufferlist{bl}, op_flags);
tracepoint(librbd, write_exit, r);
return r;
}
tracepoint(librbd, discard_exit, -EINVAL);
return -EINVAL;
}
- int r = ictx->io_work_queue->discard(
- ofs, len, ictx->discard_granularity_bytes);
+ int r = api::Io<>::discard(
+ *ictx, ofs, len, ictx->discard_granularity_bytes);
tracepoint(librbd, discard_exit, r);
return r;
}
{
ImageCtx *ictx = (ImageCtx *)ctx;
tracepoint(librbd, writesame_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(),
- ictx->read_only, ofs, len, bl.length() <= 0 ? NULL : bl.c_str(), bl.length(),
+ ictx->read_only, ofs, len, bl.length() == 0 ? NULL : bl.c_str(), bl.length(),
op_flags);
- if (bl.length() <= 0 || len % bl.length() ||
+ if (bl.length() == 0 || len % bl.length() ||
len > static_cast<size_t>(std::numeric_limits<int>::max())) {
tracepoint(librbd, writesame_exit, -EINVAL);
return -EINVAL;
bool discard_zero = ictx->config.get_val<bool>("rbd_discard_on_zeroed_write_same");
if (discard_zero && bl.is_zero()) {
- int r = ictx->io_work_queue->write_zeroes(ofs, len, 0U, op_flags);
+ int r = api::Io<>::write_zeroes(*ictx, ofs, len, 0U, op_flags);
tracepoint(librbd, writesame_exit, r);
return r;
}
- int r = ictx->io_work_queue->writesame(ofs, len, bufferlist{bl}, op_flags);
+ int r = api::Io<>::write_same(*ictx, ofs, len, bufferlist{bl}, op_flags);
tracepoint(librbd, writesame_exit, r);
return r;
}
int op_flags)
{
ImageCtx *ictx = (ImageCtx *)ctx;
- return ictx->io_work_queue->write_zeroes(ofs, len, zero_flags, op_flags);
+ return api::Io<>::write_zeroes(*ictx, ofs, len, zero_flags, op_flags);
}
ssize_t Image::compare_and_write(uint64_t ofs, size_t len,
return -EINVAL;
}
- int r = ictx->io_work_queue->compare_and_write(ofs, len, bufferlist{cmp_bl},
- bufferlist{bl}, mismatch_off,
- op_flags);
+ int r = api::Io<>::compare_and_write(
+ *ictx, ofs, len, bufferlist{cmp_bl}, bufferlist{bl}, mismatch_off,
+ op_flags);
tracepoint(librbd, compare_and_write_exit, r);
tracepoint(librbd, aio_write_exit, -EINVAL);
return -EINVAL;
}
- ictx->io_work_queue->aio_write(get_aio_completion(c), off, len,
- bufferlist{bl}, 0);
+ api::Io<>::aio_write(*ictx, get_aio_completion(c), off, len, bufferlist{bl},
+ 0, true);
tracepoint(librbd, aio_write_exit, 0);
return 0;
tracepoint(librbd, aio_write_exit, -EINVAL);
return -EINVAL;
}
- ictx->io_work_queue->aio_write(get_aio_completion(c), off, len,
- bufferlist{bl}, op_flags);
+ api::Io<>::aio_write(*ictx, get_aio_completion(c), off, len, bufferlist{bl},
+ op_flags, true);
tracepoint(librbd, aio_write_exit, 0);
return 0;
}
- int Image::aio_discard(uint64_t off, uint64_t len, RBD::AioCompletion *c)
- {
- ImageCtx *ictx = (ImageCtx *)ctx;
- tracepoint(librbd, aio_discard_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, off, len, c->pc);
- ictx->io_work_queue->aio_discard(
- get_aio_completion(c), off, len, ictx->discard_granularity_bytes);
- tracepoint(librbd, aio_discard_exit, 0);
- return 0;
- }
-
int Image::aio_read(uint64_t off, size_t len, bufferlist& bl,
RBD::AioCompletion *c)
{
ldout(ictx->cct, 10) << "Image::aio_read() buf=" << (void *)bl.c_str() << "~"
<< (void *)(bl.c_str() + len - 1) << dendl;
- ictx->io_work_queue->aio_read(get_aio_completion(c), off, len,
- io::ReadResult{&bl}, 0);
+ api::Io<>::aio_read(*ictx, get_aio_completion(c), off, len,
+ io::ReadResult{&bl}, 0, true);
tracepoint(librbd, aio_read_exit, 0);
return 0;
}
ldout(ictx->cct, 10) << "Image::aio_read() buf=" << (void *)bl.c_str() << "~"
<< (void *)(bl.c_str() + len - 1) << dendl;
- ictx->io_work_queue->aio_read(get_aio_completion(c), off, len,
- io::ReadResult{&bl}, op_flags);
+ api::Io<>::aio_read(*ictx, get_aio_completion(c), off, len,
+ io::ReadResult{&bl}, op_flags, true);
tracepoint(librbd, aio_read_exit, 0);
return 0;
}
{
ImageCtx *ictx = (ImageCtx *)ctx;
tracepoint(librbd, flush_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only);
- int r = ictx->io_work_queue->flush();
+ int r = api::Io<>::flush(*ictx);
tracepoint(librbd, flush_exit, r);
return r;
}
{
ImageCtx *ictx = (ImageCtx *)ctx;
tracepoint(librbd, aio_flush_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, c->pc);
- ictx->io_work_queue->aio_flush(get_aio_completion(c));
+ api::Io<>::aio_flush(*ictx, get_aio_completion(c), true);
tracepoint(librbd, aio_flush_exit, 0);
return 0;
}
+ int Image::aio_discard(uint64_t off, uint64_t len, RBD::AioCompletion *c)
+ {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ tracepoint(librbd, aio_discard_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, off, len, c->pc);
+ api::Io<>::aio_discard(
+ *ictx, get_aio_completion(c), off, len, ictx->discard_granularity_bytes,
+ true);
+ tracepoint(librbd, aio_discard_exit, 0);
+ return 0;
+ }
+
int Image::aio_writesame(uint64_t off, size_t len, bufferlist& bl,
RBD::AioCompletion *c, int op_flags)
{
tracepoint(librbd, aio_writesame_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(),
ictx->read_only, off, len, bl.length() <= len ? NULL : bl.c_str(), bl.length(),
c->pc, op_flags);
- if (bl.length() <= 0 || len % bl.length()) {
+ if (bl.length() == 0 || len % bl.length()) {
tracepoint(librbd, aio_writesame_exit, -EINVAL);
return -EINVAL;
}
bool discard_zero = ictx->config.get_val<bool>("rbd_discard_on_zeroed_write_same");
if (discard_zero && bl.is_zero()) {
- ictx->io_work_queue->aio_write_zeroes(get_aio_completion(c), off, len, 0U,
- op_flags, true);
+ api::Io<>::aio_write_zeroes(*ictx, get_aio_completion(c), off, len, 0U,
+ op_flags, true);
tracepoint(librbd, aio_writesame_exit, 0);
return 0;
}
- ictx->io_work_queue->aio_writesame(get_aio_completion(c), off, len,
- bufferlist{bl}, op_flags);
+ api::Io<>::aio_write_same(*ictx, get_aio_completion(c), off, len,
+ bufferlist{bl}, op_flags, true);
tracepoint(librbd, aio_writesame_exit, 0);
return 0;
}
int zero_flags, int op_flags)
{
ImageCtx *ictx = (ImageCtx *)ctx;
- ictx->io_work_queue->aio_write_zeroes(
- get_aio_completion(c), off, len, zero_flags, op_flags, true);
+ api::Io<>::aio_write_zeroes(*ictx, get_aio_completion(c), off, len,
+ zero_flags, op_flags, true);
return 0;
}
return -EINVAL;
}
- ictx->io_work_queue->aio_compare_and_write(get_aio_completion(c), off, len,
- bufferlist{cmp_bl}, bufferlist{bl},
- mismatch_off, op_flags, false);
+ api::Io<>::aio_compare_and_write(*ictx, get_aio_completion(c), off, len,
+ bufferlist{cmp_bl}, bufferlist{bl},
+ mismatch_off, op_flags, false);
tracepoint(librbd, aio_compare_and_write_exit, 0);
int Image::mirror_image_create_snapshot(uint64_t *snap_id)
{
ImageCtx *ictx = (ImageCtx *)ctx;
- return librbd::api::Mirror<>::image_snapshot_create(ictx, 0U, snap_id);
+ auto flags = librbd::util::get_default_snap_create_flags(ictx);
+ return librbd::api::Mirror<>::image_snapshot_create(ictx, flags, snap_id);
+ }
+
+ int Image::mirror_image_create_snapshot2(uint32_t flags, uint64_t *snap_id)
+ {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ return librbd::api::Mirror<>::image_snapshot_create(ictx, flags, snap_id);
}
int Image::mirror_image_get_info(mirror_image_info_t *mirror_image_info,
return librbd::api::Config<>::list(ictx, options);
}
+ int Image::quiesce_watch(QuiesceWatchCtx *wctx, uint64_t *handle) {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ int r = ictx->state->register_quiesce_watcher(wctx, handle);
+ return r;
+ }
+
+ int Image::quiesce_unwatch(uint64_t handle) {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ int r = ictx->state->unregister_quiesce_watcher(handle);
+ return r;
+ }
+
+ void Image::quiesce_complete(uint64_t handle, int r) {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ ictx->state->quiesce_complete(handle, r);
+ }
+
} // namespace librbd
extern "C" void rbd_version(int *major, int *minor, int *extra)
tracepoint(librbd, trash_undelete_enter, io_ctx.get_pool_name().c_str(),
io_ctx.get_id(), id, name);
int r = librbd::api::Trash<>::restore(
- io_ctx, librbd::api::Trash<>::RESTORE_SOURCE_WHITELIST, id, name);
+ io_ctx, librbd::api::Trash<>::ALLOWED_RESTORE_SOURCES, id, name);
tracepoint(librbd, trash_undelete_exit, r);
return r;
}
return ret;
}
+extern "C" int rbd_encryption_format(rbd_image_t image,
+ rbd_encryption_format_t format,
+ rbd_encryption_options_t opts,
+ size_t opts_size)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ return librbd::api::Image<>::encryption_format(
+ ictx, format, opts, opts_size, true);
+}
+
+extern "C" int rbd_encryption_load(rbd_image_t image,
+ rbd_encryption_format_t format,
+ rbd_encryption_options_t opts,
+ size_t opts_size)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ return librbd::api::Image<>::encryption_load(
+ ictx, format, opts, opts_size, true);
+}
+
extern "C" int rbd_flatten(rbd_image_t image)
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
return r;
}
+extern "C" int rbd_migration_prepare_import(
+ const char *source_spec, rados_ioctx_t dest_p,
+ const char *dest_image_name, rbd_image_options_t opts_) {
+ librados::IoCtx dest_io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(dest_p, dest_io_ctx);
+ librbd::ImageOptions opts(opts_);
+ return librbd::api::Migration<>::prepare_import(source_spec, dest_io_ctx,
+ dest_image_name, opts);
+}
+
extern "C" int rbd_migration_execute(rados_ioctx_t p, const char *image_name)
{
librados::IoCtx io_ctx;
return r;
}
+extern "C" int rbd_get_migration_source_spec(rbd_image_t image,
+ char* source_spec,
+ size_t* max_len)
+{
+ auto ictx = reinterpret_cast<librbd::ImageCtx*>(image);
+
+ std::string cpp_source_spec;
+ int r = librbd::api::Migration<>::get_source_spec(ictx, &cpp_source_spec);
+ if (r < 0) {
+ return r;
+ }
+
+ size_t expected_size = cpp_source_spec.size();
+ if (expected_size >= *max_len) {
+ *max_len = expected_size + 1;
+ return -ERANGE;
+ }
+
+ strncpy(source_spec, cpp_source_spec.c_str(), expected_size);
+ source_spec[expected_size] = '\0';
+ *max_len = expected_size + 1;
+
+ return 0;
+}
+
extern "C" int rbd_get_flags(rbd_image_t image, uint64_t *flags)
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
tracepoint(librbd, snap_create_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, snap_name);
- int r = ictx->operations->snap_create(cls::rbd::UserSnapshotNamespace(),
- snap_name);
+ auto flags = librbd::util::get_default_snap_create_flags(ictx);
+ librbd::NoOpProgressContext prog_ctx;
+ int r = librbd::api::Snapshot<>::create(ictx, snap_name, flags, prog_ctx);
+ tracepoint(librbd, snap_create_exit, r);
+ return r;
+}
+
+extern "C" int rbd_snap_create2(rbd_image_t image, const char *snap_name,
+ uint32_t flags, librbd_progress_fn_t cb,
+ void *cbdata)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ tracepoint(librbd, snap_create_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, snap_name);
+ librbd::CProgressContext prog_ctx(cb, cbdata);
+ int r = librbd::api::Snapshot<>::create(ictx, snap_name, flags, prog_ctx);
tracepoint(librbd, snap_create_exit, r);
return r;
}
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
tracepoint(librbd, read_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, ofs, len);
- int r = ictx->io_work_queue->read(ofs, len, librbd::io::ReadResult{buf, len},
- 0);
+ int r = librbd::api::Io<>::read(
+ *ictx, ofs, len, librbd::io::ReadResult{buf, len}, 0);
tracepoint(librbd, read_exit, r);
return r;
}
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
tracepoint(librbd, read2_enter, ictx, ictx->name.c_str(),
ictx->snap_name.c_str(), ictx->read_only, ofs, len, op_flags);
- int r = ictx->io_work_queue->read(ofs, len, librbd::io::ReadResult{buf, len},
- op_flags);
+ int r = librbd::api::Io<>::read(
+ *ictx, ofs, len, librbd::io::ReadResult{buf, len}, op_flags);
tracepoint(librbd, read_exit, r);
return r;
}
bufferlist bl;
bl.push_back(create_write_raw(ictx, buf, len, nullptr));
- int r = ictx->io_work_queue->write(ofs, len, std::move(bl), 0);
+ int r = librbd::api::Io<>::write(*ictx, ofs, len, std::move(bl), 0);
tracepoint(librbd, write_exit, r);
return r;
}
bufferlist bl;
bl.push_back(create_write_raw(ictx, buf, len, nullptr));
- int r = ictx->io_work_queue->write(ofs, len, std::move(bl), op_flags);
+ int r = librbd::api::Io<>::write(*ictx, ofs, len, std::move(bl), op_flags);
tracepoint(librbd, write_exit, r);
return r;
}
return -EINVAL;
}
- int r = ictx->io_work_queue->discard(
- ofs, len, ictx->discard_granularity_bytes);
+ int r = librbd::api::Io<>::discard(
+ *ictx, ofs, len, ictx->discard_granularity_bytes);
tracepoint(librbd, discard_exit, r);
return r;
}
bool discard_zero = ictx->config.get_val<bool>("rbd_discard_on_zeroed_write_same");
if (discard_zero && mem_is_zero(buf, data_len)) {
- int r = ictx->io_work_queue->write_zeroes(ofs, len, 0, op_flags);
+ int r = librbd::api::Io<>::write_zeroes(*ictx, ofs, len, 0, op_flags);
tracepoint(librbd, writesame_exit, r);
return r;
}
bufferlist bl;
bl.push_back(create_write_raw(ictx, buf, data_len, nullptr));
- int r = ictx->io_work_queue->writesame(ofs, len, std::move(bl), op_flags);
+ int r = librbd::api::Io<>::write_same(
+ *ictx, ofs, len, std::move(bl), op_flags);
tracepoint(librbd, writesame_exit, r);
return r;
}
int zero_flags, int op_flags)
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
- return ictx->io_work_queue->write_zeroes(ofs, len, zero_flags, op_flags);
+ return librbd::api::Io<>::write_zeroes(*ictx, ofs, len, zero_flags, op_flags);
}
extern "C" ssize_t rbd_compare_and_write(rbd_image_t image,
bufferlist bl;
bl.push_back(create_write_raw(ictx, buf, len, nullptr));
- int r = ictx->io_work_queue->compare_and_write(ofs, len, std::move(cmp_bl),
- std::move(bl), mismatch_off,
- op_flags);
+ int r = librbd::api::Io<>::compare_and_write(
+ *ictx, ofs, len, std::move(cmp_bl), std::move(bl), mismatch_off, op_flags);
tracepoint(librbd, compare_and_write_exit, r);
return r;
}
auto aio_completion = get_aio_completion(comp);
bufferlist bl;
bl.push_back(create_write_raw(ictx, buf, len, aio_completion));
- ictx->io_work_queue->aio_write(aio_completion, off, len, std::move(bl), 0);
+ librbd::api::Io<>::aio_write(
+ *ictx, aio_completion, off, len, std::move(bl), 0, true);
tracepoint(librbd, aio_write_exit, 0);
return 0;
}
auto aio_completion = get_aio_completion(comp);
bufferlist bl;
bl.push_back(create_write_raw(ictx, buf, len, aio_completion));
- ictx->io_work_queue->aio_write(aio_completion, off, len, std::move(bl),
- op_flags);
+ librbd::api::Io<>::aio_write(
+ *ictx, aio_completion, off, len, std::move(bl), op_flags, true);
tracepoint(librbd, aio_write_exit, 0);
return 0;
}
ictx->snap_name.c_str(), ictx->read_only, off, len, NULL,
comp->pc);
if (r == 0) {
- ictx->io_work_queue->aio_write(aio_completion, off, len, std::move(bl), 0);
+ librbd::api::Io<>::aio_write(
+ *ictx, aio_completion, off, len, std::move(bl), 0, true);
}
tracepoint(librbd, aio_write_exit, r);
return r;
}
-extern "C" int rbd_aio_discard(rbd_image_t image, uint64_t off, uint64_t len,
- rbd_completion_t c)
-{
- librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
- librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
- tracepoint(librbd, aio_discard_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, off, len, comp->pc);
- ictx->io_work_queue->aio_discard(
- get_aio_completion(comp), off, len, ictx->discard_granularity_bytes);
- tracepoint(librbd, aio_discard_exit, 0);
- return 0;
-}
-
extern "C" int rbd_aio_read(rbd_image_t image, uint64_t off, size_t len,
char *buf, rbd_completion_t c)
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
tracepoint(librbd, aio_read_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, off, len, buf, comp->pc);
- ictx->io_work_queue->aio_read(get_aio_completion(comp), off, len,
- librbd::io::ReadResult{buf, len}, 0);
+ librbd::api::Io<>::aio_read(
+ *ictx, get_aio_completion(comp), off, len, librbd::io::ReadResult{buf, len},
+ 0, true);
tracepoint(librbd, aio_read_exit, 0);
return 0;
}
librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
tracepoint(librbd, aio_read2_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(),
ictx->read_only, off, len, buf, comp->pc, op_flags);
- ictx->io_work_queue->aio_read(get_aio_completion(comp), off, len,
- librbd::io::ReadResult{buf, len},op_flags);
+ librbd::api::Io<>::aio_read(
+ *ictx, get_aio_completion(comp), off, len, librbd::io::ReadResult{buf, len},
+ op_flags, true);
tracepoint(librbd, aio_read_exit, 0);
return 0;
}
} else {
read_result = librbd::io::ReadResult(iov, iovcnt);
}
- ictx->io_work_queue->aio_read(get_aio_completion(comp), off, len,
- std::move(read_result), 0);
+ librbd::api::Io<>::aio_read(
+ *ictx, get_aio_completion(comp), off, len, std::move(read_result), 0,
+ true);
}
tracepoint(librbd, aio_read_exit, r);
return r;
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
tracepoint(librbd, flush_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only);
- int r = ictx->io_work_queue->flush();
+ int r = librbd::api::Io<>::flush(*ictx);
tracepoint(librbd, flush_exit, r);
return r;
}
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
tracepoint(librbd, aio_flush_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, comp->pc);
- ictx->io_work_queue->aio_flush(get_aio_completion(comp));
+ librbd::api::Io<>::aio_flush(*ictx, get_aio_completion(comp), true);
tracepoint(librbd, aio_flush_exit, 0);
return 0;
}
+extern "C" int rbd_aio_discard(rbd_image_t image, uint64_t off, uint64_t len,
+ rbd_completion_t c)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
+ tracepoint(librbd, aio_discard_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, off, len, comp->pc);
+ librbd::api::Io<>::aio_discard(
+ *ictx, get_aio_completion(comp), off, len,
+ ictx->discard_granularity_bytes, true);
+ tracepoint(librbd, aio_discard_exit, 0);
+ return 0;
+}
+
extern "C" int rbd_aio_writesame(rbd_image_t image, uint64_t off, size_t len,
const char *buf, size_t data_len, rbd_completion_t c,
int op_flags)
bool discard_zero = ictx->config.get_val<bool>("rbd_discard_on_zeroed_write_same");
if (discard_zero && mem_is_zero(buf, data_len)) {
- ictx->io_work_queue->aio_write_zeroes(get_aio_completion(comp), off, len, 0,
- op_flags, true);
+ librbd::api::Io<>::aio_write_zeroes(
+ *ictx, get_aio_completion(comp), off, len, 0, op_flags, true);
tracepoint(librbd, aio_writesame_exit, 0);
return 0;
}
auto aio_completion = get_aio_completion(comp);
bufferlist bl;
bl.push_back(create_write_raw(ictx, buf, data_len, aio_completion));
- ictx->io_work_queue->aio_writesame(aio_completion, off, len, std::move(bl),
- op_flags);
+ librbd::api::Io<>::aio_write_same(
+ *ictx, aio_completion, off, len, std::move(bl), op_flags, true);
tracepoint(librbd, aio_writesame_exit, 0);
return 0;
}
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
- ictx->io_work_queue->aio_write_zeroes(
- get_aio_completion(comp), off, len, zero_flags, op_flags, true);
+ librbd::api::Io<>::aio_write_zeroes(*ictx, get_aio_completion(comp), off, len,
+ zero_flags, op_flags, true);
return 0;
}
cmp_bl.push_back(create_write_raw(ictx, cmp_buf, len, aio_completion));
bufferlist bl;
bl.push_back(create_write_raw(ictx, buf, len, aio_completion));
- ictx->io_work_queue->aio_compare_and_write(aio_completion, off, len,
- std::move(cmp_bl), std::move(bl),
- mismatch_off, op_flags, false);
+ librbd::api::Io<>::aio_compare_and_write(
+ *ictx, aio_completion, off, len, std::move(cmp_bl), std::move(bl),
+ mismatch_off, op_flags, false);
tracepoint(librbd, aio_compare_and_write_exit, 0);
return 0;
uint64_t *snap_id)
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
- return librbd::api::Mirror<>::image_snapshot_create(ictx, 0U, snap_id);
+ auto flags = librbd::util::get_default_snap_create_flags(ictx);
+ return librbd::api::Mirror<>::image_snapshot_create(ictx, flags, snap_id);
+}
+
+extern "C" int rbd_mirror_image_create_snapshot2(rbd_image_t image,
+ uint32_t flags,
+ uint64_t *snap_id)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ return librbd::api::Mirror<>::image_snapshot_create(ictx, flags, snap_id);
}
extern "C" int rbd_mirror_image_get_info(rbd_image_t image,
group_ioctx.get_pool_name().c_str(),
group_ioctx.get_id(), group_name, snap_name);
- int r = librbd::api::Group<>::snap_create(group_ioctx, group_name, snap_name);
+ int r = librbd::api::Group<>::snap_create(group_ioctx, group_name,
+ snap_name, 0);
+ tracepoint(librbd, group_snap_create_exit, r);
+
+ return r;
+}
+
+extern "C" int rbd_group_snap_create2(rados_ioctx_t group_p,
+ const char *group_name,
+ const char *snap_name,
+ uint32_t flags)
+{
+ librados::IoCtx group_ioctx;
+ librados::IoCtx::from_rados_ioctx_t(group_p, group_ioctx);
+
+ TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
+ tracepoint(librbd, group_snap_create_enter,
+ group_ioctx.get_pool_name().c_str(),
+ group_ioctx.get_id(), group_name, snap_name);
+ int r = librbd::api::Group<>::snap_create(group_ioctx, group_name, snap_name,
+ flags);
tracepoint(librbd, group_snap_create_exit, r);
return r;
config_option_cleanup(options[i]);
}
}
+
+extern "C" int rbd_quiesce_watch(rbd_image_t image,
+ rbd_update_callback_t quiesce_cb,
+ rbd_update_callback_t unquiesce_cb,
+ void *arg, uint64_t *handle)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ auto wctx = new C_QuiesceWatchCB(quiesce_cb, unquiesce_cb, arg);
+ int r = ictx->state->register_quiesce_watcher(wctx, &wctx->handle);
+ if (r < 0) {
+ delete wctx;
+ return r;
+ }
+ *handle = reinterpret_cast<uint64_t>(wctx);
+ return 0;
+}
+
+extern "C" int rbd_quiesce_unwatch(rbd_image_t image, uint64_t handle)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ auto *wctx = reinterpret_cast<C_QuiesceWatchCB *>(handle);
+ int r = ictx->state->unregister_quiesce_watcher(wctx->handle);
+ delete wctx;
+ return r;
+}
+
+extern "C" void rbd_quiesce_complete(rbd_image_t image, uint64_t handle, int r)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ ictx->state->quiesce_complete(handle, r);
+}