1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
14 #include "include/int_types.h"
18 #include "cls/rbd/cls_rbd_types.h"
19 #include "common/dout.h"
20 #include "common/errno.h"
21 #include "common/TracepointProvider.h"
22 #include "include/Context.h"
24 #include "cls/rbd/cls_rbd_client.h"
25 #include "cls/rbd/cls_rbd_types.h"
26 #include "librbd/ImageCtx.h"
27 #include "librbd/ImageState.h"
28 #include "librbd/internal.h"
29 #include "librbd/Operations.h"
30 #include "librbd/api/DiffIterate.h"
31 #include "librbd/api/Mirror.h"
32 #include "librbd/io/AioCompletion.h"
33 #include "librbd/io/ImageRequestWQ.h"
34 #include "librbd/io/ReadResult.h"
40 #define TRACEPOINT_DEFINE
41 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
42 #include "tracing/librbd.h"
43 #undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
44 #undef TRACEPOINT_DEFINE
46 #define tracepoint(...)
49 #define dout_subsys ceph_subsys_rbd
51 #define dout_prefix *_dout << "librbd: "
56 using ceph::bufferlist
;
57 using librados::snap_t
;
58 using librados::IoCtx
;
62 TracepointProvider::Traits
tracepoint_traits("librbd_tp.so", "rbd_tracing");
64 buffer::raw
* create_write_raw(librbd::ImageCtx
*ictx
, const char *buf
,
66 // TODO: until librados can guarantee memory won't be referenced after
67 // it ACKs a request, always make a copy of the user-provided memory
68 return buffer::copy(buf
, len
);
71 CephContext
* get_cct(IoCtx
&io_ctx
) {
72 return reinterpret_cast<CephContext
*>(io_ctx
.cct());
75 librbd::io::AioCompletion
* get_aio_completion(librbd::RBD::AioCompletion
*comp
) {
76 return reinterpret_cast<librbd::io::AioCompletion
*>(comp
->pc
);
79 struct C_AioCompletion
: public Context
{
81 librbd::io::aio_type_t aio_type
;
82 librbd::io::AioCompletion
* aio_comp
;
84 C_AioCompletion(librbd::ImageCtx
*ictx
, librbd::io::aio_type_t aio_type
,
85 librbd::io::AioCompletion
* aio_comp
)
86 : cct(ictx
->cct
), aio_type(aio_type
), aio_comp(aio_comp
) {
87 aio_comp
->init_time(ictx
, aio_type
);
91 void finish(int r
) override
{
92 ldout(cct
, 20) << "C_AioComplete::finish: r=" << r
<< dendl
;
96 aio_comp
->lock
.Lock();
98 aio_comp
->put_unlock();
103 struct C_OpenComplete
: public C_AioCompletion
{
104 librbd::ImageCtx
*ictx
;
106 C_OpenComplete(librbd::ImageCtx
*ictx
, librbd::io::AioCompletion
* comp
,
108 : C_AioCompletion(ictx
, librbd::io::AIO_TYPE_OPEN
, comp
),
109 ictx(ictx
), ictxp(ictxp
) {
111 void finish(int r
) override
{
112 ldout(ictx
->cct
, 20) << "C_OpenComplete::finish: r=" << r
<< dendl
;
119 C_AioCompletion::finish(r
);
123 struct C_OpenAfterCloseComplete
: public Context
{
124 librbd::ImageCtx
*ictx
;
125 librbd::io::AioCompletion
* comp
;
127 C_OpenAfterCloseComplete(librbd::ImageCtx
*ictx
,
128 librbd::io::AioCompletion
* comp
,
130 : ictx(ictx
), comp(comp
), ictxp(ictxp
) {
132 void finish(int r
) override
{
133 ldout(ictx
->cct
, 20) << "C_OpenAfterCloseComplete::finish: r=" << r
135 delete reinterpret_cast<librbd::ImageCtx
*>(*ictxp
);
138 ictx
->state
->open(false, new C_OpenComplete(ictx
, comp
, ictxp
));
142 struct C_UpdateWatchCB
: public librbd::UpdateWatchCtx
{
143 rbd_update_callback_t watch_cb
;
147 C_UpdateWatchCB(rbd_update_callback_t watch_cb
, void *arg
) :
148 watch_cb(watch_cb
), arg(arg
) {
150 void handle_notify() override
{
155 void mirror_image_info_cpp_to_c(const librbd::mirror_image_info_t
&cpp_info
,
156 rbd_mirror_image_info_t
*c_info
) {
157 c_info
->global_id
= strdup(cpp_info
.global_id
.c_str());
158 c_info
->state
= cpp_info
.state
;
159 c_info
->primary
= cpp_info
.primary
;
162 void mirror_image_status_cpp_to_c(const librbd::mirror_image_status_t
&cpp_status
,
163 rbd_mirror_image_status_t
*c_status
) {
164 c_status
->name
= strdup(cpp_status
.name
.c_str());
165 mirror_image_info_cpp_to_c(cpp_status
.info
, &c_status
->info
);
166 c_status
->state
= cpp_status
.state
;
167 c_status
->description
= strdup(cpp_status
.description
.c_str());
168 c_status
->last_update
= cpp_status
.last_update
;
169 c_status
->up
= cpp_status
.up
;
172 void trash_image_info_cpp_to_c(const librbd::trash_image_info_t
&cpp_info
,
173 rbd_trash_image_info_t
*c_info
) {
174 c_info
->id
= strdup(cpp_info
.id
.c_str());
175 c_info
->name
= strdup(cpp_info
.name
.c_str());
176 c_info
->source
= cpp_info
.source
;
177 c_info
->deletion_time
= cpp_info
.deletion_time
;
178 c_info
->deferment_end_time
= cpp_info
.deferment_end_time
;
181 struct C_MirrorImageGetInfo
: public Context
{
182 rbd_mirror_image_info_t
*mirror_image_info
;
185 librbd::mirror_image_info_t cpp_mirror_image_info
;
187 C_MirrorImageGetInfo(rbd_mirror_image_info_t
*mirror_image_info
,
189 : mirror_image_info(mirror_image_info
), on_finish(on_finish
) {
192 void finish(int r
) override
{
194 on_finish
->complete(r
);
198 mirror_image_info_cpp_to_c(cpp_mirror_image_info
, mirror_image_info
);
199 on_finish
->complete(0);
203 struct C_MirrorImageGetStatus
: public Context
{
204 rbd_mirror_image_status_t
*mirror_image_status
;
207 librbd::mirror_image_status_t cpp_mirror_image_status
;
209 C_MirrorImageGetStatus(rbd_mirror_image_status_t
*mirror_image_status
,
211 : mirror_image_status(mirror_image_status
), on_finish(on_finish
) {
214 void finish(int r
) override
{
216 on_finish
->complete(r
);
220 mirror_image_status_cpp_to_c(cpp_mirror_image_status
, mirror_image_status
);
221 on_finish
->complete(0);
225 } // anonymous namespace
228 ProgressContext::~ProgressContext()
232 class CProgressContext
: public ProgressContext
235 CProgressContext(librbd_progress_fn_t fn
, void *data
)
236 : m_fn(fn
), m_data(data
)
239 int update_progress(uint64_t offset
, uint64_t src_size
) override
241 return m_fn(offset
, src_size
, m_data
);
244 librbd_progress_fn_t m_fn
;
259 void RBD::version(int *major
, int *minor
, int *extra
)
261 rbd_version(major
, minor
, extra
);
264 int RBD::open(IoCtx
& io_ctx
, Image
& image
, const char *name
)
266 return open(io_ctx
, image
, name
, NULL
);
269 int RBD::open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
)
271 return open_by_id(io_ctx
, image
, id
, nullptr);
274 int RBD::open(IoCtx
& io_ctx
, Image
& image
, const char *name
,
275 const char *snap_name
)
277 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, false);
278 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
279 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
281 if (image
.ctx
!= NULL
) {
282 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
286 int r
= ictx
->state
->open(false);
288 tracepoint(librbd
, open_image_exit
, r
);
292 image
.ctx
= (image_ctx_t
) ictx
;
293 tracepoint(librbd
, open_image_exit
, 0);
297 int RBD::open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
,
298 const char *snap_name
)
300 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, false);
301 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
302 tracepoint(librbd
, open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
303 ictx
->snap_name
.c_str(), ictx
->read_only
);
305 if (image
.ctx
!= nullptr) {
306 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
310 int r
= ictx
->state
->open(false);
312 tracepoint(librbd
, open_image_by_id_exit
, r
);
316 image
.ctx
= (image_ctx_t
) ictx
;
317 tracepoint(librbd
, open_image_by_id_exit
, 0);
321 int RBD::aio_open(IoCtx
& io_ctx
, Image
& image
, const char *name
,
322 const char *snap_name
, RBD::AioCompletion
*c
)
324 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, false);
325 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
326 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
328 if (image
.ctx
!= NULL
) {
329 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
330 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
332 ictx
->state
->open(false, new C_OpenComplete(ictx
, get_aio_completion(c
),
335 tracepoint(librbd
, aio_open_image_exit
, 0);
339 int RBD::aio_open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
,
340 const char *snap_name
, RBD::AioCompletion
*c
)
342 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, false);
343 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
344 tracepoint(librbd
, aio_open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
345 ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
347 if (image
.ctx
!= nullptr) {
348 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
349 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
351 ictx
->state
->open(false, new C_OpenComplete(ictx
, get_aio_completion(c
),
354 tracepoint(librbd
, aio_open_image_by_id_exit
, 0);
358 int RBD::open_read_only(IoCtx
& io_ctx
, Image
& image
, const char *name
,
359 const char *snap_name
)
361 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, true);
362 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
363 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
365 if (image
.ctx
!= NULL
) {
366 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
370 int r
= ictx
->state
->open(false);
372 tracepoint(librbd
, open_image_exit
, r
);
376 image
.ctx
= (image_ctx_t
) ictx
;
377 tracepoint(librbd
, open_image_exit
, 0);
381 int RBD::open_by_id_read_only(IoCtx
& io_ctx
, Image
& image
, const char *id
,
382 const char *snap_name
)
384 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, true);
385 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
386 tracepoint(librbd
, open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
387 ictx
->snap_name
.c_str(), ictx
->read_only
);
389 if (image
.ctx
!= nullptr) {
390 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
394 int r
= ictx
->state
->open(false);
396 tracepoint(librbd
, open_image_by_id_exit
, r
);
400 image
.ctx
= (image_ctx_t
) ictx
;
401 tracepoint(librbd
, open_image_by_id_exit
, 0);
405 int RBD::aio_open_read_only(IoCtx
& io_ctx
, Image
& image
, const char *name
,
406 const char *snap_name
, RBD::AioCompletion
*c
)
408 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, true);
409 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
410 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
412 if (image
.ctx
!= NULL
) {
413 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
414 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
416 ictx
->state
->open(false, new C_OpenComplete(ictx
, get_aio_completion(c
),
419 tracepoint(librbd
, aio_open_image_exit
, 0);
423 int RBD::aio_open_by_id_read_only(IoCtx
& io_ctx
, Image
& image
, const char *id
,
424 const char *snap_name
, RBD::AioCompletion
*c
)
426 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, true);
427 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
428 tracepoint(librbd
, aio_open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
429 ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
431 if (image
.ctx
!= nullptr) {
432 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
433 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
435 ictx
->state
->open(false, new C_OpenComplete(ictx
, get_aio_completion(c
),
438 tracepoint(librbd
, aio_open_image_by_id_exit
, 0);
442 int RBD::create(IoCtx
& io_ctx
, const char *name
, uint64_t size
, int *order
)
444 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
445 tracepoint(librbd
, create_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, *order
);
446 int r
= librbd::create(io_ctx
, name
, size
, order
);
447 tracepoint(librbd
, create_exit
, r
, *order
);
451 int RBD::create2(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
452 uint64_t features
, int *order
)
454 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
455 tracepoint(librbd
, create2_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
);
456 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
, 0, 0);
457 tracepoint(librbd
, create2_exit
, r
, *order
);
461 int RBD::create3(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
462 uint64_t features
, int *order
, uint64_t stripe_unit
,
463 uint64_t stripe_count
)
465 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
466 tracepoint(librbd
, create3_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
, stripe_unit
, stripe_count
);
467 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
,
468 stripe_unit
, stripe_count
);
469 tracepoint(librbd
, create3_exit
, r
, *order
);
473 int RBD::create4(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
476 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
477 tracepoint(librbd
, create4_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, opts
.opts
);
478 int r
= librbd::create(io_ctx
, name
, "", size
, opts
, "", "", false);
479 tracepoint(librbd
, create4_exit
, r
);
483 int RBD::clone(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
484 IoCtx
& c_ioctx
, const char *c_name
, uint64_t features
,
487 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
488 tracepoint(librbd
, clone_enter
, p_ioctx
.get_pool_name().c_str(), p_ioctx
.get_id(), p_name
, p_snap_name
, c_ioctx
.get_pool_name().c_str(), c_ioctx
.get_id(), c_name
, features
);
489 int r
= librbd::clone(p_ioctx
, p_name
, p_snap_name
, c_ioctx
, c_name
,
490 features
, c_order
, 0, 0);
491 tracepoint(librbd
, clone_exit
, r
, *c_order
);
495 int RBD::clone2(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
496 IoCtx
& c_ioctx
, const char *c_name
, uint64_t features
,
497 int *c_order
, uint64_t stripe_unit
, int stripe_count
)
499 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
500 tracepoint(librbd
, clone2_enter
, p_ioctx
.get_pool_name().c_str(), p_ioctx
.get_id(), p_name
, p_snap_name
, c_ioctx
.get_pool_name().c_str(), c_ioctx
.get_id(), c_name
, features
, stripe_unit
, stripe_count
);
501 int r
= librbd::clone(p_ioctx
, p_name
, p_snap_name
, c_ioctx
, c_name
,
502 features
, c_order
, stripe_unit
, stripe_count
);
503 tracepoint(librbd
, clone2_exit
, r
, *c_order
);
507 int RBD::clone3(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
508 IoCtx
& c_ioctx
, const char *c_name
, ImageOptions
& c_opts
)
510 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
511 tracepoint(librbd
, clone3_enter
, p_ioctx
.get_pool_name().c_str(), p_ioctx
.get_id(), p_name
, p_snap_name
, c_ioctx
.get_pool_name().c_str(), c_ioctx
.get_id(), c_name
, c_opts
.opts
);
512 int r
= librbd::clone(p_ioctx
, p_name
, p_snap_name
, c_ioctx
, c_name
,
514 tracepoint(librbd
, clone3_exit
, r
);
518 int RBD::remove(IoCtx
& io_ctx
, const char *name
)
520 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
521 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
522 librbd::NoOpProgressContext prog_ctx
;
523 int r
= librbd::remove(io_ctx
, name
, "", prog_ctx
);
524 tracepoint(librbd
, remove_exit
, r
);
528 int RBD::remove_with_progress(IoCtx
& io_ctx
, const char *name
,
529 ProgressContext
& pctx
)
531 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
532 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
533 int r
= librbd::remove(io_ctx
, name
, "", pctx
);
534 tracepoint(librbd
, remove_exit
, r
);
538 int RBD::trash_move(IoCtx
&io_ctx
, const char *name
, uint64_t delay
) {
539 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
540 tracepoint(librbd
, trash_move_enter
, io_ctx
.get_pool_name().c_str(),
541 io_ctx
.get_id(), name
);
542 int r
= librbd::trash_move(io_ctx
, RBD_TRASH_IMAGE_SOURCE_USER
, name
,
544 tracepoint(librbd
, trash_move_exit
, r
);
548 int RBD::trash_get(IoCtx
&io_ctx
, const char *id
, trash_image_info_t
*info
) {
549 return librbd::trash_get(io_ctx
, id
, info
);
552 int RBD::trash_list(IoCtx
&io_ctx
, vector
<trash_image_info_t
> &entries
) {
553 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
554 tracepoint(librbd
, trash_list_enter
,
555 io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
556 int r
= librbd::trash_list(io_ctx
, entries
);
559 for (const auto& entry
: entries
) {
560 tracepoint(librbd
, trash_list_entry
, entry
.id
.c_str());
564 tracepoint(librbd
, trash_list_exit
, r
, r
);
568 int RBD::trash_remove(IoCtx
&io_ctx
, const char *image_id
, bool force
) {
569 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
570 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
571 io_ctx
.get_id(), image_id
, force
);
572 librbd::NoOpProgressContext prog_ctx
;
573 int r
= librbd::trash_remove(io_ctx
, image_id
, force
, prog_ctx
);
574 tracepoint(librbd
, trash_remove_exit
, r
);
578 int RBD::trash_remove_with_progress(IoCtx
&io_ctx
, const char *image_id
,
579 bool force
, ProgressContext
&pctx
) {
580 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
581 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
582 io_ctx
.get_id(), image_id
, force
);
583 int r
= librbd::trash_remove(io_ctx
, image_id
, force
, pctx
);
584 tracepoint(librbd
, trash_remove_exit
, r
);
588 int RBD::trash_restore(IoCtx
&io_ctx
, const char *id
, const char *name
) {
589 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
590 tracepoint(librbd
, trash_undelete_enter
, io_ctx
.get_pool_name().c_str(),
591 io_ctx
.get_id(), id
, name
);
592 int r
= librbd::trash_restore(io_ctx
, id
, name
);
593 tracepoint(librbd
, trash_undelete_exit
, r
);
597 int RBD::list(IoCtx
& io_ctx
, vector
<string
>& names
)
599 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
600 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
601 int r
= librbd::list(io_ctx
, names
);
603 for (vector
<string
>::iterator itr
= names
.begin(), end
= names
.end(); itr
!= end
; ++itr
) {
604 tracepoint(librbd
, list_entry
, itr
->c_str());
607 tracepoint(librbd
, list_exit
, r
, r
);
611 int RBD::rename(IoCtx
& src_io_ctx
, const char *srcname
, const char *destname
)
613 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(src_io_ctx
));
614 tracepoint(librbd
, rename_enter
, src_io_ctx
.get_pool_name().c_str(), src_io_ctx
.get_id(), srcname
, destname
);
615 int r
= librbd::rename(src_io_ctx
, srcname
, destname
);
616 tracepoint(librbd
, rename_exit
, r
);
620 int RBD::mirror_mode_get(IoCtx
& io_ctx
, rbd_mirror_mode_t
*mirror_mode
) {
621 return librbd::api::Mirror
<>::mode_get(io_ctx
, mirror_mode
);
624 int RBD::mirror_mode_set(IoCtx
& io_ctx
, rbd_mirror_mode_t mirror_mode
) {
625 return librbd::api::Mirror
<>::mode_set(io_ctx
, mirror_mode
);
628 int RBD::mirror_peer_add(IoCtx
& io_ctx
, std::string
*uuid
,
629 const std::string
&cluster_name
,
630 const std::string
&client_name
) {
631 return librbd::api::Mirror
<>::peer_add(io_ctx
, uuid
, cluster_name
,
635 int RBD::mirror_peer_remove(IoCtx
& io_ctx
, const std::string
&uuid
) {
636 return librbd::api::Mirror
<>::peer_remove(io_ctx
, uuid
);
639 int RBD::mirror_peer_list(IoCtx
& io_ctx
, std::vector
<mirror_peer_t
> *peers
) {
640 return librbd::api::Mirror
<>::peer_list(io_ctx
, peers
);
643 int RBD::mirror_peer_set_client(IoCtx
& io_ctx
, const std::string
&uuid
,
644 const std::string
&client_name
) {
645 return librbd::api::Mirror
<>::peer_set_client(io_ctx
, uuid
, client_name
);
648 int RBD::mirror_peer_set_cluster(IoCtx
& io_ctx
, const std::string
&uuid
,
649 const std::string
&cluster_name
) {
650 return librbd::api::Mirror
<>::peer_set_cluster(io_ctx
, uuid
, cluster_name
);
653 int RBD::mirror_image_status_list(IoCtx
& io_ctx
, const std::string
&start_id
,
654 size_t max
, std::map
<std::string
, mirror_image_status_t
> *images
) {
655 return librbd::api::Mirror
<>::image_status_list(io_ctx
, start_id
, max
,
659 int RBD::mirror_image_status_summary(IoCtx
& io_ctx
,
660 std::map
<mirror_image_status_state_t
, int> *states
) {
661 return librbd::api::Mirror
<>::image_status_summary(io_ctx
, states
);
664 RBD::AioCompletion::AioCompletion(void *cb_arg
, callback_t complete_cb
)
666 pc
= reinterpret_cast<void*>(librbd::io::AioCompletion::create(
667 cb_arg
, complete_cb
, this));
670 bool RBD::AioCompletion::is_complete()
672 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
673 return c
->is_complete();
676 int RBD::AioCompletion::wait_for_complete()
678 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
679 return c
->wait_for_complete();
682 ssize_t
RBD::AioCompletion::get_return_value()
684 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
685 return c
->get_return_value();
688 void *RBD::AioCompletion::get_arg()
690 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
694 void RBD::AioCompletion::release()
696 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
705 ImageOptions::ImageOptions()
707 librbd::image_options_create(&opts
);
710 ImageOptions::ImageOptions(rbd_image_options_t opts_
)
712 librbd::image_options_create_ref(&opts
, opts_
);
715 ImageOptions::ImageOptions(const ImageOptions
&imgopts
)
717 librbd::image_options_copy(&opts
, imgopts
);
720 ImageOptions::~ImageOptions()
722 librbd::image_options_destroy(opts
);
725 int ImageOptions::set(int optname
, const std::string
& optval
)
727 return librbd::image_options_set(opts
, optname
, optval
);
730 int ImageOptions::set(int optname
, uint64_t optval
)
732 return librbd::image_options_set(opts
, optname
, optval
);
735 int ImageOptions::get(int optname
, std::string
* optval
) const
737 return librbd::image_options_get(opts
, optname
, optval
);
740 int ImageOptions::get(int optname
, uint64_t* optval
) const
742 return librbd::image_options_get(opts
, optname
, optval
);
745 int ImageOptions::is_set(int optname
, bool* is_set
)
747 return librbd::image_options_is_set(opts
, optname
, is_set
);
750 int ImageOptions::unset(int optname
)
752 return librbd::image_options_unset(opts
, optname
);
755 void ImageOptions::clear()
757 librbd::image_options_clear(opts
);
760 bool ImageOptions::empty() const
762 return librbd::image_options_is_empty(opts
);
769 Image::Image() : ctx(NULL
)
782 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
783 tracepoint(librbd
, close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
785 r
= ictx
->state
->close();
788 tracepoint(librbd
, close_image_exit
, r
);
793 int Image::aio_close(RBD::AioCompletion
*c
)
799 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
800 tracepoint(librbd
, aio_close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), c
->pc
);
802 ictx
->state
->close(new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_CLOSE
,
803 get_aio_completion(c
)));
806 tracepoint(librbd
, aio_close_image_exit
, 0);
810 int Image::resize(uint64_t size
)
812 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
813 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
814 librbd::NoOpProgressContext prog_ctx
;
815 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
816 tracepoint(librbd
, resize_exit
, r
);
820 int Image::resize2(uint64_t size
, bool allow_shrink
, librbd::ProgressContext
& pctx
)
822 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
823 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
824 int r
= ictx
->operations
->resize(size
, allow_shrink
, pctx
);
825 tracepoint(librbd
, resize_exit
, r
);
829 int Image::resize_with_progress(uint64_t size
, librbd::ProgressContext
& pctx
)
831 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
832 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
833 int r
= ictx
->operations
->resize(size
, true, pctx
);
834 tracepoint(librbd
, resize_exit
, r
);
838 int Image::stat(image_info_t
& info
, size_t infosize
)
840 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
841 tracepoint(librbd
, stat_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
842 int r
= librbd::info(ictx
, info
, infosize
);
843 tracepoint(librbd
, stat_exit
, r
, &info
);
847 int Image::old_format(uint8_t *old
)
849 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
850 tracepoint(librbd
, get_old_format_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
851 int r
= librbd::get_old_format(ictx
, old
);
852 tracepoint(librbd
, get_old_format_exit
, r
, *old
);
856 int Image::size(uint64_t *size
)
858 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
859 tracepoint(librbd
, get_size_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
860 int r
= librbd::get_size(ictx
, size
);
861 tracepoint(librbd
, get_size_exit
, r
, *size
);
865 int Image::features(uint64_t *features
)
867 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
868 tracepoint(librbd
, get_features_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
869 int r
= librbd::get_features(ictx
, features
);
870 tracepoint(librbd
, get_features_exit
, r
, *features
);
874 int Image::update_features(uint64_t features
, bool enabled
)
876 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
877 tracepoint(librbd
, update_features_enter
, ictx
, features
, enabled
);
878 int r
= ictx
->operations
->update_features(features
, enabled
);
879 tracepoint(librbd
, update_features_exit
, r
);
883 uint64_t Image::get_stripe_unit() const
885 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
886 tracepoint(librbd
, get_stripe_unit_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
887 uint64_t stripe_unit
= ictx
->get_stripe_unit();
888 tracepoint(librbd
, get_stripe_unit_exit
, 0, stripe_unit
);
892 uint64_t Image::get_stripe_count() const
894 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
895 tracepoint(librbd
, get_stripe_count_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
896 uint64_t stripe_count
= ictx
->get_stripe_count();
897 tracepoint(librbd
, get_stripe_count_exit
, 0, stripe_count
);
901 int Image::get_create_timestamp(struct timespec
*timestamp
)
903 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
904 tracepoint(librbd
, get_create_timestamp_enter
, ictx
, ictx
->name
.c_str(),
906 utime_t time
= ictx
->get_create_timestamp();
907 time
.to_timespec(timestamp
);
908 tracepoint(librbd
, get_create_timestamp_exit
, 0, timestamp
);
912 int Image::overlap(uint64_t *overlap
)
914 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
915 tracepoint(librbd
, get_overlap_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
916 int r
= librbd::get_overlap(ictx
, overlap
);
917 tracepoint(librbd
, get_overlap_exit
, r
, *overlap
);
921 int Image::get_id(std::string
*id
)
923 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
924 if (ictx
->old_format
) {
931 std::string
Image::get_block_name_prefix()
933 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
934 return ictx
->object_prefix
;
937 int64_t Image::get_data_pool_id()
939 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
940 return ictx
->data_ctx
.get_id();
943 int Image::parent_info(string
*parent_pool_name
, string
*parent_name
,
944 string
*parent_snap_name
)
946 return parent_info2(parent_pool_name
, parent_name
, nullptr,
950 int Image::parent_info2(string
*parent_pool_name
, string
*parent_name
,
951 string
*parent_id
, string
*parent_snap_name
)
953 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
954 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
955 ictx
->snap_name
.c_str(), ictx
->read_only
);
956 int r
= librbd::get_parent_info(ictx
, parent_pool_name
, parent_name
,
957 parent_id
, parent_snap_name
);
958 tracepoint(librbd
, get_parent_info_exit
, r
,
959 parent_pool_name
? parent_pool_name
->c_str() : NULL
,
960 parent_name
? parent_name
->c_str() : NULL
,
961 parent_id
? parent_id
->c_str() : NULL
,
962 parent_snap_name
? parent_snap_name
->c_str() : NULL
);
966 int Image::get_flags(uint64_t *flags
)
968 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
969 tracepoint(librbd
, get_flags_enter
, ictx
);
970 int r
= librbd::get_flags(ictx
, flags
);
971 tracepoint(librbd
, get_flags_exit
, ictx
, r
, *flags
);
975 int Image::set_image_notification(int fd
, int type
)
977 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
978 tracepoint(librbd
, set_image_notification_enter
, ictx
, fd
, type
);
979 int r
= librbd::set_image_notification(ictx
, fd
, type
);
980 tracepoint(librbd
, set_image_notification_exit
, ictx
, r
);
984 int Image::is_exclusive_lock_owner(bool *is_owner
)
986 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
987 tracepoint(librbd
, is_exclusive_lock_owner_enter
, ictx
);
988 int r
= librbd::is_exclusive_lock_owner(ictx
, is_owner
);
989 tracepoint(librbd
, is_exclusive_lock_owner_exit
, ictx
, r
, *is_owner
);
993 int Image::lock_acquire(rbd_lock_mode_t lock_mode
)
995 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
996 tracepoint(librbd
, lock_acquire_enter
, ictx
, lock_mode
);
997 int r
= librbd::lock_acquire(ictx
, lock_mode
);
998 tracepoint(librbd
, lock_acquire_exit
, ictx
, r
);
1002 int Image::lock_release()
1004 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1005 tracepoint(librbd
, lock_release_enter
, ictx
);
1006 int r
= librbd::lock_release(ictx
);
1007 tracepoint(librbd
, lock_release_exit
, ictx
, r
);
1011 int Image::lock_get_owners(rbd_lock_mode_t
*lock_mode
,
1012 std::list
<std::string
> *lock_owners
)
1014 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1015 tracepoint(librbd
, lock_get_owners_enter
, ictx
);
1016 int r
= librbd::lock_get_owners(ictx
, lock_mode
, lock_owners
);
1017 tracepoint(librbd
, lock_get_owners_exit
, ictx
, r
);
1021 int Image::lock_break(rbd_lock_mode_t lock_mode
,
1022 const std::string
&lock_owner
)
1024 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1025 tracepoint(librbd
, lock_break_enter
, ictx
, lock_mode
, lock_owner
.c_str());
1026 int r
= librbd::lock_break(ictx
, lock_mode
, lock_owner
);
1027 tracepoint(librbd
, lock_break_exit
, ictx
, r
);
1031 int Image::rebuild_object_map(ProgressContext
&prog_ctx
)
1033 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1034 return ictx
->operations
->rebuild_object_map(prog_ctx
);
1037 int Image::check_object_map(ProgressContext
&prog_ctx
)
1039 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1040 return ictx
->operations
->check_object_map(prog_ctx
);
1043 int Image::copy(IoCtx
& dest_io_ctx
, const char *destname
)
1045 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1046 tracepoint(librbd
, copy_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
);
1048 librbd::NoOpProgressContext prog_ctx
;
1049 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
1050 tracepoint(librbd
, copy_exit
, r
);
1054 int Image::copy2(Image
& dest
)
1056 ImageCtx
*srcctx
= (ImageCtx
*)ctx
;
1057 ImageCtx
*destctx
= (ImageCtx
*)dest
.ctx
;
1058 tracepoint(librbd
, copy2_enter
, srcctx
, srcctx
->name
.c_str(), srcctx
->snap_name
.c_str(), srcctx
->read_only
, destctx
, destctx
->name
.c_str(), destctx
->snap_name
.c_str(), destctx
->read_only
);
1059 librbd::NoOpProgressContext prog_ctx
;
1060 int r
= librbd::copy(srcctx
, destctx
, prog_ctx
, 0);
1061 tracepoint(librbd
, copy2_exit
, r
);
1065 int Image::copy3(IoCtx
& dest_io_ctx
, const char *destname
, ImageOptions
& opts
)
1067 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1068 tracepoint(librbd
, copy3_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
, opts
.opts
);
1069 librbd::NoOpProgressContext prog_ctx
;
1070 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
1071 tracepoint(librbd
, copy3_exit
, r
);
1075 int Image::copy4(IoCtx
& dest_io_ctx
, const char *destname
, ImageOptions
& opts
, size_t sparse_size
)
1077 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1078 tracepoint(librbd
, copy4_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
, opts
.opts
, sparse_size
);
1079 librbd::NoOpProgressContext prog_ctx
;
1080 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, sparse_size
);
1081 tracepoint(librbd
, copy4_exit
, r
);
1085 int Image::copy_with_progress(IoCtx
& dest_io_ctx
, const char *destname
,
1086 librbd::ProgressContext
&pctx
)
1088 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1089 tracepoint(librbd
, copy_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
);
1091 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, 0);
1092 tracepoint(librbd
, copy_exit
, r
);
1096 int Image::copy_with_progress2(Image
& dest
, librbd::ProgressContext
&pctx
)
1098 ImageCtx
*srcctx
= (ImageCtx
*)ctx
;
1099 ImageCtx
*destctx
= (ImageCtx
*)dest
.ctx
;
1100 tracepoint(librbd
, copy2_enter
, srcctx
, srcctx
->name
.c_str(), srcctx
->snap_name
.c_str(), srcctx
->read_only
, destctx
, destctx
->name
.c_str(), destctx
->snap_name
.c_str(), destctx
->read_only
);
1101 int r
= librbd::copy(srcctx
, destctx
, pctx
, 0);
1102 tracepoint(librbd
, copy2_exit
, r
);
1106 int Image::copy_with_progress3(IoCtx
& dest_io_ctx
, const char *destname
,
1108 librbd::ProgressContext
&pctx
)
1110 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1111 tracepoint(librbd
, copy3_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
, opts
.opts
);
1112 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, 0);
1113 tracepoint(librbd
, copy3_exit
, r
);
1117 int Image::copy_with_progress4(IoCtx
& dest_io_ctx
, const char *destname
,
1119 librbd::ProgressContext
&pctx
,
1122 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1123 tracepoint(librbd
, copy4_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
, opts
.opts
, sparse_size
);
1124 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, sparse_size
);
1125 tracepoint(librbd
, copy4_exit
, r
);
1129 int Image::flatten()
1131 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1132 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
1133 librbd::NoOpProgressContext prog_ctx
;
1134 int r
= ictx
->operations
->flatten(prog_ctx
);
1135 tracepoint(librbd
, flatten_exit
, r
);
1139 int Image::flatten_with_progress(librbd::ProgressContext
& prog_ctx
)
1141 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1142 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
1143 int r
= ictx
->operations
->flatten(prog_ctx
);
1144 tracepoint(librbd
, flatten_exit
, r
);
1148 int Image::list_children(set
<pair
<string
, string
> > *children
)
1150 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1151 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1152 int r
= librbd::list_children(ictx
, *children
);
1154 for (set
<pair
<string
, string
> >::const_iterator it
= children
->begin();
1155 it
!= children
->end(); ++it
) {
1156 tracepoint(librbd
, list_children_entry
, it
->first
.c_str(), it
->second
.c_str());
1159 tracepoint(librbd
, list_children_exit
, r
);
1163 int Image::list_lockers(std::list
<librbd::locker_t
> *lockers
,
1164 bool *exclusive
, string
*tag
)
1166 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1167 tracepoint(librbd
, list_lockers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1168 int r
= librbd::list_lockers(ictx
, lockers
, exclusive
, tag
);
1170 for (std::list
<librbd::locker_t
>::const_iterator it
= lockers
->begin();
1171 it
!= lockers
->end(); ++it
) {
1172 tracepoint(librbd
, list_lockers_entry
, it
->client
.c_str(), it
->cookie
.c_str(), it
->address
.c_str());
1175 tracepoint(librbd
, list_lockers_exit
, r
);
1179 int Image::lock_exclusive(const string
& cookie
)
1181 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1182 tracepoint(librbd
, lock_exclusive_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str());
1183 int r
= librbd::lock(ictx
, true, cookie
, "");
1184 tracepoint(librbd
, lock_exclusive_exit
, r
);
1188 int Image::lock_shared(const string
& cookie
, const std::string
& tag
)
1190 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1191 tracepoint(librbd
, lock_shared_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str(), tag
.c_str());
1192 int r
= librbd::lock(ictx
, false, cookie
, tag
);
1193 tracepoint(librbd
, lock_shared_exit
, r
);
1197 int Image::unlock(const string
& cookie
)
1199 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1200 tracepoint(librbd
, unlock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str());
1201 int r
= librbd::unlock(ictx
, cookie
);
1202 tracepoint(librbd
, unlock_exit
, r
);
1206 int Image::break_lock(const string
& client
, const string
& cookie
)
1208 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1209 tracepoint(librbd
, break_lock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, client
.c_str(), cookie
.c_str());
1210 int r
= librbd::break_lock(ictx
, client
, cookie
);
1211 tracepoint(librbd
, break_lock_exit
, r
);
1215 int Image::snap_create(const char *snap_name
)
1217 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1218 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1219 int r
= ictx
->operations
->snap_create(cls::rbd::UserSnapshotNamespace(),
1221 tracepoint(librbd
, snap_create_exit
, r
);
1225 int Image::snap_remove(const char *snap_name
)
1227 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1228 tracepoint(librbd
, snap_remove_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1229 librbd::NoOpProgressContext prog_ctx
;
1230 int r
= librbd::snap_remove(ictx
, snap_name
, 0, prog_ctx
);
1231 tracepoint(librbd
, snap_remove_exit
, r
);
1235 int Image::snap_remove2(const char *snap_name
, uint32_t flags
, ProgressContext
& pctx
)
1237 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1238 tracepoint(librbd
, snap_remove2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
, flags
);
1239 int r
= librbd::snap_remove(ictx
, snap_name
, flags
, pctx
);
1240 tracepoint(librbd
, snap_remove_exit
, r
);
1244 int Image::snap_rollback(const char *snap_name
)
1246 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1247 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1248 librbd::NoOpProgressContext prog_ctx
;
1249 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
1250 tracepoint(librbd
, snap_rollback_exit
, r
);
1254 int Image::snap_rename(const char *srcname
, const char *dstname
)
1256 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1257 tracepoint(librbd
, snap_rename_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, srcname
, dstname
);
1258 int r
= ictx
->operations
->snap_rename(srcname
, dstname
);
1259 tracepoint(librbd
, snap_rename_exit
, r
);
1263 int Image::snap_rollback_with_progress(const char *snap_name
,
1264 ProgressContext
& prog_ctx
)
1266 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1267 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1268 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
1269 tracepoint(librbd
, snap_rollback_exit
, r
);
1273 int Image::snap_protect(const char *snap_name
)
1275 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1276 tracepoint(librbd
, snap_protect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1277 int r
= ictx
->operations
->snap_protect(cls::rbd::UserSnapshotNamespace(), snap_name
);
1278 tracepoint(librbd
, snap_protect_exit
, r
);
1282 int Image::snap_unprotect(const char *snap_name
)
1284 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1285 tracepoint(librbd
, snap_unprotect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1286 int r
= ictx
->operations
->snap_unprotect(cls::rbd::UserSnapshotNamespace(), snap_name
);
1287 tracepoint(librbd
, snap_unprotect_exit
, r
);
1291 int Image::snap_is_protected(const char *snap_name
, bool *is_protected
)
1293 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1294 tracepoint(librbd
, snap_is_protected_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1295 int r
= librbd::snap_is_protected(ictx
, snap_name
, is_protected
);
1296 tracepoint(librbd
, snap_is_protected_exit
, r
, *is_protected
? 1 : 0);
1300 int Image::snap_list(vector
<librbd::snap_info_t
>& snaps
)
1302 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1303 tracepoint(librbd
, snap_list_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, &snaps
);
1304 int r
= librbd::snap_list(ictx
, snaps
);
1306 for (int i
= 0, n
= snaps
.size(); i
< n
; i
++) {
1307 tracepoint(librbd
, snap_list_entry
, snaps
[i
].id
, snaps
[i
].size
, snaps
[i
].name
.c_str());
1310 tracepoint(librbd
, snap_list_exit
, r
, snaps
.size());
1312 // A little ugly, but the C++ API doesn't need a Image::snap_list_end,
1313 // and we want the tracepoints to mirror the C API
1314 tracepoint(librbd
, snap_list_end_enter
, &snaps
);
1315 tracepoint(librbd
, snap_list_end_exit
);
1320 bool Image::snap_exists(const char *snap_name
)
1322 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1323 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
1324 ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1326 int r
= librbd::snap_exists(ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
, &exists
);
1327 tracepoint(librbd
, snap_exists_exit
, r
, exists
);
1329 // lie to caller since we don't know the real answer yet.
1335 // A safer verion of snap_exists.
1336 int Image::snap_exists2(const char *snap_name
, bool *exists
)
1338 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1339 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
1340 ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1341 int r
= librbd::snap_exists(ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
, exists
);
1342 tracepoint(librbd
, snap_exists_exit
, r
, *exists
);
1346 int Image::snap_get_timestamp(uint64_t snap_id
, struct timespec
*timestamp
)
1348 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1349 tracepoint(librbd
, snap_get_timestamp_enter
, ictx
, ictx
->name
.c_str());
1350 int r
= librbd::snap_get_timestamp(ictx
, snap_id
, timestamp
);
1351 tracepoint(librbd
, snap_get_timestamp_exit
, r
);
1355 int Image::snap_get_limit(uint64_t *limit
)
1357 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1358 tracepoint(librbd
, snap_get_limit_enter
, ictx
, ictx
->name
.c_str());
1359 int r
= librbd::snap_get_limit(ictx
, limit
);
1360 tracepoint(librbd
, snap_get_limit_exit
, r
, *limit
);
1364 int Image::snap_set_limit(uint64_t limit
)
1366 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1368 tracepoint(librbd
, snap_set_limit_enter
, ictx
, ictx
->name
.c_str(), limit
);
1369 int r
= ictx
->operations
->snap_set_limit(limit
);
1370 tracepoint(librbd
, snap_set_limit_exit
, r
);
1374 int Image::snap_set(const char *snap_name
)
1376 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1377 tracepoint(librbd
, snap_set_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
1378 int r
= librbd::snap_set(ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
);
1379 tracepoint(librbd
, snap_set_exit
, r
);
1383 ssize_t
Image::read(uint64_t ofs
, size_t len
, bufferlist
& bl
)
1385 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1386 tracepoint(librbd
, read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
1388 bl
.push_back(std::move(ptr
));
1389 int r
= ictx
->io_work_queue
->read(ofs
, len
, io::ReadResult
{&bl
}, 0);
1390 tracepoint(librbd
, read_exit
, r
);
1394 ssize_t
Image::read2(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
1396 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1397 tracepoint(librbd
, read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
1398 ictx
->read_only
, ofs
, len
, op_flags
);
1400 bl
.push_back(std::move(ptr
));
1401 int r
= ictx
->io_work_queue
->read(ofs
, len
, io::ReadResult
{&bl
}, op_flags
);
1402 tracepoint(librbd
, read_exit
, r
);
1406 int64_t Image::read_iterate(uint64_t ofs
, size_t len
,
1407 int (*cb
)(uint64_t, size_t, const char *, void *),
1410 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1411 tracepoint(librbd
, read_iterate_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
1412 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
1413 tracepoint(librbd
, read_iterate_exit
, r
);
1417 int Image::read_iterate2(uint64_t ofs
, uint64_t len
,
1418 int (*cb
)(uint64_t, size_t, const char *, void *),
1421 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1422 tracepoint(librbd
, read_iterate2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
1423 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
1426 tracepoint(librbd
, read_iterate2_exit
, r
);
1430 int Image::diff_iterate(const char *fromsnapname
,
1431 uint64_t ofs
, uint64_t len
,
1432 int (*cb
)(uint64_t, size_t, int, void *),
1435 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1436 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
1437 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
1439 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
1440 cls::rbd::UserSnapshotNamespace(),
1442 len
, true, false, cb
, arg
);
1443 tracepoint(librbd
, diff_iterate_exit
, r
);
1447 int Image::diff_iterate2(const char *fromsnapname
, uint64_t ofs
, uint64_t len
,
1448 bool include_parent
, bool whole_object
,
1449 int (*cb
)(uint64_t, size_t, int, void *), void *arg
)
1451 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1452 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
1453 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
1454 include_parent
, whole_object
);
1455 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
1456 cls::rbd::UserSnapshotNamespace(),
1458 len
, include_parent
,
1459 whole_object
, cb
, arg
);
1460 tracepoint(librbd
, diff_iterate_exit
, r
);
1464 ssize_t
Image::write(uint64_t ofs
, size_t len
, bufferlist
& bl
)
1466 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1467 tracepoint(librbd
, write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, bl
.length() < len
? NULL
: bl
.c_str());
1468 if (bl
.length() < len
) {
1469 tracepoint(librbd
, write_exit
, -EINVAL
);
1472 int r
= ictx
->io_work_queue
->write(ofs
, len
, bufferlist
{bl
}, 0);
1473 tracepoint(librbd
, write_exit
, r
);
1477 ssize_t
Image::write2(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
1479 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1480 tracepoint(librbd
, write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
,
1481 ofs
, len
, bl
.length() < len
? NULL
: bl
.c_str(), op_flags
);
1482 if (bl
.length() < len
) {
1483 tracepoint(librbd
, write_exit
, -EINVAL
);
1486 int r
= ictx
->io_work_queue
->write(ofs
, len
, bufferlist
{bl
}, op_flags
);
1487 tracepoint(librbd
, write_exit
, r
);
1491 int Image::discard(uint64_t ofs
, uint64_t len
)
1493 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1494 tracepoint(librbd
, discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
1495 if (len
> std::numeric_limits
<int32_t>::max()) {
1496 tracepoint(librbd
, discard_exit
, -EINVAL
);
1499 int r
= ictx
->io_work_queue
->discard(ofs
, len
, ictx
->skip_partial_discard
);
1500 tracepoint(librbd
, discard_exit
, r
);
1504 ssize_t
Image::writesame(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
1506 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1507 tracepoint(librbd
, writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
1508 ictx
->read_only
, ofs
, len
, bl
.length() <= 0 ? NULL
: bl
.c_str(), bl
.length(),
1510 if (bl
.length() <= 0 || len
% bl
.length() ||
1511 len
> std::numeric_limits
<int>::max()) {
1512 tracepoint(librbd
, writesame_exit
, -EINVAL
);
1516 if (mem_is_zero(bl
.c_str(), bl
.length())) {
1517 int r
= ictx
->io_work_queue
->discard(ofs
, len
, false);
1518 tracepoint(librbd
, writesame_exit
, r
);
1522 int r
= ictx
->io_work_queue
->writesame(ofs
, len
, bufferlist
{bl
}, op_flags
);
1523 tracepoint(librbd
, writesame_exit
, r
);
1527 ssize_t
Image::compare_and_write(uint64_t ofs
, size_t len
,
1528 ceph::bufferlist
&cmp_bl
, ceph::bufferlist
& bl
,
1529 uint64_t *mismatch_off
, int op_flags
)
1531 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1532 tracepoint(librbd
, compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
1533 ictx
->snap_name
.c_str(),
1534 ictx
->read_only
, ofs
, len
, cmp_bl
.length() < len
? NULL
: cmp_bl
.c_str(),
1535 bl
.length() < len
? NULL
: bl
.c_str(), op_flags
);
1537 if (bl
.length() < len
) {
1538 tracepoint(librbd
, write_exit
, -EINVAL
);
1542 int r
= ictx
->io_work_queue
->compare_and_write(ofs
, len
, bufferlist
{cmp_bl
},
1543 bufferlist
{bl
}, mismatch_off
,
1546 tracepoint(librbd
, compare_and_write_exit
, r
);
1550 int Image::aio_write(uint64_t off
, size_t len
, bufferlist
& bl
,
1551 RBD::AioCompletion
*c
)
1553 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1554 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
);
1555 if (bl
.length() < len
) {
1556 tracepoint(librbd
, aio_write_exit
, -EINVAL
);
1559 ictx
->io_work_queue
->aio_write(get_aio_completion(c
), off
, len
,
1561 tracepoint(librbd
, aio_write_exit
, 0);
1565 int Image::aio_write2(uint64_t off
, size_t len
, bufferlist
& bl
,
1566 RBD::AioCompletion
*c
, int op_flags
)
1568 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1569 tracepoint(librbd
, aio_write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
1570 ictx
->read_only
, off
, len
, bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
, op_flags
);
1571 if (bl
.length() < len
) {
1572 tracepoint(librbd
, aio_write_exit
, -EINVAL
);
1575 ictx
->io_work_queue
->aio_write(get_aio_completion(c
), off
, len
,
1576 bufferlist
{bl
}, op_flags
);
1577 tracepoint(librbd
, aio_write_exit
, 0);
1581 int Image::aio_discard(uint64_t off
, uint64_t len
, RBD::AioCompletion
*c
)
1583 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1584 tracepoint(librbd
, aio_discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, c
->pc
);
1585 ictx
->io_work_queue
->aio_discard(get_aio_completion(c
), off
, len
, ictx
->skip_partial_discard
);
1586 tracepoint(librbd
, aio_discard_exit
, 0);
1590 int Image::aio_read(uint64_t off
, size_t len
, bufferlist
& bl
,
1591 RBD::AioCompletion
*c
)
1593 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1594 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, bl
.c_str(), c
->pc
);
1595 ldout(ictx
->cct
, 10) << "Image::aio_read() buf=" << (void *)bl
.c_str() << "~"
1596 << (void *)(bl
.c_str() + len
- 1) << dendl
;
1597 ictx
->io_work_queue
->aio_read(get_aio_completion(c
), off
, len
,
1598 io::ReadResult
{&bl
}, 0);
1599 tracepoint(librbd
, aio_read_exit
, 0);
1603 int Image::aio_read2(uint64_t off
, size_t len
, bufferlist
& bl
,
1604 RBD::AioCompletion
*c
, int op_flags
)
1606 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1607 tracepoint(librbd
, aio_read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
1608 ictx
->read_only
, off
, len
, bl
.c_str(), c
->pc
, op_flags
);
1609 ldout(ictx
->cct
, 10) << "Image::aio_read() buf=" << (void *)bl
.c_str() << "~"
1610 << (void *)(bl
.c_str() + len
- 1) << dendl
;
1611 ictx
->io_work_queue
->aio_read(get_aio_completion(c
), off
, len
,
1612 io::ReadResult
{&bl
}, op_flags
);
1613 tracepoint(librbd
, aio_read_exit
, 0);
1619 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1620 tracepoint(librbd
, flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1621 int r
= librbd::flush(ictx
);
1622 tracepoint(librbd
, flush_exit
, r
);
1626 int Image::aio_flush(RBD::AioCompletion
*c
)
1628 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1629 tracepoint(librbd
, aio_flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
1630 ictx
->io_work_queue
->aio_flush(get_aio_completion(c
));
1631 tracepoint(librbd
, aio_flush_exit
, 0);
1635 int Image::aio_writesame(uint64_t off
, size_t len
, bufferlist
& bl
,
1636 RBD::AioCompletion
*c
, int op_flags
)
1638 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1639 tracepoint(librbd
, aio_writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
1640 ictx
->read_only
, off
, len
, bl
.length() <= len
? NULL
: bl
.c_str(), bl
.length(),
1642 if (bl
.length() <= 0 || len
% bl
.length()) {
1643 tracepoint(librbd
, aio_writesame_exit
, -EINVAL
);
1647 if (mem_is_zero(bl
.c_str(), bl
.length())) {
1648 ictx
->io_work_queue
->aio_discard(get_aio_completion(c
), off
, len
, false);
1649 tracepoint(librbd
, aio_writesame_exit
, 0);
1653 ictx
->io_work_queue
->aio_writesame(get_aio_completion(c
), off
, len
,
1654 bufferlist
{bl
}, op_flags
);
1655 tracepoint(librbd
, aio_writesame_exit
, 0);
1659 int Image::aio_compare_and_write(uint64_t off
, size_t len
,
1660 ceph::bufferlist
& cmp_bl
, ceph::bufferlist
& bl
,
1661 RBD::AioCompletion
*c
, uint64_t *mismatch_off
,
1664 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1665 tracepoint(librbd
, aio_compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
1666 ictx
->snap_name
.c_str(),
1667 ictx
->read_only
, off
, len
, cmp_bl
.length() < len
? NULL
: cmp_bl
.c_str(),
1668 bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
, op_flags
);
1670 if (bl
.length() < len
) {
1671 tracepoint(librbd
, compare_and_write_exit
, -EINVAL
);
1675 ictx
->io_work_queue
->aio_compare_and_write(get_aio_completion(c
), off
, len
,
1676 bufferlist
{cmp_bl
}, bufferlist
{bl
},
1677 mismatch_off
, op_flags
, false);
1679 tracepoint(librbd
, aio_compare_and_write_exit
, 0);
1684 int Image::invalidate_cache()
1686 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1687 tracepoint(librbd
, invalidate_cache_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1688 int r
= librbd::invalidate_cache(ictx
);
1689 tracepoint(librbd
, invalidate_cache_exit
, r
);
1693 int Image::poll_io_events(RBD::AioCompletion
**comps
, int numcomp
)
1695 io::AioCompletion
*cs
[numcomp
];
1696 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1697 tracepoint(librbd
, poll_io_events_enter
, ictx
, numcomp
);
1698 int r
= librbd::poll_io_events(ictx
, cs
, numcomp
);
1699 tracepoint(librbd
, poll_io_events_exit
, r
);
1701 for (int i
= 0; i
< numcomp
; ++i
)
1702 comps
[i
] = (RBD::AioCompletion
*)cs
[i
]->rbd_comp
;
1707 int Image::metadata_get(const std::string
&key
, std::string
*value
)
1709 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1710 tracepoint(librbd
, metadata_get_enter
, ictx
, key
.c_str());
1711 int r
= librbd::metadata_get(ictx
, key
, value
);
1713 tracepoint(librbd
, metadata_get_exit
, r
, key
.c_str(), NULL
);
1715 tracepoint(librbd
, metadata_get_exit
, r
, key
.c_str(), value
->c_str());
1720 int Image::metadata_set(const std::string
&key
, const std::string
&value
)
1722 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1723 tracepoint(librbd
, metadata_set_enter
, ictx
, key
.c_str(), value
.c_str());
1724 int r
= ictx
->operations
->metadata_set(key
, value
);
1725 tracepoint(librbd
, metadata_set_exit
, r
);
1729 int Image::metadata_remove(const std::string
&key
)
1731 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1732 tracepoint(librbd
, metadata_remove_enter
, ictx
, key
.c_str());
1733 int r
= ictx
->operations
->metadata_remove(key
);
1734 tracepoint(librbd
, metadata_remove_exit
, r
);
1738 int Image::metadata_list(const std::string
&start
, uint64_t max
, map
<string
, bufferlist
> *pairs
)
1740 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1741 tracepoint(librbd
, metadata_list_enter
, ictx
);
1742 int r
= librbd::metadata_list(ictx
, start
, max
, pairs
);
1744 for (map
<string
, bufferlist
>::iterator it
= pairs
->begin();
1745 it
!= pairs
->end(); ++it
) {
1746 tracepoint(librbd
, metadata_list_entry
, it
->first
.c_str(), it
->second
.c_str());
1749 tracepoint(librbd
, metadata_list_exit
, r
);
1753 int Image::mirror_image_enable() {
1754 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1755 return librbd::api::Mirror
<>::image_enable(ictx
, false);
1758 int Image::mirror_image_disable(bool force
) {
1759 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1760 return librbd::api::Mirror
<>::image_disable(ictx
, force
);
1763 int Image::mirror_image_promote(bool force
) {
1764 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1765 return librbd::api::Mirror
<>::image_promote(ictx
, force
);
1768 int Image::mirror_image_demote() {
1769 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1770 return librbd::api::Mirror
<>::image_demote(ictx
);
1773 int Image::mirror_image_resync()
1775 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1776 return librbd::api::Mirror
<>::image_resync(ictx
);
1779 int Image::mirror_image_get_info(mirror_image_info_t
*mirror_image_info
,
1781 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1782 return librbd::api::Mirror
<>::image_get_info(ictx
, mirror_image_info
,
1786 int Image::mirror_image_get_status(mirror_image_status_t
*mirror_image_status
,
1787 size_t status_size
) {
1788 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1789 return librbd::api::Mirror
<>::image_get_status(ictx
, mirror_image_status
,
1793 int Image::aio_mirror_image_promote(bool force
, RBD::AioCompletion
*c
) {
1794 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1795 librbd::api::Mirror
<>::image_promote(
1796 ictx
, force
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
1797 get_aio_completion(c
)));
1801 int Image::aio_mirror_image_demote(RBD::AioCompletion
*c
) {
1802 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1803 librbd::api::Mirror
<>::image_demote(
1804 ictx
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
1805 get_aio_completion(c
)));
1809 int Image::aio_mirror_image_get_info(mirror_image_info_t
*mirror_image_info
,
1811 RBD::AioCompletion
*c
) {
1812 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1813 librbd::api::Mirror
<>::image_get_info(
1814 ictx
, mirror_image_info
, info_size
,
1815 new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
1816 get_aio_completion(c
)));
1820 int Image::aio_mirror_image_get_status(mirror_image_status_t
*status
,
1822 RBD::AioCompletion
*c
) {
1823 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1824 librbd::api::Mirror
<>::image_get_status(
1825 ictx
, status
, status_size
,
1826 new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
1827 get_aio_completion(c
)));
1831 int Image::update_watch(UpdateWatchCtx
*wctx
, uint64_t *handle
) {
1832 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1833 tracepoint(librbd
, update_watch_enter
, ictx
, wctx
);
1834 int r
= ictx
->state
->register_update_watcher(wctx
, handle
);
1835 tracepoint(librbd
, update_watch_exit
, r
, *handle
);
1839 int Image::update_unwatch(uint64_t handle
) {
1840 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1841 tracepoint(librbd
, update_unwatch_enter
, ictx
, handle
);
1842 int r
= ictx
->state
->unregister_update_watcher(handle
);
1843 tracepoint(librbd
, update_unwatch_exit
, r
);
1847 } // namespace librbd
1849 extern "C" void rbd_version(int *major
, int *minor
, int *extra
)
1852 *major
= LIBRBD_VER_MAJOR
;
1854 *minor
= LIBRBD_VER_MINOR
;
1856 *extra
= LIBRBD_VER_EXTRA
;
1859 extern "C" void rbd_image_options_create(rbd_image_options_t
* opts
)
1861 librbd::image_options_create(opts
);
1864 extern "C" void rbd_image_options_destroy(rbd_image_options_t opts
)
1866 librbd::image_options_destroy(opts
);
1869 extern "C" int rbd_image_options_set_string(rbd_image_options_t opts
, int optname
,
1872 return librbd::image_options_set(opts
, optname
, optval
);
1875 extern "C" int rbd_image_options_set_uint64(rbd_image_options_t opts
, int optname
,
1878 return librbd::image_options_set(opts
, optname
, optval
);
1881 extern "C" int rbd_image_options_get_string(rbd_image_options_t opts
, int optname
,
1882 char* optval
, size_t maxlen
)
1884 std::string optval_
;
1886 int r
= librbd::image_options_get(opts
, optname
, &optval_
);
1892 if (optval_
.size() >= maxlen
) {
1896 strncpy(optval
, optval_
.c_str(), maxlen
);
1901 extern "C" int rbd_image_options_get_uint64(rbd_image_options_t opts
, int optname
,
1904 return librbd::image_options_get(opts
, optname
, optval
);
1907 extern "C" int rbd_image_options_is_set(rbd_image_options_t opts
, int optname
,
1910 return librbd::image_options_is_set(opts
, optname
, is_set
);
1913 extern "C" int rbd_image_options_unset(rbd_image_options_t opts
, int optname
)
1915 return librbd::image_options_unset(opts
, optname
);
1918 extern "C" void rbd_image_options_clear(rbd_image_options_t opts
)
1920 librbd::image_options_clear(opts
);
1923 extern "C" int rbd_image_options_is_empty(rbd_image_options_t opts
)
1925 return librbd::image_options_is_empty(opts
);
1928 /* pool mirroring */
1929 extern "C" int rbd_mirror_mode_get(rados_ioctx_t p
,
1930 rbd_mirror_mode_t
*mirror_mode
) {
1931 librados::IoCtx io_ctx
;
1932 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
1933 return librbd::api::Mirror
<>::mode_get(io_ctx
, mirror_mode
);
1936 extern "C" int rbd_mirror_mode_set(rados_ioctx_t p
,
1937 rbd_mirror_mode_t mirror_mode
) {
1938 librados::IoCtx io_ctx
;
1939 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
1940 return librbd::api::Mirror
<>::mode_set(io_ctx
, mirror_mode
);
1943 extern "C" int rbd_mirror_peer_add(rados_ioctx_t p
, char *uuid
,
1944 size_t uuid_max_length
,
1945 const char *cluster_name
,
1946 const char *client_name
) {
1947 static const std::size_t UUID_LENGTH
= 36;
1949 librados::IoCtx io_ctx
;
1950 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
1952 if (uuid_max_length
< UUID_LENGTH
+ 1) {
1956 std::string uuid_str
;
1957 int r
= librbd::api::Mirror
<>::peer_add(io_ctx
, &uuid_str
, cluster_name
,
1960 strncpy(uuid
, uuid_str
.c_str(), uuid_max_length
);
1961 uuid
[uuid_max_length
- 1] = '\0';
1966 extern "C" int rbd_mirror_peer_remove(rados_ioctx_t p
, const char *uuid
) {
1967 librados::IoCtx io_ctx
;
1968 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
1969 int r
= librbd::api::Mirror
<>::peer_remove(io_ctx
, uuid
);
1973 extern "C" int rbd_mirror_peer_list(rados_ioctx_t p
,
1974 rbd_mirror_peer_t
*peers
, int *max_peers
) {
1975 librados::IoCtx io_ctx
;
1976 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
1978 std::vector
<librbd::mirror_peer_t
> peer_vector
;
1979 int r
= librbd::api::Mirror
<>::peer_list(io_ctx
, &peer_vector
);
1984 if (*max_peers
< static_cast<int>(peer_vector
.size())) {
1985 *max_peers
= static_cast<int>(peer_vector
.size());
1989 for (int i
= 0; i
< static_cast<int>(peer_vector
.size()); ++i
) {
1990 peers
[i
].uuid
= strdup(peer_vector
[i
].uuid
.c_str());
1991 peers
[i
].cluster_name
= strdup(peer_vector
[i
].cluster_name
.c_str());
1992 peers
[i
].client_name
= strdup(peer_vector
[i
].client_name
.c_str());
1994 *max_peers
= static_cast<int>(peer_vector
.size());
1998 extern "C" void rbd_mirror_peer_list_cleanup(rbd_mirror_peer_t
*peers
,
2000 for (int i
= 0; i
< max_peers
; ++i
) {
2001 free(peers
[i
].uuid
);
2002 free(peers
[i
].cluster_name
);
2003 free(peers
[i
].client_name
);
2007 extern "C" int rbd_mirror_peer_set_client(rados_ioctx_t p
, const char *uuid
,
2008 const char *client_name
) {
2009 librados::IoCtx io_ctx
;
2010 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2011 return librbd::api::Mirror
<>::peer_set_client(io_ctx
, uuid
, client_name
);
2014 extern "C" int rbd_mirror_peer_set_cluster(rados_ioctx_t p
, const char *uuid
,
2015 const char *cluster_name
) {
2016 librados::IoCtx io_ctx
;
2017 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2018 return librbd::api::Mirror
<>::peer_set_cluster(io_ctx
, uuid
, cluster_name
);
2021 extern "C" int rbd_mirror_image_status_list(rados_ioctx_t p
,
2022 const char *start_id
, size_t max
, char **image_ids
,
2023 rbd_mirror_image_status_t
*images
, size_t *len
) {
2024 librados::IoCtx io_ctx
;
2025 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2026 std::map
<std::string
, librbd::mirror_image_status_t
> cpp_images
;
2028 int r
= librbd::api::Mirror
<>::image_status_list(io_ctx
, start_id
, max
,
2035 for (auto &it
: cpp_images
) {
2037 const std::string
&image_id
= it
.first
;
2038 image_ids
[i
] = strdup(image_id
.c_str());
2039 mirror_image_status_cpp_to_c(it
.second
, &images
[i
]);
2046 extern "C" void rbd_mirror_image_status_list_cleanup(char **image_ids
,
2047 rbd_mirror_image_status_t
*images
, size_t len
) {
2048 for (size_t i
= 0; i
< len
; i
++) {
2050 free(images
[i
].name
);
2051 free(images
[i
].info
.global_id
);
2052 free(images
[i
].description
);
2056 extern "C" int rbd_mirror_image_status_summary(rados_ioctx_t p
,
2057 rbd_mirror_image_status_state_t
*states
, int *counts
, size_t *maxlen
) {
2059 librados::IoCtx io_ctx
;
2060 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2062 std::map
<librbd::mirror_image_status_state_t
, int> states_
;
2063 int r
= librbd::api::Mirror
<>::image_status_summary(io_ctx
, &states_
);
2069 for (auto &it
: states_
) {
2073 states
[i
] = it
.first
;
2074 counts
[i
] = it
.second
;
2082 extern "C" int rbd_list(rados_ioctx_t p
, char *names
, size_t *size
)
2084 librados::IoCtx io_ctx
;
2085 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2086 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2087 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
2088 vector
<string
> cpp_names
;
2089 int r
= librbd::list(io_ctx
, cpp_names
);
2091 tracepoint(librbd
, list_exit
, r
, *size
);
2095 size_t expected_size
= 0;
2097 for (size_t i
= 0; i
< cpp_names
.size(); i
++) {
2098 expected_size
+= cpp_names
[i
].size() + 1;
2100 if (*size
< expected_size
) {
2101 *size
= expected_size
;
2102 tracepoint(librbd
, list_exit
, -ERANGE
, *size
);
2109 for (int i
= 0; i
< (int)cpp_names
.size(); i
++) {
2110 const char* name
= cpp_names
[i
].c_str();
2111 tracepoint(librbd
, list_entry
, name
);
2112 strcpy(names
, name
);
2113 names
+= strlen(names
) + 1;
2115 tracepoint(librbd
, list_exit
, (int)expected_size
, *size
);
2116 return (int)expected_size
;
2119 extern "C" int rbd_create(rados_ioctx_t p
, const char *name
, uint64_t size
, int *order
)
2121 librados::IoCtx io_ctx
;
2122 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2123 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2124 tracepoint(librbd
, create_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, *order
);
2125 int r
= librbd::create(io_ctx
, name
, size
, order
);
2126 tracepoint(librbd
, create_exit
, r
, *order
);
2130 extern "C" int rbd_create2(rados_ioctx_t p
, const char *name
,
2131 uint64_t size
, uint64_t features
,
2134 librados::IoCtx io_ctx
;
2135 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2136 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2137 tracepoint(librbd
, create2_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
);
2138 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
, 0, 0);
2139 tracepoint(librbd
, create2_exit
, r
, *order
);
2143 extern "C" int rbd_create3(rados_ioctx_t p
, const char *name
,
2144 uint64_t size
, uint64_t features
,
2146 uint64_t stripe_unit
, uint64_t stripe_count
)
2148 librados::IoCtx io_ctx
;
2149 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2150 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2151 tracepoint(librbd
, create3_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
, stripe_unit
, stripe_count
);
2152 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
,
2153 stripe_unit
, stripe_count
);
2154 tracepoint(librbd
, create3_exit
, r
, *order
);
2158 extern "C" int rbd_create4(rados_ioctx_t p
, const char *name
,
2159 uint64_t size
, rbd_image_options_t opts
)
2161 librados::IoCtx io_ctx
;
2162 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2163 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2164 tracepoint(librbd
, create4_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, opts
);
2165 librbd::ImageOptions
opts_(opts
);
2166 int r
= librbd::create(io_ctx
, name
, "", size
, opts_
, "", "", false);
2167 tracepoint(librbd
, create4_exit
, r
);
2171 extern "C" int rbd_clone(rados_ioctx_t p_ioctx
, const char *p_name
,
2172 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
2173 const char *c_name
, uint64_t features
, int *c_order
)
2175 librados::IoCtx p_ioc
, c_ioc
;
2176 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
2177 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
2178 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
2179 tracepoint(librbd
, clone_enter
, p_ioc
.get_pool_name().c_str(), p_ioc
.get_id(), p_name
, p_snap_name
, c_ioc
.get_pool_name().c_str(), c_ioc
.get_id(), c_name
, features
);
2180 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
,
2181 features
, c_order
, 0, 0);
2182 tracepoint(librbd
, clone_exit
, r
, *c_order
);
2186 extern "C" int rbd_clone2(rados_ioctx_t p_ioctx
, const char *p_name
,
2187 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
2188 const char *c_name
, uint64_t features
, int *c_order
,
2189 uint64_t stripe_unit
, int stripe_count
)
2191 librados::IoCtx p_ioc
, c_ioc
;
2192 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
2193 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
2194 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
2195 tracepoint(librbd
, clone2_enter
, p_ioc
.get_pool_name().c_str(), p_ioc
.get_id(), p_name
, p_snap_name
, c_ioc
.get_pool_name().c_str(), c_ioc
.get_id(), c_name
, features
, stripe_unit
, stripe_count
);
2196 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
,
2197 features
, c_order
, stripe_unit
, stripe_count
);
2198 tracepoint(librbd
, clone2_exit
, r
, *c_order
);
2202 extern "C" int rbd_clone3(rados_ioctx_t p_ioctx
, const char *p_name
,
2203 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
2204 const char *c_name
, rbd_image_options_t c_opts
)
2206 librados::IoCtx p_ioc
, c_ioc
;
2207 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
2208 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
2209 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
2210 tracepoint(librbd
, clone3_enter
, p_ioc
.get_pool_name().c_str(), p_ioc
.get_id(), p_name
, p_snap_name
, c_ioc
.get_pool_name().c_str(), c_ioc
.get_id(), c_name
, c_opts
);
2211 librbd::ImageOptions
c_opts_(c_opts
);
2212 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
, c_opts_
);
2213 tracepoint(librbd
, clone3_exit
, r
);
2217 extern "C" int rbd_remove(rados_ioctx_t p
, const char *name
)
2219 librados::IoCtx io_ctx
;
2220 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2221 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2222 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
2223 librbd::NoOpProgressContext prog_ctx
;
2224 int r
= librbd::remove(io_ctx
, name
, "", prog_ctx
);
2225 tracepoint(librbd
, remove_exit
, r
);
2229 extern "C" int rbd_remove_with_progress(rados_ioctx_t p
, const char *name
,
2230 librbd_progress_fn_t cb
, void *cbdata
)
2232 librados::IoCtx io_ctx
;
2233 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2234 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2235 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
2236 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
2237 int r
= librbd::remove(io_ctx
, name
, "", prog_ctx
);
2238 tracepoint(librbd
, remove_exit
, r
);
2242 extern "C" int rbd_trash_move(rados_ioctx_t p
, const char *name
,
2244 librados::IoCtx io_ctx
;
2245 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2246 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2247 tracepoint(librbd
, trash_move_enter
, io_ctx
.get_pool_name().c_str(),
2248 io_ctx
.get_id(), name
);
2249 int r
= librbd::trash_move(io_ctx
, RBD_TRASH_IMAGE_SOURCE_USER
, name
, delay
);
2250 tracepoint(librbd
, trash_move_exit
, r
);
2254 extern "C" int rbd_trash_get(rados_ioctx_t io
, const char *id
,
2255 rbd_trash_image_info_t
*info
) {
2256 librados::IoCtx io_ctx
;
2257 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
2259 librbd::trash_image_info_t cpp_info
;
2260 int r
= librbd::trash_get(io_ctx
, id
, &cpp_info
);
2265 trash_image_info_cpp_to_c(cpp_info
, info
);
2269 extern "C" void rbd_trash_get_cleanup(rbd_trash_image_info_t
*info
) {
2274 extern "C" int rbd_trash_list(rados_ioctx_t p
, rbd_trash_image_info_t
*entries
,
2275 size_t *num_entries
) {
2276 librados::IoCtx io_ctx
;
2277 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2278 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2279 tracepoint(librbd
, trash_list_enter
,
2280 io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
2282 vector
<librbd::trash_image_info_t
> cpp_entries
;
2283 int r
= librbd::trash_list(io_ctx
, cpp_entries
);
2285 tracepoint(librbd
, trash_list_exit
, r
, *num_entries
);
2289 if (*num_entries
< cpp_entries
.size()) {
2290 *num_entries
= cpp_entries
.size();
2291 tracepoint(librbd
, trash_list_exit
, -ERANGE
, *num_entries
);
2296 for (const auto &entry
: cpp_entries
) {
2297 trash_image_info_cpp_to_c(entry
, &entries
[i
++]);
2299 *num_entries
= cpp_entries
.size();
2301 return *num_entries
;
2304 extern "C" void rbd_trash_list_cleanup(rbd_trash_image_info_t
*entries
,
2305 size_t num_entries
) {
2306 for (size_t i
=0; i
< num_entries
; i
++) {
2307 rbd_trash_get_cleanup(&entries
[i
]);
2311 extern "C" int rbd_trash_remove(rados_ioctx_t p
, const char *image_id
,
2313 librados::IoCtx io_ctx
;
2314 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2315 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2316 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
2317 io_ctx
.get_id(), image_id
, force
);
2318 librbd::NoOpProgressContext prog_ctx
;
2319 int r
= librbd::trash_remove(io_ctx
, image_id
, force
, prog_ctx
);
2320 tracepoint(librbd
, trash_remove_exit
, r
);
2324 extern "C" int rbd_trash_remove_with_progress(rados_ioctx_t p
,
2325 const char *image_id
,
2327 librbd_progress_fn_t cb
,
2329 librados::IoCtx io_ctx
;
2330 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2331 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2332 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
2333 io_ctx
.get_id(), image_id
, force
);
2334 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
2335 int r
= librbd::trash_remove(io_ctx
, image_id
, force
, prog_ctx
);
2336 tracepoint(librbd
, trash_remove_exit
, r
);
2340 extern "C" int rbd_trash_restore(rados_ioctx_t p
, const char *id
,
2342 librados::IoCtx io_ctx
;
2343 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2344 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2345 tracepoint(librbd
, trash_undelete_enter
, io_ctx
.get_pool_name().c_str(),
2346 io_ctx
.get_id(), id
, name
);
2347 int r
= librbd::trash_restore(io_ctx
, id
, name
);
2348 tracepoint(librbd
, trash_undelete_exit
, r
);
2352 extern "C" int rbd_copy(rbd_image_t image
, rados_ioctx_t dest_p
,
2353 const char *destname
)
2355 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2356 librados::IoCtx dest_io_ctx
;
2357 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
2358 tracepoint(librbd
, copy_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
);
2359 librbd::ImageOptions opts
;
2360 librbd::NoOpProgressContext prog_ctx
;
2361 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
2362 tracepoint(librbd
, copy_exit
, r
);
2366 extern "C" int rbd_copy2(rbd_image_t srcp
, rbd_image_t destp
)
2368 librbd::ImageCtx
*src
= (librbd::ImageCtx
*)srcp
;
2369 librbd::ImageCtx
*dest
= (librbd::ImageCtx
*)destp
;
2370 tracepoint(librbd
, copy2_enter
, src
, src
->name
.c_str(), src
->snap_name
.c_str(), src
->read_only
, dest
, dest
->name
.c_str(), dest
->snap_name
.c_str(), dest
->read_only
);
2371 librbd::NoOpProgressContext prog_ctx
;
2372 int r
= librbd::copy(src
, dest
, prog_ctx
, 0);
2373 tracepoint(librbd
, copy2_exit
, r
);
2377 extern "C" int rbd_copy3(rbd_image_t image
, rados_ioctx_t dest_p
,
2378 const char *destname
, rbd_image_options_t c_opts
)
2380 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2381 librados::IoCtx dest_io_ctx
;
2382 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
2383 tracepoint(librbd
, copy3_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
, c_opts
);
2384 librbd::ImageOptions
c_opts_(c_opts
);
2385 librbd::NoOpProgressContext prog_ctx
;
2386 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, c_opts_
, prog_ctx
, 0);
2387 tracepoint(librbd
, copy3_exit
, r
);
2391 extern "C" int rbd_copy4(rbd_image_t image
, rados_ioctx_t dest_p
,
2392 const char *destname
, rbd_image_options_t c_opts
, size_t sparse_size
)
2394 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2395 librados::IoCtx dest_io_ctx
;
2396 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
2397 tracepoint(librbd
, copy4_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
, c_opts
, sparse_size
);
2398 librbd::ImageOptions
c_opts_(c_opts
);
2399 librbd::NoOpProgressContext prog_ctx
;
2400 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, c_opts_
, prog_ctx
, sparse_size
);
2401 tracepoint(librbd
, copy4_exit
, r
);
2405 extern "C" int rbd_copy_with_progress(rbd_image_t image
, rados_ioctx_t dest_p
,
2406 const char *destname
,
2407 librbd_progress_fn_t fn
, void *data
)
2409 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2410 librados::IoCtx dest_io_ctx
;
2411 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
2412 tracepoint(librbd
, copy_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
);
2413 librbd::ImageOptions opts
;
2414 librbd::CProgressContext
prog_ctx(fn
, data
);
2415 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
2416 tracepoint(librbd
, copy_exit
, ret
);
2420 extern "C" int rbd_copy_with_progress2(rbd_image_t srcp
, rbd_image_t destp
,
2421 librbd_progress_fn_t fn
, void *data
)
2423 librbd::ImageCtx
*src
= (librbd::ImageCtx
*)srcp
;
2424 librbd::ImageCtx
*dest
= (librbd::ImageCtx
*)destp
;
2425 tracepoint(librbd
, copy2_enter
, src
, src
->name
.c_str(), src
->snap_name
.c_str(), src
->read_only
, dest
, dest
->name
.c_str(), dest
->snap_name
.c_str(), dest
->read_only
);
2426 librbd::CProgressContext
prog_ctx(fn
, data
);
2427 int ret
= librbd::copy(src
, dest
, prog_ctx
, 0);
2428 tracepoint(librbd
, copy2_exit
, ret
);
2432 extern "C" int rbd_copy_with_progress3(rbd_image_t image
, rados_ioctx_t dest_p
,
2433 const char *destname
,
2434 rbd_image_options_t dest_opts
,
2435 librbd_progress_fn_t fn
, void *data
)
2437 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2438 librados::IoCtx dest_io_ctx
;
2439 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
2440 tracepoint(librbd
, copy3_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
, dest_opts
);
2441 librbd::ImageOptions
dest_opts_(dest_opts
);
2442 librbd::CProgressContext
prog_ctx(fn
, data
);
2443 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, dest_opts_
, prog_ctx
, 0);
2444 tracepoint(librbd
, copy3_exit
, ret
);
2448 extern "C" int rbd_copy_with_progress4(rbd_image_t image
, rados_ioctx_t dest_p
,
2449 const char *destname
,
2450 rbd_image_options_t dest_opts
,
2451 librbd_progress_fn_t fn
, void *data
, size_t sparse_size
)
2453 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2454 librados::IoCtx dest_io_ctx
;
2455 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
2456 tracepoint(librbd
, copy4_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(), destname
, dest_opts
, sparse_size
);
2457 librbd::ImageOptions
dest_opts_(dest_opts
);
2458 librbd::CProgressContext
prog_ctx(fn
, data
);
2459 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, dest_opts_
, prog_ctx
, sparse_size
);
2460 tracepoint(librbd
, copy4_exit
, ret
);
2465 extern "C" int rbd_flatten(rbd_image_t image
)
2467 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2468 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
2469 librbd::NoOpProgressContext prog_ctx
;
2470 int r
= ictx
->operations
->flatten(prog_ctx
);
2471 tracepoint(librbd
, flatten_exit
, r
);
2475 extern "C" int rbd_flatten_with_progress(rbd_image_t image
,
2476 librbd_progress_fn_t cb
, void *cbdata
)
2478 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2479 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
2480 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
2481 int r
= ictx
->operations
->flatten(prog_ctx
);
2482 tracepoint(librbd
, flatten_exit
, r
);
2486 extern "C" int rbd_rename(rados_ioctx_t src_p
, const char *srcname
,
2487 const char *destname
)
2489 librados::IoCtx src_io_ctx
;
2490 librados::IoCtx::from_rados_ioctx_t(src_p
, src_io_ctx
);
2491 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(src_io_ctx
));
2492 tracepoint(librbd
, rename_enter
, src_io_ctx
.get_pool_name().c_str(), src_io_ctx
.get_id(), srcname
, destname
);
2493 int r
= librbd::rename(src_io_ctx
, srcname
, destname
);
2494 tracepoint(librbd
, rename_exit
, r
);
2498 extern "C" int rbd_open(rados_ioctx_t p
, const char *name
, rbd_image_t
*image
,
2499 const char *snap_name
)
2501 librados::IoCtx io_ctx
;
2502 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2503 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2504 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
2506 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2508 int r
= ictx
->state
->open(false);
2510 *image
= (rbd_image_t
)ictx
;
2512 tracepoint(librbd
, open_image_exit
, r
);
2516 extern "C" int rbd_open_by_id(rados_ioctx_t p
, const char *id
,
2517 rbd_image_t
*image
, const char *snap_name
)
2519 librados::IoCtx io_ctx
;
2520 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2521 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2522 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
2524 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(),
2525 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2527 int r
= ictx
->state
->open(false);
2531 *image
= (rbd_image_t
)ictx
;
2533 tracepoint(librbd
, open_image_exit
, r
);
2537 extern "C" int rbd_aio_open(rados_ioctx_t p
, const char *name
,
2538 rbd_image_t
*image
, const char *snap_name
,
2541 librados::IoCtx io_ctx
;
2542 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2543 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2544 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
2546 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
2547 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
2548 ictx
->state
->open(false, new C_OpenComplete(ictx
, get_aio_completion(comp
), image
));
2549 tracepoint(librbd
, aio_open_image_exit
, 0);
2553 extern "C" int rbd_aio_open_by_id(rados_ioctx_t p
, const char *id
,
2554 rbd_image_t
*image
, const char *snap_name
,
2557 librados::IoCtx io_ctx
;
2558 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2559 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2560 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
2562 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
2563 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(),
2564 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
,
2566 ictx
->state
->open(false, new C_OpenComplete(ictx
, get_aio_completion(comp
), image
));
2567 tracepoint(librbd
, aio_open_image_exit
, 0);
2571 extern "C" int rbd_open_read_only(rados_ioctx_t p
, const char *name
,
2572 rbd_image_t
*image
, const char *snap_name
)
2574 librados::IoCtx io_ctx
;
2575 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2576 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2577 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
2579 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2581 int r
= ictx
->state
->open(false);
2583 *image
= (rbd_image_t
)ictx
;
2585 tracepoint(librbd
, open_image_exit
, r
);
2589 extern "C" int rbd_open_by_id_read_only(rados_ioctx_t p
, const char *id
,
2590 rbd_image_t
*image
, const char *snap_name
)
2592 librados::IoCtx io_ctx
;
2593 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2594 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2595 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
2597 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(),
2598 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2600 int r
= ictx
->state
->open(false);
2604 *image
= (rbd_image_t
)ictx
;
2606 tracepoint(librbd
, open_image_exit
, r
);
2610 extern "C" int rbd_aio_open_read_only(rados_ioctx_t p
, const char *name
,
2611 rbd_image_t
*image
, const char *snap_name
,
2614 librados::IoCtx io_ctx
;
2615 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2616 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2617 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
2619 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
2620 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
2621 ictx
->state
->open(false, new C_OpenComplete(ictx
, get_aio_completion(comp
),
2623 tracepoint(librbd
, aio_open_image_exit
, 0);
2627 extern "C" int rbd_aio_open_by_id_read_only(rados_ioctx_t p
, const char *id
,
2629 const char *snap_name
,
2632 librados::IoCtx io_ctx
;
2633 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
2634 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
2635 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
2637 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
2638 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(),
2639 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
2640 ictx
->state
->open(false, new C_OpenComplete(ictx
, get_aio_completion(comp
),
2642 tracepoint(librbd
, aio_open_image_exit
, 0);
2646 extern "C" int rbd_close(rbd_image_t image
)
2648 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2649 tracepoint(librbd
, close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
2651 int r
= ictx
->state
->close();
2653 tracepoint(librbd
, close_image_exit
, r
);
2657 extern "C" int rbd_aio_close(rbd_image_t image
, rbd_completion_t c
)
2659 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2660 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
2661 tracepoint(librbd
, aio_close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), comp
->pc
);
2662 ictx
->state
->close(new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_CLOSE
,
2663 get_aio_completion(comp
)));
2664 tracepoint(librbd
, aio_close_image_exit
, 0);
2668 extern "C" int rbd_resize(rbd_image_t image
, uint64_t size
)
2670 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2671 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
2672 librbd::NoOpProgressContext prog_ctx
;
2673 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
2674 tracepoint(librbd
, resize_exit
, r
);
2678 extern "C" int rbd_resize2(rbd_image_t image
, uint64_t size
, bool allow_shrink
,
2679 librbd_progress_fn_t cb
, void *cbdata
)
2681 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2682 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
2683 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
2684 int r
= ictx
->operations
->resize(size
, allow_shrink
, prog_ctx
);
2685 tracepoint(librbd
, resize_exit
, r
);
2689 extern "C" int rbd_resize_with_progress(rbd_image_t image
, uint64_t size
,
2690 librbd_progress_fn_t cb
, void *cbdata
)
2692 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2693 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
2694 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
2695 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
2696 tracepoint(librbd
, resize_exit
, r
);
2700 extern "C" int rbd_stat(rbd_image_t image
, rbd_image_info_t
*info
,
2703 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2704 tracepoint(librbd
, stat_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2705 int r
= librbd::info(ictx
, *info
, infosize
);
2706 tracepoint(librbd
, stat_exit
, r
, info
);
2710 extern "C" int rbd_get_old_format(rbd_image_t image
, uint8_t *old
)
2712 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2713 tracepoint(librbd
, get_old_format_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2714 int r
= librbd::get_old_format(ictx
, old
);
2715 tracepoint(librbd
, get_old_format_exit
, r
, *old
);
2719 extern "C" int rbd_get_size(rbd_image_t image
, uint64_t *size
)
2721 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2722 tracepoint(librbd
, get_size_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2723 int r
= librbd::get_size(ictx
, size
);
2724 tracepoint(librbd
, get_size_exit
, r
, *size
);
2728 extern "C" int rbd_get_features(rbd_image_t image
, uint64_t *features
)
2730 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2731 tracepoint(librbd
, get_features_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2732 int r
= librbd::get_features(ictx
, features
);
2733 tracepoint(librbd
, get_features_exit
, r
, *features
);
2737 extern "C" int rbd_update_features(rbd_image_t image
, uint64_t features
,
2740 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
2741 bool features_enabled
= enabled
!= 0;
2742 tracepoint(librbd
, update_features_enter
, ictx
, features
, features_enabled
);
2743 int r
= ictx
->operations
->update_features(features
, features_enabled
);
2744 tracepoint(librbd
, update_features_exit
, r
);
2748 extern "C" int rbd_get_stripe_unit(rbd_image_t image
, uint64_t *stripe_unit
)
2750 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2751 tracepoint(librbd
, get_stripe_unit_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2752 *stripe_unit
= ictx
->get_stripe_unit();
2753 tracepoint(librbd
, get_stripe_unit_exit
, 0, *stripe_unit
);
2757 extern "C" int rbd_get_stripe_count(rbd_image_t image
, uint64_t *stripe_count
)
2759 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2760 tracepoint(librbd
, get_stripe_count_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2761 *stripe_count
= ictx
->get_stripe_count();
2762 tracepoint(librbd
, get_stripe_count_exit
, 0, *stripe_count
);
2766 extern "C" int rbd_get_create_timestamp(rbd_image_t image
,
2767 struct timespec
*timestamp
)
2769 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2770 tracepoint(librbd
, get_create_timestamp_enter
, ictx
, ictx
->name
.c_str(),
2772 utime_t time
= ictx
->get_create_timestamp();
2773 time
.to_timespec(timestamp
);
2774 tracepoint(librbd
, get_create_timestamp_exit
, 0, timestamp
);
2778 extern "C" int rbd_get_overlap(rbd_image_t image
, uint64_t *overlap
)
2780 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2781 tracepoint(librbd
, get_overlap_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2782 int r
= librbd::get_overlap(ictx
, overlap
);
2783 tracepoint(librbd
, get_overlap_exit
, r
, *overlap
);
2787 extern "C" int rbd_get_id(rbd_image_t image
, char *id
, size_t id_len
)
2789 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
2790 if (ictx
->old_format
) {
2793 if (ictx
->id
.size() >= id_len
) {
2797 strncpy(id
, ictx
->id
.c_str(), id_len
- 1);
2798 id
[id_len
- 1] = '\0';
2802 extern "C" int rbd_get_block_name_prefix(rbd_image_t image
, char *prefix
,
2805 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
2806 if (ictx
->object_prefix
.size() >= prefix_len
) {
2810 strncpy(prefix
, ictx
->object_prefix
.c_str(), prefix_len
- 1);
2811 prefix
[prefix_len
- 1] = '\0';
2815 extern "C" int64_t rbd_get_data_pool_id(rbd_image_t image
)
2817 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
2818 return ictx
->data_ctx
.get_id();
2821 extern "C" int rbd_get_parent_info(rbd_image_t image
,
2822 char *parent_pool_name
, size_t ppool_namelen
,
2823 char *parent_name
, size_t pnamelen
,
2824 char *parent_snap_name
, size_t psnap_namelen
)
2826 return rbd_get_parent_info2(image
, parent_pool_name
, ppool_namelen
,
2827 parent_name
, pnamelen
, nullptr, 0,
2828 parent_snap_name
, psnap_namelen
);
2831 extern "C" int rbd_get_parent_info2(rbd_image_t image
,
2832 char *parent_pool_name
,
2833 size_t ppool_namelen
,
2834 char *parent_name
, size_t pnamelen
,
2835 char *parent_id
, size_t pidlen
,
2836 char *parent_snap_name
,
2837 size_t psnap_namelen
)
2839 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2840 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
2841 ictx
->snap_name
.c_str(), ictx
->read_only
);
2842 string p_pool_name
, p_name
, p_id
, p_snap_name
;
2844 int r
= librbd::get_parent_info(ictx
, &p_pool_name
, &p_name
, &p_id
,
2847 tracepoint(librbd
, get_parent_info_exit
, r
, NULL
, NULL
, NULL
, NULL
);
2851 if (parent_pool_name
) {
2852 if (p_pool_name
.length() + 1 > ppool_namelen
) {
2853 tracepoint(librbd
, get_parent_info_exit
, -ERANGE
, NULL
, NULL
, NULL
, NULL
);
2857 strcpy(parent_pool_name
, p_pool_name
.c_str());
2860 if (p_name
.length() + 1 > pnamelen
) {
2861 tracepoint(librbd
, get_parent_info_exit
, -ERANGE
, NULL
, NULL
, NULL
, NULL
);
2865 strcpy(parent_name
, p_name
.c_str());
2868 if (p_id
.length() + 1 > pidlen
) {
2869 tracepoint(librbd
, get_parent_info_exit
, -ERANGE
, NULL
, NULL
, NULL
, NULL
);
2873 strcpy(parent_id
, p_id
.c_str());
2875 if (parent_snap_name
) {
2876 if (p_snap_name
.length() + 1 > psnap_namelen
) {
2877 tracepoint(librbd
, get_parent_info_exit
, -ERANGE
, NULL
, NULL
, NULL
, NULL
);
2881 strcpy(parent_snap_name
, p_snap_name
.c_str());
2884 tracepoint(librbd
, get_parent_info_exit
, 0, parent_pool_name
, parent_name
,
2885 parent_id
, parent_snap_name
);
2889 extern "C" int rbd_get_flags(rbd_image_t image
, uint64_t *flags
)
2891 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2892 tracepoint(librbd
, get_flags_enter
, ictx
);
2893 int r
= librbd::get_flags(ictx
, flags
);
2894 tracepoint(librbd
, get_flags_exit
, ictx
, r
, *flags
);
2898 extern "C" int rbd_set_image_notification(rbd_image_t image
, int fd
, int type
)
2900 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2901 tracepoint(librbd
, set_image_notification_enter
, ictx
, fd
, type
);
2902 int r
= librbd::set_image_notification(ictx
, fd
, type
);
2903 tracepoint(librbd
, set_image_notification_exit
, ictx
, r
);
2907 extern "C" int rbd_is_exclusive_lock_owner(rbd_image_t image
, int *is_owner
)
2909 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2910 tracepoint(librbd
, is_exclusive_lock_owner_enter
, ictx
);
2912 int r
= librbd::is_exclusive_lock_owner(ictx
, &owner
);
2913 *is_owner
= owner
? 1 : 0;
2914 tracepoint(librbd
, is_exclusive_lock_owner_exit
, ictx
, r
, *is_owner
);
2918 extern "C" int rbd_lock_acquire(rbd_image_t image
, rbd_lock_mode_t lock_mode
)
2920 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2921 tracepoint(librbd
, lock_acquire_enter
, ictx
, lock_mode
);
2922 int r
= librbd::lock_acquire(ictx
, lock_mode
);
2923 tracepoint(librbd
, lock_acquire_exit
, ictx
, r
);
2927 extern "C" int rbd_lock_release(rbd_image_t image
)
2929 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2930 tracepoint(librbd
, lock_release_enter
, ictx
);
2931 int r
= librbd::lock_release(ictx
);
2932 tracepoint(librbd
, lock_release_exit
, ictx
, r
);
2936 extern "C" int rbd_lock_get_owners(rbd_image_t image
,
2937 rbd_lock_mode_t
*lock_mode
,
2939 size_t *max_lock_owners
)
2941 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
2942 tracepoint(librbd
, lock_get_owners_enter
, ictx
);
2943 std::list
<std::string
> lock_owner_list
;
2944 int r
= librbd::lock_get_owners(ictx
, lock_mode
, &lock_owner_list
);
2946 if (*max_lock_owners
>= lock_owner_list
.size()) {
2947 *max_lock_owners
= 0;
2948 for (auto &lock_owner
: lock_owner_list
) {
2949 lock_owners
[(*max_lock_owners
)++] = strdup(lock_owner
.c_str());
2952 *max_lock_owners
= lock_owner_list
.size();
2956 tracepoint(librbd
, lock_get_owners_exit
, ictx
, r
);
2960 extern "C" void rbd_lock_get_owners_cleanup(char **lock_owners
,
2961 size_t lock_owner_count
)
2963 for (size_t i
= 0; i
< lock_owner_count
; ++i
) {
2964 free(lock_owners
[i
]);
2968 extern "C" int rbd_lock_break(rbd_image_t image
, rbd_lock_mode_t lock_mode
,
2969 const char *lock_owner
)
2971 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
2972 tracepoint(librbd
, lock_break_enter
, ictx
, lock_mode
, lock_owner
);
2973 int r
= librbd::lock_break(ictx
, lock_mode
, lock_owner
);
2974 tracepoint(librbd
, lock_break_exit
, ictx
, r
);
2978 extern "C" int rbd_rebuild_object_map(rbd_image_t image
,
2979 librbd_progress_fn_t cb
, void *cbdata
)
2981 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
2982 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
2983 return ictx
->operations
->rebuild_object_map(prog_ctx
);
2987 extern "C" int rbd_snap_create(rbd_image_t image
, const char *snap_name
)
2989 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
2990 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2991 int r
= ictx
->operations
->snap_create(cls::rbd::UserSnapshotNamespace(),
2993 tracepoint(librbd
, snap_create_exit
, r
);
2997 extern "C" int rbd_snap_rename(rbd_image_t image
, const char *srcname
, const char *dstname
)
2999 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3000 tracepoint(librbd
, snap_rename_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, srcname
, dstname
);
3001 int r
= ictx
->operations
->snap_rename(srcname
, dstname
);
3002 tracepoint(librbd
, snap_rename_exit
, r
);
3006 extern "C" int rbd_snap_remove(rbd_image_t image
, const char *snap_name
)
3008 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3009 tracepoint(librbd
, snap_remove_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
3010 librbd::NoOpProgressContext prog_ctx
;
3011 int r
= librbd::snap_remove(ictx
, snap_name
, 0, prog_ctx
);
3012 tracepoint(librbd
, snap_remove_exit
, r
);
3016 extern "C" int rbd_snap_remove2(rbd_image_t image
, const char *snap_name
, uint32_t flags
,
3017 librbd_progress_fn_t cb
, void *cbdata
)
3019 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3020 tracepoint(librbd
, snap_remove2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
, flags
);
3021 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
3022 int r
= librbd::snap_remove(ictx
, snap_name
, flags
, prog_ctx
);
3023 tracepoint(librbd
, snap_remove_exit
, r
);
3027 extern "C" int rbd_snap_rollback(rbd_image_t image
, const char *snap_name
)
3029 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3030 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
3031 librbd::NoOpProgressContext prog_ctx
;
3032 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
3033 tracepoint(librbd
, snap_rollback_exit
, r
);
3037 extern "C" int rbd_snap_rollback_with_progress(rbd_image_t image
,
3038 const char *snap_name
,
3039 librbd_progress_fn_t cb
,
3042 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3043 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
3044 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
3045 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
3046 tracepoint(librbd
, snap_rollback_exit
, r
);
3050 extern "C" int rbd_snap_list(rbd_image_t image
, rbd_snap_info_t
*snaps
,
3053 vector
<librbd::snap_info_t
> cpp_snaps
;
3054 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3055 tracepoint(librbd
, snap_list_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snaps
);
3058 tracepoint(librbd
, snap_list_exit
, -EINVAL
, 0);
3062 int r
= librbd::snap_list(ictx
, cpp_snaps
);
3064 tracepoint(librbd
, snap_list_exit
, 0, *max_snaps
);
3068 tracepoint(librbd
, snap_list_exit
, r
, *max_snaps
);
3071 if (*max_snaps
< (int)cpp_snaps
.size() + 1) {
3072 *max_snaps
= (int)cpp_snaps
.size() + 1;
3073 tracepoint(librbd
, snap_list_exit
, -ERANGE
, *max_snaps
);
3079 for (i
= 0; i
< (int)cpp_snaps
.size(); i
++) {
3080 snaps
[i
].id
= cpp_snaps
[i
].id
;
3081 snaps
[i
].size
= cpp_snaps
[i
].size
;
3082 snaps
[i
].name
= strdup(cpp_snaps
[i
].name
.c_str());
3083 if (!snaps
[i
].name
) {
3084 for (int j
= 0; j
< i
; j
++)
3085 free((void *)snaps
[j
].name
);
3086 tracepoint(librbd
, snap_list_exit
, -ENOMEM
, *max_snaps
);
3089 tracepoint(librbd
, snap_list_entry
, snaps
[i
].id
, snaps
[i
].size
, snaps
[i
].name
);
3093 snaps
[i
].name
= NULL
;
3095 r
= (int)cpp_snaps
.size();
3096 tracepoint(librbd
, snap_list_exit
, r
, *max_snaps
);
3100 extern "C" void rbd_snap_list_end(rbd_snap_info_t
*snaps
)
3102 tracepoint(librbd
, snap_list_end_enter
, snaps
);
3103 while (snaps
->name
) {
3104 free((void *)snaps
->name
);
3107 tracepoint(librbd
, snap_list_end_exit
);
3110 extern "C" int rbd_snap_protect(rbd_image_t image
, const char *snap_name
)
3112 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3113 tracepoint(librbd
, snap_protect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
3114 int r
= ictx
->operations
->snap_protect(cls::rbd::UserSnapshotNamespace(), snap_name
);
3115 tracepoint(librbd
, snap_protect_exit
, r
);
3119 extern "C" int rbd_snap_unprotect(rbd_image_t image
, const char *snap_name
)
3121 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3122 tracepoint(librbd
, snap_unprotect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
3123 int r
= ictx
->operations
->snap_unprotect(cls::rbd::UserSnapshotNamespace(), snap_name
);
3124 tracepoint(librbd
, snap_unprotect_exit
, r
);
3128 extern "C" int rbd_snap_is_protected(rbd_image_t image
, const char *snap_name
,
3131 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3132 tracepoint(librbd
, snap_is_protected_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
3133 bool protected_snap
;
3134 int r
= librbd::snap_is_protected(ictx
, snap_name
, &protected_snap
);
3136 tracepoint(librbd
, snap_is_protected_exit
, r
, *is_protected
? 1 : 0);
3139 *is_protected
= protected_snap
? 1 : 0;
3140 tracepoint(librbd
, snap_is_protected_exit
, 0, *is_protected
? 1 : 0);
3144 extern "C" int rbd_snap_get_limit(rbd_image_t image
, uint64_t *limit
)
3146 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3147 tracepoint(librbd
, snap_get_limit_enter
, ictx
, ictx
->name
.c_str());
3148 int r
= librbd::snap_get_limit(ictx
, limit
);
3149 tracepoint(librbd
, snap_get_limit_exit
, r
, *limit
);
3153 extern "C" int rbd_snap_get_timestamp(rbd_image_t image
, uint64_t snap_id
, struct timespec
*timestamp
)
3155 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3156 tracepoint(librbd
, snap_get_timestamp_enter
, ictx
, ictx
->name
.c_str());
3157 int r
= librbd::snap_get_timestamp(ictx
, snap_id
, timestamp
);
3158 tracepoint(librbd
, snap_get_timestamp_exit
, r
);
3162 extern "C" int rbd_snap_set_limit(rbd_image_t image
, uint64_t limit
)
3164 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3165 tracepoint(librbd
, snap_set_limit_enter
, ictx
, ictx
->name
.c_str(), limit
);
3166 int r
= librbd::snap_set_limit(ictx
, limit
);
3167 tracepoint(librbd
, snap_set_limit_exit
, r
);
3171 extern "C" int rbd_snap_set(rbd_image_t image
, const char *snap_name
)
3173 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3174 tracepoint(librbd
, snap_set_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
3175 int r
= librbd::snap_set(ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
);
3176 tracepoint(librbd
, snap_set_exit
, r
);
3180 extern "C" ssize_t
rbd_list_children(rbd_image_t image
, char *pools
,
3181 size_t *pools_len
, char *images
,
3184 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3185 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
3186 set
<pair
<string
, string
> > image_set
;
3188 int r
= librbd::list_children(ictx
, image_set
);
3190 tracepoint(librbd
, list_children_exit
, r
);
3194 size_t pools_total
= 0;
3195 size_t images_total
= 0;
3196 for (set
<pair
<string
, string
> >::const_iterator it
= image_set
.begin();
3197 it
!= image_set
.end(); ++it
) {
3198 pools_total
+= it
->first
.length() + 1;
3199 images_total
+= it
->second
.length() + 1;
3202 bool too_short
= false;
3203 if (pools_total
> *pools_len
)
3205 if (images_total
> *images_len
)
3207 *pools_len
= pools_total
;
3208 *images_len
= images_total
;
3210 tracepoint(librbd
, list_children_exit
, -ERANGE
);
3214 char *pools_p
= pools
;
3215 char *images_p
= images
;
3216 for (set
<pair
<string
, string
> >::const_iterator it
= image_set
.begin();
3217 it
!= image_set
.end(); ++it
) {
3218 const char* pool
= it
->first
.c_str();
3219 strcpy(pools_p
, pool
);
3220 pools_p
+= it
->first
.length() + 1;
3221 const char* image
= it
->second
.c_str();
3222 strcpy(images_p
, image
);
3223 images_p
+= it
->second
.length() + 1;
3224 tracepoint(librbd
, list_children_entry
, pool
, image
);
3227 ssize_t ret
= image_set
.size();
3228 tracepoint(librbd
, list_children_exit
, ret
);
3232 extern "C" ssize_t
rbd_list_lockers(rbd_image_t image
, int *exclusive
,
3233 char *tag
, size_t *tag_len
,
3234 char *clients
, size_t *clients_len
,
3235 char *cookies
, size_t *cookies_len
,
3236 char *addrs
, size_t *addrs_len
)
3238 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3239 tracepoint(librbd
, list_lockers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
3240 std::list
<librbd::locker_t
> lockers
;
3241 bool exclusive_bool
;
3244 int r
= list_lockers(ictx
, &lockers
, &exclusive_bool
, &tag_str
);
3246 tracepoint(librbd
, list_lockers_exit
, r
);
3250 ldout(ictx
->cct
, 20) << "list_lockers r = " << r
<< " lockers.size() = " << lockers
.size() << dendl
;
3252 *exclusive
= (int)exclusive_bool
;
3253 size_t clients_total
= 0;
3254 size_t cookies_total
= 0;
3255 size_t addrs_total
= 0;
3256 for (list
<librbd::locker_t
>::const_iterator it
= lockers
.begin();
3257 it
!= lockers
.end(); ++it
) {
3258 clients_total
+= it
->client
.length() + 1;
3259 cookies_total
+= it
->cookie
.length() + 1;
3260 addrs_total
+= it
->address
.length() + 1;
3263 bool too_short
= ((clients_total
> *clients_len
) ||
3264 (cookies_total
> *cookies_len
) ||
3265 (addrs_total
> *addrs_len
) ||
3266 (tag_str
.length() + 1 > *tag_len
));
3267 *clients_len
= clients_total
;
3268 *cookies_len
= cookies_total
;
3269 *addrs_len
= addrs_total
;
3270 *tag_len
= tag_str
.length() + 1;
3272 tracepoint(librbd
, list_lockers_exit
, -ERANGE
);
3276 strcpy(tag
, tag_str
.c_str());
3277 char *clients_p
= clients
;
3278 char *cookies_p
= cookies
;
3279 char *addrs_p
= addrs
;
3280 for (list
<librbd::locker_t
>::const_iterator it
= lockers
.begin();
3281 it
!= lockers
.end(); ++it
) {
3282 const char* client
= it
->client
.c_str();
3283 strcpy(clients_p
, client
);
3284 clients_p
+= it
->client
.length() + 1;
3285 const char* cookie
= it
->cookie
.c_str();
3286 strcpy(cookies_p
, cookie
);
3287 cookies_p
+= it
->cookie
.length() + 1;
3288 const char* address
= it
->address
.c_str();
3289 strcpy(addrs_p
, address
);
3290 addrs_p
+= it
->address
.length() + 1;
3291 tracepoint(librbd
, list_lockers_entry
, client
, cookie
, address
);
3294 ssize_t ret
= lockers
.size();
3295 tracepoint(librbd
, list_lockers_exit
, ret
);
3299 extern "C" int rbd_lock_exclusive(rbd_image_t image
, const char *cookie
)
3301 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3302 tracepoint(librbd
, lock_exclusive_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
);
3303 int r
= librbd::lock(ictx
, true, cookie
? cookie
: "", "");
3304 tracepoint(librbd
, lock_exclusive_exit
, r
);
3308 extern "C" int rbd_lock_shared(rbd_image_t image
, const char *cookie
,
3311 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3312 tracepoint(librbd
, lock_shared_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
, tag
);
3313 int r
= librbd::lock(ictx
, false, cookie
? cookie
: "", tag
? tag
: "");
3314 tracepoint(librbd
, lock_shared_exit
, r
);
3318 extern "C" int rbd_unlock(rbd_image_t image
, const char *cookie
)
3320 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3321 tracepoint(librbd
, unlock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
);
3322 int r
= librbd::unlock(ictx
, cookie
? cookie
: "");
3323 tracepoint(librbd
, unlock_exit
, r
);
3327 extern "C" int rbd_break_lock(rbd_image_t image
, const char *client
,
3330 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3331 tracepoint(librbd
, break_lock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, client
, cookie
);
3332 int r
= librbd::break_lock(ictx
, client
, cookie
? cookie
: "");
3333 tracepoint(librbd
, break_lock_exit
, r
);
3338 extern "C" ssize_t
rbd_read(rbd_image_t image
, uint64_t ofs
, size_t len
,
3341 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3342 tracepoint(librbd
, read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
3343 int r
= ictx
->io_work_queue
->read(ofs
, len
, librbd::io::ReadResult
{buf
, len
},
3345 tracepoint(librbd
, read_exit
, r
);
3349 extern "C" ssize_t
rbd_read2(rbd_image_t image
, uint64_t ofs
, size_t len
,
3350 char *buf
, int op_flags
)
3352 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3353 tracepoint(librbd
, read2_enter
, ictx
, ictx
->name
.c_str(),
3354 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, op_flags
);
3355 int r
= ictx
->io_work_queue
->read(ofs
, len
, librbd::io::ReadResult
{buf
, len
},
3357 tracepoint(librbd
, read_exit
, r
);
3362 extern "C" int64_t rbd_read_iterate(rbd_image_t image
, uint64_t ofs
, size_t len
,
3363 int (*cb
)(uint64_t, size_t, const char *, void *),
3366 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3367 tracepoint(librbd
, read_iterate_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
3368 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
3369 tracepoint(librbd
, read_iterate_exit
, r
);
3373 extern "C" int rbd_read_iterate2(rbd_image_t image
, uint64_t ofs
, uint64_t len
,
3374 int (*cb
)(uint64_t, size_t, const char *, void *),
3377 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3378 tracepoint(librbd
, read_iterate2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
3379 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
3382 tracepoint(librbd
, read_iterate2_exit
, r
);
3386 extern "C" int rbd_diff_iterate(rbd_image_t image
,
3387 const char *fromsnapname
,
3388 uint64_t ofs
, uint64_t len
,
3389 int (*cb
)(uint64_t, size_t, int, void *),
3392 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3393 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
3394 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
3396 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
3397 cls::rbd::UserSnapshotNamespace(),
3398 fromsnapname
, ofs
, len
,
3399 true, false, cb
, arg
);
3400 tracepoint(librbd
, diff_iterate_exit
, r
);
3404 extern "C" int rbd_diff_iterate2(rbd_image_t image
, const char *fromsnapname
,
3405 uint64_t ofs
, uint64_t len
,
3406 uint8_t include_parent
, uint8_t whole_object
,
3407 int (*cb
)(uint64_t, size_t, int, void *),
3410 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3411 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
3412 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
3413 include_parent
!= 0, whole_object
!= 0);
3414 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
3415 cls::rbd::UserSnapshotNamespace(),
3416 fromsnapname
, ofs
, len
,
3417 include_parent
, whole_object
,
3419 tracepoint(librbd
, diff_iterate_exit
, r
);
3423 extern "C" ssize_t
rbd_write(rbd_image_t image
, uint64_t ofs
, size_t len
,
3426 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3427 tracepoint(librbd
, write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, buf
);
3430 bl
.push_back(create_write_raw(ictx
, buf
, len
));
3431 int r
= ictx
->io_work_queue
->write(ofs
, len
, std::move(bl
), 0);
3432 tracepoint(librbd
, write_exit
, r
);
3436 extern "C" ssize_t
rbd_write2(rbd_image_t image
, uint64_t ofs
, size_t len
,
3437 const char *buf
, int op_flags
)
3439 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3440 tracepoint(librbd
, write2_enter
, ictx
, ictx
->name
.c_str(),
3441 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, buf
, op_flags
);
3444 bl
.push_back(create_write_raw(ictx
, buf
, len
));
3445 int r
= ictx
->io_work_queue
->write(ofs
, len
, std::move(bl
), op_flags
);
3446 tracepoint(librbd
, write_exit
, r
);
3451 extern "C" int rbd_discard(rbd_image_t image
, uint64_t ofs
, uint64_t len
)
3453 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3454 tracepoint(librbd
, discard_enter
, ictx
, ictx
->name
.c_str(),
3455 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
3456 if (len
> std::numeric_limits
<int>::max()) {
3457 tracepoint(librbd
, discard_exit
, -EINVAL
);
3461 int r
= ictx
->io_work_queue
->discard(ofs
, len
, ictx
->skip_partial_discard
);
3462 tracepoint(librbd
, discard_exit
, r
);
3466 extern "C" ssize_t
rbd_writesame(rbd_image_t image
, uint64_t ofs
, size_t len
,
3467 const char *buf
, size_t data_len
, int op_flags
)
3469 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3470 tracepoint(librbd
, writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
3471 ictx
->read_only
, ofs
, len
, data_len
<= 0 ? NULL
: buf
, data_len
, op_flags
);
3473 if (data_len
== 0 || len
% data_len
||
3474 len
> std::numeric_limits
<int>::max()) {
3475 tracepoint(librbd
, writesame_exit
, -EINVAL
);
3479 if (mem_is_zero(buf
, data_len
)) {
3480 int r
= ictx
->io_work_queue
->discard(ofs
, len
, false);
3481 tracepoint(librbd
, writesame_exit
, r
);
3486 bl
.push_back(create_write_raw(ictx
, buf
, data_len
));
3487 int r
= ictx
->io_work_queue
->writesame(ofs
, len
, std::move(bl
), op_flags
);
3488 tracepoint(librbd
, writesame_exit
, r
);
3492 extern "C" ssize_t
rbd_compare_and_write(rbd_image_t image
,
3493 uint64_t ofs
, size_t len
,
3494 const char *cmp_buf
,
3496 uint64_t *mismatch_off
,
3499 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3500 tracepoint(librbd
, compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
3501 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
,
3502 len
, cmp_buf
, buf
, op_flags
);
3505 cmp_bl
.push_back(create_write_raw(ictx
, cmp_buf
, len
));
3507 bl
.push_back(create_write_raw(ictx
, buf
, len
));
3509 int r
= ictx
->io_work_queue
->compare_and_write(ofs
, len
, std::move(cmp_bl
),
3510 std::move(bl
), mismatch_off
,
3512 tracepoint(librbd
, compare_and_write_exit
, r
);
3516 extern "C" int rbd_aio_create_completion(void *cb_arg
,
3517 rbd_callback_t complete_cb
,
3518 rbd_completion_t
*c
)
3520 librbd::RBD::AioCompletion
*rbd_comp
=
3521 new librbd::RBD::AioCompletion(cb_arg
, complete_cb
);
3522 *c
= (rbd_completion_t
) rbd_comp
;
3526 extern "C" int rbd_aio_write(rbd_image_t image
, uint64_t off
, size_t len
,
3527 const char *buf
, rbd_completion_t c
)
3529 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3530 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3531 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, buf
, comp
->pc
);
3534 bl
.push_back(create_write_raw(ictx
, buf
, len
));
3535 ictx
->io_work_queue
->aio_write(get_aio_completion(comp
), off
, len
,
3537 tracepoint(librbd
, aio_write_exit
, 0);
3541 extern "C" int rbd_aio_write2(rbd_image_t image
, uint64_t off
, size_t len
,
3542 const char *buf
, rbd_completion_t c
, int op_flags
)
3544 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3545 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3546 tracepoint(librbd
, aio_write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
3547 ictx
->read_only
, off
, len
, buf
, comp
->pc
, op_flags
);
3550 bl
.push_back(create_write_raw(ictx
, buf
, len
));
3551 ictx
->io_work_queue
->aio_write(get_aio_completion(comp
), off
, len
,
3552 std::move(bl
), op_flags
);
3553 tracepoint(librbd
, aio_write_exit
, 0);
3557 extern "C" int rbd_aio_writev(rbd_image_t image
, const struct iovec
*iov
,
3558 int iovcnt
, uint64_t off
, rbd_completion_t c
)
3560 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3561 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3563 // convert the scatter list into a bufferlist
3566 for (int i
= 0; i
< iovcnt
; ++i
) {
3567 const struct iovec
&io
= iov
[i
];
3573 bl
.push_back(create_write_raw(ictx
, static_cast<char*>(io
.iov_base
),
3578 if (iovcnt
<= 0 || len
< 0) {
3582 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(),
3583 ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, NULL
,
3586 ictx
->io_work_queue
->aio_write(get_aio_completion(comp
), off
, len
,
3589 tracepoint(librbd
, aio_write_exit
, r
);
3593 extern "C" int rbd_aio_discard(rbd_image_t image
, uint64_t off
, uint64_t len
,
3596 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3597 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3598 tracepoint(librbd
, aio_discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, comp
->pc
);
3599 ictx
->io_work_queue
->aio_discard(get_aio_completion(comp
), off
, len
, ictx
->skip_partial_discard
);
3600 tracepoint(librbd
, aio_discard_exit
, 0);
3604 extern "C" int rbd_aio_read(rbd_image_t image
, uint64_t off
, size_t len
,
3605 char *buf
, rbd_completion_t c
)
3607 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3608 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3609 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, buf
, comp
->pc
);
3610 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
3611 librbd::io::ReadResult
{buf
, len
}, 0);
3612 tracepoint(librbd
, aio_read_exit
, 0);
3616 extern "C" int rbd_aio_read2(rbd_image_t image
, uint64_t off
, size_t len
,
3617 char *buf
, rbd_completion_t c
, int op_flags
)
3619 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3620 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3621 tracepoint(librbd
, aio_read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
3622 ictx
->read_only
, off
, len
, buf
, comp
->pc
, op_flags
);
3623 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
3624 librbd::io::ReadResult
{buf
, len
},op_flags
);
3625 tracepoint(librbd
, aio_read_exit
, 0);
3629 extern "C" int rbd_aio_readv(rbd_image_t image
, const struct iovec
*iov
,
3630 int iovcnt
, uint64_t off
, rbd_completion_t c
)
3632 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3633 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3636 for (int i
= 0; i
< iovcnt
; ++i
) {
3637 len
+= iov
[i
].iov_len
;
3644 if (iovcnt
== 0 || len
< 0) {
3648 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(),
3649 ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, NULL
,
3652 librbd::io::ReadResult read_result
;
3654 read_result
= librbd::io::ReadResult(
3655 static_cast<char *>(iov
[0].iov_base
), iov
[0].iov_len
);
3657 read_result
= librbd::io::ReadResult(iov
, iovcnt
);
3659 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
3660 std::move(read_result
), 0);
3662 tracepoint(librbd
, aio_read_exit
, r
);
3666 extern "C" int rbd_flush(rbd_image_t image
)
3668 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3669 tracepoint(librbd
, flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
3670 int r
= librbd::flush(ictx
);
3671 tracepoint(librbd
, flush_exit
, r
);
3675 extern "C" int rbd_aio_flush(rbd_image_t image
, rbd_completion_t c
)
3677 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3678 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3679 tracepoint(librbd
, aio_flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
3680 ictx
->io_work_queue
->aio_flush(get_aio_completion(comp
));
3681 tracepoint(librbd
, aio_flush_exit
, 0);
3685 extern "C" int rbd_aio_writesame(rbd_image_t image
, uint64_t off
, size_t len
,
3686 const char *buf
, size_t data_len
, rbd_completion_t c
,
3689 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3690 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3691 tracepoint(librbd
, aio_writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
3692 ictx
->read_only
, off
, len
, data_len
<= 0 ? NULL
: buf
, data_len
, comp
->pc
,
3695 if (data_len
<= 0 || len
% data_len
) {
3696 tracepoint(librbd
, aio_writesame_exit
, -EINVAL
);
3700 if (mem_is_zero(buf
, data_len
)) {
3701 ictx
->io_work_queue
->aio_discard(get_aio_completion(comp
), off
, len
, false);
3702 tracepoint(librbd
, aio_writesame_exit
, 0);
3707 bl
.push_back(create_write_raw(ictx
, buf
, data_len
));
3708 ictx
->io_work_queue
->aio_writesame(get_aio_completion(comp
), off
, len
,
3709 std::move(bl
), op_flags
);
3710 tracepoint(librbd
, aio_writesame_exit
, 0);
3714 extern "C" ssize_t
rbd_aio_compare_and_write(rbd_image_t image
, uint64_t off
,
3715 size_t len
, const char *cmp_buf
,
3716 const char *buf
, rbd_completion_t c
,
3717 uint64_t *mismatch_off
,
3720 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3721 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3722 tracepoint(librbd
, aio_compare_and_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
3723 ictx
->read_only
, off
, len
, cmp_buf
, buf
, comp
->pc
, op_flags
);
3726 cmp_bl
.push_back(create_write_raw(ictx
, cmp_buf
, len
));
3728 bl
.push_back(create_write_raw(ictx
, buf
, len
));
3729 ictx
->io_work_queue
->aio_compare_and_write(get_aio_completion(comp
), off
, len
,
3730 std::move(cmp_bl
), std::move(bl
),
3731 mismatch_off
, op_flags
, false);
3733 tracepoint(librbd
, aio_compare_and_write_exit
, 0);
3737 extern "C" int rbd_invalidate_cache(rbd_image_t image
)
3739 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3740 tracepoint(librbd
, invalidate_cache_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
3741 int r
= librbd::invalidate_cache(ictx
);
3742 tracepoint(librbd
, invalidate_cache_exit
, r
);
3746 extern "C" int rbd_poll_io_events(rbd_image_t image
, rbd_completion_t
*comps
, int numcomp
)
3748 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3749 librbd::io::AioCompletion
*cs
[numcomp
];
3750 tracepoint(librbd
, poll_io_events_enter
, ictx
, numcomp
);
3751 int r
= librbd::poll_io_events(ictx
, cs
, numcomp
);
3752 tracepoint(librbd
, poll_io_events_exit
, r
);
3754 for (int i
= 0; i
< r
; ++i
)
3755 comps
[i
] = cs
[i
]->rbd_comp
;
3760 extern "C" int rbd_metadata_get(rbd_image_t image
, const char *key
, char *value
, size_t *vallen
)
3762 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3764 tracepoint(librbd
, metadata_get_enter
, ictx
, key
);
3765 int r
= librbd::metadata_get(ictx
, key
, &val_s
);
3767 tracepoint(librbd
, metadata_get_exit
, r
, key
, NULL
);
3770 if (*vallen
< val_s
.size() + 1) {
3772 *vallen
= val_s
.size() + 1;
3773 tracepoint(librbd
, metadata_get_exit
, r
, key
, NULL
);
3775 strncpy(value
, val_s
.c_str(), val_s
.size() + 1);
3776 tracepoint(librbd
, metadata_get_exit
, r
, key
, value
);
3781 extern "C" int rbd_metadata_set(rbd_image_t image
, const char *key
, const char *value
)
3783 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3784 tracepoint(librbd
, metadata_set_enter
, ictx
, key
, value
);
3785 int r
= ictx
->operations
->metadata_set(key
, value
);
3786 tracepoint(librbd
, metadata_set_exit
, r
);
3790 extern "C" int rbd_metadata_remove(rbd_image_t image
, const char *key
)
3792 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3793 tracepoint(librbd
, metadata_remove_enter
, ictx
, key
);
3794 int r
= ictx
->operations
->metadata_remove(key
);
3795 tracepoint(librbd
, metadata_remove_exit
, r
);
3799 extern "C" int rbd_metadata_list(rbd_image_t image
, const char *start
, uint64_t max
,
3800 char *key
, size_t *key_len
, char *value
, size_t *val_len
)
3802 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3803 tracepoint(librbd
, metadata_list_enter
, ictx
);
3804 map
<string
, bufferlist
> pairs
;
3805 int r
= librbd::metadata_list(ictx
, start
, max
, &pairs
);
3806 size_t key_total_len
= 0, val_total_len
= 0;
3807 bool too_short
= false;
3808 for (map
<string
, bufferlist
>::iterator it
= pairs
.begin();
3809 it
!= pairs
.end(); ++it
) {
3810 key_total_len
+= it
->first
.size() + 1;
3811 val_total_len
+= it
->second
.length() + 1;
3813 if (*key_len
< key_total_len
|| *val_len
< val_total_len
)
3815 *key_len
= key_total_len
;
3816 *val_len
= val_total_len
;
3818 tracepoint(librbd
, metadata_list_exit
, -ERANGE
);
3822 char *key_p
= key
, *value_p
= value
;
3824 for (map
<string
, bufferlist
>::iterator it
= pairs
.begin();
3825 it
!= pairs
.end(); ++it
) {
3826 strncpy(key_p
, it
->first
.c_str(), it
->first
.size() + 1);
3827 key_p
+= it
->first
.size() + 1;
3828 strncpy(value_p
, it
->second
.c_str(), it
->second
.length());
3829 value_p
+= it
->second
.length();
3832 tracepoint(librbd
, metadata_list_entry
, it
->first
.c_str(), it
->second
.c_str());
3834 tracepoint(librbd
, metadata_list_exit
, r
);
3838 extern "C" int rbd_mirror_image_enable(rbd_image_t image
)
3840 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3841 return librbd::api::Mirror
<>::image_enable(ictx
, false);
3844 extern "C" int rbd_mirror_image_disable(rbd_image_t image
, bool force
)
3846 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3847 return librbd::api::Mirror
<>::image_disable(ictx
, force
);
3850 extern "C" int rbd_mirror_image_promote(rbd_image_t image
, bool force
)
3852 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3853 return librbd::api::Mirror
<>::image_promote(ictx
, force
);
3856 extern "C" int rbd_mirror_image_demote(rbd_image_t image
)
3858 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3859 return librbd::api::Mirror
<>::image_demote(ictx
);
3862 extern "C" int rbd_mirror_image_resync(rbd_image_t image
)
3864 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3865 return librbd::api::Mirror
<>::image_resync(ictx
);
3868 extern "C" int rbd_mirror_image_get_info(rbd_image_t image
,
3869 rbd_mirror_image_info_t
*mirror_image_info
,
3872 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3874 librbd::mirror_image_info_t cpp_mirror_image
;
3875 int r
= librbd::api::Mirror
<>::image_get_info(ictx
, &cpp_mirror_image
,
3876 sizeof(cpp_mirror_image
));
3881 mirror_image_info_cpp_to_c(cpp_mirror_image
, mirror_image_info
);
3885 extern "C" int rbd_mirror_image_get_status(rbd_image_t image
,
3886 rbd_mirror_image_status_t
*status
,
3889 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3891 librbd::mirror_image_status_t cpp_status
;
3892 int r
= librbd::api::Mirror
<>::image_get_status(ictx
, &cpp_status
,
3893 sizeof(cpp_status
));
3898 mirror_image_status_cpp_to_c(cpp_status
, status
);
3902 extern "C" int rbd_aio_mirror_image_promote(rbd_image_t image
, bool force
,
3903 rbd_completion_t c
) {
3904 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3905 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3906 librbd::api::Mirror
<>::image_promote(
3907 ictx
, force
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3908 get_aio_completion(comp
)));
3912 extern "C" int rbd_aio_mirror_image_demote(rbd_image_t image
,
3913 rbd_completion_t c
) {
3914 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3915 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3916 librbd::api::Mirror
<>::image_demote(
3917 ictx
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3918 get_aio_completion(comp
)));
3922 extern "C" int rbd_aio_mirror_image_get_info(rbd_image_t image
,
3923 rbd_mirror_image_info_t
*info
,
3925 rbd_completion_t c
) {
3926 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3927 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3929 if (sizeof(rbd_mirror_image_info_t
) > info_size
) {
3933 auto ctx
= new C_MirrorImageGetInfo(
3934 info
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3935 get_aio_completion(comp
)));
3936 librbd::api::Mirror
<>::image_get_info(
3937 ictx
, &ctx
->cpp_mirror_image_info
, sizeof(ctx
->cpp_mirror_image_info
), ctx
);
3941 extern "C" int rbd_aio_mirror_image_get_status(rbd_image_t image
,
3942 rbd_mirror_image_status_t
*status
,
3944 rbd_completion_t c
) {
3945 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3946 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3948 if (sizeof(rbd_mirror_image_status_t
) > status_size
) {
3952 auto ctx
= new C_MirrorImageGetStatus(
3953 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3954 get_aio_completion(comp
)));
3955 librbd::api::Mirror
<>::image_get_status(
3956 ictx
, &ctx
->cpp_mirror_image_status
, sizeof(ctx
->cpp_mirror_image_status
),
3961 extern "C" int rbd_update_watch(rbd_image_t image
, uint64_t *handle
,
3962 rbd_update_callback_t watch_cb
, void *arg
)
3964 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3965 C_UpdateWatchCB
*wctx
= new C_UpdateWatchCB(watch_cb
, arg
);
3966 tracepoint(librbd
, update_watch_enter
, ictx
, wctx
);
3967 int r
= ictx
->state
->register_update_watcher(wctx
, &wctx
->handle
);
3968 tracepoint(librbd
, update_watch_exit
, r
, wctx
->handle
);
3969 *handle
= reinterpret_cast<uint64_t>(wctx
);
3973 extern "C" int rbd_update_unwatch(rbd_image_t image
, uint64_t handle
)
3975 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
3976 C_UpdateWatchCB
*wctx
= reinterpret_cast<C_UpdateWatchCB
*>(handle
);
3977 tracepoint(librbd
, update_unwatch_enter
, ictx
, wctx
->handle
);
3978 int r
= ictx
->state
->unregister_update_watcher(wctx
->handle
);
3980 tracepoint(librbd
, update_unwatch_exit
, r
);
3984 extern "C" int rbd_aio_is_complete(rbd_completion_t c
)
3986 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3987 return comp
->is_complete();
3990 extern "C" int rbd_aio_wait_for_complete(rbd_completion_t c
)
3992 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3993 return comp
->wait_for_complete();
3996 extern "C" ssize_t
rbd_aio_get_return_value(rbd_completion_t c
)
3998 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
3999 return comp
->get_return_value();
4002 extern "C" void *rbd_aio_get_arg(rbd_completion_t c
)
4004 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4005 return comp
->get_arg();
4008 extern "C" void rbd_aio_release(rbd_completion_t c
)
4010 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;