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 "common/deleter.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/Features.h"
27 #include "librbd/ImageCtx.h"
28 #include "librbd/ImageState.h"
29 #include "librbd/internal.h"
30 #include "librbd/Operations.h"
31 #include "librbd/Utils.h"
32 #include "librbd/api/Config.h"
33 #include "librbd/api/DiffIterate.h"
34 #include "librbd/api/Group.h"
35 #include "librbd/api/Image.h"
36 #include "librbd/api/Io.h"
37 #include "librbd/api/Migration.h"
38 #include "librbd/api/Mirror.h"
39 #include "librbd/api/Namespace.h"
40 #include "librbd/api/Pool.h"
41 #include "librbd/api/PoolMetadata.h"
42 #include "librbd/api/Snapshot.h"
43 #include "librbd/api/Trash.h"
44 #include "librbd/io/AioCompletion.h"
45 #include "librbd/io/ReadResult.h"
51 #define TRACEPOINT_DEFINE
52 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
53 #include "tracing/librbd.h"
54 #undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
55 #undef TRACEPOINT_DEFINE
57 #define tracepoint(...)
60 #define dout_subsys ceph_subsys_rbd
62 #define dout_prefix *_dout << "librbd: "
71 using ceph::bufferlist
;
72 using librados::snap_t
;
73 using librados::IoCtx
;
77 TracepointProvider::Traits
tracepoint_traits("librbd_tp.so", "rbd_tracing");
79 struct UserBufferDeleter
: public deleter::impl
{
81 librbd::io::AioCompletion
* aio_completion
;
83 UserBufferDeleter(CephContext
* cct
, librbd::io::AioCompletion
* aio_completion
)
84 : deleter::impl(deleter()), cct(cct
), aio_completion(aio_completion
) {
85 aio_completion
->block(cct
);
88 ~UserBufferDeleter() override
{
89 aio_completion
->unblock(cct
);
93 static auto create_write_raw(librbd::ImageCtx
*ictx
, const char *buf
,
95 librbd::io::AioCompletion
* aio_completion
) {
96 if (ictx
->disable_zero_copy
|| aio_completion
== nullptr) {
97 // must copy the buffer if writeback/writearound cache is in-use (or using
99 return buffer::copy(buf
, len
);
102 // avoid copying memory for AIO operations, but possibly delay completions
103 // until the last reference to the user's memory has been released
104 return ceph::unique_leakable_ptr
<ceph::buffer::raw
>(
105 buffer::claim_buffer(
106 len
, const_cast<char*>(buf
),
107 deleter(new UserBufferDeleter(ictx
->cct
, aio_completion
))));
110 static int get_iovec_length(const struct iovec
*iov
, int iovcnt
, size_t &len
)
118 for (int i
= 0; i
< iovcnt
; ++i
) {
119 const struct iovec
&io
= iov
[i
];
120 // check for overflow
121 if (len
+ io
.iov_len
< len
) {
130 static bufferlist
iovec_to_bufferlist(librbd::ImageCtx
*ictx
,
131 const struct iovec
*iov
,
133 librbd::io::AioCompletion
* aio_completion
)
136 for (int i
= 0; i
< iovcnt
; ++i
) {
137 const struct iovec
&io
= iov
[i
];
138 bl
.push_back(create_write_raw(ictx
, static_cast<char*>(io
.iov_base
),
139 io
.iov_len
, aio_completion
));
144 CephContext
* get_cct(IoCtx
&io_ctx
) {
145 return reinterpret_cast<CephContext
*>(io_ctx
.cct());
148 librbd::io::AioCompletion
* get_aio_completion(librbd::RBD::AioCompletion
*comp
) {
149 return reinterpret_cast<librbd::io::AioCompletion
*>(comp
->pc
);
152 struct C_AioCompletion
: public Context
{
154 librbd::io::aio_type_t aio_type
;
155 librbd::io::AioCompletion
* aio_comp
;
157 C_AioCompletion(librbd::ImageCtx
*ictx
, librbd::io::aio_type_t aio_type
,
158 librbd::io::AioCompletion
* aio_comp
)
159 : cct(ictx
->cct
), aio_type(aio_type
), aio_comp(aio_comp
) {
160 aio_comp
->init_time(ictx
, aio_type
);
163 virtual ~C_AioCompletion() {
167 void finish(int r
) override
{
168 ldout(cct
, 20) << "C_AioCompletion::finish: r=" << r
<< dendl
;
172 aio_comp
->complete();
177 struct C_OpenComplete
: public C_AioCompletion
{
178 librbd::ImageCtx
*ictx
;
180 C_OpenComplete(librbd::ImageCtx
*ictx
, librbd::io::AioCompletion
* comp
,
182 : C_AioCompletion(ictx
, librbd::io::AIO_TYPE_OPEN
, comp
),
183 ictx(ictx
), ictxp(ictxp
) {
185 void finish(int r
) override
{
186 ldout(cct
, 20) << "C_OpenComplete::finish: r=" << r
<< dendl
;
193 C_AioCompletion::finish(r
);
197 struct C_OpenAfterCloseComplete
: public Context
{
198 librbd::ImageCtx
*ictx
;
199 librbd::io::AioCompletion
* comp
;
201 C_OpenAfterCloseComplete(librbd::ImageCtx
*ictx
,
202 librbd::io::AioCompletion
* comp
,
204 : ictx(ictx
), comp(comp
), ictxp(ictxp
) {
206 void finish(int r
) override
{
207 ldout(ictx
->cct
, 20) << "C_OpenAfterCloseComplete::finish: r=" << r
211 ictx
->state
->open(0, new C_OpenComplete(ictx
, comp
, ictxp
));
215 struct C_UpdateWatchCB
: public librbd::UpdateWatchCtx
{
216 rbd_update_callback_t watch_cb
;
220 C_UpdateWatchCB(rbd_update_callback_t watch_cb
, void *arg
) :
221 watch_cb(watch_cb
), arg(arg
) {
223 void handle_notify() override
{
228 struct C_QuiesceWatchCB
: public librbd::QuiesceWatchCtx
{
229 rbd_update_callback_t quiesce_cb
;
230 rbd_update_callback_t unquiesce_cb
;
234 C_QuiesceWatchCB(rbd_update_callback_t quiesce_cb
,
235 rbd_update_callback_t unquiesce_cb
, void *arg
) :
236 quiesce_cb(quiesce_cb
), unquiesce_cb(unquiesce_cb
), arg(arg
) {
238 void handle_quiesce() override
{
241 void handle_unquiesce() override
{
246 void group_image_status_cpp_to_c(const librbd::group_image_info_t
&cpp_info
,
247 rbd_group_image_info_t
*c_info
) {
248 c_info
->name
= strdup(cpp_info
.name
.c_str());
249 c_info
->pool
= cpp_info
.pool
;
250 c_info
->state
= cpp_info
.state
;
253 void group_info_cpp_to_c(const librbd::group_info_t
&cpp_info
,
254 rbd_group_info_t
*c_info
) {
255 c_info
->name
= strdup(cpp_info
.name
.c_str());
256 c_info
->pool
= cpp_info
.pool
;
259 void group_snap_info_cpp_to_c(const librbd::group_snap_info_t
&cpp_info
,
260 rbd_group_snap_info_t
*c_info
) {
261 c_info
->name
= strdup(cpp_info
.name
.c_str());
262 c_info
->state
= cpp_info
.state
;
265 void mirror_image_info_cpp_to_c(const librbd::mirror_image_info_t
&cpp_info
,
266 rbd_mirror_image_info_t
*c_info
) {
267 c_info
->global_id
= strdup(cpp_info
.global_id
.c_str());
268 c_info
->state
= cpp_info
.state
;
269 c_info
->primary
= cpp_info
.primary
;
272 int get_local_mirror_image_site_status(
273 const librbd::mirror_image_global_status_t
& status
,
274 librbd::mirror_image_site_status_t
* local_status
) {
275 auto it
= std::find_if(status
.site_statuses
.begin(),
276 status
.site_statuses
.end(),
277 [](const librbd::mirror_image_site_status_t
& s
) {
278 return (s
.mirror_uuid
==
279 cls::rbd::MirrorImageSiteStatus::LOCAL_MIRROR_UUID
);
281 if (it
== status
.site_statuses
.end()) {
289 #pragma GCC diagnostic push
290 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
292 int mirror_image_global_status_cpp_to_c(
293 const librbd::mirror_image_global_status_t
&cpp_status
,
294 rbd_mirror_image_status_t
*c_status
) {
295 c_status
->name
= strdup(cpp_status
.name
.c_str());
296 mirror_image_info_cpp_to_c(cpp_status
.info
, &c_status
->info
);
298 librbd::mirror_image_site_status_t local_status
;
299 int r
= get_local_mirror_image_site_status(cpp_status
, &local_status
);
304 c_status
->state
= local_status
.state
;
305 c_status
->description
= strdup(local_status
.description
.c_str());
306 c_status
->last_update
= local_status
.last_update
;
307 c_status
->up
= local_status
.up
;
311 #pragma GCC diagnostic pop
313 void mirror_image_global_status_cpp_to_c(
314 const librbd::mirror_image_global_status_t
&cpp_status
,
315 rbd_mirror_image_global_status_t
*c_status
) {
316 c_status
->name
= strdup(cpp_status
.name
.c_str());
317 mirror_image_info_cpp_to_c(cpp_status
.info
, &c_status
->info
);
319 c_status
->site_statuses_count
= cpp_status
.site_statuses
.size();
320 c_status
->site_statuses
= (rbd_mirror_image_site_status_t
*)calloc(
321 cpp_status
.site_statuses
.size(), sizeof(rbd_mirror_image_site_status_t
));
324 for (auto it
= cpp_status
.site_statuses
.begin();
325 it
!= cpp_status
.site_statuses
.end(); ++it
) {
326 auto& s_status
= c_status
->site_statuses
[idx
++];
327 s_status
.mirror_uuid
= strdup(it
->mirror_uuid
.c_str());
328 s_status
.state
= it
->state
;
329 s_status
.description
= strdup(it
->description
.c_str());
330 s_status
.last_update
= it
->last_update
;
331 s_status
.up
= it
->up
;
335 void trash_image_info_cpp_to_c(const librbd::trash_image_info_t
&cpp_info
,
336 rbd_trash_image_info_t
*c_info
) {
337 c_info
->id
= strdup(cpp_info
.id
.c_str());
338 c_info
->name
= strdup(cpp_info
.name
.c_str());
339 c_info
->source
= cpp_info
.source
;
340 c_info
->deletion_time
= cpp_info
.deletion_time
;
341 c_info
->deferment_end_time
= cpp_info
.deferment_end_time
;
344 void config_option_cpp_to_c(const librbd::config_option_t
&cpp_option
,
345 rbd_config_option_t
*c_option
) {
346 c_option
->name
= strdup(cpp_option
.name
.c_str());
347 c_option
->value
= strdup(cpp_option
.value
.c_str());
348 c_option
->source
= cpp_option
.source
;
351 void config_option_cleanup(rbd_config_option_t
&option
) {
356 struct C_MirrorImageGetInfo
: public Context
{
357 rbd_mirror_image_info_t
*mirror_image_info
;
360 librbd::mirror_image_info_t cpp_mirror_image_info
;
362 C_MirrorImageGetInfo(rbd_mirror_image_info_t
*mirror_image_info
,
364 : mirror_image_info(mirror_image_info
), on_finish(on_finish
) {
367 void finish(int r
) override
{
369 on_finish
->complete(r
);
373 mirror_image_info_cpp_to_c(cpp_mirror_image_info
, mirror_image_info
);
374 on_finish
->complete(0);
378 struct C_MirrorImageGetGlobalStatus
: public Context
{
379 rbd_mirror_image_global_status_t
*mirror_image_global_status
;
382 librbd::mirror_image_global_status_t cpp_mirror_image_global_status
;
384 C_MirrorImageGetGlobalStatus(
385 rbd_mirror_image_global_status_t
*mirror_image_global_status
,
387 : mirror_image_global_status(mirror_image_global_status
),
388 on_finish(on_finish
) {
391 void finish(int r
) override
{
393 on_finish
->complete(r
);
397 mirror_image_global_status_cpp_to_c(cpp_mirror_image_global_status
,
398 mirror_image_global_status
);
399 on_finish
->complete(0);
403 #pragma GCC diagnostic push
404 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
406 struct C_MirrorImageGetStatus
: public Context
{
407 librbd::mirror_image_status_t
*mirror_image_status_cpp
= nullptr;
408 rbd_mirror_image_status_t
*mirror_image_status
= nullptr;
411 librbd::mirror_image_global_status_t cpp_mirror_image_global_status
;
413 C_MirrorImageGetStatus(rbd_mirror_image_status_t
*mirror_image_status
,
415 : mirror_image_status(mirror_image_status
), on_finish(on_finish
) {
417 C_MirrorImageGetStatus(librbd::mirror_image_status_t
*mirror_image_status
,
419 : mirror_image_status_cpp(mirror_image_status
), on_finish(on_finish
) {
423 void finish(int r
) override
{
425 on_finish
->complete(r
);
429 if (mirror_image_status
!= nullptr) {
430 r
= mirror_image_global_status_cpp_to_c(cpp_mirror_image_global_status
,
431 mirror_image_status
);
432 } else if (mirror_image_status_cpp
!= nullptr) {
433 librbd::mirror_image_site_status_t local_status
;
434 r
= get_local_mirror_image_site_status(cpp_mirror_image_global_status
,
437 *mirror_image_status_cpp
= {
438 cpp_mirror_image_global_status
.name
,
439 cpp_mirror_image_global_status
.info
,
440 local_status
.state
, local_status
.description
,
441 local_status
.last_update
, local_status
.up
};
444 on_finish
->complete(r
);
448 #pragma GCC diagnostic pop
450 } // anonymous namespace
453 ProgressContext::~ProgressContext()
457 class CProgressContext
: public ProgressContext
460 CProgressContext(librbd_progress_fn_t fn
, void *data
)
461 : m_fn(fn
), m_data(data
)
464 int update_progress(uint64_t offset
, uint64_t src_size
) override
466 return m_fn(offset
, src_size
, m_data
);
469 librbd_progress_fn_t m_fn
;
476 PoolStats::PoolStats() {
477 rbd_pool_stats_create(&pool_stats
);
480 PoolStats::~PoolStats() {
481 rbd_pool_stats_destroy(pool_stats
);
484 int PoolStats::add(rbd_pool_stat_option_t option
, uint64_t* opt_val
) {
485 return rbd_pool_stats_option_add_uint64(pool_stats
, option
, opt_val
);
499 void RBD::version(int *major
, int *minor
, int *extra
)
501 rbd_version(major
, minor
, extra
);
504 int RBD::open(IoCtx
& io_ctx
, Image
& image
, const char *name
)
506 return open(io_ctx
, image
, name
, NULL
);
509 int RBD::open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
)
511 return open_by_id(io_ctx
, image
, id
, nullptr);
514 int RBD::open(IoCtx
& io_ctx
, Image
& image
, const char *name
,
515 const char *snap_name
)
517 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, false);
518 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
519 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
521 if (image
.ctx
!= NULL
) {
522 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
526 int r
= ictx
->state
->open(0);
528 tracepoint(librbd
, open_image_exit
, r
);
532 image
.ctx
= (image_ctx_t
) ictx
;
533 tracepoint(librbd
, open_image_exit
, 0);
537 int RBD::open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
,
538 const char *snap_name
)
540 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, false);
541 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
542 tracepoint(librbd
, open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
543 ictx
->snap_name
.c_str(), ictx
->read_only
);
545 if (image
.ctx
!= nullptr) {
546 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
550 int r
= ictx
->state
->open(0);
552 tracepoint(librbd
, open_image_by_id_exit
, r
);
556 image
.ctx
= (image_ctx_t
) ictx
;
557 tracepoint(librbd
, open_image_by_id_exit
, 0);
561 int RBD::aio_open(IoCtx
& io_ctx
, Image
& image
, const char *name
,
562 const char *snap_name
, RBD::AioCompletion
*c
)
564 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, false);
565 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
566 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
);
568 if (image
.ctx
!= NULL
) {
569 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
570 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
572 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(c
),
575 tracepoint(librbd
, aio_open_image_exit
, 0);
579 int RBD::aio_open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
,
580 const char *snap_name
, RBD::AioCompletion
*c
)
582 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, false);
583 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
584 tracepoint(librbd
, aio_open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
585 ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
587 if (image
.ctx
!= nullptr) {
588 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
589 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
591 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(c
),
594 tracepoint(librbd
, aio_open_image_by_id_exit
, 0);
598 int RBD::open_read_only(IoCtx
& io_ctx
, Image
& image
, const char *name
,
599 const char *snap_name
)
601 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, true);
602 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
603 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
605 if (image
.ctx
!= NULL
) {
606 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
610 int r
= ictx
->state
->open(0);
612 tracepoint(librbd
, open_image_exit
, r
);
616 image
.ctx
= (image_ctx_t
) ictx
;
617 tracepoint(librbd
, open_image_exit
, 0);
621 int RBD::open_by_id_read_only(IoCtx
& io_ctx
, Image
& image
, const char *id
,
622 const char *snap_name
)
624 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, true);
625 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
626 tracepoint(librbd
, open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
627 ictx
->snap_name
.c_str(), ictx
->read_only
);
629 if (image
.ctx
!= nullptr) {
630 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
634 int r
= ictx
->state
->open(0);
636 tracepoint(librbd
, open_image_by_id_exit
, r
);
640 image
.ctx
= (image_ctx_t
) ictx
;
641 tracepoint(librbd
, open_image_by_id_exit
, 0);
645 int RBD::aio_open_read_only(IoCtx
& io_ctx
, Image
& image
, const char *name
,
646 const char *snap_name
, RBD::AioCompletion
*c
)
648 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, true);
649 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
650 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
);
652 if (image
.ctx
!= NULL
) {
653 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
654 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
656 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(c
),
659 tracepoint(librbd
, aio_open_image_exit
, 0);
663 int RBD::aio_open_by_id_read_only(IoCtx
& io_ctx
, Image
& image
, const char *id
,
664 const char *snap_name
, RBD::AioCompletion
*c
)
666 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, true);
667 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
668 tracepoint(librbd
, aio_open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
669 ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
671 if (image
.ctx
!= nullptr) {
672 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
673 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
675 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(c
),
678 tracepoint(librbd
, aio_open_image_by_id_exit
, 0);
682 int RBD::features_to_string(uint64_t features
, std::string
*str_features
)
684 std::stringstream err
;
685 *str_features
= librbd::rbd_features_to_string(features
, &err
);
686 if (!err
.str().empty()) {
693 int RBD::features_from_string(const std::string str_features
, uint64_t *features
)
695 std::stringstream err
;
696 *features
= librbd::rbd_features_from_string(str_features
, &err
);
697 if (!err
.str().empty()) {
704 int RBD::create(IoCtx
& io_ctx
, const char *name
, uint64_t size
, int *order
)
706 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
707 tracepoint(librbd
, create_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, *order
);
708 int r
= librbd::create(io_ctx
, name
, size
, order
);
709 tracepoint(librbd
, create_exit
, r
, *order
);
713 int RBD::create2(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
714 uint64_t features
, int *order
)
716 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
717 tracepoint(librbd
, create2_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
);
718 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
, 0, 0);
719 tracepoint(librbd
, create2_exit
, r
, *order
);
723 int RBD::create3(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
724 uint64_t features
, int *order
, uint64_t stripe_unit
,
725 uint64_t stripe_count
)
727 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
728 tracepoint(librbd
, create3_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
, stripe_unit
, stripe_count
);
729 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
,
730 stripe_unit
, stripe_count
);
731 tracepoint(librbd
, create3_exit
, r
, *order
);
735 int RBD::create4(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
738 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
739 tracepoint(librbd
, create4_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, opts
.opts
);
740 int r
= librbd::create(io_ctx
, name
, "", size
, opts
, "", "", false);
741 tracepoint(librbd
, create4_exit
, r
);
745 int RBD::clone(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
746 IoCtx
& c_ioctx
, const char *c_name
, uint64_t features
,
749 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
750 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
);
751 int r
= librbd::clone(p_ioctx
, p_name
, p_snap_name
, c_ioctx
, c_name
,
752 features
, c_order
, 0, 0);
753 tracepoint(librbd
, clone_exit
, r
, *c_order
);
757 int RBD::clone2(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
758 IoCtx
& c_ioctx
, const char *c_name
, uint64_t features
,
759 int *c_order
, uint64_t stripe_unit
, int stripe_count
)
761 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
762 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
);
763 int r
= librbd::clone(p_ioctx
, p_name
, p_snap_name
, c_ioctx
, c_name
,
764 features
, c_order
, stripe_unit
, stripe_count
);
765 tracepoint(librbd
, clone2_exit
, r
, *c_order
);
769 int RBD::clone3(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
770 IoCtx
& c_ioctx
, const char *c_name
, ImageOptions
& c_opts
)
772 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
773 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
);
774 int r
= librbd::clone(p_ioctx
, nullptr, p_name
, p_snap_name
, c_ioctx
,
775 nullptr, c_name
, c_opts
, "", "");
776 tracepoint(librbd
, clone3_exit
, r
);
780 int RBD::remove(IoCtx
& io_ctx
, const char *name
)
782 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
783 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
784 librbd::NoOpProgressContext prog_ctx
;
785 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, prog_ctx
);
786 tracepoint(librbd
, remove_exit
, r
);
790 int RBD::remove_with_progress(IoCtx
& io_ctx
, const char *name
,
791 ProgressContext
& pctx
)
793 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
794 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
795 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, pctx
);
796 tracepoint(librbd
, remove_exit
, r
);
800 int RBD::trash_move(IoCtx
&io_ctx
, const char *name
, uint64_t delay
) {
801 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
802 tracepoint(librbd
, trash_move_enter
, io_ctx
.get_pool_name().c_str(),
803 io_ctx
.get_id(), name
);
804 int r
= librbd::api::Trash
<>::move(io_ctx
, RBD_TRASH_IMAGE_SOURCE_USER
,
806 tracepoint(librbd
, trash_move_exit
, r
);
810 int RBD::trash_get(IoCtx
&io_ctx
, const char *id
, trash_image_info_t
*info
) {
811 return librbd::api::Trash
<>::get(io_ctx
, id
, info
);
814 int RBD::trash_list(IoCtx
&io_ctx
, vector
<trash_image_info_t
> &entries
) {
815 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
816 tracepoint(librbd
, trash_list_enter
,
817 io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
818 int r
= librbd::api::Trash
<>::list(io_ctx
, entries
, true);
821 for (const auto& entry
: entries
) {
822 tracepoint(librbd
, trash_list_entry
, entry
.id
.c_str());
826 tracepoint(librbd
, trash_list_exit
, r
, r
);
830 int RBD::trash_remove(IoCtx
&io_ctx
, const char *image_id
, bool force
) {
831 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
832 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
833 io_ctx
.get_id(), image_id
, force
);
834 librbd::NoOpProgressContext prog_ctx
;
835 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, prog_ctx
);
836 tracepoint(librbd
, trash_remove_exit
, r
);
840 int RBD::trash_remove_with_progress(IoCtx
&io_ctx
, const char *image_id
,
841 bool force
, ProgressContext
&pctx
) {
842 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
843 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
844 io_ctx
.get_id(), image_id
, force
);
845 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, pctx
);
846 tracepoint(librbd
, trash_remove_exit
, r
);
850 int RBD::trash_restore(IoCtx
&io_ctx
, const char *id
, const char *name
) {
851 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
852 tracepoint(librbd
, trash_undelete_enter
, io_ctx
.get_pool_name().c_str(),
853 io_ctx
.get_id(), id
, name
);
854 int r
= librbd::api::Trash
<>::restore(
855 io_ctx
, librbd::api::Trash
<>::ALLOWED_RESTORE_SOURCES
, id
, name
);
856 tracepoint(librbd
, trash_undelete_exit
, r
);
860 int RBD::trash_purge(IoCtx
&io_ctx
, time_t expire_ts
, float threshold
) {
861 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
862 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
863 io_ctx
.get_id(), expire_ts
, threshold
);
864 NoOpProgressContext nop_pctx
;
865 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, nop_pctx
);
866 tracepoint(librbd
, trash_purge_exit
, r
);
870 int RBD::trash_purge_with_progress(IoCtx
&io_ctx
, time_t expire_ts
,
871 float threshold
, ProgressContext
&pctx
) {
872 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
873 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
874 io_ctx
.get_id(), expire_ts
, threshold
);
875 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, pctx
);
876 tracepoint(librbd
, trash_purge_exit
, r
);
880 int RBD::namespace_create(IoCtx
& io_ctx
, const char *namespace_name
) {
881 return librbd::api::Namespace
<>::create(io_ctx
, namespace_name
);
884 int RBD::namespace_remove(IoCtx
& io_ctx
, const char *namespace_name
) {
885 return librbd::api::Namespace
<>::remove(io_ctx
, namespace_name
);
888 int RBD::namespace_list(IoCtx
& io_ctx
,
889 std::vector
<std::string
>* namespace_names
) {
890 return librbd::api::Namespace
<>::list(io_ctx
, namespace_names
);
893 int RBD::namespace_exists(IoCtx
& io_ctx
, const char *namespace_name
,
895 return librbd::api::Namespace
<>::exists(io_ctx
, namespace_name
, exists
);
898 int RBD::pool_init(IoCtx
& io_ctx
, bool force
) {
899 return librbd::api::Pool
<>::init(io_ctx
, force
);
902 int RBD::pool_stats_get(IoCtx
& io_ctx
, PoolStats
* stats
) {
903 auto pool_stat_options
=
904 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(stats
->pool_stats
);
905 return librbd::api::Pool
<>::get_stats(io_ctx
, pool_stat_options
);
908 int RBD::list(IoCtx
& io_ctx
, vector
<string
>& names
)
910 std::vector
<image_spec_t
> image_specs
;
911 int r
= list2(io_ctx
, &image_specs
);
917 for (auto& it
: image_specs
) {
918 names
.push_back(it
.name
);
923 int RBD::list2(IoCtx
& io_ctx
, std::vector
<image_spec_t
> *images
)
925 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
926 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(),
929 int r
= librbd::api::Image
<>::list_images(io_ctx
, images
);
932 for (auto& it
: *images
) {
933 tracepoint(librbd
, list_entry
, it
.name
.c_str());
937 tracepoint(librbd
, list_exit
, r
, r
);
941 int RBD::rename(IoCtx
& src_io_ctx
, const char *srcname
, const char *destname
)
943 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(src_io_ctx
));
944 tracepoint(librbd
, rename_enter
, src_io_ctx
.get_pool_name().c_str(), src_io_ctx
.get_id(), srcname
, destname
);
945 int r
= librbd::rename(src_io_ctx
, srcname
, destname
);
946 tracepoint(librbd
, rename_exit
, r
);
950 int RBD::migration_prepare(IoCtx
& io_ctx
, const char *image_name
,
951 IoCtx
& dest_io_ctx
, const char *dest_image_name
,
954 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
955 tracepoint(librbd
, migration_prepare_enter
, io_ctx
.get_pool_name().c_str(),
956 io_ctx
.get_id(), image_name
, dest_io_ctx
.get_pool_name().c_str(),
957 dest_io_ctx
.get_id(), dest_image_name
, opts
.opts
);
958 int r
= librbd::api::Migration
<>::prepare(io_ctx
, image_name
, dest_io_ctx
,
959 dest_image_name
, opts
);
960 tracepoint(librbd
, migration_prepare_exit
, r
);
964 int RBD::migration_prepare_import(const char *source_spec
, IoCtx
& dest_io_ctx
,
965 const char *dest_image_name
,
966 ImageOptions
& opts
) {
967 return librbd::api::Migration
<>::prepare_import(source_spec
, dest_io_ctx
,
968 dest_image_name
, opts
);
971 int RBD::migration_execute(IoCtx
& io_ctx
, const char *image_name
)
973 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
974 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
975 io_ctx
.get_id(), image_name
);
976 librbd::NoOpProgressContext prog_ctx
;
977 int r
= librbd::api::Migration
<>::execute(io_ctx
, image_name
, prog_ctx
);
978 tracepoint(librbd
, migration_execute_exit
, r
);
982 int RBD::migration_execute_with_progress(IoCtx
& io_ctx
,
983 const char *image_name
,
984 librbd::ProgressContext
&prog_ctx
)
986 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
987 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
988 io_ctx
.get_id(), image_name
);
989 int r
= librbd::api::Migration
<>::execute(io_ctx
, image_name
, prog_ctx
);
990 tracepoint(librbd
, migration_execute_exit
, r
);
994 int RBD::migration_abort(IoCtx
& io_ctx
, const char *image_name
)
996 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
997 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
998 io_ctx
.get_id(), image_name
);
999 librbd::NoOpProgressContext prog_ctx
;
1000 int r
= librbd::api::Migration
<>::abort(io_ctx
, image_name
, prog_ctx
);
1001 tracepoint(librbd
, migration_abort_exit
, r
);
1005 int RBD::migration_abort_with_progress(IoCtx
& io_ctx
, const char *image_name
,
1006 librbd::ProgressContext
&prog_ctx
)
1008 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1009 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
1010 io_ctx
.get_id(), image_name
);
1011 int r
= librbd::api::Migration
<>::abort(io_ctx
, image_name
, prog_ctx
);
1012 tracepoint(librbd
, migration_abort_exit
, r
);
1016 int RBD::migration_commit(IoCtx
& io_ctx
, const char *image_name
)
1018 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1019 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
1020 io_ctx
.get_id(), image_name
);
1021 librbd::NoOpProgressContext prog_ctx
;
1022 int r
= librbd::api::Migration
<>::commit(io_ctx
, image_name
, prog_ctx
);
1023 tracepoint(librbd
, migration_commit_exit
, r
);
1027 int RBD::migration_commit_with_progress(IoCtx
& io_ctx
, const char *image_name
,
1028 librbd::ProgressContext
&prog_ctx
)
1030 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1031 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
1032 io_ctx
.get_id(), image_name
);
1033 int r
= librbd::api::Migration
<>::commit(io_ctx
, image_name
, prog_ctx
);
1034 tracepoint(librbd
, migration_commit_exit
, r
);
1038 int RBD::migration_status(IoCtx
& io_ctx
, const char *image_name
,
1039 image_migration_status_t
*status
,
1042 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1043 tracepoint(librbd
, migration_status_enter
, io_ctx
.get_pool_name().c_str(),
1044 io_ctx
.get_id(), image_name
);
1046 if (status_size
!= sizeof(image_migration_status_t
)) {
1047 tracepoint(librbd
, migration_status_exit
, -ERANGE
);
1051 int r
= librbd::api::Migration
<>::status(io_ctx
, image_name
, status
);
1052 tracepoint(librbd
, migration_status_exit
, r
);
1056 int RBD::mirror_mode_get(IoCtx
& io_ctx
, rbd_mirror_mode_t
*mirror_mode
) {
1057 return librbd::api::Mirror
<>::mode_get(io_ctx
, mirror_mode
);
1060 int RBD::mirror_mode_set(IoCtx
& io_ctx
, rbd_mirror_mode_t mirror_mode
) {
1061 return librbd::api::Mirror
<>::mode_set(io_ctx
, mirror_mode
);
1064 int RBD::mirror_uuid_get(IoCtx
& io_ctx
, std::string
* mirror_uuid
) {
1065 return librbd::api::Mirror
<>::uuid_get(io_ctx
, mirror_uuid
);
1068 int RBD::mirror_site_name_get(librados::Rados
& rados
,
1069 std::string
* site_name
) {
1070 return librbd::api::Mirror
<>::site_name_get(rados
, site_name
);
1073 int RBD::mirror_site_name_set(librados::Rados
& rados
,
1074 const std::string
& site_name
) {
1075 return librbd::api::Mirror
<>::site_name_set(rados
, site_name
);
1078 int RBD::mirror_peer_bootstrap_create(IoCtx
& io_ctx
, std::string
* token
) {
1079 return librbd::api::Mirror
<>::peer_bootstrap_create(io_ctx
, token
);
1082 int RBD::mirror_peer_bootstrap_import(IoCtx
& io_ctx
,
1083 rbd_mirror_peer_direction_t direction
,
1084 const std::string
& token
) {
1085 return librbd::api::Mirror
<>::peer_bootstrap_import(io_ctx
, direction
,
1089 int RBD::mirror_peer_site_add(IoCtx
& io_ctx
, std::string
*uuid
,
1090 mirror_peer_direction_t direction
,
1091 const std::string
&site_name
,
1092 const std::string
&client_name
) {
1093 return librbd::api::Mirror
<>::peer_site_add(
1094 io_ctx
, uuid
, direction
, site_name
, client_name
);
1097 int RBD::mirror_peer_site_remove(IoCtx
& io_ctx
, const std::string
&uuid
) {
1098 return librbd::api::Mirror
<>::peer_site_remove(io_ctx
, uuid
);
1101 int RBD::mirror_peer_site_list(
1102 IoCtx
& io_ctx
, std::vector
<mirror_peer_site_t
> *peer_sites
) {
1103 return librbd::api::Mirror
<>::peer_site_list(io_ctx
, peer_sites
);
1106 int RBD::mirror_peer_site_set_client_name(
1107 IoCtx
& io_ctx
, const std::string
&uuid
, const std::string
&client_name
) {
1108 return librbd::api::Mirror
<>::peer_site_set_client(io_ctx
, uuid
,
1112 int RBD::mirror_peer_site_set_name(IoCtx
& io_ctx
, const std::string
&uuid
,
1113 const std::string
&site_name
) {
1114 return librbd::api::Mirror
<>::peer_site_set_name(io_ctx
, uuid
,
1118 int RBD::mirror_peer_site_set_direction(IoCtx
& io_ctx
,
1119 const std::string
& uuid
,
1120 mirror_peer_direction_t direction
) {
1121 return librbd::api::Mirror
<>::peer_site_set_direction(io_ctx
, uuid
,
1125 int RBD::mirror_peer_site_get_attributes(
1126 IoCtx
& io_ctx
, const std::string
&uuid
,
1127 std::map
<std::string
, std::string
> *key_vals
) {
1128 return librbd::api::Mirror
<>::peer_site_get_attributes(io_ctx
, uuid
,
1132 int RBD::mirror_peer_site_set_attributes(
1133 IoCtx
& io_ctx
, const std::string
&uuid
,
1134 const std::map
<std::string
, std::string
>& key_vals
) {
1135 return librbd::api::Mirror
<>::peer_site_set_attributes(io_ctx
, uuid
,
1139 int RBD::mirror_image_global_status_list(
1140 IoCtx
& io_ctx
, const std::string
&start_id
, size_t max
,
1141 std::map
<std::string
, mirror_image_global_status_t
> *global_statuses
) {
1142 return librbd::api::Mirror
<>::image_global_status_list(
1143 io_ctx
, start_id
, max
, global_statuses
);
1146 #pragma GCC diagnostic push
1147 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1149 int RBD::mirror_peer_add(IoCtx
& io_ctx
, std::string
*uuid
,
1150 const std::string
&cluster_name
,
1151 const std::string
&client_name
) {
1152 return librbd::api::Mirror
<>::peer_site_add(
1153 io_ctx
, uuid
, RBD_MIRROR_PEER_DIRECTION_RX_TX
, cluster_name
, client_name
);
1156 int RBD::mirror_peer_remove(IoCtx
& io_ctx
, const std::string
&uuid
) {
1157 return librbd::api::Mirror
<>::peer_site_remove(io_ctx
, uuid
);
1160 int RBD::mirror_peer_list(IoCtx
& io_ctx
, std::vector
<mirror_peer_t
> *peers
) {
1161 std::vector
<mirror_peer_site_t
> peer_sites
;
1162 int r
= librbd::api::Mirror
<>::peer_site_list(io_ctx
, &peer_sites
);
1168 peers
->reserve(peer_sites
.size());
1169 for (auto& peer_site
: peer_sites
) {
1170 peers
->push_back({peer_site
.uuid
, peer_site
.site_name
,
1171 peer_site
.client_name
});
1176 int RBD::mirror_peer_set_client(IoCtx
& io_ctx
, const std::string
&uuid
,
1177 const std::string
&client_name
) {
1178 return librbd::api::Mirror
<>::peer_site_set_client(io_ctx
, uuid
,
1182 int RBD::mirror_peer_set_cluster(IoCtx
& io_ctx
, const std::string
&uuid
,
1183 const std::string
&cluster_name
) {
1184 return librbd::api::Mirror
<>::peer_site_set_name(io_ctx
, uuid
,
1188 int RBD::mirror_peer_get_attributes(
1189 IoCtx
& io_ctx
, const std::string
&uuid
,
1190 std::map
<std::string
, std::string
> *key_vals
) {
1191 return librbd::api::Mirror
<>::peer_site_get_attributes(io_ctx
, uuid
,
1195 int RBD::mirror_peer_set_attributes(
1196 IoCtx
& io_ctx
, const std::string
&uuid
,
1197 const std::map
<std::string
, std::string
>& key_vals
) {
1198 return librbd::api::Mirror
<>::peer_site_set_attributes(io_ctx
, uuid
,
1202 int RBD::mirror_image_status_list(IoCtx
& io_ctx
, const std::string
&start_id
,
1203 size_t max
, std::map
<std::string
, mirror_image_status_t
> *images
) {
1204 std::map
<std::string
, mirror_image_global_status_t
> global_statuses
;
1206 int r
= librbd::api::Mirror
<>::image_global_status_list(
1207 io_ctx
, start_id
, max
, &global_statuses
);
1213 for (auto &[id
, global_status
] : global_statuses
) {
1214 if (global_status
.site_statuses
.empty() ||
1215 global_status
.site_statuses
[0].mirror_uuid
!=
1216 cls::rbd::MirrorImageSiteStatus::LOCAL_MIRROR_UUID
) {
1220 auto& site_status
= global_status
.site_statuses
[0];
1221 (*images
)[id
] = mirror_image_status_t
{
1222 global_status
.name
, global_status
.info
, site_status
.state
,
1223 site_status
.description
, site_status
.last_update
, site_status
.up
};
1229 #pragma GCC diagnostic pop
1231 int RBD::mirror_image_status_summary(IoCtx
& io_ctx
,
1232 std::map
<mirror_image_status_state_t
, int> *states
) {
1233 return librbd::api::Mirror
<>::image_status_summary(io_ctx
, states
);
1236 int RBD::mirror_image_instance_id_list(IoCtx
& io_ctx
,
1237 const std::string
&start_id
, size_t max
,
1238 std::map
<std::string
, std::string
> *instance_ids
) {
1239 return librbd::api::Mirror
<>::image_instance_id_list(io_ctx
, start_id
, max
,
1243 int RBD::mirror_image_info_list(
1244 IoCtx
& io_ctx
, mirror_image_mode_t
*mode_filter
,
1245 const std::string
&start_id
, size_t max
,
1246 std::map
<std::string
, std::pair
<mirror_image_mode_t
,
1247 mirror_image_info_t
>> *entries
) {
1248 return librbd::api::Mirror
<>::image_info_list(io_ctx
, mode_filter
, start_id
,
1252 int RBD::group_create(IoCtx
& io_ctx
, const char *group_name
)
1254 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1255 tracepoint(librbd
, group_create_enter
, io_ctx
.get_pool_name().c_str(),
1256 io_ctx
.get_id(), group_name
);
1257 int r
= librbd::api::Group
<>::create(io_ctx
, group_name
);
1258 tracepoint(librbd
, group_create_exit
, r
);
1262 int RBD::group_remove(IoCtx
& io_ctx
, const char *group_name
)
1264 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1265 tracepoint(librbd
, group_remove_enter
, io_ctx
.get_pool_name().c_str(),
1266 io_ctx
.get_id(), group_name
);
1267 int r
= librbd::api::Group
<>::remove(io_ctx
, group_name
);
1268 tracepoint(librbd
, group_remove_exit
, r
);
1272 int RBD::group_list(IoCtx
& io_ctx
, vector
<string
> *names
)
1274 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1275 tracepoint(librbd
, group_list_enter
, io_ctx
.get_pool_name().c_str(),
1278 int r
= librbd::api::Group
<>::list(io_ctx
, names
);
1280 for (auto itr
: *names
) {
1281 tracepoint(librbd
, group_list_entry
, itr
.c_str());
1284 tracepoint(librbd
, group_list_exit
, r
);
1288 int RBD::group_rename(IoCtx
& io_ctx
, const char *src_name
,
1289 const char *dest_name
)
1291 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1292 tracepoint(librbd
, group_rename_enter
, io_ctx
.get_pool_name().c_str(),
1293 io_ctx
.get_id(), src_name
, dest_name
);
1294 int r
= librbd::api::Group
<>::rename(io_ctx
, src_name
, dest_name
);
1295 tracepoint(librbd
, group_rename_exit
, r
);
1299 int RBD::group_image_add(IoCtx
& group_ioctx
, const char *group_name
,
1300 IoCtx
& image_ioctx
, const char *image_name
)
1302 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1303 tracepoint(librbd
, group_image_add_enter
,
1304 group_ioctx
.get_pool_name().c_str(),
1305 group_ioctx
.get_id(), group_name
,
1306 image_ioctx
.get_pool_name().c_str(),
1307 image_ioctx
.get_id(), image_name
);
1308 int r
= librbd::api::Group
<>::image_add(group_ioctx
, group_name
,
1309 image_ioctx
, image_name
);
1310 tracepoint(librbd
, group_image_add_exit
, r
);
1314 int RBD::group_image_remove(IoCtx
& group_ioctx
, const char *group_name
,
1315 IoCtx
& image_ioctx
, const char *image_name
)
1317 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1318 tracepoint(librbd
, group_image_remove_enter
,
1319 group_ioctx
.get_pool_name().c_str(),
1320 group_ioctx
.get_id(), group_name
,
1321 image_ioctx
.get_pool_name().c_str(),
1322 image_ioctx
.get_id(), image_name
);
1323 int r
= librbd::api::Group
<>::image_remove(group_ioctx
, group_name
,
1324 image_ioctx
, image_name
);
1325 tracepoint(librbd
, group_image_remove_exit
, r
);
1329 int RBD::group_image_remove_by_id(IoCtx
& group_ioctx
, const char *group_name
,
1330 IoCtx
& image_ioctx
, const char *image_id
)
1332 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1333 tracepoint(librbd
, group_image_remove_by_id_enter
,
1334 group_ioctx
.get_pool_name().c_str(),
1335 group_ioctx
.get_id(), group_name
,
1336 image_ioctx
.get_pool_name().c_str(),
1337 image_ioctx
.get_id(), image_id
);
1338 int r
= librbd::api::Group
<>::image_remove_by_id(group_ioctx
, group_name
,
1339 image_ioctx
, image_id
);
1340 tracepoint(librbd
, group_image_remove_by_id_exit
, r
);
1344 int RBD::group_image_list(IoCtx
& group_ioctx
, const char *group_name
,
1345 std::vector
<group_image_info_t
> *images
,
1346 size_t group_image_info_size
)
1348 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1349 tracepoint(librbd
, group_image_list_enter
,
1350 group_ioctx
.get_pool_name().c_str(),
1351 group_ioctx
.get_id(), group_name
);
1353 if (group_image_info_size
!= sizeof(group_image_info_t
)) {
1354 tracepoint(librbd
, group_image_list_exit
, -ERANGE
);
1358 int r
= librbd::api::Group
<>::image_list(group_ioctx
, group_name
, images
);
1359 tracepoint(librbd
, group_image_list_exit
, r
);
1363 int RBD::group_snap_create(IoCtx
& group_ioctx
, const char *group_name
,
1364 const char *snap_name
) {
1365 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1366 tracepoint(librbd
, group_snap_create_enter
,
1367 group_ioctx
.get_pool_name().c_str(),
1368 group_ioctx
.get_id(), group_name
, snap_name
);
1369 int r
= librbd::api::Group
<>::snap_create(group_ioctx
, group_name
,
1371 tracepoint(librbd
, group_snap_create_exit
, r
);
1375 int RBD::group_snap_create2(IoCtx
& group_ioctx
, const char *group_name
,
1376 const char *snap_name
, uint32_t flags
) {
1377 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1378 tracepoint(librbd
, group_snap_create_enter
,
1379 group_ioctx
.get_pool_name().c_str(),
1380 group_ioctx
.get_id(), group_name
, snap_name
);
1381 int r
= librbd::api::Group
<>::snap_create(group_ioctx
, group_name
,
1383 tracepoint(librbd
, group_snap_create_exit
, r
);
1387 int RBD::group_snap_remove(IoCtx
& group_ioctx
, const char *group_name
,
1388 const char *snap_name
) {
1389 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1390 tracepoint(librbd
, group_snap_remove_enter
,
1391 group_ioctx
.get_pool_name().c_str(),
1392 group_ioctx
.get_id(), group_name
, snap_name
);
1393 int r
= librbd::api::Group
<>::snap_remove(group_ioctx
, group_name
,
1395 tracepoint(librbd
, group_snap_remove_exit
, r
);
1399 int RBD::group_snap_list(IoCtx
& group_ioctx
, const char *group_name
,
1400 std::vector
<group_snap_info_t
> *snaps
,
1401 size_t group_snap_info_size
)
1403 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1404 tracepoint(librbd
, group_snap_list_enter
,
1405 group_ioctx
.get_pool_name().c_str(),
1406 group_ioctx
.get_id(), group_name
);
1408 if (group_snap_info_size
!= sizeof(group_snap_info_t
)) {
1409 tracepoint(librbd
, group_snap_list_exit
, -ERANGE
);
1413 int r
= librbd::api::Group
<>::snap_list(group_ioctx
, group_name
, snaps
);
1414 tracepoint(librbd
, group_snap_list_exit
, r
);
1418 int RBD::group_snap_rename(IoCtx
& group_ioctx
, const char *group_name
,
1419 const char *old_snap_name
,
1420 const char *new_snap_name
)
1422 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1423 tracepoint(librbd
, group_snap_rename_enter
,
1424 group_ioctx
.get_pool_name().c_str(), group_ioctx
.get_id(),
1425 group_name
, old_snap_name
, new_snap_name
);
1426 int r
= librbd::api::Group
<>::snap_rename(group_ioctx
, group_name
,
1427 old_snap_name
, new_snap_name
);
1428 tracepoint(librbd
, group_snap_list_exit
, r
);
1432 int RBD::group_snap_rollback(IoCtx
& group_ioctx
, const char *group_name
,
1433 const char *snap_name
) {
1434 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1435 tracepoint(librbd
, group_snap_rollback_enter
,
1436 group_ioctx
.get_pool_name().c_str(),
1437 group_ioctx
.get_id(), group_name
, snap_name
);
1438 librbd::NoOpProgressContext prog_ctx
;
1439 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
1440 snap_name
, prog_ctx
);
1441 tracepoint(librbd
, group_snap_rollback_exit
, r
);
1445 int RBD::group_snap_rollback_with_progress(IoCtx
& group_ioctx
,
1446 const char *group_name
,
1447 const char *snap_name
,
1448 ProgressContext
& prog_ctx
) {
1449 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1450 tracepoint(librbd
, group_snap_rollback_enter
,
1451 group_ioctx
.get_pool_name().c_str(),
1452 group_ioctx
.get_id(), group_name
, snap_name
);
1453 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
1454 snap_name
, prog_ctx
);
1455 tracepoint(librbd
, group_snap_rollback_exit
, r
);
1459 int RBD::pool_metadata_get(IoCtx
& ioctx
, const std::string
&key
,
1462 int r
= librbd::api::PoolMetadata
<>::get(ioctx
, key
, value
);
1466 int RBD::pool_metadata_set(IoCtx
& ioctx
, const std::string
&key
,
1467 const std::string
&value
)
1469 int r
= librbd::api::PoolMetadata
<>::set(ioctx
, key
, value
);
1473 int RBD::pool_metadata_remove(IoCtx
& ioctx
, const std::string
&key
)
1475 int r
= librbd::api::PoolMetadata
<>::remove(ioctx
, key
);
1479 int RBD::pool_metadata_list(IoCtx
& ioctx
, const std::string
&start
,
1480 uint64_t max
, map
<string
, bufferlist
> *pairs
)
1482 int r
= librbd::api::PoolMetadata
<>::list(ioctx
, start
, max
, pairs
);
1486 int RBD::config_list(IoCtx
& io_ctx
, std::vector
<config_option_t
> *options
) {
1487 return librbd::api::Config
<>::list(io_ctx
, options
);
1490 RBD::AioCompletion::AioCompletion(void *cb_arg
, callback_t complete_cb
)
1492 auto aio_comp
= librbd::io::AioCompletion::create(
1493 cb_arg
, complete_cb
, this);
1494 aio_comp
->external_callback
= true;
1495 pc
= reinterpret_cast<void*>(aio_comp
);
1498 bool RBD::AioCompletion::is_complete()
1500 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1501 return c
->is_complete();
1504 int RBD::AioCompletion::wait_for_complete()
1506 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1507 return c
->wait_for_complete();
1510 ssize_t
RBD::AioCompletion::get_return_value()
1512 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1513 return c
->get_return_value();
1516 void *RBD::AioCompletion::get_arg()
1518 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1519 return c
->get_arg();
1522 void RBD::AioCompletion::release()
1524 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1533 ImageOptions::ImageOptions()
1535 librbd::image_options_create(&opts
);
1538 ImageOptions::ImageOptions(rbd_image_options_t opts_
)
1540 librbd::image_options_create_ref(&opts
, opts_
);
1543 ImageOptions::ImageOptions(const ImageOptions
&imgopts
)
1545 librbd::image_options_copy(&opts
, imgopts
);
1548 ImageOptions::~ImageOptions()
1550 librbd::image_options_destroy(opts
);
1553 int ImageOptions::set(int optname
, const std::string
& optval
)
1555 return librbd::image_options_set(opts
, optname
, optval
);
1558 int ImageOptions::set(int optname
, uint64_t optval
)
1560 return librbd::image_options_set(opts
, optname
, optval
);
1563 int ImageOptions::get(int optname
, std::string
* optval
) const
1565 return librbd::image_options_get(opts
, optname
, optval
);
1568 int ImageOptions::get(int optname
, uint64_t* optval
) const
1570 return librbd::image_options_get(opts
, optname
, optval
);
1573 int ImageOptions::is_set(int optname
, bool* is_set
)
1575 return librbd::image_options_is_set(opts
, optname
, is_set
);
1578 int ImageOptions::unset(int optname
)
1580 return librbd::image_options_unset(opts
, optname
);
1583 void ImageOptions::clear()
1585 librbd::image_options_clear(opts
);
1588 bool ImageOptions::empty() const
1590 return librbd::image_options_is_empty(opts
);
1597 Image::Image() : ctx(NULL
)
1610 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1611 tracepoint(librbd
, close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
1613 r
= ictx
->state
->close();
1616 tracepoint(librbd
, close_image_exit
, r
);
1621 int Image::aio_close(RBD::AioCompletion
*c
)
1627 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1628 tracepoint(librbd
, aio_close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), c
->pc
);
1630 ictx
->state
->close(new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_CLOSE
,
1631 get_aio_completion(c
)));
1634 tracepoint(librbd
, aio_close_image_exit
, 0);
1638 int Image::resize(uint64_t size
)
1640 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1641 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
1642 librbd::NoOpProgressContext prog_ctx
;
1643 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
1644 tracepoint(librbd
, resize_exit
, r
);
1648 int Image::resize2(uint64_t size
, bool allow_shrink
, librbd::ProgressContext
& pctx
)
1650 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1651 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
1652 int r
= ictx
->operations
->resize(size
, allow_shrink
, pctx
);
1653 tracepoint(librbd
, resize_exit
, r
);
1657 int Image::resize_with_progress(uint64_t size
, librbd::ProgressContext
& pctx
)
1659 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1660 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
1661 int r
= ictx
->operations
->resize(size
, true, pctx
);
1662 tracepoint(librbd
, resize_exit
, r
);
1666 int Image::stat(image_info_t
& info
, size_t infosize
)
1668 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1669 tracepoint(librbd
, stat_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1670 int r
= librbd::info(ictx
, info
, infosize
);
1671 tracepoint(librbd
, stat_exit
, r
, &info
);
1675 int Image::old_format(uint8_t *old
)
1677 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1678 tracepoint(librbd
, get_old_format_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1679 int r
= librbd::get_old_format(ictx
, old
);
1680 tracepoint(librbd
, get_old_format_exit
, r
, *old
);
1684 int Image::size(uint64_t *size
)
1686 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1687 tracepoint(librbd
, get_size_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1688 int r
= librbd::get_size(ictx
, size
);
1689 tracepoint(librbd
, get_size_exit
, r
, *size
);
1693 int Image::get_group(group_info_t
*group_info
, size_t group_info_size
)
1695 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1696 tracepoint(librbd
, image_get_group_enter
, ictx
->name
.c_str());
1698 if (group_info_size
!= sizeof(group_info_t
)) {
1699 tracepoint(librbd
, image_get_group_exit
, -ERANGE
);
1703 int r
= librbd::api::Group
<>::image_get_group(ictx
, group_info
);
1704 tracepoint(librbd
, image_get_group_exit
, r
);
1708 int Image::features(uint64_t *features
)
1710 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1711 tracepoint(librbd
, get_features_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1712 int r
= librbd::get_features(ictx
, features
);
1713 tracepoint(librbd
, get_features_exit
, r
, *features
);
1717 int Image::update_features(uint64_t features
, bool enabled
)
1719 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1720 tracepoint(librbd
, update_features_enter
, ictx
, features
, enabled
);
1721 int r
= ictx
->operations
->update_features(features
, enabled
);
1722 tracepoint(librbd
, update_features_exit
, r
);
1726 int Image::get_op_features(uint64_t *op_features
)
1728 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1729 return librbd::api::Image
<>::get_op_features(ictx
, op_features
);
1732 uint64_t Image::get_stripe_unit() const
1734 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1735 tracepoint(librbd
, get_stripe_unit_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1736 uint64_t stripe_unit
= ictx
->get_stripe_unit();
1737 tracepoint(librbd
, get_stripe_unit_exit
, 0, stripe_unit
);
1741 uint64_t Image::get_stripe_count() const
1743 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1744 tracepoint(librbd
, get_stripe_count_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1745 uint64_t stripe_count
= ictx
->get_stripe_count();
1746 tracepoint(librbd
, get_stripe_count_exit
, 0, stripe_count
);
1747 return stripe_count
;
1750 int Image::get_create_timestamp(struct timespec
*timestamp
)
1752 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1753 tracepoint(librbd
, get_create_timestamp_enter
, ictx
, ictx
->name
.c_str(),
1755 utime_t time
= ictx
->get_create_timestamp();
1756 time
.to_timespec(timestamp
);
1757 tracepoint(librbd
, get_create_timestamp_exit
, 0, timestamp
);
1761 int Image::get_access_timestamp(struct timespec
*timestamp
)
1763 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1764 tracepoint(librbd
, get_access_timestamp_enter
, ictx
, ictx
->name
.c_str(),
1767 std::shared_lock timestamp_locker
{ictx
->timestamp_lock
};
1768 utime_t time
= ictx
->get_access_timestamp();
1769 time
.to_timespec(timestamp
);
1771 tracepoint(librbd
, get_access_timestamp_exit
, 0, timestamp
);
1775 int Image::get_modify_timestamp(struct timespec
*timestamp
)
1777 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1778 tracepoint(librbd
, get_modify_timestamp_enter
, ictx
, ictx
->name
.c_str(),
1781 std::shared_lock timestamp_locker
{ictx
->timestamp_lock
};
1782 utime_t time
= ictx
->get_modify_timestamp();
1783 time
.to_timespec(timestamp
);
1785 tracepoint(librbd
, get_modify_timestamp_exit
, 0, timestamp
);
1789 int Image::overlap(uint64_t *overlap
)
1791 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1792 tracepoint(librbd
, get_overlap_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1793 int r
= librbd::get_overlap(ictx
, overlap
);
1794 tracepoint(librbd
, get_overlap_exit
, r
, *overlap
);
1798 int Image::get_name(std::string
*name
)
1800 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1805 int Image::get_id(std::string
*id
)
1807 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1808 if (ictx
->old_format
) {
1815 std::string
Image::get_block_name_prefix()
1817 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1818 return ictx
->object_prefix
;
1821 int64_t Image::get_data_pool_id()
1823 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1824 return librbd::api::Image
<>::get_data_pool_id(ictx
);
1827 int Image::parent_info(string
*parent_pool_name
, string
*parent_name
,
1828 string
*parent_snap_name
)
1830 librbd::linked_image_spec_t parent_image
;
1831 librbd::snap_spec_t parent_snap
;
1832 int r
= get_parent(&parent_image
, &parent_snap
);
1834 if (parent_pool_name
!= nullptr) {
1835 *parent_pool_name
= parent_image
.pool_name
;
1837 if (parent_name
!= nullptr) {
1838 *parent_name
= parent_image
.image_name
;
1840 if (parent_snap_name
!= nullptr) {
1841 *parent_snap_name
= parent_snap
.name
;
1847 int Image::parent_info2(string
*parent_pool_name
, string
*parent_name
,
1848 string
*parent_id
, string
*parent_snap_name
)
1850 librbd::linked_image_spec_t parent_image
;
1851 librbd::snap_spec_t parent_snap
;
1852 int r
= get_parent(&parent_image
, &parent_snap
);
1854 if (parent_pool_name
!= nullptr) {
1855 *parent_pool_name
= parent_image
.pool_name
;
1857 if (parent_name
!= nullptr) {
1858 *parent_name
= parent_image
.image_name
;
1860 if (parent_id
!= nullptr) {
1861 *parent_id
= parent_image
.image_id
;
1863 if (parent_snap_name
!= nullptr) {
1864 *parent_snap_name
= parent_snap
.name
;
1870 int Image::get_parent(linked_image_spec_t
*parent_image
,
1871 snap_spec_t
*parent_snap
)
1873 auto ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1874 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
1875 ictx
->snap_name
.c_str(), ictx
->read_only
);
1877 int r
= librbd::api::Image
<>::get_parent(ictx
, parent_image
, parent_snap
);
1879 tracepoint(librbd
, get_parent_info_exit
, r
,
1880 parent_image
->pool_name
.c_str(),
1881 parent_image
->image_name
.c_str(),
1882 parent_image
->image_id
.c_str(),
1883 parent_snap
->name
.c_str());
1887 int Image::get_migration_source_spec(std::string
* source_spec
)
1889 auto ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1890 return librbd::api::Migration
<>::get_source_spec(ictx
, source_spec
);
1893 int Image::get_flags(uint64_t *flags
)
1895 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1896 tracepoint(librbd
, get_flags_enter
, ictx
);
1897 int r
= librbd::get_flags(ictx
, flags
);
1898 tracepoint(librbd
, get_flags_exit
, ictx
, r
, *flags
);
1902 int Image::set_image_notification(int fd
, int type
)
1904 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1905 tracepoint(librbd
, set_image_notification_enter
, ictx
, fd
, type
);
1906 int r
= librbd::set_image_notification(ictx
, fd
, type
);
1907 tracepoint(librbd
, set_image_notification_exit
, ictx
, r
);
1911 int Image::is_exclusive_lock_owner(bool *is_owner
)
1913 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1914 tracepoint(librbd
, is_exclusive_lock_owner_enter
, ictx
);
1915 int r
= librbd::is_exclusive_lock_owner(ictx
, is_owner
);
1916 tracepoint(librbd
, is_exclusive_lock_owner_exit
, ictx
, r
, *is_owner
);
1920 int Image::lock_acquire(rbd_lock_mode_t lock_mode
)
1922 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1923 tracepoint(librbd
, lock_acquire_enter
, ictx
, lock_mode
);
1924 int r
= librbd::lock_acquire(ictx
, lock_mode
);
1925 tracepoint(librbd
, lock_acquire_exit
, ictx
, r
);
1929 int Image::lock_release()
1931 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1932 tracepoint(librbd
, lock_release_enter
, ictx
);
1933 int r
= librbd::lock_release(ictx
);
1934 tracepoint(librbd
, lock_release_exit
, ictx
, r
);
1938 int Image::lock_get_owners(rbd_lock_mode_t
*lock_mode
,
1939 std::list
<std::string
> *lock_owners
)
1941 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1942 tracepoint(librbd
, lock_get_owners_enter
, ictx
);
1943 int r
= librbd::lock_get_owners(ictx
, lock_mode
, lock_owners
);
1944 tracepoint(librbd
, lock_get_owners_exit
, ictx
, r
);
1948 int Image::lock_break(rbd_lock_mode_t lock_mode
,
1949 const std::string
&lock_owner
)
1951 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1952 tracepoint(librbd
, lock_break_enter
, ictx
, lock_mode
, lock_owner
.c_str());
1953 int r
= librbd::lock_break(ictx
, lock_mode
, lock_owner
);
1954 tracepoint(librbd
, lock_break_exit
, ictx
, r
);
1958 int Image::rebuild_object_map(ProgressContext
&prog_ctx
)
1960 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1961 return ictx
->operations
->rebuild_object_map(prog_ctx
);
1964 int Image::check_object_map(ProgressContext
&prog_ctx
)
1966 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1967 return ictx
->operations
->check_object_map(prog_ctx
);
1970 int Image::copy(IoCtx
& dest_io_ctx
, const char *destname
)
1972 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1973 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
);
1975 librbd::NoOpProgressContext prog_ctx
;
1976 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
1977 tracepoint(librbd
, copy_exit
, r
);
1981 int Image::copy2(Image
& dest
)
1983 ImageCtx
*srcctx
= (ImageCtx
*)ctx
;
1984 ImageCtx
*destctx
= (ImageCtx
*)dest
.ctx
;
1985 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
);
1986 librbd::NoOpProgressContext prog_ctx
;
1987 int r
= librbd::copy(srcctx
, destctx
, prog_ctx
, 0);
1988 tracepoint(librbd
, copy2_exit
, r
);
1992 int Image::copy3(IoCtx
& dest_io_ctx
, const char *destname
, ImageOptions
& opts
)
1994 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1995 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
);
1996 librbd::NoOpProgressContext prog_ctx
;
1997 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
1998 tracepoint(librbd
, copy3_exit
, r
);
2002 int Image::copy4(IoCtx
& dest_io_ctx
, const char *destname
, ImageOptions
& opts
, size_t sparse_size
)
2004 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2005 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
);
2006 librbd::NoOpProgressContext prog_ctx
;
2007 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, sparse_size
);
2008 tracepoint(librbd
, copy4_exit
, r
);
2012 int Image::copy_with_progress(IoCtx
& dest_io_ctx
, const char *destname
,
2013 librbd::ProgressContext
&pctx
)
2015 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2016 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
);
2018 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, 0);
2019 tracepoint(librbd
, copy_exit
, r
);
2023 int Image::copy_with_progress2(Image
& dest
, librbd::ProgressContext
&pctx
)
2025 ImageCtx
*srcctx
= (ImageCtx
*)ctx
;
2026 ImageCtx
*destctx
= (ImageCtx
*)dest
.ctx
;
2027 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
);
2028 int r
= librbd::copy(srcctx
, destctx
, pctx
, 0);
2029 tracepoint(librbd
, copy2_exit
, r
);
2033 int Image::copy_with_progress3(IoCtx
& dest_io_ctx
, const char *destname
,
2035 librbd::ProgressContext
&pctx
)
2037 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2038 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
);
2039 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, 0);
2040 tracepoint(librbd
, copy3_exit
, r
);
2044 int Image::copy_with_progress4(IoCtx
& dest_io_ctx
, const char *destname
,
2046 librbd::ProgressContext
&pctx
,
2049 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2050 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
);
2051 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, sparse_size
);
2052 tracepoint(librbd
, copy4_exit
, r
);
2056 int Image::deep_copy(IoCtx
& dest_io_ctx
, const char *destname
,
2059 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2060 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
2061 ictx
->snap_name
.c_str(), ictx
->read_only
,
2062 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
2063 destname
, opts
.opts
);
2064 librbd::NoOpProgressContext prog_ctx
;
2065 int r
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
2067 tracepoint(librbd
, deep_copy_exit
, r
);
2071 int Image::deep_copy_with_progress(IoCtx
& dest_io_ctx
, const char *destname
,
2073 librbd::ProgressContext
&prog_ctx
)
2075 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2076 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
2077 ictx
->snap_name
.c_str(), ictx
->read_only
,
2078 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
2079 destname
, opts
.opts
);
2080 int r
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
2082 tracepoint(librbd
, deep_copy_exit
, r
);
2086 int Image::encryption_format(encryption_format_t format
,
2087 encryption_options_t opts
,
2090 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2091 return librbd::api::Image
<>::encryption_format(
2092 ictx
, format
, opts
, opts_size
, false);
2095 int Image::encryption_load(encryption_format_t format
,
2096 encryption_options_t opts
,
2099 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2100 return librbd::api::Image
<>::encryption_load(
2101 ictx
, format
, opts
, opts_size
, false);
2104 int Image::flatten()
2106 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2107 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
2108 librbd::NoOpProgressContext prog_ctx
;
2109 int r
= ictx
->operations
->flatten(prog_ctx
);
2110 tracepoint(librbd
, flatten_exit
, r
);
2114 int Image::flatten_with_progress(librbd::ProgressContext
& prog_ctx
)
2116 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2117 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
2118 int r
= ictx
->operations
->flatten(prog_ctx
);
2119 tracepoint(librbd
, flatten_exit
, r
);
2123 int Image::sparsify(size_t sparse_size
)
2125 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2126 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
2128 librbd::NoOpProgressContext prog_ctx
;
2129 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
2130 tracepoint(librbd
, sparsify_exit
, r
);
2134 int Image::sparsify_with_progress(size_t sparse_size
,
2135 librbd::ProgressContext
& prog_ctx
)
2137 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2138 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
2140 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
2141 tracepoint(librbd
, sparsify_exit
, r
);
2145 int Image::list_children(set
<pair
<string
, string
> > *children
)
2147 std::vector
<linked_image_spec_t
> images
;
2148 int r
= list_children3(&images
);
2153 for (auto& image
: images
) {
2155 children
->insert({image
.pool_name
, image
.image_name
});
2161 int Image::list_children2(vector
<librbd::child_info_t
> *children
)
2163 std::vector
<linked_image_spec_t
> images
;
2164 int r
= list_children3(&images
);
2169 for (auto& image
: images
) {
2170 children
->push_back({
2171 .pool_name
= image
.pool_name
,
2172 .image_name
= image
.image_name
,
2173 .image_id
= image
.image_id
,
2174 .trash
= image
.trash
});
2180 int Image::list_children3(std::vector
<linked_image_spec_t
> *images
)
2182 auto ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
2183 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
2184 ictx
->snap_name
.c_str(), ictx
->read_only
);
2186 int r
= librbd::api::Image
<>::list_children(ictx
, images
);
2189 for (auto& it
: *images
) {
2190 tracepoint(librbd
, list_children_entry
, it
.pool_name
.c_str(),
2191 it
.image_name
.c_str());
2195 tracepoint(librbd
, list_children_exit
, r
);
2199 int Image::list_descendants(std::vector
<linked_image_spec_t
> *images
)
2201 auto ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
2204 int r
= librbd::api::Image
<>::list_descendants(ictx
, {}, images
);
2208 int Image::list_lockers(std::list
<librbd::locker_t
> *lockers
,
2209 bool *exclusive
, string
*tag
)
2211 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2212 tracepoint(librbd
, list_lockers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2213 int r
= librbd::list_lockers(ictx
, lockers
, exclusive
, tag
);
2215 for (std::list
<librbd::locker_t
>::const_iterator it
= lockers
->begin();
2216 it
!= lockers
->end(); ++it
) {
2217 tracepoint(librbd
, list_lockers_entry
, it
->client
.c_str(), it
->cookie
.c_str(), it
->address
.c_str());
2220 tracepoint(librbd
, list_lockers_exit
, r
);
2224 int Image::lock_exclusive(const string
& cookie
)
2226 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2227 tracepoint(librbd
, lock_exclusive_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str());
2228 int r
= librbd::lock(ictx
, true, cookie
, "");
2229 tracepoint(librbd
, lock_exclusive_exit
, r
);
2233 int Image::lock_shared(const string
& cookie
, const std::string
& tag
)
2235 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2236 tracepoint(librbd
, lock_shared_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str(), tag
.c_str());
2237 int r
= librbd::lock(ictx
, false, cookie
, tag
);
2238 tracepoint(librbd
, lock_shared_exit
, r
);
2242 int Image::unlock(const string
& cookie
)
2244 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2245 tracepoint(librbd
, unlock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str());
2246 int r
= librbd::unlock(ictx
, cookie
);
2247 tracepoint(librbd
, unlock_exit
, r
);
2251 int Image::break_lock(const string
& client
, const string
& cookie
)
2253 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2254 tracepoint(librbd
, break_lock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, client
.c_str(), cookie
.c_str());
2255 int r
= librbd::break_lock(ictx
, client
, cookie
);
2256 tracepoint(librbd
, break_lock_exit
, r
);
2260 int Image::snap_create(const char *snap_name
)
2262 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2263 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2264 auto flags
= librbd::util::get_default_snap_create_flags(ictx
);
2265 librbd::NoOpProgressContext prog_ctx
;
2266 int r
= librbd::api::Snapshot
<>::create(ictx
, snap_name
, flags
, prog_ctx
);
2267 tracepoint(librbd
, snap_create_exit
, r
);
2271 int Image::snap_create2(const char *snap_name
, uint32_t flags
,
2272 ProgressContext
& prog_ctx
)
2274 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2275 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2276 int r
= librbd::api::Snapshot
<>::create(ictx
, snap_name
, flags
, prog_ctx
);
2277 tracepoint(librbd
, snap_create_exit
, r
);
2281 int Image::snap_remove(const char *snap_name
)
2283 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2284 tracepoint(librbd
, snap_remove_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2285 librbd::NoOpProgressContext prog_ctx
;
2286 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, 0, prog_ctx
);
2287 tracepoint(librbd
, snap_remove_exit
, r
);
2291 int Image::snap_remove2(const char *snap_name
, uint32_t flags
, ProgressContext
& pctx
)
2293 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2294 tracepoint(librbd
, snap_remove2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
, flags
);
2295 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, flags
, pctx
);
2296 tracepoint(librbd
, snap_remove_exit
, r
);
2300 int Image::snap_remove_by_id(uint64_t snap_id
)
2302 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2303 return librbd::api::Snapshot
<>::remove(ictx
, snap_id
);
2306 int Image::snap_rollback(const char *snap_name
)
2308 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2309 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2310 librbd::NoOpProgressContext prog_ctx
;
2311 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
2312 tracepoint(librbd
, snap_rollback_exit
, r
);
2316 int Image::snap_rename(const char *srcname
, const char *dstname
)
2318 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2319 tracepoint(librbd
, snap_rename_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, srcname
, dstname
);
2320 int r
= ictx
->operations
->snap_rename(srcname
, dstname
);
2321 tracepoint(librbd
, snap_rename_exit
, r
);
2325 int Image::snap_rollback_with_progress(const char *snap_name
,
2326 ProgressContext
& prog_ctx
)
2328 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2329 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2330 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
2331 tracepoint(librbd
, snap_rollback_exit
, r
);
2335 int Image::snap_protect(const char *snap_name
)
2337 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2338 tracepoint(librbd
, snap_protect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2339 int r
= ictx
->operations
->snap_protect(cls::rbd::UserSnapshotNamespace(), snap_name
);
2340 tracepoint(librbd
, snap_protect_exit
, r
);
2344 int Image::snap_unprotect(const char *snap_name
)
2346 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2347 tracepoint(librbd
, snap_unprotect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2348 int r
= ictx
->operations
->snap_unprotect(cls::rbd::UserSnapshotNamespace(), snap_name
);
2349 tracepoint(librbd
, snap_unprotect_exit
, r
);
2353 int Image::snap_is_protected(const char *snap_name
, bool *is_protected
)
2355 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2356 tracepoint(librbd
, snap_is_protected_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2357 int r
= librbd::api::Snapshot
<>::is_protected(ictx
, snap_name
, is_protected
);
2358 tracepoint(librbd
, snap_is_protected_exit
, r
, *is_protected
? 1 : 0);
2362 int Image::snap_list(vector
<librbd::snap_info_t
>& snaps
)
2364 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2365 tracepoint(librbd
, snap_list_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, &snaps
);
2366 int r
= librbd::api::Snapshot
<>::list(ictx
, snaps
);
2368 for (int i
= 0, n
= snaps
.size(); i
< n
; i
++) {
2369 tracepoint(librbd
, snap_list_entry
, snaps
[i
].id
, snaps
[i
].size
, snaps
[i
].name
.c_str());
2372 tracepoint(librbd
, snap_list_exit
, r
, snaps
.size());
2374 // A little ugly, but the C++ API doesn't need a Image::snap_list_end,
2375 // and we want the tracepoints to mirror the C API
2376 tracepoint(librbd
, snap_list_end_enter
, &snaps
);
2377 tracepoint(librbd
, snap_list_end_exit
);
2382 bool Image::snap_exists(const char *snap_name
)
2384 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2385 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
2386 ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2388 int r
= librbd::api::Snapshot
<>::exists(ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
, &exists
);
2389 tracepoint(librbd
, snap_exists_exit
, r
, exists
);
2391 // lie to caller since we don't know the real answer yet.
2397 // A safer verion of snap_exists.
2398 int Image::snap_exists2(const char *snap_name
, bool *exists
)
2400 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2401 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
2402 ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2403 int r
= librbd::api::Snapshot
<>::exists(ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
, exists
);
2404 tracepoint(librbd
, snap_exists_exit
, r
, *exists
);
2408 int Image::snap_get_timestamp(uint64_t snap_id
, struct timespec
*timestamp
)
2410 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2411 tracepoint(librbd
, snap_get_timestamp_enter
, ictx
, ictx
->name
.c_str());
2412 int r
= librbd::api::Snapshot
<>::get_timestamp(ictx
, snap_id
, timestamp
);
2413 tracepoint(librbd
, snap_get_timestamp_exit
, r
);
2417 int Image::snap_get_limit(uint64_t *limit
)
2419 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2420 tracepoint(librbd
, snap_get_limit_enter
, ictx
, ictx
->name
.c_str());
2421 int r
= librbd::api::Snapshot
<>::get_limit(ictx
, limit
);
2422 tracepoint(librbd
, snap_get_limit_exit
, r
, *limit
);
2426 int Image::snap_get_namespace_type(uint64_t snap_id
,
2427 snap_namespace_type_t
*namespace_type
) {
2428 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2429 tracepoint(librbd
, snap_get_namespace_type_enter
, ictx
, ictx
->name
.c_str());
2430 int r
= librbd::api::Snapshot
<>::get_namespace_type(ictx
, snap_id
, namespace_type
);
2431 tracepoint(librbd
, snap_get_namespace_type_exit
, r
);
2435 int Image::snap_get_group_namespace(uint64_t snap_id
,
2436 snap_group_namespace_t
*group_snap
,
2437 size_t group_snap_size
) {
2438 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2439 tracepoint(librbd
, snap_get_group_namespace_enter
, ictx
,
2440 ictx
->name
.c_str());
2442 if (group_snap_size
!= sizeof(snap_group_namespace_t
)) {
2443 tracepoint(librbd
, snap_get_group_namespace_exit
, -ERANGE
);
2447 int r
= librbd::api::Snapshot
<>::get_group_namespace(ictx
, snap_id
,
2449 tracepoint(librbd
, snap_get_group_namespace_exit
, r
);
2453 int Image::snap_get_trash_namespace(uint64_t snap_id
,
2454 std::string
* original_name
) {
2455 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2456 return librbd::api::Snapshot
<>::get_trash_namespace(ictx
, snap_id
,
2460 int Image::snap_get_mirror_namespace(
2461 uint64_t snap_id
, snap_mirror_namespace_t
*mirror_snap
,
2462 size_t mirror_snap_size
) {
2463 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2465 if (mirror_snap_size
!= sizeof(snap_mirror_namespace_t
)) {
2469 int r
= librbd::api::Snapshot
<>::get_mirror_namespace(
2470 ictx
, snap_id
, mirror_snap
);
2474 int Image::snap_set_limit(uint64_t limit
)
2476 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2478 tracepoint(librbd
, snap_set_limit_enter
, ictx
, ictx
->name
.c_str(), limit
);
2479 int r
= ictx
->operations
->snap_set_limit(limit
);
2480 tracepoint(librbd
, snap_set_limit_exit
, r
);
2484 int Image::snap_set(const char *snap_name
)
2486 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2487 tracepoint(librbd
, snap_set_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2488 int r
= librbd::api::Image
<>::snap_set(
2489 ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
);
2490 tracepoint(librbd
, snap_set_exit
, r
);
2494 int Image::snap_set_by_id(uint64_t snap_id
)
2496 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2497 return librbd::api::Image
<>::snap_set(ictx
, snap_id
);
2500 int Image::snap_get_name(uint64_t snap_id
, std::string
*snap_name
)
2502 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2503 return librbd::api::Snapshot
<>::get_name(ictx
, snap_id
, snap_name
);
2506 int Image::snap_get_id(const std::string snap_name
, uint64_t *snap_id
)
2508 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2509 return librbd::api::Snapshot
<>::get_id(ictx
, snap_name
, snap_id
);
2512 ssize_t
Image::read(uint64_t ofs
, size_t len
, bufferlist
& bl
)
2514 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2515 tracepoint(librbd
, read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
2517 int r
= api::Io
<>::read(*ictx
, ofs
, len
, io::ReadResult
{&bl
}, 0);
2518 tracepoint(librbd
, read_exit
, r
);
2522 ssize_t
Image::read2(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
2524 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2525 tracepoint(librbd
, read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2526 ictx
->read_only
, ofs
, len
, op_flags
);
2528 int r
= api::Io
<>::read(*ictx
, ofs
, len
, io::ReadResult
{&bl
}, op_flags
);
2529 tracepoint(librbd
, read_exit
, r
);
2533 int64_t Image::read_iterate(uint64_t ofs
, size_t len
,
2534 int (*cb
)(uint64_t, size_t, const char *, void *),
2537 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2538 tracepoint(librbd
, read_iterate_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
2540 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
2541 tracepoint(librbd
, read_iterate_exit
, r
);
2545 int Image::read_iterate2(uint64_t ofs
, uint64_t len
,
2546 int (*cb
)(uint64_t, size_t, const char *, void *),
2549 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2550 tracepoint(librbd
, read_iterate2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
2552 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
2555 tracepoint(librbd
, read_iterate2_exit
, r
);
2559 int Image::diff_iterate(const char *fromsnapname
,
2560 uint64_t ofs
, uint64_t len
,
2561 int (*cb
)(uint64_t, size_t, int, void *),
2564 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2565 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
2566 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
2568 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
2569 cls::rbd::UserSnapshotNamespace(),
2571 len
, true, false, cb
, arg
);
2572 tracepoint(librbd
, diff_iterate_exit
, r
);
2576 int Image::diff_iterate2(const char *fromsnapname
, uint64_t ofs
, uint64_t len
,
2577 bool include_parent
, bool whole_object
,
2578 int (*cb
)(uint64_t, size_t, int, void *), void *arg
)
2580 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2581 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
2582 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
2583 include_parent
, whole_object
);
2584 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
2585 cls::rbd::UserSnapshotNamespace(),
2587 len
, include_parent
,
2588 whole_object
, cb
, arg
);
2589 tracepoint(librbd
, diff_iterate_exit
, r
);
2593 ssize_t
Image::write(uint64_t ofs
, size_t len
, bufferlist
& bl
)
2595 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2596 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());
2597 if (bl
.length() < len
) {
2598 tracepoint(librbd
, write_exit
, -EINVAL
);
2602 int r
= api::Io
<>::write(*ictx
, ofs
, len
, bufferlist
{bl
}, 0);
2603 tracepoint(librbd
, write_exit
, r
);
2607 ssize_t
Image::write2(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
2609 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2610 tracepoint(librbd
, write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
,
2611 ofs
, len
, bl
.length() < len
? NULL
: bl
.c_str(), op_flags
);
2612 if (bl
.length() < len
) {
2613 tracepoint(librbd
, write_exit
, -EINVAL
);
2617 int r
= api::Io
<>::write(*ictx
, ofs
, len
, bufferlist
{bl
}, op_flags
);
2618 tracepoint(librbd
, write_exit
, r
);
2622 int Image::discard(uint64_t ofs
, uint64_t len
)
2624 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2625 tracepoint(librbd
, discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
2626 if (len
> static_cast<uint64_t>(std::numeric_limits
<int32_t>::max())) {
2627 tracepoint(librbd
, discard_exit
, -EINVAL
);
2630 int r
= api::Io
<>::discard(
2631 *ictx
, ofs
, len
, ictx
->discard_granularity_bytes
);
2632 tracepoint(librbd
, discard_exit
, r
);
2636 ssize_t
Image::writesame(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
2638 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2639 tracepoint(librbd
, writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2640 ictx
->read_only
, ofs
, len
, bl
.length() == 0 ? NULL
: bl
.c_str(), bl
.length(),
2642 if (bl
.length() == 0 || len
% bl
.length() ||
2643 len
> static_cast<size_t>(std::numeric_limits
<int>::max())) {
2644 tracepoint(librbd
, writesame_exit
, -EINVAL
);
2648 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
2649 if (discard_zero
&& bl
.is_zero()) {
2650 int r
= api::Io
<>::write_zeroes(*ictx
, ofs
, len
, 0U, op_flags
);
2651 tracepoint(librbd
, writesame_exit
, r
);
2655 int r
= api::Io
<>::write_same(*ictx
, ofs
, len
, bufferlist
{bl
}, op_flags
);
2656 tracepoint(librbd
, writesame_exit
, r
);
2660 ssize_t
Image::write_zeroes(uint64_t ofs
, size_t len
, int zero_flags
,
2663 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2664 return api::Io
<>::write_zeroes(*ictx
, ofs
, len
, zero_flags
, op_flags
);
2667 ssize_t
Image::compare_and_write(uint64_t ofs
, size_t len
,
2668 ceph::bufferlist
&cmp_bl
, ceph::bufferlist
& bl
,
2669 uint64_t *mismatch_off
, int op_flags
)
2671 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2672 tracepoint(librbd
, compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
2673 ictx
->snap_name
.c_str(),
2674 ictx
->read_only
, ofs
, len
, cmp_bl
.length() < len
? NULL
: cmp_bl
.c_str(),
2675 bl
.length() < len
? NULL
: bl
.c_str(), op_flags
);
2677 if (bl
.length() < len
) {
2678 tracepoint(librbd
, write_exit
, -EINVAL
);
2682 int r
= api::Io
<>::compare_and_write(
2683 *ictx
, ofs
, len
, bufferlist
{cmp_bl
}, bufferlist
{bl
}, mismatch_off
,
2686 tracepoint(librbd
, compare_and_write_exit
, r
);
2691 int Image::aio_write(uint64_t off
, size_t len
, bufferlist
& bl
,
2692 RBD::AioCompletion
*c
)
2694 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2695 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
);
2696 if (bl
.length() < len
) {
2697 tracepoint(librbd
, aio_write_exit
, -EINVAL
);
2700 api::Io
<>::aio_write(*ictx
, get_aio_completion(c
), off
, len
, bufferlist
{bl
},
2703 tracepoint(librbd
, aio_write_exit
, 0);
2707 int Image::aio_write2(uint64_t off
, size_t len
, bufferlist
& bl
,
2708 RBD::AioCompletion
*c
, int op_flags
)
2710 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2711 tracepoint(librbd
, aio_write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2712 ictx
->read_only
, off
, len
, bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
, op_flags
);
2713 if (bl
.length() < len
) {
2714 tracepoint(librbd
, aio_write_exit
, -EINVAL
);
2717 api::Io
<>::aio_write(*ictx
, get_aio_completion(c
), off
, len
, bufferlist
{bl
},
2720 tracepoint(librbd
, aio_write_exit
, 0);
2724 int Image::aio_read(uint64_t off
, size_t len
, bufferlist
& bl
,
2725 RBD::AioCompletion
*c
)
2727 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2728 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
);
2729 ldout(ictx
->cct
, 10) << "Image::aio_read() buf=" << (void *)bl
.c_str() << "~"
2730 << (void *)(bl
.c_str() + len
- 1) << dendl
;
2732 api::Io
<>::aio_read(*ictx
, get_aio_completion(c
), off
, len
,
2733 io::ReadResult
{&bl
}, 0, true);
2734 tracepoint(librbd
, aio_read_exit
, 0);
2738 int Image::aio_read2(uint64_t off
, size_t len
, bufferlist
& bl
,
2739 RBD::AioCompletion
*c
, int op_flags
)
2741 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2742 tracepoint(librbd
, aio_read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2743 ictx
->read_only
, off
, len
, bl
.c_str(), c
->pc
, op_flags
);
2744 ldout(ictx
->cct
, 10) << "Image::aio_read() buf=" << (void *)bl
.c_str() << "~"
2745 << (void *)(bl
.c_str() + len
- 1) << dendl
;
2747 api::Io
<>::aio_read(*ictx
, get_aio_completion(c
), off
, len
,
2748 io::ReadResult
{&bl
}, op_flags
, true);
2749 tracepoint(librbd
, aio_read_exit
, 0);
2755 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2756 tracepoint(librbd
, flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2757 int r
= api::Io
<>::flush(*ictx
);
2758 tracepoint(librbd
, flush_exit
, r
);
2762 int Image::aio_flush(RBD::AioCompletion
*c
)
2764 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2765 tracepoint(librbd
, aio_flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
2766 api::Io
<>::aio_flush(*ictx
, get_aio_completion(c
), true);
2767 tracepoint(librbd
, aio_flush_exit
, 0);
2771 int Image::aio_discard(uint64_t off
, uint64_t len
, RBD::AioCompletion
*c
)
2773 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2774 tracepoint(librbd
, aio_discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, c
->pc
);
2775 api::Io
<>::aio_discard(
2776 *ictx
, get_aio_completion(c
), off
, len
, ictx
->discard_granularity_bytes
,
2778 tracepoint(librbd
, aio_discard_exit
, 0);
2782 int Image::aio_writesame(uint64_t off
, size_t len
, bufferlist
& bl
,
2783 RBD::AioCompletion
*c
, int op_flags
)
2785 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2786 tracepoint(librbd
, aio_writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2787 ictx
->read_only
, off
, len
, bl
.length() <= len
? NULL
: bl
.c_str(), bl
.length(),
2789 if (bl
.length() == 0 || len
% bl
.length()) {
2790 tracepoint(librbd
, aio_writesame_exit
, -EINVAL
);
2794 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
2795 if (discard_zero
&& bl
.is_zero()) {
2796 api::Io
<>::aio_write_zeroes(*ictx
, get_aio_completion(c
), off
, len
, 0U,
2798 tracepoint(librbd
, aio_writesame_exit
, 0);
2802 api::Io
<>::aio_write_same(*ictx
, get_aio_completion(c
), off
, len
,
2803 bufferlist
{bl
}, op_flags
, true);
2804 tracepoint(librbd
, aio_writesame_exit
, 0);
2808 int Image::aio_write_zeroes(uint64_t off
, size_t len
, RBD::AioCompletion
*c
,
2809 int zero_flags
, int op_flags
)
2811 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2812 api::Io
<>::aio_write_zeroes(*ictx
, get_aio_completion(c
), off
, len
,
2813 zero_flags
, op_flags
, true);
2817 int Image::aio_compare_and_write(uint64_t off
, size_t len
,
2818 ceph::bufferlist
& cmp_bl
, ceph::bufferlist
& bl
,
2819 RBD::AioCompletion
*c
, uint64_t *mismatch_off
,
2822 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2823 tracepoint(librbd
, aio_compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
2824 ictx
->snap_name
.c_str(),
2825 ictx
->read_only
, off
, len
, cmp_bl
.length() < len
? NULL
: cmp_bl
.c_str(),
2826 bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
, op_flags
);
2828 if (bl
.length() < len
) {
2829 tracepoint(librbd
, compare_and_write_exit
, -EINVAL
);
2833 api::Io
<>::aio_compare_and_write(*ictx
, get_aio_completion(c
), off
, len
,
2834 bufferlist
{cmp_bl
}, bufferlist
{bl
},
2835 mismatch_off
, op_flags
, false);
2837 tracepoint(librbd
, aio_compare_and_write_exit
, 0);
2842 int Image::invalidate_cache()
2844 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2845 tracepoint(librbd
, invalidate_cache_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2846 int r
= librbd::invalidate_cache(ictx
);
2847 tracepoint(librbd
, invalidate_cache_exit
, r
);
2851 int Image::poll_io_events(RBD::AioCompletion
**comps
, int numcomp
)
2853 io::AioCompletion
*cs
[numcomp
];
2854 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2855 tracepoint(librbd
, poll_io_events_enter
, ictx
, numcomp
);
2856 int r
= librbd::poll_io_events(ictx
, cs
, numcomp
);
2857 tracepoint(librbd
, poll_io_events_exit
, r
);
2859 for (int i
= 0; i
< r
; ++i
)
2860 comps
[i
] = (RBD::AioCompletion
*)cs
[i
]->rbd_comp
;
2865 int Image::metadata_get(const std::string
&key
, std::string
*value
)
2867 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2868 tracepoint(librbd
, metadata_get_enter
, ictx
, key
.c_str());
2869 int r
= librbd::metadata_get(ictx
, key
, value
);
2871 tracepoint(librbd
, metadata_get_exit
, r
, key
.c_str(), NULL
);
2873 tracepoint(librbd
, metadata_get_exit
, r
, key
.c_str(), value
->c_str());
2878 int Image::metadata_set(const std::string
&key
, const std::string
&value
)
2880 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2881 tracepoint(librbd
, metadata_set_enter
, ictx
, key
.c_str(), value
.c_str());
2882 int r
= ictx
->operations
->metadata_set(key
, value
);
2883 tracepoint(librbd
, metadata_set_exit
, r
);
2887 int Image::metadata_remove(const std::string
&key
)
2889 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2890 tracepoint(librbd
, metadata_remove_enter
, ictx
, key
.c_str());
2891 int r
= ictx
->operations
->metadata_remove(key
);
2892 tracepoint(librbd
, metadata_remove_exit
, r
);
2896 int Image::metadata_list(const std::string
&start
, uint64_t max
, map
<string
, bufferlist
> *pairs
)
2898 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2899 tracepoint(librbd
, metadata_list_enter
, ictx
);
2900 int r
= librbd::metadata_list(ictx
, start
, max
, pairs
);
2902 for (map
<string
, bufferlist
>::iterator it
= pairs
->begin();
2903 it
!= pairs
->end(); ++it
) {
2904 tracepoint(librbd
, metadata_list_entry
, it
->first
.c_str(), it
->second
.c_str());
2907 tracepoint(librbd
, metadata_list_exit
, r
);
2911 int Image::mirror_image_enable() {
2912 return mirror_image_enable2(RBD_MIRROR_IMAGE_MODE_JOURNAL
);
2915 int Image::mirror_image_enable2(mirror_image_mode_t mode
) {
2916 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2917 return librbd::api::Mirror
<>::image_enable(ictx
, mode
, false);
2920 int Image::mirror_image_disable(bool force
) {
2921 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2922 return librbd::api::Mirror
<>::image_disable(ictx
, force
);
2925 int Image::mirror_image_promote(bool force
) {
2926 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2927 return librbd::api::Mirror
<>::image_promote(ictx
, force
);
2930 int Image::mirror_image_demote() {
2931 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2932 return librbd::api::Mirror
<>::image_demote(ictx
);
2935 int Image::mirror_image_resync()
2937 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2938 return librbd::api::Mirror
<>::image_resync(ictx
);
2941 int Image::mirror_image_create_snapshot(uint64_t *snap_id
)
2943 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2944 auto flags
= librbd::util::get_default_snap_create_flags(ictx
);
2945 return librbd::api::Mirror
<>::image_snapshot_create(ictx
, flags
, snap_id
);
2948 int Image::mirror_image_create_snapshot2(uint32_t flags
, uint64_t *snap_id
)
2950 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2951 return librbd::api::Mirror
<>::image_snapshot_create(ictx
, flags
, snap_id
);
2954 int Image::mirror_image_get_info(mirror_image_info_t
*mirror_image_info
,
2956 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2958 if (sizeof(mirror_image_info_t
) != info_size
) {
2962 return librbd::api::Mirror
<>::image_get_info(ictx
, mirror_image_info
);
2965 int Image::mirror_image_get_mode(mirror_image_mode_t
*mode
) {
2966 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2968 return librbd::api::Mirror
<>::image_get_mode(ictx
, mode
);
2971 int Image::mirror_image_get_global_status(
2972 mirror_image_global_status_t
*mirror_image_global_status
,
2973 size_t status_size
) {
2974 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2976 if (sizeof(mirror_image_global_status_t
) != status_size
) {
2980 return librbd::api::Mirror
<>::image_get_global_status(
2981 ictx
, mirror_image_global_status
);
2984 #pragma GCC diagnostic push
2985 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2987 int Image::mirror_image_get_status(mirror_image_status_t
*mirror_image_status
,
2988 size_t status_size
) {
2989 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2991 if (sizeof(mirror_image_status_t
) != status_size
) {
2995 mirror_image_global_status_t mirror_image_global_status
;
2996 int r
= librbd::api::Mirror
<>::image_get_global_status(
2997 ictx
, &mirror_image_global_status
);
3002 librbd::mirror_image_site_status_t local_status
;
3003 r
= get_local_mirror_image_site_status(mirror_image_global_status
,
3009 *mirror_image_status
= mirror_image_status_t
{
3010 mirror_image_global_status
.name
, mirror_image_global_status
.info
,
3011 local_status
.state
, local_status
.description
, local_status
.last_update
,
3016 #pragma GCC diagnostic pop
3018 int Image::mirror_image_get_instance_id(std::string
*instance_id
) {
3019 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3021 return librbd::api::Mirror
<>::image_get_instance_id(ictx
, instance_id
);
3024 int Image::aio_mirror_image_promote(bool force
, RBD::AioCompletion
*c
) {
3025 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3026 librbd::api::Mirror
<>::image_promote(
3027 ictx
, force
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3028 get_aio_completion(c
)));
3032 int Image::aio_mirror_image_demote(RBD::AioCompletion
*c
) {
3033 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3034 librbd::api::Mirror
<>::image_demote(
3035 ictx
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3036 get_aio_completion(c
)));
3040 int Image::aio_mirror_image_get_info(mirror_image_info_t
*mirror_image_info
,
3042 RBD::AioCompletion
*c
) {
3043 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3045 if (sizeof(mirror_image_info_t
) != info_size
) {
3049 librbd::api::Mirror
<>::image_get_info(
3050 ictx
, mirror_image_info
,
3051 new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3052 get_aio_completion(c
)));
3056 int Image::aio_mirror_image_get_mode(mirror_image_mode_t
*mode
,
3057 RBD::AioCompletion
*c
) {
3058 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3060 librbd::api::Mirror
<>::image_get_mode(
3061 ictx
, mode
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3062 get_aio_completion(c
)));
3066 int Image::aio_mirror_image_get_global_status(
3067 mirror_image_global_status_t
*status
, size_t status_size
,
3068 RBD::AioCompletion
*c
) {
3069 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3071 if (sizeof(mirror_image_global_status_t
) != status_size
) {
3075 librbd::api::Mirror
<>::image_get_global_status(
3076 ictx
, status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3077 get_aio_completion(c
)));
3081 #pragma GCC diagnostic push
3082 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
3084 int Image::aio_mirror_image_get_status(mirror_image_status_t
*status
,
3086 RBD::AioCompletion
*c
) {
3087 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3089 if (sizeof(mirror_image_status_t
) != status_size
) {
3093 auto ctx
= new C_MirrorImageGetStatus(
3094 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
3095 get_aio_completion(c
)));
3096 librbd::api::Mirror
<>::image_get_global_status(
3097 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
3101 #pragma GCC diagnostic pop
3103 int Image::aio_mirror_image_create_snapshot(uint32_t flags
, uint64_t *snap_id
,
3104 RBD::AioCompletion
*c
) {
3105 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3107 librbd::api::Mirror
<>::image_snapshot_create(
3108 ictx
, flags
, snap_id
, new C_AioCompletion(ictx
,
3109 librbd::io::AIO_TYPE_GENERIC
,
3110 get_aio_completion(c
)));
3114 int Image::update_watch(UpdateWatchCtx
*wctx
, uint64_t *handle
) {
3115 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3116 tracepoint(librbd
, update_watch_enter
, ictx
, wctx
);
3117 int r
= ictx
->state
->register_update_watcher(wctx
, handle
);
3118 tracepoint(librbd
, update_watch_exit
, r
, *handle
);
3122 int Image::update_unwatch(uint64_t handle
) {
3123 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3124 tracepoint(librbd
, update_unwatch_enter
, ictx
, handle
);
3125 int r
= ictx
->state
->unregister_update_watcher(handle
);
3126 tracepoint(librbd
, update_unwatch_exit
, r
);
3130 int Image::list_watchers(std::list
<librbd::image_watcher_t
> &watchers
) {
3131 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3132 tracepoint(librbd
, list_watchers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
3133 int r
= librbd::list_watchers(ictx
, watchers
);
3136 for (auto &watcher
: watchers
) {
3137 tracepoint(librbd
, list_watchers_entry
, watcher
.addr
.c_str(), watcher
.id
, watcher
.cookie
);
3141 tracepoint(librbd
, list_watchers_exit
, r
, watchers
.size());
3145 int Image::config_list(std::vector
<config_option_t
> *options
) {
3146 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3147 return librbd::api::Config
<>::list(ictx
, options
);
3150 int Image::quiesce_watch(QuiesceWatchCtx
*wctx
, uint64_t *handle
) {
3151 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3152 int r
= ictx
->state
->register_quiesce_watcher(wctx
, handle
);
3156 int Image::quiesce_unwatch(uint64_t handle
) {
3157 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3158 int r
= ictx
->state
->unregister_quiesce_watcher(handle
);
3162 void Image::quiesce_complete(uint64_t handle
, int r
) {
3163 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3164 ictx
->state
->quiesce_complete(handle
, r
);
3167 } // namespace librbd
3169 extern "C" void rbd_version(int *major
, int *minor
, int *extra
)
3172 *major
= LIBRBD_VER_MAJOR
;
3174 *minor
= LIBRBD_VER_MINOR
;
3176 *extra
= LIBRBD_VER_EXTRA
;
3179 extern "C" void rbd_image_options_create(rbd_image_options_t
* opts
)
3181 librbd::image_options_create(opts
);
3184 extern "C" void rbd_image_options_destroy(rbd_image_options_t opts
)
3186 librbd::image_options_destroy(opts
);
3189 extern "C" int rbd_image_options_set_string(rbd_image_options_t opts
, int optname
,
3192 return librbd::image_options_set(opts
, optname
, optval
);
3195 extern "C" int rbd_image_options_set_uint64(rbd_image_options_t opts
, int optname
,
3198 return librbd::image_options_set(opts
, optname
, optval
);
3201 extern "C" int rbd_image_options_get_string(rbd_image_options_t opts
, int optname
,
3202 char* optval
, size_t maxlen
)
3204 std::string optval_
;
3206 int r
= librbd::image_options_get(opts
, optname
, &optval_
);
3212 if (optval_
.size() >= maxlen
) {
3216 strncpy(optval
, optval_
.c_str(), maxlen
);
3221 extern "C" int rbd_image_options_get_uint64(rbd_image_options_t opts
, int optname
,
3224 return librbd::image_options_get(opts
, optname
, optval
);
3227 extern "C" int rbd_image_options_is_set(rbd_image_options_t opts
, int optname
,
3230 return librbd::image_options_is_set(opts
, optname
, is_set
);
3233 extern "C" int rbd_image_options_unset(rbd_image_options_t opts
, int optname
)
3235 return librbd::image_options_unset(opts
, optname
);
3238 extern "C" void rbd_image_options_clear(rbd_image_options_t opts
)
3240 librbd::image_options_clear(opts
);
3243 extern "C" int rbd_image_options_is_empty(rbd_image_options_t opts
)
3245 return librbd::image_options_is_empty(opts
);
3248 /* pool mirroring */
3249 extern "C" int rbd_mirror_site_name_get(rados_t cluster
, char *name
,
3251 librados::Rados rados
;
3252 librados::Rados::from_rados_t(cluster
, rados
);
3254 std::string site_name
;
3255 int r
= librbd::api::Mirror
<>::site_name_get(rados
, &site_name
);
3260 auto total_len
= site_name
.size() + 1;
3261 if (*max_len
< total_len
) {
3262 *max_len
= total_len
;
3265 *max_len
= total_len
;
3267 strcpy(name
, site_name
.c_str());
3271 extern "C" int rbd_mirror_site_name_set(rados_t cluster
, const char *name
) {
3272 librados::Rados rados
;
3273 librados::Rados::from_rados_t(cluster
, rados
);
3274 return librbd::api::Mirror
<>::site_name_set(rados
, name
);
3277 extern "C" int rbd_mirror_mode_get(rados_ioctx_t p
,
3278 rbd_mirror_mode_t
*mirror_mode
) {
3279 librados::IoCtx io_ctx
;
3280 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3281 return librbd::api::Mirror
<>::mode_get(io_ctx
, mirror_mode
);
3284 extern "C" int rbd_mirror_mode_set(rados_ioctx_t p
,
3285 rbd_mirror_mode_t mirror_mode
) {
3286 librados::IoCtx io_ctx
;
3287 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3288 return librbd::api::Mirror
<>::mode_set(io_ctx
, mirror_mode
);
3291 extern "C" int rbd_mirror_uuid_get(rados_ioctx_t p
,
3292 char *mirror_uuid
, size_t *max_len
) {
3293 librados::IoCtx io_ctx
;
3294 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3296 std::string mirror_uuid_str
;
3297 int r
= librbd::api::Mirror
<>::uuid_get(io_ctx
, &mirror_uuid_str
);
3302 auto total_len
= mirror_uuid_str
.size() + 1;
3303 if (*max_len
< total_len
) {
3304 *max_len
= total_len
;
3307 *max_len
= total_len
;
3309 strcpy(mirror_uuid
, mirror_uuid_str
.c_str());
3313 extern "C" int rbd_mirror_peer_bootstrap_create(rados_ioctx_t p
, char *token
,
3315 librados::IoCtx io_ctx
;
3316 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3318 std::string token_str
;
3319 int r
= librbd::api::Mirror
<>::peer_bootstrap_create(io_ctx
, &token_str
);
3324 auto total_len
= token_str
.size() + 1;
3325 if (*max_len
< total_len
) {
3326 *max_len
= total_len
;
3329 *max_len
= total_len
;
3331 strcpy(token
, token_str
.c_str());
3335 extern "C" int rbd_mirror_peer_bootstrap_import(
3336 rados_ioctx_t p
, rbd_mirror_peer_direction_t direction
,
3337 const char *token
) {
3338 librados::IoCtx io_ctx
;
3339 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3341 return librbd::api::Mirror
<>::peer_bootstrap_import(io_ctx
, direction
, token
);
3344 extern "C" int rbd_mirror_peer_site_add(rados_ioctx_t p
, char *uuid
,
3345 size_t uuid_max_length
,
3346 rbd_mirror_peer_direction_t direction
,
3347 const char *site_name
,
3348 const char *client_name
) {
3349 static const std::size_t UUID_LENGTH
= 36;
3351 librados::IoCtx io_ctx
;
3352 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3354 if (uuid_max_length
< UUID_LENGTH
+ 1) {
3358 std::string uuid_str
;
3359 int r
= librbd::api::Mirror
<>::peer_site_add(io_ctx
, &uuid_str
, direction
,
3360 site_name
, client_name
);
3362 strncpy(uuid
, uuid_str
.c_str(), uuid_max_length
);
3363 uuid
[uuid_max_length
- 1] = '\0';
3368 extern "C" int rbd_mirror_peer_site_remove(rados_ioctx_t p
, const char *uuid
) {
3369 librados::IoCtx io_ctx
;
3370 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3371 int r
= librbd::api::Mirror
<>::peer_site_remove(io_ctx
, uuid
);
3375 extern "C" int rbd_mirror_peer_site_list(
3376 rados_ioctx_t p
, rbd_mirror_peer_site_t
*peers
, int *max_peers
) {
3377 librados::IoCtx io_ctx
;
3378 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3380 std::vector
<librbd::mirror_peer_site_t
> peer_vector
;
3381 int r
= librbd::api::Mirror
<>::peer_site_list(io_ctx
, &peer_vector
);
3386 if (*max_peers
< static_cast<int>(peer_vector
.size())) {
3387 *max_peers
= static_cast<int>(peer_vector
.size());
3391 for (int i
= 0; i
< static_cast<int>(peer_vector
.size()); ++i
) {
3392 peers
[i
].uuid
= strdup(peer_vector
[i
].uuid
.c_str());
3393 peers
[i
].direction
= peer_vector
[i
].direction
;
3394 peers
[i
].site_name
= strdup(peer_vector
[i
].site_name
.c_str());
3395 peers
[i
].mirror_uuid
= strdup(peer_vector
[i
].mirror_uuid
.c_str());
3396 peers
[i
].client_name
= strdup(peer_vector
[i
].client_name
.c_str());
3398 *max_peers
= static_cast<int>(peer_vector
.size());
3402 extern "C" void rbd_mirror_peer_site_list_cleanup(rbd_mirror_peer_site_t
*peers
,
3404 for (int i
= 0; i
< max_peers
; ++i
) {
3405 free(peers
[i
].uuid
);
3406 free(peers
[i
].site_name
);
3407 free(peers
[i
].mirror_uuid
);
3408 free(peers
[i
].client_name
);
3412 extern "C" int rbd_mirror_peer_site_set_client_name(
3413 rados_ioctx_t p
, const char *uuid
, const char *client_name
) {
3414 librados::IoCtx io_ctx
;
3415 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3416 return librbd::api::Mirror
<>::peer_site_set_client(io_ctx
, uuid
, client_name
);
3419 extern "C" int rbd_mirror_peer_site_set_name(
3420 rados_ioctx_t p
, const char *uuid
, const char *site_name
) {
3421 librados::IoCtx io_ctx
;
3422 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3423 return librbd::api::Mirror
<>::peer_site_set_name(io_ctx
, uuid
, site_name
);
3426 extern "C" int rbd_mirror_peer_site_set_direction(
3427 rados_ioctx_t p
, const char *uuid
, rbd_mirror_peer_direction_t direction
) {
3428 librados::IoCtx io_ctx
;
3429 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3430 return librbd::api::Mirror
<>::peer_site_set_direction(io_ctx
, uuid
,
3434 extern "C" int rbd_mirror_peer_site_get_attributes(
3435 rados_ioctx_t p
, const char *uuid
, char *keys
, size_t *max_key_len
,
3436 char *values
, size_t *max_val_len
, size_t *key_value_count
) {
3437 librados::IoCtx io_ctx
;
3438 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3440 std::map
<std::string
, std::string
> attributes
;
3441 int r
= librbd::api::Mirror
<>::peer_site_get_attributes(
3442 io_ctx
, uuid
, &attributes
);
3447 size_t key_total_len
= 0, val_total_len
= 0;
3448 for (auto& it
: attributes
) {
3449 key_total_len
+= it
.first
.size() + 1;
3450 val_total_len
+= it
.second
.length() + 1;
3453 bool too_short
= ((*max_key_len
< key_total_len
) ||
3454 (*max_val_len
< val_total_len
));
3456 *max_key_len
= key_total_len
;
3457 *max_val_len
= val_total_len
;
3458 *key_value_count
= attributes
.size();
3463 char *keys_p
= keys
;
3464 char *values_p
= values
;
3465 for (auto& it
: attributes
) {
3466 strncpy(keys_p
, it
.first
.c_str(), it
.first
.size() + 1);
3467 keys_p
+= it
.first
.size() + 1;
3469 strncpy(values_p
, it
.second
.c_str(), it
.second
.length() + 1);
3470 values_p
+= it
.second
.length() + 1;
3476 extern "C" int rbd_mirror_peer_site_set_attributes(
3477 rados_ioctx_t p
, const char *uuid
, const char *keys
, const char *values
,
3479 librados::IoCtx io_ctx
;
3480 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3482 std::map
<std::string
, std::string
> attributes
;
3484 for (size_t i
= 0; i
< count
; ++i
) {
3485 const char* key
= keys
;
3486 keys
+= strlen(key
) + 1;
3487 const char* value
= values
;
3488 values
+= strlen(value
) + 1;
3489 attributes
[key
] = value
;
3492 return librbd::api::Mirror
<>::peer_site_set_attributes(
3493 io_ctx
, uuid
, attributes
);
3496 extern "C" int rbd_mirror_image_global_status_list(rados_ioctx_t p
,
3497 const char *start_id
, size_t max
, char **image_ids
,
3498 rbd_mirror_image_global_status_t
*images
, size_t *len
) {
3499 librados::IoCtx io_ctx
;
3500 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3501 std::map
<std::string
, librbd::mirror_image_global_status_t
> cpp_images
;
3503 int r
= librbd::api::Mirror
<>::image_global_status_list(
3504 io_ctx
, start_id
, max
, &cpp_images
);
3510 for (auto &it
: cpp_images
) {
3511 ceph_assert(i
< max
);
3512 const std::string
&image_id
= it
.first
;
3513 image_ids
[i
] = strdup(image_id
.c_str());
3514 mirror_image_global_status_cpp_to_c(it
.second
, &images
[i
]);
3521 extern "C" void rbd_mirror_image_global_status_cleanup(
3522 rbd_mirror_image_global_status_t
*global_status
) {
3523 free(global_status
->name
);
3524 rbd_mirror_image_get_info_cleanup(&global_status
->info
);
3525 for (auto idx
= 0U; idx
< global_status
->site_statuses_count
; ++idx
) {
3526 free(global_status
->site_statuses
[idx
].mirror_uuid
);
3527 free(global_status
->site_statuses
[idx
].description
);
3529 free(global_status
->site_statuses
);
3532 extern "C" void rbd_mirror_image_global_status_list_cleanup(
3533 char **image_ids
, rbd_mirror_image_global_status_t
*images
, size_t len
) {
3534 for (size_t i
= 0; i
< len
; i
++) {
3536 rbd_mirror_image_global_status_cleanup(&images
[i
]);
3540 #pragma GCC diagnostic push
3541 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
3543 extern "C" int rbd_mirror_peer_add(rados_ioctx_t p
, char *uuid
,
3544 size_t uuid_max_length
,
3545 const char *cluster_name
,
3546 const char *client_name
) {
3547 return rbd_mirror_peer_site_add(
3548 p
, uuid
, uuid_max_length
, RBD_MIRROR_PEER_DIRECTION_RX_TX
, cluster_name
,
3552 extern "C" int rbd_mirror_peer_remove(rados_ioctx_t p
, const char *uuid
) {
3553 return rbd_mirror_peer_site_remove(p
, uuid
);
3556 extern "C" int rbd_mirror_peer_list(rados_ioctx_t p
,
3557 rbd_mirror_peer_t
*peers
, int *max_peers
) {
3558 librados::IoCtx io_ctx
;
3559 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3561 std::vector
<librbd::mirror_peer_site_t
> peer_vector
;
3562 int r
= librbd::api::Mirror
<>::peer_site_list(io_ctx
, &peer_vector
);
3567 if (*max_peers
< static_cast<int>(peer_vector
.size())) {
3568 *max_peers
= static_cast<int>(peer_vector
.size());
3572 for (int i
= 0; i
< static_cast<int>(peer_vector
.size()); ++i
) {
3573 peers
[i
].uuid
= strdup(peer_vector
[i
].uuid
.c_str());
3574 peers
[i
].cluster_name
= strdup(peer_vector
[i
].site_name
.c_str());
3575 peers
[i
].client_name
= strdup(peer_vector
[i
].client_name
.c_str());
3577 *max_peers
= static_cast<int>(peer_vector
.size());
3581 extern "C" void rbd_mirror_peer_list_cleanup(rbd_mirror_peer_t
*peers
,
3583 for (int i
= 0; i
< max_peers
; ++i
) {
3584 free(peers
[i
].uuid
);
3585 free(peers
[i
].cluster_name
);
3586 free(peers
[i
].client_name
);
3590 extern "C" int rbd_mirror_peer_set_client(rados_ioctx_t p
, const char *uuid
,
3591 const char *client_name
) {
3592 return rbd_mirror_peer_site_set_client_name(p
, uuid
, client_name
);
3595 extern "C" int rbd_mirror_peer_set_cluster(rados_ioctx_t p
, const char *uuid
,
3596 const char *cluster_name
) {
3597 return rbd_mirror_peer_site_set_name(p
, uuid
, cluster_name
);
3600 extern "C" int rbd_mirror_peer_get_attributes(
3601 rados_ioctx_t p
, const char *uuid
, char *keys
, size_t *max_key_len
,
3602 char *values
, size_t *max_val_len
, size_t *key_value_count
) {
3603 return rbd_mirror_peer_site_get_attributes(
3604 p
, uuid
, keys
, max_key_len
, values
, max_val_len
, key_value_count
);
3607 extern "C" int rbd_mirror_peer_set_attributes(
3608 rados_ioctx_t p
, const char *uuid
, const char *keys
, const char *values
,
3610 return rbd_mirror_peer_site_set_attributes(
3611 p
, uuid
, keys
, values
, count
);
3614 extern "C" int rbd_mirror_image_status_list(rados_ioctx_t p
,
3615 const char *start_id
, size_t max
, char **image_ids
,
3616 rbd_mirror_image_status_t
*images
, size_t *len
) {
3617 librados::IoCtx io_ctx
;
3618 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3619 std::map
<std::string
, librbd::mirror_image_global_status_t
> cpp_images
;
3621 int r
= librbd::api::Mirror
<>::image_global_status_list(
3622 io_ctx
, start_id
, max
, &cpp_images
);
3628 for (auto &it
: cpp_images
) {
3629 ceph_assert(i
< max
);
3630 const std::string
&image_id
= it
.first
;
3631 image_ids
[i
] = strdup(image_id
.c_str());
3632 mirror_image_global_status_cpp_to_c(it
.second
, &images
[i
]);
3639 extern "C" void rbd_mirror_image_status_list_cleanup(char **image_ids
,
3640 rbd_mirror_image_status_t
*images
, size_t len
) {
3641 for (size_t i
= 0; i
< len
; i
++) {
3643 free(images
[i
].name
);
3644 rbd_mirror_image_get_info_cleanup(&images
[i
].info
);
3645 free(images
[i
].description
);
3649 #pragma GCC diagnostic pop
3651 extern "C" int rbd_mirror_image_status_summary(rados_ioctx_t p
,
3652 rbd_mirror_image_status_state_t
*states
, int *counts
, size_t *maxlen
) {
3654 librados::IoCtx io_ctx
;
3655 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3657 std::map
<librbd::mirror_image_status_state_t
, int> states_
;
3658 int r
= librbd::api::Mirror
<>::image_status_summary(io_ctx
, &states_
);
3664 for (auto &it
: states_
) {
3668 states
[i
] = it
.first
;
3669 counts
[i
] = it
.second
;
3676 extern "C" int rbd_mirror_image_instance_id_list(
3677 rados_ioctx_t p
, const char *start_id
, size_t max
, char **image_ids
,
3678 char **instance_ids
, size_t *len
) {
3679 librados::IoCtx io_ctx
;
3680 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3681 std::map
<std::string
, std::string
> cpp_instance_ids
;
3683 int r
= librbd::api::Mirror
<>::image_instance_id_list(io_ctx
, start_id
, max
,
3690 for (auto &it
: cpp_instance_ids
) {
3691 ceph_assert(i
< max
);
3692 image_ids
[i
] = strdup(it
.first
.c_str());
3693 instance_ids
[i
] = strdup(it
.second
.c_str());
3700 extern "C" void rbd_mirror_image_instance_id_list_cleanup(
3701 char **image_ids
, char **instance_ids
, size_t len
) {
3702 for (size_t i
= 0; i
< len
; i
++) {
3704 free(instance_ids
[i
]);
3708 extern "C" int rbd_mirror_image_info_list(
3709 rados_ioctx_t p
, rbd_mirror_image_mode_t
*mode_filter
,
3710 const char *start_id
, size_t max
, char **image_ids
,
3711 rbd_mirror_image_mode_t
*mode_entries
,
3712 rbd_mirror_image_info_t
*info_entries
, size_t *num_entries
) {
3713 librados::IoCtx io_ctx
;
3714 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3715 std::map
<std::string
, std::pair
<librbd::mirror_image_mode_t
,
3716 librbd::mirror_image_info_t
>> cpp_entries
;
3718 int r
= librbd::api::Mirror
<>::image_info_list(io_ctx
, mode_filter
, start_id
,
3724 ceph_assert(cpp_entries
.size() <= max
);
3726 for (auto &it
: cpp_entries
) {
3727 *(image_ids
++) = strdup(it
.first
.c_str());
3728 *(mode_entries
++) = it
.second
.first
;
3729 mirror_image_info_cpp_to_c(it
.second
.second
, info_entries
++);
3731 *num_entries
= cpp_entries
.size();
3736 extern "C" void rbd_mirror_image_info_list_cleanup(
3737 char **image_ids
, rbd_mirror_image_info_t
*info_entries
,
3738 size_t num_entries
) {
3739 for (size_t i
= 0; i
< num_entries
; i
++) {
3740 free(*(image_ids
++));
3741 rbd_mirror_image_get_info_cleanup(info_entries
++);
3747 extern "C" void rbd_image_spec_cleanup(rbd_image_spec_t
*image
)
3753 extern "C" void rbd_image_spec_list_cleanup(rbd_image_spec_t
*images
,
3756 for (size_t idx
= 0; idx
< num_images
; ++idx
) {
3757 rbd_image_spec_cleanup(&images
[idx
]);
3761 extern "C" void rbd_linked_image_spec_cleanup(rbd_linked_image_spec_t
*image
)
3763 free(image
->pool_name
);
3764 free(image
->pool_namespace
);
3765 free(image
->image_id
);
3766 free(image
->image_name
);
3769 extern "C" void rbd_linked_image_spec_list_cleanup(
3770 rbd_linked_image_spec_t
*images
, size_t num_images
)
3772 for (size_t idx
= 0; idx
< num_images
; ++idx
) {
3773 rbd_linked_image_spec_cleanup(&images
[idx
]);
3777 extern "C" void rbd_snap_spec_cleanup(rbd_snap_spec_t
*snap
)
3783 extern "C" int rbd_list(rados_ioctx_t p
, char *names
, size_t *size
)
3785 librados::IoCtx io_ctx
;
3786 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3788 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3789 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(),
3791 std::vector
<librbd::image_spec_t
> cpp_image_specs
;
3792 int r
= librbd::api::Image
<>::list_images(io_ctx
, &cpp_image_specs
);
3794 tracepoint(librbd
, list_exit
, r
, *size
);
3798 size_t expected_size
= 0;
3800 for (auto& it
: cpp_image_specs
) {
3801 expected_size
+= it
.name
.size() + 1;
3803 if (*size
< expected_size
) {
3804 *size
= expected_size
;
3805 tracepoint(librbd
, list_exit
, -ERANGE
, *size
);
3809 if (names
== NULL
) {
3810 tracepoint(librbd
, list_exit
, -EINVAL
, *size
);
3814 for (auto& it
: cpp_image_specs
) {
3815 const char* name
= it
.name
.c_str();
3816 tracepoint(librbd
, list_entry
, name
);
3817 strcpy(names
, name
);
3818 names
+= strlen(names
) + 1;
3820 tracepoint(librbd
, list_exit
, (int)expected_size
, *size
);
3821 return (int)expected_size
;
3824 extern "C" int rbd_list2(rados_ioctx_t p
, rbd_image_spec_t
*images
,
3827 librados::IoCtx io_ctx
;
3828 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3830 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3831 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(),
3833 // FIPS zeroization audit 20191117: this memset is not security related.
3834 memset(images
, 0, sizeof(*images
) * *size
);
3835 std::vector
<librbd::image_spec_t
> cpp_image_specs
;
3836 int r
= librbd::api::Image
<>::list_images(io_ctx
, &cpp_image_specs
);
3838 tracepoint(librbd
, list_exit
, r
, *size
);
3842 size_t expected_size
= cpp_image_specs
.size();
3843 if (*size
< expected_size
) {
3844 *size
= expected_size
;
3845 tracepoint(librbd
, list_exit
, -ERANGE
, *size
);
3849 *size
= expected_size
;
3850 for (size_t idx
= 0; idx
< expected_size
; ++idx
) {
3851 images
[idx
].id
= strdup(cpp_image_specs
[idx
].id
.c_str());
3852 images
[idx
].name
= strdup(cpp_image_specs
[idx
].name
.c_str());
3854 tracepoint(librbd
, list_exit
, 0, *size
);
3858 extern "C" int rbd_create(rados_ioctx_t p
, const char *name
, uint64_t size
, int *order
)
3860 librados::IoCtx io_ctx
;
3861 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3862 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3863 tracepoint(librbd
, create_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, *order
);
3864 int r
= librbd::create(io_ctx
, name
, size
, order
);
3865 tracepoint(librbd
, create_exit
, r
, *order
);
3869 extern "C" int rbd_create2(rados_ioctx_t p
, const char *name
,
3870 uint64_t size
, uint64_t features
,
3873 librados::IoCtx io_ctx
;
3874 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3875 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3876 tracepoint(librbd
, create2_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
);
3877 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
, 0, 0);
3878 tracepoint(librbd
, create2_exit
, r
, *order
);
3882 extern "C" int rbd_create3(rados_ioctx_t p
, const char *name
,
3883 uint64_t size
, uint64_t features
,
3885 uint64_t stripe_unit
, uint64_t stripe_count
)
3887 librados::IoCtx io_ctx
;
3888 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3889 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3890 tracepoint(librbd
, create3_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
, stripe_unit
, stripe_count
);
3891 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
,
3892 stripe_unit
, stripe_count
);
3893 tracepoint(librbd
, create3_exit
, r
, *order
);
3897 extern "C" int rbd_create4(rados_ioctx_t p
, const char *name
,
3898 uint64_t size
, rbd_image_options_t opts
)
3900 librados::IoCtx io_ctx
;
3901 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3902 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3903 tracepoint(librbd
, create4_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, opts
);
3904 librbd::ImageOptions
opts_(opts
);
3905 int r
= librbd::create(io_ctx
, name
, "", size
, opts_
, "", "", false);
3906 tracepoint(librbd
, create4_exit
, r
);
3910 extern "C" int rbd_clone(rados_ioctx_t p_ioctx
, const char *p_name
,
3911 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3912 const char *c_name
, uint64_t features
, int *c_order
)
3914 librados::IoCtx p_ioc
, c_ioc
;
3915 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3916 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3917 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3918 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
);
3919 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
,
3920 features
, c_order
, 0, 0);
3921 tracepoint(librbd
, clone_exit
, r
, *c_order
);
3925 extern "C" int rbd_clone2(rados_ioctx_t p_ioctx
, const char *p_name
,
3926 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3927 const char *c_name
, uint64_t features
, int *c_order
,
3928 uint64_t stripe_unit
, int stripe_count
)
3930 librados::IoCtx p_ioc
, c_ioc
;
3931 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3932 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3933 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3934 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
);
3935 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
,
3936 features
, c_order
, stripe_unit
, stripe_count
);
3937 tracepoint(librbd
, clone2_exit
, r
, *c_order
);
3941 extern "C" int rbd_clone3(rados_ioctx_t p_ioctx
, const char *p_name
,
3942 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3943 const char *c_name
, rbd_image_options_t c_opts
)
3945 librados::IoCtx p_ioc
, c_ioc
;
3946 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3947 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3948 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3949 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
);
3950 librbd::ImageOptions
c_opts_(c_opts
);
3951 int r
= librbd::clone(p_ioc
, nullptr, p_name
, p_snap_name
, c_ioc
, nullptr,
3952 c_name
, c_opts_
, "", "");
3953 tracepoint(librbd
, clone3_exit
, r
);
3957 extern "C" int rbd_remove(rados_ioctx_t p
, const char *name
)
3959 librados::IoCtx io_ctx
;
3960 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3961 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3962 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
3963 librbd::NoOpProgressContext prog_ctx
;
3964 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, prog_ctx
);
3965 tracepoint(librbd
, remove_exit
, r
);
3969 extern "C" int rbd_remove_with_progress(rados_ioctx_t p
, const char *name
,
3970 librbd_progress_fn_t cb
, void *cbdata
)
3972 librados::IoCtx io_ctx
;
3973 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3974 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3975 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
3976 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
3977 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, prog_ctx
);
3978 tracepoint(librbd
, remove_exit
, r
);
3982 extern "C" int rbd_trash_move(rados_ioctx_t p
, const char *name
,
3984 librados::IoCtx io_ctx
;
3985 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3986 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3987 tracepoint(librbd
, trash_move_enter
, io_ctx
.get_pool_name().c_str(),
3988 io_ctx
.get_id(), name
);
3989 int r
= librbd::api::Trash
<>::move(io_ctx
, RBD_TRASH_IMAGE_SOURCE_USER
, name
,
3991 tracepoint(librbd
, trash_move_exit
, r
);
3995 extern "C" int rbd_trash_get(rados_ioctx_t io
, const char *id
,
3996 rbd_trash_image_info_t
*info
) {
3997 librados::IoCtx io_ctx
;
3998 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4000 librbd::trash_image_info_t cpp_info
;
4001 int r
= librbd::api::Trash
<>::get(io_ctx
, id
, &cpp_info
);
4006 trash_image_info_cpp_to_c(cpp_info
, info
);
4010 extern "C" void rbd_trash_get_cleanup(rbd_trash_image_info_t
*info
) {
4015 extern "C" int rbd_trash_list(rados_ioctx_t p
, rbd_trash_image_info_t
*entries
,
4016 size_t *num_entries
) {
4017 librados::IoCtx io_ctx
;
4018 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4019 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4020 tracepoint(librbd
, trash_list_enter
,
4021 io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
4022 // FIPS zeroization audit 20191117: this memset is not security related.
4023 memset(entries
, 0, sizeof(*entries
) * *num_entries
);
4025 vector
<librbd::trash_image_info_t
> cpp_entries
;
4026 int r
= librbd::api::Trash
<>::list(io_ctx
, cpp_entries
, true);
4028 tracepoint(librbd
, trash_list_exit
, r
, *num_entries
);
4032 if (*num_entries
< cpp_entries
.size()) {
4033 *num_entries
= cpp_entries
.size();
4034 tracepoint(librbd
, trash_list_exit
, -ERANGE
, *num_entries
);
4039 for (const auto &entry
: cpp_entries
) {
4040 trash_image_info_cpp_to_c(entry
, &entries
[i
++]);
4042 *num_entries
= cpp_entries
.size();
4044 return *num_entries
;
4047 extern "C" void rbd_trash_list_cleanup(rbd_trash_image_info_t
*entries
,
4048 size_t num_entries
) {
4049 for (size_t i
=0; i
< num_entries
; i
++) {
4050 rbd_trash_get_cleanup(&entries
[i
]);
4054 extern "C" int rbd_trash_purge(rados_ioctx_t io
, time_t expire_ts
,
4056 librados::IoCtx io_ctx
;
4057 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4058 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4059 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
4060 io_ctx
.get_id(), expire_ts
, threshold
);
4061 librbd::NoOpProgressContext nop_pctx
;
4062 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, nop_pctx
);
4063 tracepoint(librbd
, trash_purge_exit
, r
);
4067 extern "C" int rbd_trash_purge_with_progress(rados_ioctx_t io
, time_t expire_ts
,
4068 float threshold
, librbd_progress_fn_t cb
, void* cbdata
) {
4069 librados::IoCtx io_ctx
;
4070 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4071 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4072 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
4073 io_ctx
.get_id(), expire_ts
, threshold
);
4074 librbd::CProgressContext
pctx(cb
, cbdata
);
4075 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, pctx
);
4076 tracepoint(librbd
, trash_purge_exit
, r
);
4080 extern "C" int rbd_trash_remove(rados_ioctx_t p
, const char *image_id
,
4082 librados::IoCtx io_ctx
;
4083 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4084 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4085 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
4086 io_ctx
.get_id(), image_id
, force
);
4087 librbd::NoOpProgressContext prog_ctx
;
4088 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, prog_ctx
);
4089 tracepoint(librbd
, trash_remove_exit
, r
);
4093 extern "C" int rbd_trash_remove_with_progress(rados_ioctx_t p
,
4094 const char *image_id
,
4096 librbd_progress_fn_t cb
,
4098 librados::IoCtx io_ctx
;
4099 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4100 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4101 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
4102 io_ctx
.get_id(), image_id
, force
);
4103 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4104 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, prog_ctx
);
4105 tracepoint(librbd
, trash_remove_exit
, r
);
4109 extern "C" int rbd_trash_restore(rados_ioctx_t p
, const char *id
,
4111 librados::IoCtx io_ctx
;
4112 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4113 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4114 tracepoint(librbd
, trash_undelete_enter
, io_ctx
.get_pool_name().c_str(),
4115 io_ctx
.get_id(), id
, name
);
4116 int r
= librbd::api::Trash
<>::restore(
4117 io_ctx
, librbd::api::Trash
<>::ALLOWED_RESTORE_SOURCES
, id
, name
);
4118 tracepoint(librbd
, trash_undelete_exit
, r
);
4122 extern "C" int rbd_namespace_create(rados_ioctx_t io
,
4123 const char *namespace_name
) {
4124 librados::IoCtx io_ctx
;
4125 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4127 return librbd::api::Namespace
<>::create(io_ctx
, namespace_name
);
4130 extern "C" int rbd_namespace_remove(rados_ioctx_t io
,
4131 const char *namespace_name
) {
4132 librados::IoCtx io_ctx
;
4133 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4135 return librbd::api::Namespace
<>::remove(io_ctx
, namespace_name
);
4138 extern "C" int rbd_namespace_list(rados_ioctx_t io
, char *names
, size_t *size
) {
4139 librados::IoCtx io_ctx
;
4140 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4142 if (names
== nullptr || size
== nullptr) {
4146 std::vector
<std::string
> cpp_names
;
4147 int r
= librbd::api::Namespace
<>::list(io_ctx
, &cpp_names
);
4152 size_t expected_size
= 0;
4153 for (size_t i
= 0; i
< cpp_names
.size(); i
++) {
4154 expected_size
+= cpp_names
[i
].size() + 1;
4156 if (*size
< expected_size
) {
4157 *size
= expected_size
;
4161 *size
= expected_size
;
4162 for (int i
= 0; i
< (int)cpp_names
.size(); i
++) {
4163 const char* name
= cpp_names
[i
].c_str();
4164 strcpy(names
, name
);
4165 names
+= strlen(names
) + 1;
4168 return (int)expected_size
;
4171 extern "C" int rbd_namespace_exists(rados_ioctx_t io
,
4172 const char *namespace_name
,
4174 librados::IoCtx io_ctx
;
4175 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4177 return librbd::api::Namespace
<>::exists(io_ctx
, namespace_name
, exists
);
4180 extern "C" int rbd_pool_init(rados_ioctx_t io
, bool force
) {
4181 librados::IoCtx io_ctx
;
4182 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4184 return librbd::api::Pool
<>::init(io_ctx
, force
);
4187 extern "C" void rbd_pool_stats_create(rbd_pool_stats_t
*stats
) {
4188 *stats
= reinterpret_cast<rbd_pool_stats_t
>(
4189 new librbd::api::Pool
<>::StatOptions
{});
4192 extern "C" void rbd_pool_stats_destroy(rbd_pool_stats_t stats
) {
4193 auto pool_stat_options
=
4194 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(stats
);
4195 delete pool_stat_options
;
4198 extern "C" int rbd_pool_stats_option_add_uint64(rbd_pool_stats_t stats
,
4200 uint64_t* stat_val
) {
4201 auto pool_stat_options
=
4202 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(stats
);
4203 return librbd::api::Pool
<>::add_stat_option(
4204 pool_stat_options
, static_cast<rbd_pool_stat_option_t
>(stat_option
),
4208 extern "C" int rbd_pool_stats_get(
4209 rados_ioctx_t io
, rbd_pool_stats_t pool_stats
) {
4210 librados::IoCtx io_ctx
;
4211 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4213 auto pool_stat_options
=
4214 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(pool_stats
);
4215 return librbd::api::Pool
<>::get_stats(io_ctx
, pool_stat_options
);
4218 extern "C" int rbd_copy(rbd_image_t image
, rados_ioctx_t dest_p
,
4219 const char *destname
)
4221 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4222 librados::IoCtx dest_io_ctx
;
4223 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4224 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
);
4225 librbd::ImageOptions opts
;
4226 librbd::NoOpProgressContext prog_ctx
;
4227 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
4228 tracepoint(librbd
, copy_exit
, r
);
4232 extern "C" int rbd_copy2(rbd_image_t srcp
, rbd_image_t destp
)
4234 librbd::ImageCtx
*src
= (librbd::ImageCtx
*)srcp
;
4235 librbd::ImageCtx
*dest
= (librbd::ImageCtx
*)destp
;
4236 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
);
4237 librbd::NoOpProgressContext prog_ctx
;
4238 int r
= librbd::copy(src
, dest
, prog_ctx
, 0);
4239 tracepoint(librbd
, copy2_exit
, r
);
4243 extern "C" int rbd_copy3(rbd_image_t image
, rados_ioctx_t dest_p
,
4244 const char *destname
, rbd_image_options_t c_opts
)
4246 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4247 librados::IoCtx dest_io_ctx
;
4248 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4249 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
);
4250 librbd::ImageOptions
c_opts_(c_opts
);
4251 librbd::NoOpProgressContext prog_ctx
;
4252 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, c_opts_
, prog_ctx
, 0);
4253 tracepoint(librbd
, copy3_exit
, r
);
4257 extern "C" int rbd_copy4(rbd_image_t image
, rados_ioctx_t dest_p
,
4258 const char *destname
, rbd_image_options_t c_opts
, size_t sparse_size
)
4260 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4261 librados::IoCtx dest_io_ctx
;
4262 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4263 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
);
4264 librbd::ImageOptions
c_opts_(c_opts
);
4265 librbd::NoOpProgressContext prog_ctx
;
4266 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, c_opts_
, prog_ctx
, sparse_size
);
4267 tracepoint(librbd
, copy4_exit
, r
);
4271 extern "C" int rbd_copy_with_progress(rbd_image_t image
, rados_ioctx_t dest_p
,
4272 const char *destname
,
4273 librbd_progress_fn_t fn
, void *data
)
4275 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4276 librados::IoCtx dest_io_ctx
;
4277 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4278 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
);
4279 librbd::ImageOptions opts
;
4280 librbd::CProgressContext
prog_ctx(fn
, data
);
4281 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
4282 tracepoint(librbd
, copy_exit
, ret
);
4286 extern "C" int rbd_copy_with_progress2(rbd_image_t srcp
, rbd_image_t destp
,
4287 librbd_progress_fn_t fn
, void *data
)
4289 librbd::ImageCtx
*src
= (librbd::ImageCtx
*)srcp
;
4290 librbd::ImageCtx
*dest
= (librbd::ImageCtx
*)destp
;
4291 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
);
4292 librbd::CProgressContext
prog_ctx(fn
, data
);
4293 int ret
= librbd::copy(src
, dest
, prog_ctx
, 0);
4294 tracepoint(librbd
, copy2_exit
, ret
);
4298 extern "C" int rbd_copy_with_progress3(rbd_image_t image
, rados_ioctx_t dest_p
,
4299 const char *destname
,
4300 rbd_image_options_t dest_opts
,
4301 librbd_progress_fn_t fn
, void *data
)
4303 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4304 librados::IoCtx dest_io_ctx
;
4305 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4306 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
);
4307 librbd::ImageOptions
dest_opts_(dest_opts
);
4308 librbd::CProgressContext
prog_ctx(fn
, data
);
4309 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, dest_opts_
, prog_ctx
, 0);
4310 tracepoint(librbd
, copy3_exit
, ret
);
4314 extern "C" int rbd_copy_with_progress4(rbd_image_t image
, rados_ioctx_t dest_p
,
4315 const char *destname
,
4316 rbd_image_options_t dest_opts
,
4317 librbd_progress_fn_t fn
, void *data
, size_t sparse_size
)
4319 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4320 librados::IoCtx dest_io_ctx
;
4321 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4322 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
);
4323 librbd::ImageOptions
dest_opts_(dest_opts
);
4324 librbd::CProgressContext
prog_ctx(fn
, data
);
4325 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, dest_opts_
, prog_ctx
, sparse_size
);
4326 tracepoint(librbd
, copy4_exit
, ret
);
4330 extern "C" int rbd_deep_copy(rbd_image_t image
, rados_ioctx_t dest_p
,
4331 const char *destname
, rbd_image_options_t c_opts
)
4333 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4334 librados::IoCtx dest_io_ctx
;
4335 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4336 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
4337 ictx
->snap_name
.c_str(), ictx
->read_only
,
4338 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
4340 librbd::ImageOptions
opts(c_opts
);
4341 librbd::NoOpProgressContext prog_ctx
;
4342 int r
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
4344 tracepoint(librbd
, deep_copy_exit
, r
);
4348 extern "C" int rbd_deep_copy_with_progress(rbd_image_t image
,
4349 rados_ioctx_t dest_p
,
4350 const char *destname
,
4351 rbd_image_options_t dest_opts
,
4352 librbd_progress_fn_t fn
, void *data
)
4354 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4355 librados::IoCtx dest_io_ctx
;
4356 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4357 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
4358 ictx
->snap_name
.c_str(), ictx
->read_only
,
4359 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
4360 destname
, dest_opts
);
4361 librbd::ImageOptions
opts(dest_opts
);
4362 librbd::CProgressContext
prog_ctx(fn
, data
);
4363 int ret
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
4365 tracepoint(librbd
, deep_copy_exit
, ret
);
4369 extern "C" int rbd_encryption_format(rbd_image_t image
,
4370 rbd_encryption_format_t format
,
4371 rbd_encryption_options_t opts
,
4374 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4375 return librbd::api::Image
<>::encryption_format(
4376 ictx
, format
, opts
, opts_size
, true);
4379 extern "C" int rbd_encryption_load(rbd_image_t image
,
4380 rbd_encryption_format_t format
,
4381 rbd_encryption_options_t opts
,
4384 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4385 return librbd::api::Image
<>::encryption_load(
4386 ictx
, format
, opts
, opts_size
, true);
4389 extern "C" int rbd_flatten(rbd_image_t image
)
4391 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4392 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4393 librbd::NoOpProgressContext prog_ctx
;
4394 int r
= ictx
->operations
->flatten(prog_ctx
);
4395 tracepoint(librbd
, flatten_exit
, r
);
4399 extern "C" int rbd_flatten_with_progress(rbd_image_t image
,
4400 librbd_progress_fn_t cb
, void *cbdata
)
4402 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4403 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4404 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4405 int r
= ictx
->operations
->flatten(prog_ctx
);
4406 tracepoint(librbd
, flatten_exit
, r
);
4410 extern "C" int rbd_sparsify(rbd_image_t image
, size_t sparse_size
)
4412 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4413 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
4415 librbd::NoOpProgressContext prog_ctx
;
4416 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
4417 tracepoint(librbd
, sparsify_exit
, r
);
4421 extern "C" int rbd_sparsify_with_progress(rbd_image_t image
, size_t sparse_size
,
4422 librbd_progress_fn_t cb
, void *cbdata
)
4424 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4425 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
4427 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4428 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
4429 tracepoint(librbd
, sparsify_exit
, r
);
4433 extern "C" int rbd_rename(rados_ioctx_t src_p
, const char *srcname
,
4434 const char *destname
)
4436 librados::IoCtx src_io_ctx
;
4437 librados::IoCtx::from_rados_ioctx_t(src_p
, src_io_ctx
);
4438 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(src_io_ctx
));
4439 tracepoint(librbd
, rename_enter
, src_io_ctx
.get_pool_name().c_str(), src_io_ctx
.get_id(), srcname
, destname
);
4440 int r
= librbd::rename(src_io_ctx
, srcname
, destname
);
4441 tracepoint(librbd
, rename_exit
, r
);
4445 extern "C" int rbd_migration_prepare(rados_ioctx_t p
, const char *image_name
,
4446 rados_ioctx_t dest_p
,
4447 const char *dest_image_name
,
4448 rbd_image_options_t opts_
)
4450 librados::IoCtx io_ctx
;
4451 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4452 librados::IoCtx dest_io_ctx
;
4453 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4454 tracepoint(librbd
, migration_prepare_enter
, io_ctx
.get_pool_name().c_str(),
4455 io_ctx
.get_id(), image_name
, dest_io_ctx
.get_pool_name().c_str(),
4456 dest_io_ctx
.get_id(), dest_image_name
, opts_
);
4457 librbd::ImageOptions
opts(opts_
);
4458 int r
= librbd::api::Migration
<>::prepare(io_ctx
, image_name
, dest_io_ctx
,
4459 dest_image_name
, opts
);
4460 tracepoint(librbd
, migration_prepare_exit
, r
);
4464 extern "C" int rbd_migration_prepare_import(
4465 const char *source_spec
, rados_ioctx_t dest_p
,
4466 const char *dest_image_name
, rbd_image_options_t opts_
) {
4467 librados::IoCtx dest_io_ctx
;
4468 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4469 librbd::ImageOptions
opts(opts_
);
4470 return librbd::api::Migration
<>::prepare_import(source_spec
, dest_io_ctx
,
4471 dest_image_name
, opts
);
4474 extern "C" int rbd_migration_execute(rados_ioctx_t p
, const char *image_name
)
4476 librados::IoCtx io_ctx
;
4477 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4478 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4479 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
4480 io_ctx
.get_id(), image_name
);
4481 librbd::NoOpProgressContext prog_ctx
;
4482 int r
= librbd::api::Migration
<>::execute(io_ctx
, image_name
, prog_ctx
);
4483 tracepoint(librbd
, migration_execute_exit
, r
);
4487 extern "C" int rbd_migration_execute_with_progress(rados_ioctx_t p
,
4489 librbd_progress_fn_t fn
,
4492 librados::IoCtx io_ctx
;
4493 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4494 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4495 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
4496 io_ctx
.get_id(), name
);
4497 librbd::CProgressContext
prog_ctx(fn
, data
);
4498 int r
= librbd::api::Migration
<>::execute(io_ctx
, name
, prog_ctx
);
4499 tracepoint(librbd
, migration_execute_exit
, r
);
4503 extern "C" int rbd_migration_abort(rados_ioctx_t p
, const char *image_name
)
4505 librados::IoCtx io_ctx
;
4506 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4507 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4508 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
4509 io_ctx
.get_id(), image_name
);
4510 librbd::NoOpProgressContext prog_ctx
;
4511 int r
= librbd::api::Migration
<>::abort(io_ctx
, image_name
, prog_ctx
);
4512 tracepoint(librbd
, migration_abort_exit
, r
);
4516 extern "C" int rbd_migration_abort_with_progress(rados_ioctx_t p
,
4518 librbd_progress_fn_t fn
,
4521 librados::IoCtx io_ctx
;
4522 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4523 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4524 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
4525 io_ctx
.get_id(), name
);
4526 librbd::CProgressContext
prog_ctx(fn
, data
);
4527 int r
= librbd::api::Migration
<>::abort(io_ctx
, name
, prog_ctx
);
4528 tracepoint(librbd
, migration_abort_exit
, r
);
4532 extern "C" int rbd_migration_commit(rados_ioctx_t p
, const char *image_name
)
4534 librados::IoCtx io_ctx
;
4535 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4536 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4537 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
4538 io_ctx
.get_id(), image_name
);
4539 librbd::NoOpProgressContext prog_ctx
;
4540 int r
= librbd::api::Migration
<>::commit(io_ctx
, image_name
, prog_ctx
);
4541 tracepoint(librbd
, migration_commit_exit
, r
);
4545 extern "C" int rbd_migration_commit_with_progress(rados_ioctx_t p
,
4547 librbd_progress_fn_t fn
,
4550 librados::IoCtx io_ctx
;
4551 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4552 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4553 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
4554 io_ctx
.get_id(), name
);
4555 librbd::CProgressContext
prog_ctx(fn
, data
);
4556 int r
= librbd::api::Migration
<>::commit(io_ctx
, name
, prog_ctx
);
4557 tracepoint(librbd
, migration_commit_exit
, r
);
4561 extern "C" int rbd_migration_status(rados_ioctx_t p
, const char *image_name
,
4562 rbd_image_migration_status_t
*status
,
4565 librados::IoCtx io_ctx
;
4566 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4567 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4568 tracepoint(librbd
, migration_status_enter
, io_ctx
.get_pool_name().c_str(),
4569 io_ctx
.get_id(), image_name
);
4571 if (status_size
!= sizeof(rbd_image_migration_status_t
)) {
4572 tracepoint(librbd
, migration_status_exit
, -ERANGE
);
4576 librbd::image_migration_status_t cpp_status
;
4577 int r
= librbd::api::Migration
<>::status(io_ctx
, image_name
, &cpp_status
);
4579 status
->source_pool_id
= cpp_status
.source_pool_id
;
4580 status
->source_pool_namespace
=
4581 strdup(cpp_status
.source_pool_namespace
.c_str());
4582 status
->source_image_name
= strdup(cpp_status
.source_image_name
.c_str());
4583 status
->source_image_id
= strdup(cpp_status
.source_image_id
.c_str());
4584 status
->dest_pool_id
= cpp_status
.dest_pool_id
;
4585 status
->dest_pool_namespace
=
4586 strdup(cpp_status
.dest_pool_namespace
.c_str());
4587 status
->dest_image_name
= strdup(cpp_status
.dest_image_name
.c_str());
4588 status
->dest_image_id
= strdup(cpp_status
.dest_image_id
.c_str());
4589 status
->state
= cpp_status
.state
;
4590 status
->state_description
= strdup(cpp_status
.state_description
.c_str());
4593 tracepoint(librbd
, migration_status_exit
, r
);
4597 extern "C" void rbd_migration_status_cleanup(rbd_image_migration_status_t
*s
)
4599 free(s
->source_pool_namespace
);
4600 free(s
->source_image_name
);
4601 free(s
->source_image_id
);
4602 free(s
->dest_pool_namespace
);
4603 free(s
->dest_image_name
);
4604 free(s
->dest_image_id
);
4605 free(s
->state_description
);
4608 extern "C" int rbd_pool_metadata_get(rados_ioctx_t p
, const char *key
,
4609 char *value
, size_t *vallen
)
4611 librados::IoCtx io_ctx
;
4612 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4614 int r
= librbd::api::PoolMetadata
<>::get(io_ctx
, key
, &val_s
);
4615 if (*vallen
< val_s
.size() + 1) {
4617 *vallen
= val_s
.size() + 1;
4619 strncpy(value
, val_s
.c_str(), val_s
.size() + 1);
4625 extern "C" int rbd_pool_metadata_set(rados_ioctx_t p
, const char *key
,
4628 librados::IoCtx io_ctx
;
4629 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4630 int r
= librbd::api::PoolMetadata
<>::set(io_ctx
, key
, value
);
4634 extern "C" int rbd_pool_metadata_remove(rados_ioctx_t p
, const char *key
)
4636 librados::IoCtx io_ctx
;
4637 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4638 int r
= librbd::api::PoolMetadata
<>::remove(io_ctx
, key
);
4642 extern "C" int rbd_pool_metadata_list(rados_ioctx_t p
, const char *start
,
4643 uint64_t max
, char *key
, size_t *key_len
,
4644 char *value
, size_t *val_len
)
4646 librados::IoCtx io_ctx
;
4647 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4648 map
<string
, bufferlist
> pairs
;
4649 int r
= librbd::api::PoolMetadata
<>::list(io_ctx
, start
, max
, &pairs
);
4653 size_t key_total_len
= 0, val_total_len
= 0;
4654 for (auto &it
: pairs
) {
4655 key_total_len
+= it
.first
.size() + 1;
4656 val_total_len
+= it
.second
.length() + 1;
4658 if (*key_len
< key_total_len
|| *val_len
< val_total_len
) {
4659 *key_len
= key_total_len
;
4660 *val_len
= val_total_len
;
4663 *key_len
= key_total_len
;
4664 *val_len
= val_total_len
;
4666 char *key_p
= key
, *value_p
= value
;
4667 for (auto &it
: pairs
) {
4668 strncpy(key_p
, it
.first
.c_str(), it
.first
.size() + 1);
4669 key_p
+= it
.first
.size() + 1;
4670 strncpy(value_p
, it
.second
.c_str(), it
.second
.length());
4671 value_p
+= it
.second
.length();
4678 extern "C" int rbd_config_pool_list(rados_ioctx_t p
,
4679 rbd_config_option_t
*options
,
4681 librados::IoCtx io_ctx
;
4682 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4684 std::vector
<librbd::config_option_t
> option_vector
;
4685 int r
= librbd::api::Config
<>::list(io_ctx
, &option_vector
);
4690 if (*max_options
< static_cast<int>(option_vector
.size())) {
4691 *max_options
= static_cast<int>(option_vector
.size());
4695 for (int i
= 0; i
< static_cast<int>(option_vector
.size()); ++i
) {
4696 config_option_cpp_to_c(option_vector
[i
], &options
[i
]);
4698 *max_options
= static_cast<int>(option_vector
.size());
4702 extern "C" void rbd_config_pool_list_cleanup(rbd_config_option_t
*options
,
4704 for (int i
= 0; i
< max_options
; ++i
) {
4705 config_option_cleanup(options
[i
]);
4709 extern "C" int rbd_open(rados_ioctx_t p
, const char *name
, rbd_image_t
*image
,
4710 const char *snap_name
)
4712 librados::IoCtx io_ctx
;
4713 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4714 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4715 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4717 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4719 int r
= ictx
->state
->open(0);
4721 *image
= (rbd_image_t
)ictx
;
4723 tracepoint(librbd
, open_image_exit
, r
);
4727 extern "C" int rbd_open_by_id(rados_ioctx_t p
, const char *id
,
4728 rbd_image_t
*image
, const char *snap_name
)
4730 librados::IoCtx io_ctx
;
4731 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4732 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4733 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4735 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(),
4736 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4738 int r
= ictx
->state
->open(0);
4740 *image
= (rbd_image_t
)ictx
;
4742 tracepoint(librbd
, open_image_exit
, r
);
4746 extern "C" int rbd_aio_open(rados_ioctx_t p
, const char *name
,
4747 rbd_image_t
*image
, const char *snap_name
,
4750 librados::IoCtx io_ctx
;
4751 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4752 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4753 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4755 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4756 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
);
4757 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4759 tracepoint(librbd
, aio_open_image_exit
, 0);
4763 extern "C" int rbd_aio_open_by_id(rados_ioctx_t p
, const char *id
,
4764 rbd_image_t
*image
, const char *snap_name
,
4767 librados::IoCtx io_ctx
;
4768 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4769 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4770 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4772 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4773 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(),
4774 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
,
4776 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4778 tracepoint(librbd
, aio_open_image_exit
, 0);
4782 extern "C" int rbd_open_read_only(rados_ioctx_t p
, const char *name
,
4783 rbd_image_t
*image
, const char *snap_name
)
4785 librados::IoCtx io_ctx
;
4786 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4787 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4788 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4790 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4792 int r
= ictx
->state
->open(0);
4794 *image
= (rbd_image_t
)ictx
;
4796 tracepoint(librbd
, open_image_exit
, r
);
4800 extern "C" int rbd_open_by_id_read_only(rados_ioctx_t p
, const char *id
,
4801 rbd_image_t
*image
, const char *snap_name
)
4803 librados::IoCtx io_ctx
;
4804 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4805 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4806 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4808 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(),
4809 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4811 int r
= ictx
->state
->open(0);
4813 *image
= (rbd_image_t
)ictx
;
4815 tracepoint(librbd
, open_image_exit
, r
);
4819 extern "C" int rbd_aio_open_read_only(rados_ioctx_t p
, const char *name
,
4820 rbd_image_t
*image
, const char *snap_name
,
4823 librados::IoCtx io_ctx
;
4824 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4825 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4826 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4828 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4829 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
);
4830 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4832 tracepoint(librbd
, aio_open_image_exit
, 0);
4836 extern "C" int rbd_aio_open_by_id_read_only(rados_ioctx_t p
, const char *id
,
4838 const char *snap_name
,
4841 librados::IoCtx io_ctx
;
4842 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4843 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4844 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4846 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4847 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(),
4848 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
4849 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4851 tracepoint(librbd
, aio_open_image_exit
, 0);
4855 extern "C" int rbd_features_to_string(uint64_t features
, char *str_features
, size_t *size
)
4857 std::stringstream err
;
4858 std::string get_str_features
= librbd::rbd_features_to_string(features
, &err
);
4859 if (!err
.str().empty()) {
4862 uint64_t expected_size
= get_str_features
.size();
4863 if (*size
<= expected_size
) {
4864 *size
= expected_size
+ 1;
4867 strncpy(str_features
, get_str_features
.c_str(), expected_size
);
4868 str_features
[expected_size
] = '\0';
4869 *size
= expected_size
+ 1;
4873 extern "C" int rbd_features_from_string(const char *str_features
, uint64_t *features
)
4875 std::stringstream err
;
4876 *features
= librbd::rbd_features_from_string(str_features
, &err
);
4877 if (!err
.str().empty()) {
4884 extern "C" int rbd_close(rbd_image_t image
)
4886 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4887 tracepoint(librbd
, close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4889 int r
= ictx
->state
->close();
4891 tracepoint(librbd
, close_image_exit
, r
);
4895 extern "C" int rbd_aio_close(rbd_image_t image
, rbd_completion_t c
)
4897 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4898 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4899 tracepoint(librbd
, aio_close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), comp
->pc
);
4900 ictx
->state
->close(new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_CLOSE
,
4901 get_aio_completion(comp
)));
4902 tracepoint(librbd
, aio_close_image_exit
, 0);
4906 extern "C" int rbd_resize(rbd_image_t image
, uint64_t size
)
4908 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4909 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4910 librbd::NoOpProgressContext prog_ctx
;
4911 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
4912 tracepoint(librbd
, resize_exit
, r
);
4916 extern "C" int rbd_resize2(rbd_image_t image
, uint64_t size
, bool allow_shrink
,
4917 librbd_progress_fn_t cb
, void *cbdata
)
4919 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4920 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4921 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4922 int r
= ictx
->operations
->resize(size
, allow_shrink
, prog_ctx
);
4923 tracepoint(librbd
, resize_exit
, r
);
4927 extern "C" int rbd_resize_with_progress(rbd_image_t image
, uint64_t size
,
4928 librbd_progress_fn_t cb
, void *cbdata
)
4930 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4931 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4932 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4933 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
4934 tracepoint(librbd
, resize_exit
, r
);
4938 extern "C" int rbd_stat(rbd_image_t image
, rbd_image_info_t
*info
,
4941 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4942 tracepoint(librbd
, stat_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4943 int r
= librbd::info(ictx
, *info
, infosize
);
4944 tracepoint(librbd
, stat_exit
, r
, info
);
4948 extern "C" int rbd_get_old_format(rbd_image_t image
, uint8_t *old
)
4950 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4951 tracepoint(librbd
, get_old_format_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4952 int r
= librbd::get_old_format(ictx
, old
);
4953 tracepoint(librbd
, get_old_format_exit
, r
, *old
);
4957 extern "C" int rbd_get_size(rbd_image_t image
, uint64_t *size
)
4959 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4960 tracepoint(librbd
, get_size_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4961 int r
= librbd::get_size(ictx
, size
);
4962 tracepoint(librbd
, get_size_exit
, r
, *size
);
4966 extern "C" int rbd_get_features(rbd_image_t image
, uint64_t *features
)
4968 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4969 tracepoint(librbd
, get_features_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4970 int r
= librbd::get_features(ictx
, features
);
4971 tracepoint(librbd
, get_features_exit
, r
, *features
);
4975 extern "C" int rbd_update_features(rbd_image_t image
, uint64_t features
,
4978 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4979 bool features_enabled
= enabled
!= 0;
4980 tracepoint(librbd
, update_features_enter
, ictx
, features
, features_enabled
);
4981 int r
= ictx
->operations
->update_features(features
, features_enabled
);
4982 tracepoint(librbd
, update_features_exit
, r
);
4986 extern "C" int rbd_get_op_features(rbd_image_t image
, uint64_t *op_features
)
4988 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4989 return librbd::api::Image
<>::get_op_features(ictx
, op_features
);
4992 extern "C" int rbd_get_stripe_unit(rbd_image_t image
, uint64_t *stripe_unit
)
4994 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4995 tracepoint(librbd
, get_stripe_unit_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4996 *stripe_unit
= ictx
->get_stripe_unit();
4997 tracepoint(librbd
, get_stripe_unit_exit
, 0, *stripe_unit
);
5001 extern "C" int rbd_get_stripe_count(rbd_image_t image
, uint64_t *stripe_count
)
5003 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5004 tracepoint(librbd
, get_stripe_count_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
5005 *stripe_count
= ictx
->get_stripe_count();
5006 tracepoint(librbd
, get_stripe_count_exit
, 0, *stripe_count
);
5010 extern "C" int rbd_get_create_timestamp(rbd_image_t image
,
5011 struct timespec
*timestamp
)
5013 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5014 tracepoint(librbd
, get_create_timestamp_enter
, ictx
, ictx
->name
.c_str(),
5016 utime_t time
= ictx
->get_create_timestamp();
5017 time
.to_timespec(timestamp
);
5018 tracepoint(librbd
, get_create_timestamp_exit
, 0, timestamp
);
5022 extern "C" int rbd_get_access_timestamp(rbd_image_t image
,
5023 struct timespec
*timestamp
)
5025 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5026 tracepoint(librbd
, get_access_timestamp_enter
, ictx
, ictx
->name
.c_str(),
5028 utime_t time
= ictx
->get_access_timestamp();
5029 time
.to_timespec(timestamp
);
5030 tracepoint(librbd
, get_access_timestamp_exit
, 0, timestamp
);
5034 extern "C" int rbd_get_modify_timestamp(rbd_image_t image
,
5035 struct timespec
*timestamp
)
5037 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5038 tracepoint(librbd
, get_modify_timestamp_enter
, ictx
, ictx
->name
.c_str(),
5040 utime_t time
= ictx
->get_modify_timestamp();
5041 time
.to_timespec(timestamp
);
5042 tracepoint(librbd
, get_modify_timestamp_exit
, 0, timestamp
);
5047 extern "C" int rbd_get_overlap(rbd_image_t image
, uint64_t *overlap
)
5049 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5050 tracepoint(librbd
, get_overlap_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
5051 int r
= librbd::get_overlap(ictx
, overlap
);
5052 tracepoint(librbd
, get_overlap_exit
, r
, *overlap
);
5056 extern "C" int rbd_get_name(rbd_image_t image
, char *name
, size_t *name_len
)
5058 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5059 if (*name_len
<= ictx
->name
.size()) {
5060 *name_len
= ictx
->name
.size() + 1;
5064 strncpy(name
, ictx
->name
.c_str(), ictx
->name
.size());
5065 name
[ictx
->name
.size()] = '\0';
5066 *name_len
= ictx
->name
.size() + 1;
5070 extern "C" int rbd_get_id(rbd_image_t image
, char *id
, size_t id_len
)
5072 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5073 if (ictx
->old_format
) {
5076 if (ictx
->id
.size() >= id_len
) {
5080 strncpy(id
, ictx
->id
.c_str(), id_len
- 1);
5081 id
[id_len
- 1] = '\0';
5085 extern "C" int rbd_get_block_name_prefix(rbd_image_t image
, char *prefix
,
5088 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5089 if (ictx
->object_prefix
.size() >= prefix_len
) {
5093 strncpy(prefix
, ictx
->object_prefix
.c_str(), prefix_len
- 1);
5094 prefix
[prefix_len
- 1] = '\0';
5098 extern "C" int64_t rbd_get_data_pool_id(rbd_image_t image
)
5100 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5101 return librbd::api::Image
<>::get_data_pool_id(ictx
);
5104 extern "C" int rbd_get_parent_info(rbd_image_t image
,
5105 char *parent_pool_name
, size_t ppool_namelen
,
5106 char *parent_name
, size_t pnamelen
,
5107 char *parent_snap_name
, size_t psnap_namelen
)
5109 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5110 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
5111 ictx
->snap_name
.c_str(), ictx
->read_only
);
5113 librbd::linked_image_spec_t parent_image
;
5114 librbd::snap_spec_t parent_snap
;
5115 int r
= librbd::api::Image
<>::get_parent(ictx
, &parent_image
, &parent_snap
);
5117 if (parent_pool_name
) {
5118 if (parent_image
.pool_name
.length() + 1 > ppool_namelen
) {
5121 strcpy(parent_pool_name
, parent_image
.pool_name
.c_str());
5125 if (parent_image
.image_name
.length() + 1 > pnamelen
) {
5128 strcpy(parent_name
, parent_image
.image_name
.c_str());
5131 if (parent_snap_name
) {
5132 if (parent_snap
.name
.length() + 1 > psnap_namelen
) {
5135 strcpy(parent_snap_name
, parent_snap
.name
.c_str());
5141 tracepoint(librbd
, get_parent_info_exit
, r
, NULL
, NULL
, NULL
, NULL
);
5145 tracepoint(librbd
, get_parent_info_exit
, r
,
5146 parent_image
.pool_name
.c_str(),
5147 parent_image
.image_name
.c_str(),
5148 parent_image
.image_id
.c_str(),
5149 parent_snap
.name
.c_str());
5153 extern "C" int rbd_get_parent_info2(rbd_image_t image
,
5154 char *parent_pool_name
,
5155 size_t ppool_namelen
,
5156 char *parent_name
, size_t pnamelen
,
5157 char *parent_id
, size_t pidlen
,
5158 char *parent_snap_name
,
5159 size_t psnap_namelen
)
5161 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5162 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
5163 ictx
->snap_name
.c_str(), ictx
->read_only
);
5165 librbd::linked_image_spec_t parent_image
;
5166 librbd::snap_spec_t parent_snap
;
5167 int r
= librbd::api::Image
<>::get_parent(ictx
, &parent_image
, &parent_snap
);
5169 if (parent_pool_name
) {
5170 if (parent_image
.pool_name
.length() + 1 > ppool_namelen
) {
5173 strcpy(parent_pool_name
, parent_image
.pool_name
.c_str());
5177 if (parent_image
.image_name
.length() + 1 > pnamelen
) {
5180 strcpy(parent_name
, parent_image
.image_name
.c_str());
5184 if (parent_image
.image_id
.length() + 1 > pidlen
) {
5187 strcpy(parent_id
, parent_image
.image_id
.c_str());
5190 if (parent_snap_name
) {
5191 if (parent_snap
.name
.length() + 1 > psnap_namelen
) {
5194 strcpy(parent_snap_name
, parent_snap
.name
.c_str());
5200 tracepoint(librbd
, get_parent_info_exit
, r
, NULL
, NULL
, NULL
, NULL
);
5204 tracepoint(librbd
, get_parent_info_exit
, r
,
5205 parent_image
.pool_name
.c_str(),
5206 parent_image
.image_name
.c_str(),
5207 parent_image
.image_id
.c_str(),
5208 parent_snap
.name
.c_str());
5212 extern "C" int rbd_get_parent(rbd_image_t image
,
5213 rbd_linked_image_spec_t
*parent_image
,
5214 rbd_snap_spec_t
*parent_snap
)
5216 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5217 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
5218 ictx
->snap_name
.c_str(), ictx
->read_only
);
5220 librbd::linked_image_spec_t cpp_parent_image
;
5221 librbd::snap_spec_t cpp_parent_snap
;
5222 int r
= librbd::api::Image
<>::get_parent(ictx
, &cpp_parent_image
,
5225 // FIPS zeroization audit 20191117: these memsets are not security related.
5226 memset(parent_image
, 0, sizeof(rbd_linked_image_spec_t
));
5227 memset(parent_snap
, 0, sizeof(rbd_snap_spec_t
));
5230 .pool_id
= cpp_parent_image
.pool_id
,
5231 .pool_name
= strdup(cpp_parent_image
.pool_name
.c_str()),
5232 .pool_namespace
= strdup(cpp_parent_image
.pool_namespace
.c_str()),
5233 .image_id
= strdup(cpp_parent_image
.image_id
.c_str()),
5234 .image_name
= strdup(cpp_parent_image
.image_name
.c_str()),
5235 .trash
= cpp_parent_image
.trash
};
5237 .id
= cpp_parent_snap
.id
,
5238 .namespace_type
= cpp_parent_snap
.namespace_type
,
5239 .name
= strdup(cpp_parent_snap
.name
.c_str())};
5242 tracepoint(librbd
, get_parent_info_exit
, r
,
5243 parent_image
->pool_name
,
5244 parent_image
->image_name
,
5245 parent_image
->image_id
,
5250 extern "C" int rbd_get_migration_source_spec(rbd_image_t image
,
5254 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5256 std::string cpp_source_spec
;
5257 int r
= librbd::api::Migration
<>::get_source_spec(ictx
, &cpp_source_spec
);
5262 size_t expected_size
= cpp_source_spec
.size();
5263 if (expected_size
>= *max_len
) {
5264 *max_len
= expected_size
+ 1;
5268 strncpy(source_spec
, cpp_source_spec
.c_str(), expected_size
);
5269 source_spec
[expected_size
] = '\0';
5270 *max_len
= expected_size
+ 1;
5275 extern "C" int rbd_get_flags(rbd_image_t image
, uint64_t *flags
)
5277 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5278 tracepoint(librbd
, get_flags_enter
, ictx
);
5279 int r
= librbd::get_flags(ictx
, flags
);
5280 tracepoint(librbd
, get_flags_exit
, ictx
, r
, *flags
);
5284 extern "C" int rbd_get_group(rbd_image_t image
, rbd_group_info_t
*group_info
,
5285 size_t group_info_size
)
5287 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5288 tracepoint(librbd
, image_get_group_enter
, ictx
->name
.c_str());
5290 if (group_info_size
!= sizeof(rbd_group_info_t
)) {
5291 tracepoint(librbd
, image_get_group_exit
, -ERANGE
);
5295 librbd::group_info_t cpp_group_info
;
5296 int r
= librbd::api::Group
<>::image_get_group(ictx
, &cpp_group_info
);
5298 group_info_cpp_to_c(cpp_group_info
, group_info
);
5300 group_info
->name
= NULL
;
5303 tracepoint(librbd
, image_get_group_exit
, r
);
5307 extern "C" int rbd_set_image_notification(rbd_image_t image
, int fd
, int type
)
5309 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5310 tracepoint(librbd
, set_image_notification_enter
, ictx
, fd
, type
);
5311 int r
= librbd::set_image_notification(ictx
, fd
, type
);
5312 tracepoint(librbd
, set_image_notification_exit
, ictx
, r
);
5316 extern "C" int rbd_is_exclusive_lock_owner(rbd_image_t image
, int *is_owner
)
5318 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5319 tracepoint(librbd
, is_exclusive_lock_owner_enter
, ictx
);
5321 int r
= librbd::is_exclusive_lock_owner(ictx
, &owner
);
5322 *is_owner
= owner
? 1 : 0;
5323 tracepoint(librbd
, is_exclusive_lock_owner_exit
, ictx
, r
, *is_owner
);
5327 extern "C" int rbd_lock_acquire(rbd_image_t image
, rbd_lock_mode_t lock_mode
)
5329 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5330 tracepoint(librbd
, lock_acquire_enter
, ictx
, lock_mode
);
5331 int r
= librbd::lock_acquire(ictx
, lock_mode
);
5332 tracepoint(librbd
, lock_acquire_exit
, ictx
, r
);
5336 extern "C" int rbd_lock_release(rbd_image_t image
)
5338 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5339 tracepoint(librbd
, lock_release_enter
, ictx
);
5340 int r
= librbd::lock_release(ictx
);
5341 tracepoint(librbd
, lock_release_exit
, ictx
, r
);
5345 extern "C" int rbd_lock_get_owners(rbd_image_t image
,
5346 rbd_lock_mode_t
*lock_mode
,
5348 size_t *max_lock_owners
)
5350 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5351 tracepoint(librbd
, lock_get_owners_enter
, ictx
);
5352 // FIPS zeroization audit 20191117: this memset is not security related.
5353 memset(lock_owners
, 0, sizeof(*lock_owners
) * *max_lock_owners
);
5354 std::list
<std::string
> lock_owner_list
;
5355 int r
= librbd::lock_get_owners(ictx
, lock_mode
, &lock_owner_list
);
5357 if (*max_lock_owners
>= lock_owner_list
.size()) {
5358 *max_lock_owners
= 0;
5359 for (auto &lock_owner
: lock_owner_list
) {
5360 lock_owners
[(*max_lock_owners
)++] = strdup(lock_owner
.c_str());
5363 *max_lock_owners
= lock_owner_list
.size();
5367 tracepoint(librbd
, lock_get_owners_exit
, ictx
, r
);
5371 extern "C" void rbd_lock_get_owners_cleanup(char **lock_owners
,
5372 size_t lock_owner_count
)
5374 for (size_t i
= 0; i
< lock_owner_count
; ++i
) {
5375 free(lock_owners
[i
]);
5379 extern "C" int rbd_lock_break(rbd_image_t image
, rbd_lock_mode_t lock_mode
,
5380 const char *lock_owner
)
5382 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5383 tracepoint(librbd
, lock_break_enter
, ictx
, lock_mode
, lock_owner
);
5384 int r
= librbd::lock_break(ictx
, lock_mode
, lock_owner
);
5385 tracepoint(librbd
, lock_break_exit
, ictx
, r
);
5389 extern "C" int rbd_rebuild_object_map(rbd_image_t image
,
5390 librbd_progress_fn_t cb
, void *cbdata
)
5392 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5393 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5394 return ictx
->operations
->rebuild_object_map(prog_ctx
);
5398 extern "C" int rbd_snap_create(rbd_image_t image
, const char *snap_name
)
5400 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5401 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5402 auto flags
= librbd::util::get_default_snap_create_flags(ictx
);
5403 librbd::NoOpProgressContext prog_ctx
;
5404 int r
= librbd::api::Snapshot
<>::create(ictx
, snap_name
, flags
, prog_ctx
);
5405 tracepoint(librbd
, snap_create_exit
, r
);
5409 extern "C" int rbd_snap_create2(rbd_image_t image
, const char *snap_name
,
5410 uint32_t flags
, librbd_progress_fn_t cb
,
5413 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5414 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5415 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5416 int r
= librbd::api::Snapshot
<>::create(ictx
, snap_name
, flags
, prog_ctx
);
5417 tracepoint(librbd
, snap_create_exit
, r
);
5421 extern "C" int rbd_snap_rename(rbd_image_t image
, const char *srcname
, const char *dstname
)
5423 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5424 tracepoint(librbd
, snap_rename_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, srcname
, dstname
);
5425 int r
= ictx
->operations
->snap_rename(srcname
, dstname
);
5426 tracepoint(librbd
, snap_rename_exit
, r
);
5430 extern "C" int rbd_snap_remove(rbd_image_t image
, const char *snap_name
)
5432 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5433 tracepoint(librbd
, snap_remove_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5434 librbd::NoOpProgressContext prog_ctx
;
5435 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, 0, prog_ctx
);
5436 tracepoint(librbd
, snap_remove_exit
, r
);
5440 extern "C" int rbd_snap_remove2(rbd_image_t image
, const char *snap_name
, uint32_t flags
,
5441 librbd_progress_fn_t cb
, void *cbdata
)
5443 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5444 tracepoint(librbd
, snap_remove2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
, flags
);
5445 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5446 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, flags
, prog_ctx
);
5447 tracepoint(librbd
, snap_remove_exit
, r
);
5451 extern "C" int rbd_snap_remove_by_id(rbd_image_t image
, uint64_t snap_id
)
5453 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5454 return librbd::api::Snapshot
<>::remove(ictx
, snap_id
);
5457 extern "C" int rbd_snap_rollback(rbd_image_t image
, const char *snap_name
)
5459 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5460 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5461 librbd::NoOpProgressContext prog_ctx
;
5462 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
5463 tracepoint(librbd
, snap_rollback_exit
, r
);
5467 extern "C" int rbd_snap_rollback_with_progress(rbd_image_t image
,
5468 const char *snap_name
,
5469 librbd_progress_fn_t cb
,
5472 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5473 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5474 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5475 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
5476 tracepoint(librbd
, snap_rollback_exit
, r
);
5480 extern "C" int rbd_snap_list(rbd_image_t image
, rbd_snap_info_t
*snaps
,
5483 vector
<librbd::snap_info_t
> cpp_snaps
;
5484 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5485 tracepoint(librbd
, snap_list_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snaps
);
5488 tracepoint(librbd
, snap_list_exit
, -EINVAL
, 0);
5491 // FIPS zeroization audit 20191117: this memset is not security related.
5492 memset(snaps
, 0, sizeof(*snaps
) * *max_snaps
);
5494 int r
= librbd::api::Snapshot
<>::list(ictx
, cpp_snaps
);
5496 tracepoint(librbd
, snap_list_exit
, 0, *max_snaps
);
5500 tracepoint(librbd
, snap_list_exit
, r
, *max_snaps
);
5503 if (*max_snaps
< (int)cpp_snaps
.size() + 1) {
5504 *max_snaps
= (int)cpp_snaps
.size() + 1;
5505 tracepoint(librbd
, snap_list_exit
, -ERANGE
, *max_snaps
);
5511 for (i
= 0; i
< (int)cpp_snaps
.size(); i
++) {
5512 snaps
[i
].id
= cpp_snaps
[i
].id
;
5513 snaps
[i
].size
= cpp_snaps
[i
].size
;
5514 snaps
[i
].name
= strdup(cpp_snaps
[i
].name
.c_str());
5515 if (!snaps
[i
].name
) {
5516 for (int j
= 0; j
< i
; j
++)
5517 free((void *)snaps
[j
].name
);
5518 tracepoint(librbd
, snap_list_exit
, -ENOMEM
, *max_snaps
);
5521 tracepoint(librbd
, snap_list_entry
, snaps
[i
].id
, snaps
[i
].size
, snaps
[i
].name
);
5525 snaps
[i
].name
= NULL
;
5527 r
= (int)cpp_snaps
.size();
5528 tracepoint(librbd
, snap_list_exit
, r
, *max_snaps
);
5532 extern "C" void rbd_snap_list_end(rbd_snap_info_t
*snaps
)
5534 tracepoint(librbd
, snap_list_end_enter
, snaps
);
5535 while (snaps
->name
) {
5536 free((void *)snaps
->name
);
5539 tracepoint(librbd
, snap_list_end_exit
);
5542 extern "C" int rbd_snap_protect(rbd_image_t image
, const char *snap_name
)
5544 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5545 tracepoint(librbd
, snap_protect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5546 int r
= ictx
->operations
->snap_protect(cls::rbd::UserSnapshotNamespace(), snap_name
);
5547 tracepoint(librbd
, snap_protect_exit
, r
);
5551 extern "C" int rbd_snap_unprotect(rbd_image_t image
, const char *snap_name
)
5553 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5554 tracepoint(librbd
, snap_unprotect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5555 int r
= ictx
->operations
->snap_unprotect(cls::rbd::UserSnapshotNamespace(), snap_name
);
5556 tracepoint(librbd
, snap_unprotect_exit
, r
);
5560 extern "C" int rbd_snap_is_protected(rbd_image_t image
, const char *snap_name
,
5563 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5564 tracepoint(librbd
, snap_is_protected_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5565 bool protected_snap
;
5566 int r
= librbd::api::Snapshot
<>::is_protected(ictx
, snap_name
, &protected_snap
);
5568 tracepoint(librbd
, snap_is_protected_exit
, r
, *is_protected
? 1 : 0);
5571 *is_protected
= protected_snap
? 1 : 0;
5572 tracepoint(librbd
, snap_is_protected_exit
, 0, *is_protected
? 1 : 0);
5576 extern "C" int rbd_snap_get_limit(rbd_image_t image
, uint64_t *limit
)
5578 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5579 tracepoint(librbd
, snap_get_limit_enter
, ictx
, ictx
->name
.c_str());
5580 int r
= librbd::api::Snapshot
<>::get_limit(ictx
, limit
);
5581 tracepoint(librbd
, snap_get_limit_exit
, r
, *limit
);
5585 extern "C" int rbd_snap_exists(rbd_image_t image
, const char *snapname
, bool *exists
)
5587 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5588 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
5589 ictx
->snap_name
.c_str(), ictx
->read_only
, snapname
);
5590 int r
= librbd::api::Snapshot
<>::exists(ictx
, cls::rbd::UserSnapshotNamespace(), snapname
, exists
);
5591 tracepoint(librbd
, snap_exists_exit
, r
, *exists
);
5595 extern "C" int rbd_snap_get_timestamp(rbd_image_t image
, uint64_t snap_id
, struct timespec
*timestamp
)
5597 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5598 tracepoint(librbd
, snap_get_timestamp_enter
, ictx
, ictx
->name
.c_str());
5599 int r
= librbd::api::Snapshot
<>::get_timestamp(ictx
, snap_id
, timestamp
);
5600 tracepoint(librbd
, snap_get_timestamp_exit
, r
);
5604 extern "C" int rbd_snap_set_limit(rbd_image_t image
, uint64_t limit
)
5606 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5607 tracepoint(librbd
, snap_set_limit_enter
, ictx
, ictx
->name
.c_str(), limit
);
5608 int r
= librbd::api::Snapshot
<>::set_limit(ictx
, limit
);
5609 tracepoint(librbd
, snap_set_limit_exit
, r
);
5613 extern "C" int rbd_snap_set(rbd_image_t image
, const char *snap_name
)
5615 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5616 tracepoint(librbd
, snap_set_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5617 int r
= librbd::api::Image
<>::snap_set(
5618 ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
);
5619 tracepoint(librbd
, snap_set_exit
, r
);
5623 extern "C" int rbd_snap_set_by_id(rbd_image_t image
, uint64_t snap_id
)
5625 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5626 return librbd::api::Image
<>::snap_set(ictx
, snap_id
);
5629 extern "C" int rbd_snap_get_name(rbd_image_t image
, uint64_t snap_id
, char *snapname
, size_t *name_len
)
5631 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5632 std::string snap_name
;
5633 int r
= librbd::api::Snapshot
<>::get_name(ictx
, snap_id
, &snap_name
);
5634 size_t expected_size
= snap_name
.size();
5635 if (*name_len
<= expected_size
) {
5636 *name_len
= expected_size
+ 1;
5639 strncpy(snapname
, snap_name
.c_str(), expected_size
);
5640 snapname
[expected_size
] = '\0';
5641 *name_len
= expected_size
+ 1;
5645 extern "C" int rbd_snap_get_id(rbd_image_t image
, const char *snapname
, uint64_t *snap_id
)
5647 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5648 return librbd::api::Snapshot
<>::get_id(ictx
, snapname
, snap_id
);
5651 extern "C" ssize_t
rbd_list_children(rbd_image_t image
, char *pools
,
5652 size_t *pools_len
, char *images
,
5655 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5656 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5657 ictx
->snap_name
.c_str(), ictx
->read_only
);
5659 std::vector
<librbd::linked_image_spec_t
> cpp_images
;
5660 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_images
);
5662 tracepoint(librbd
, list_children_exit
, r
);
5666 std::set
<std::pair
<std::string
, std::string
>> image_set
;
5667 for (auto& image
: cpp_images
) {
5669 image_set
.insert({image
.pool_name
, image
.image_name
});
5673 size_t pools_total
= 0;
5674 size_t images_total
= 0;
5675 for (auto it
: image_set
) {
5676 pools_total
+= it
.first
.length() + 1;
5677 images_total
+= it
.second
.length() + 1;
5680 bool too_short
= false;
5681 if (pools_total
> *pools_len
)
5683 if (images_total
> *images_len
)
5685 *pools_len
= pools_total
;
5686 *images_len
= images_total
;
5688 tracepoint(librbd
, list_children_exit
, -ERANGE
);
5692 char *pools_p
= pools
;
5693 char *images_p
= images
;
5694 for (auto it
: image_set
) {
5695 const char* pool
= it
.first
.c_str();
5696 strcpy(pools_p
, pool
);
5697 pools_p
+= it
.first
.length() + 1;
5698 const char* image
= it
.second
.c_str();
5699 strcpy(images_p
, image
);
5700 images_p
+= it
.second
.length() + 1;
5701 tracepoint(librbd
, list_children_entry
, pool
, image
);
5704 ssize_t ret
= image_set
.size();
5705 tracepoint(librbd
, list_children_exit
, ret
);
5709 extern "C" int rbd_list_children2(rbd_image_t image
,
5710 rbd_child_info_t
*children
,
5713 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5714 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5715 ictx
->snap_name
.c_str(), ictx
->read_only
);
5716 // FIPS zeroization audit 20191117: this memset is not security related.
5717 memset(children
, 0, sizeof(*children
) * *max_children
);
5719 if (!max_children
) {
5720 tracepoint(librbd
, list_children_exit
, -EINVAL
);
5724 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5725 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_children
);
5727 tracepoint(librbd
, list_children_exit
, r
);
5731 if (*max_children
< (int)cpp_children
.size() + 1) {
5732 *max_children
= (int)cpp_children
.size() + 1;
5733 tracepoint(librbd
, list_children_exit
, *max_children
);
5738 for (i
= 0; i
< (int)cpp_children
.size(); i
++) {
5739 children
[i
].pool_name
= strdup(cpp_children
[i
].pool_name
.c_str());
5740 children
[i
].image_name
= strdup(cpp_children
[i
].image_name
.c_str());
5741 children
[i
].image_id
= strdup(cpp_children
[i
].image_id
.c_str());
5742 children
[i
].trash
= cpp_children
[i
].trash
;
5743 tracepoint(librbd
, list_children_entry
, children
[i
].pool_name
,
5744 children
[i
].image_name
);
5746 children
[i
].pool_name
= NULL
;
5747 children
[i
].image_name
= NULL
;
5748 children
[i
].image_id
= NULL
;
5750 r
= (int)cpp_children
.size();
5751 tracepoint(librbd
, list_children_exit
, *max_children
);
5755 extern "C" void rbd_list_child_cleanup(rbd_child_info_t
*child
)
5757 free((void *)child
->pool_name
);
5758 free((void *)child
->image_name
);
5759 free((void *)child
->image_id
);
5762 extern "C" void rbd_list_children_cleanup(rbd_child_info_t
*children
,
5763 size_t num_children
)
5765 for (size_t i
=0; i
< num_children
; i
++) {
5766 free((void *)children
[i
].pool_name
);
5767 free((void *)children
[i
].image_name
);
5768 free((void *)children
[i
].image_id
);
5772 extern "C" int rbd_list_children3(rbd_image_t image
,
5773 rbd_linked_image_spec_t
*images
,
5776 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5777 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5778 ictx
->snap_name
.c_str(), ictx
->read_only
);
5779 // FIPS zeroization audit 20191117: this memset is not security related.
5780 memset(images
, 0, sizeof(*images
) * *max_images
);
5782 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5783 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_children
);
5785 tracepoint(librbd
, list_children_exit
, r
);
5789 if (*max_images
< cpp_children
.size()) {
5790 *max_images
= cpp_children
.size();
5794 *max_images
= cpp_children
.size();
5795 for (size_t idx
= 0; idx
< cpp_children
.size(); ++idx
) {
5797 .pool_id
= cpp_children
[idx
].pool_id
,
5798 .pool_name
= strdup(cpp_children
[idx
].pool_name
.c_str()),
5799 .pool_namespace
= strdup(cpp_children
[idx
].pool_namespace
.c_str()),
5800 .image_id
= strdup(cpp_children
[idx
].image_id
.c_str()),
5801 .image_name
= strdup(cpp_children
[idx
].image_name
.c_str()),
5802 .trash
= cpp_children
[idx
].trash
};
5803 tracepoint(librbd
, list_children_entry
, images
[idx
].pool_name
,
5804 images
[idx
].image_name
);
5809 extern "C" int rbd_list_descendants(rbd_image_t image
,
5810 rbd_linked_image_spec_t
*images
,
5813 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5814 // FIPS zeroization audit 20191117: this memset is not security related.
5815 memset(images
, 0, sizeof(*images
) * *max_images
);
5817 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5818 int r
= librbd::api::Image
<>::list_descendants(ictx
, {}, &cpp_children
);
5823 if (*max_images
< cpp_children
.size()) {
5824 *max_images
= cpp_children
.size();
5828 *max_images
= cpp_children
.size();
5829 for (size_t idx
= 0; idx
< cpp_children
.size(); ++idx
) {
5831 .pool_id
= cpp_children
[idx
].pool_id
,
5832 .pool_name
= strdup(cpp_children
[idx
].pool_name
.c_str()),
5833 .pool_namespace
= strdup(cpp_children
[idx
].pool_namespace
.c_str()),
5834 .image_id
= strdup(cpp_children
[idx
].image_id
.c_str()),
5835 .image_name
= strdup(cpp_children
[idx
].image_name
.c_str()),
5836 .trash
= cpp_children
[idx
].trash
};
5841 extern "C" ssize_t
rbd_list_lockers(rbd_image_t image
, int *exclusive
,
5842 char *tag
, size_t *tag_len
,
5843 char *clients
, size_t *clients_len
,
5844 char *cookies
, size_t *cookies_len
,
5845 char *addrs
, size_t *addrs_len
)
5847 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5848 tracepoint(librbd
, list_lockers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
5849 std::list
<librbd::locker_t
> lockers
;
5850 bool exclusive_bool
;
5853 int r
= list_lockers(ictx
, &lockers
, &exclusive_bool
, &tag_str
);
5855 tracepoint(librbd
, list_lockers_exit
, r
);
5859 ldout(ictx
->cct
, 20) << "list_lockers r = " << r
<< " lockers.size() = " << lockers
.size() << dendl
;
5861 *exclusive
= (int)exclusive_bool
;
5862 size_t clients_total
= 0;
5863 size_t cookies_total
= 0;
5864 size_t addrs_total
= 0;
5865 for (list
<librbd::locker_t
>::const_iterator it
= lockers
.begin();
5866 it
!= lockers
.end(); ++it
) {
5867 clients_total
+= it
->client
.length() + 1;
5868 cookies_total
+= it
->cookie
.length() + 1;
5869 addrs_total
+= it
->address
.length() + 1;
5872 bool too_short
= ((clients_total
> *clients_len
) ||
5873 (cookies_total
> *cookies_len
) ||
5874 (addrs_total
> *addrs_len
) ||
5875 (tag_str
.length() + 1 > *tag_len
));
5876 *clients_len
= clients_total
;
5877 *cookies_len
= cookies_total
;
5878 *addrs_len
= addrs_total
;
5879 *tag_len
= tag_str
.length() + 1;
5881 tracepoint(librbd
, list_lockers_exit
, -ERANGE
);
5885 strcpy(tag
, tag_str
.c_str());
5886 char *clients_p
= clients
;
5887 char *cookies_p
= cookies
;
5888 char *addrs_p
= addrs
;
5889 for (list
<librbd::locker_t
>::const_iterator it
= lockers
.begin();
5890 it
!= lockers
.end(); ++it
) {
5891 const char* client
= it
->client
.c_str();
5892 strcpy(clients_p
, client
);
5893 clients_p
+= it
->client
.length() + 1;
5894 const char* cookie
= it
->cookie
.c_str();
5895 strcpy(cookies_p
, cookie
);
5896 cookies_p
+= it
->cookie
.length() + 1;
5897 const char* address
= it
->address
.c_str();
5898 strcpy(addrs_p
, address
);
5899 addrs_p
+= it
->address
.length() + 1;
5900 tracepoint(librbd
, list_lockers_entry
, client
, cookie
, address
);
5903 ssize_t ret
= lockers
.size();
5904 tracepoint(librbd
, list_lockers_exit
, ret
);
5908 extern "C" int rbd_lock_exclusive(rbd_image_t image
, const char *cookie
)
5910 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5911 tracepoint(librbd
, lock_exclusive_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
);
5912 int r
= librbd::lock(ictx
, true, cookie
? cookie
: "", "");
5913 tracepoint(librbd
, lock_exclusive_exit
, r
);
5917 extern "C" int rbd_lock_shared(rbd_image_t image
, const char *cookie
,
5920 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5921 tracepoint(librbd
, lock_shared_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
, tag
);
5922 int r
= librbd::lock(ictx
, false, cookie
? cookie
: "", tag
? tag
: "");
5923 tracepoint(librbd
, lock_shared_exit
, r
);
5927 extern "C" int rbd_unlock(rbd_image_t image
, const char *cookie
)
5929 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5930 tracepoint(librbd
, unlock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
);
5931 int r
= librbd::unlock(ictx
, cookie
? cookie
: "");
5932 tracepoint(librbd
, unlock_exit
, r
);
5936 extern "C" int rbd_break_lock(rbd_image_t image
, const char *client
,
5939 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5940 tracepoint(librbd
, break_lock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, client
, cookie
);
5941 int r
= librbd::break_lock(ictx
, client
, cookie
? cookie
: "");
5942 tracepoint(librbd
, break_lock_exit
, r
);
5947 extern "C" ssize_t
rbd_read(rbd_image_t image
, uint64_t ofs
, size_t len
,
5950 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5951 tracepoint(librbd
, read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5952 int r
= librbd::api::Io
<>::read(
5953 *ictx
, ofs
, len
, librbd::io::ReadResult
{buf
, len
}, 0);
5954 tracepoint(librbd
, read_exit
, r
);
5958 extern "C" ssize_t
rbd_read2(rbd_image_t image
, uint64_t ofs
, size_t len
,
5959 char *buf
, int op_flags
)
5961 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5962 tracepoint(librbd
, read2_enter
, ictx
, ictx
->name
.c_str(),
5963 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, op_flags
);
5964 int r
= librbd::api::Io
<>::read(
5965 *ictx
, ofs
, len
, librbd::io::ReadResult
{buf
, len
}, op_flags
);
5966 tracepoint(librbd
, read_exit
, r
);
5971 extern "C" int64_t rbd_read_iterate(rbd_image_t image
, uint64_t ofs
, size_t len
,
5972 int (*cb
)(uint64_t, size_t, const char *, void *),
5975 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5976 tracepoint(librbd
, read_iterate_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5977 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
5978 tracepoint(librbd
, read_iterate_exit
, r
);
5982 extern "C" int rbd_read_iterate2(rbd_image_t image
, uint64_t ofs
, uint64_t len
,
5983 int (*cb
)(uint64_t, size_t, const char *, void *),
5986 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5987 tracepoint(librbd
, read_iterate2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5988 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
5991 tracepoint(librbd
, read_iterate2_exit
, r
);
5995 extern "C" int rbd_diff_iterate(rbd_image_t image
,
5996 const char *fromsnapname
,
5997 uint64_t ofs
, uint64_t len
,
5998 int (*cb
)(uint64_t, size_t, int, void *),
6001 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6002 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
6003 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
6005 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
6006 cls::rbd::UserSnapshotNamespace(),
6007 fromsnapname
, ofs
, len
,
6008 true, false, cb
, arg
);
6009 tracepoint(librbd
, diff_iterate_exit
, r
);
6013 extern "C" int rbd_diff_iterate2(rbd_image_t image
, const char *fromsnapname
,
6014 uint64_t ofs
, uint64_t len
,
6015 uint8_t include_parent
, uint8_t whole_object
,
6016 int (*cb
)(uint64_t, size_t, int, void *),
6019 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6020 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
6021 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
6022 include_parent
!= 0, whole_object
!= 0);
6023 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
6024 cls::rbd::UserSnapshotNamespace(),
6025 fromsnapname
, ofs
, len
,
6026 include_parent
, whole_object
,
6028 tracepoint(librbd
, diff_iterate_exit
, r
);
6032 extern "C" ssize_t
rbd_write(rbd_image_t image
, uint64_t ofs
, size_t len
,
6035 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6036 tracepoint(librbd
, write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, buf
);
6039 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
6040 int r
= librbd::api::Io
<>::write(*ictx
, ofs
, len
, std::move(bl
), 0);
6041 tracepoint(librbd
, write_exit
, r
);
6045 extern "C" ssize_t
rbd_write2(rbd_image_t image
, uint64_t ofs
, size_t len
,
6046 const char *buf
, int op_flags
)
6048 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6049 tracepoint(librbd
, write2_enter
, ictx
, ictx
->name
.c_str(),
6050 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, buf
, op_flags
);
6053 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
6054 int r
= librbd::api::Io
<>::write(*ictx
, ofs
, len
, std::move(bl
), op_flags
);
6055 tracepoint(librbd
, write_exit
, r
);
6060 extern "C" int rbd_discard(rbd_image_t image
, uint64_t ofs
, uint64_t len
)
6062 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6063 tracepoint(librbd
, discard_enter
, ictx
, ictx
->name
.c_str(),
6064 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
6065 if (len
> static_cast<uint64_t>(std::numeric_limits
<int>::max())) {
6066 tracepoint(librbd
, discard_exit
, -EINVAL
);
6070 int r
= librbd::api::Io
<>::discard(
6071 *ictx
, ofs
, len
, ictx
->discard_granularity_bytes
);
6072 tracepoint(librbd
, discard_exit
, r
);
6076 extern "C" ssize_t
rbd_writesame(rbd_image_t image
, uint64_t ofs
, size_t len
,
6077 const char *buf
, size_t data_len
, int op_flags
)
6079 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6080 tracepoint(librbd
, writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6081 ictx
->read_only
, ofs
, len
, data_len
== 0 ? NULL
: buf
, data_len
, op_flags
);
6083 if (data_len
== 0 || len
% data_len
||
6084 len
> static_cast<uint64_t>(std::numeric_limits
<int>::max())) {
6085 tracepoint(librbd
, writesame_exit
, -EINVAL
);
6089 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
6090 if (discard_zero
&& mem_is_zero(buf
, data_len
)) {
6091 int r
= librbd::api::Io
<>::write_zeroes(*ictx
, ofs
, len
, 0, op_flags
);
6092 tracepoint(librbd
, writesame_exit
, r
);
6097 bl
.push_back(create_write_raw(ictx
, buf
, data_len
, nullptr));
6098 int r
= librbd::api::Io
<>::write_same(
6099 *ictx
, ofs
, len
, std::move(bl
), op_flags
);
6100 tracepoint(librbd
, writesame_exit
, r
);
6104 extern "C" ssize_t
rbd_write_zeroes(rbd_image_t image
, uint64_t ofs
, size_t len
,
6105 int zero_flags
, int op_flags
)
6107 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6108 return librbd::api::Io
<>::write_zeroes(*ictx
, ofs
, len
, zero_flags
, op_flags
);
6111 extern "C" ssize_t
rbd_compare_and_write(rbd_image_t image
,
6112 uint64_t ofs
, size_t len
,
6113 const char *cmp_buf
,
6115 uint64_t *mismatch_off
,
6118 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6119 tracepoint(librbd
, compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
6120 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
,
6121 len
, cmp_buf
, buf
, op_flags
);
6124 cmp_bl
.push_back(create_write_raw(ictx
, cmp_buf
, len
, nullptr));
6126 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
6128 int r
= librbd::api::Io
<>::compare_and_write(
6129 *ictx
, ofs
, len
, std::move(cmp_bl
), std::move(bl
), mismatch_off
, op_flags
);
6130 tracepoint(librbd
, compare_and_write_exit
, r
);
6134 extern "C" int rbd_aio_create_completion(void *cb_arg
,
6135 rbd_callback_t complete_cb
,
6136 rbd_completion_t
*c
)
6138 librbd::RBD::AioCompletion
*rbd_comp
=
6139 new librbd::RBD::AioCompletion(cb_arg
, complete_cb
);
6140 *c
= (rbd_completion_t
) rbd_comp
;
6144 extern "C" int rbd_aio_write(rbd_image_t image
, uint64_t off
, size_t len
,
6145 const char *buf
, rbd_completion_t c
)
6147 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6148 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6149 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, buf
, comp
->pc
);
6151 auto aio_completion
= get_aio_completion(comp
);
6153 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
6154 librbd::api::Io
<>::aio_write(
6155 *ictx
, aio_completion
, off
, len
, std::move(bl
), 0, true);
6156 tracepoint(librbd
, aio_write_exit
, 0);
6160 extern "C" int rbd_aio_write2(rbd_image_t image
, uint64_t off
, size_t len
,
6161 const char *buf
, rbd_completion_t c
, int op_flags
)
6163 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6164 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6165 tracepoint(librbd
, aio_write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6166 ictx
->read_only
, off
, len
, buf
, comp
->pc
, op_flags
);
6168 auto aio_completion
= get_aio_completion(comp
);
6170 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
6171 librbd::api::Io
<>::aio_write(
6172 *ictx
, aio_completion
, off
, len
, std::move(bl
), op_flags
, true);
6173 tracepoint(librbd
, aio_write_exit
, 0);
6177 extern "C" int rbd_aio_writev(rbd_image_t image
, const struct iovec
*iov
,
6178 int iovcnt
, uint64_t off
, rbd_completion_t c
)
6180 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6181 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6184 int r
= get_iovec_length(iov
, iovcnt
, len
);
6186 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(),
6187 ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, NULL
,
6191 auto aio_completion
= get_aio_completion(comp
);
6192 auto bl
= iovec_to_bufferlist(ictx
, iov
, iovcnt
, aio_completion
);
6193 librbd::api::Io
<>::aio_write(
6194 *ictx
, aio_completion
, off
, len
, std::move(bl
), 0, true);
6196 tracepoint(librbd
, aio_write_exit
, r
);
6200 extern "C" int rbd_aio_read(rbd_image_t image
, uint64_t off
, size_t len
,
6201 char *buf
, rbd_completion_t c
)
6203 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6204 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6205 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, buf
, comp
->pc
);
6206 librbd::api::Io
<>::aio_read(
6207 *ictx
, get_aio_completion(comp
), off
, len
, librbd::io::ReadResult
{buf
, len
},
6209 tracepoint(librbd
, aio_read_exit
, 0);
6213 extern "C" int rbd_aio_read2(rbd_image_t image
, uint64_t off
, size_t len
,
6214 char *buf
, rbd_completion_t c
, int op_flags
)
6216 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6217 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6218 tracepoint(librbd
, aio_read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6219 ictx
->read_only
, off
, len
, buf
, comp
->pc
, op_flags
);
6220 librbd::api::Io
<>::aio_read(
6221 *ictx
, get_aio_completion(comp
), off
, len
, librbd::io::ReadResult
{buf
, len
},
6223 tracepoint(librbd
, aio_read_exit
, 0);
6227 extern "C" int rbd_aio_readv(rbd_image_t image
, const struct iovec
*iov
,
6228 int iovcnt
, uint64_t off
, rbd_completion_t c
)
6230 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6231 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6234 int r
= get_iovec_length(iov
, iovcnt
, len
);
6236 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(),
6237 ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, NULL
,
6240 librbd::io::ReadResult read_result
;
6242 read_result
= librbd::io::ReadResult(
6243 static_cast<char *>(iov
[0].iov_base
), iov
[0].iov_len
);
6245 read_result
= librbd::io::ReadResult(iov
, iovcnt
);
6247 librbd::api::Io
<>::aio_read(
6248 *ictx
, get_aio_completion(comp
), off
, len
, std::move(read_result
), 0,
6251 tracepoint(librbd
, aio_read_exit
, r
);
6255 extern "C" int rbd_flush(rbd_image_t image
)
6257 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6258 tracepoint(librbd
, flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
6259 int r
= librbd::api::Io
<>::flush(*ictx
);
6260 tracepoint(librbd
, flush_exit
, r
);
6264 extern "C" int rbd_aio_flush(rbd_image_t image
, rbd_completion_t c
)
6266 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6267 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6268 tracepoint(librbd
, aio_flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
6269 librbd::api::Io
<>::aio_flush(*ictx
, get_aio_completion(comp
), true);
6270 tracepoint(librbd
, aio_flush_exit
, 0);
6274 extern "C" int rbd_aio_discard(rbd_image_t image
, uint64_t off
, uint64_t len
,
6277 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6278 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6279 tracepoint(librbd
, aio_discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, comp
->pc
);
6280 librbd::api::Io
<>::aio_discard(
6281 *ictx
, get_aio_completion(comp
), off
, len
,
6282 ictx
->discard_granularity_bytes
, true);
6283 tracepoint(librbd
, aio_discard_exit
, 0);
6287 extern "C" int rbd_aio_writesame(rbd_image_t image
, uint64_t off
, size_t len
,
6288 const char *buf
, size_t data_len
, rbd_completion_t c
,
6291 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6292 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6293 tracepoint(librbd
, aio_writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6294 ictx
->read_only
, off
, len
, data_len
== 0 ? NULL
: buf
, data_len
, comp
->pc
,
6297 if (data_len
== 0 || len
% data_len
) {
6298 tracepoint(librbd
, aio_writesame_exit
, -EINVAL
);
6302 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
6303 if (discard_zero
&& mem_is_zero(buf
, data_len
)) {
6304 librbd::api::Io
<>::aio_write_zeroes(
6305 *ictx
, get_aio_completion(comp
), off
, len
, 0, op_flags
, true);
6306 tracepoint(librbd
, aio_writesame_exit
, 0);
6310 auto aio_completion
= get_aio_completion(comp
);
6312 bl
.push_back(create_write_raw(ictx
, buf
, data_len
, aio_completion
));
6313 librbd::api::Io
<>::aio_write_same(
6314 *ictx
, aio_completion
, off
, len
, std::move(bl
), op_flags
, true);
6315 tracepoint(librbd
, aio_writesame_exit
, 0);
6319 extern "C" int rbd_aio_write_zeroes(rbd_image_t image
, uint64_t off
, size_t len
,
6320 rbd_completion_t c
, int zero_flags
,
6323 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6324 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6326 librbd::api::Io
<>::aio_write_zeroes(*ictx
, get_aio_completion(comp
), off
, len
,
6327 zero_flags
, op_flags
, true);
6331 extern "C" ssize_t
rbd_aio_compare_and_write(rbd_image_t image
, uint64_t off
,
6332 size_t len
, const char *cmp_buf
,
6333 const char *buf
, rbd_completion_t c
,
6334 uint64_t *mismatch_off
,
6337 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6338 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6339 tracepoint(librbd
, aio_compare_and_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6340 ictx
->read_only
, off
, len
, cmp_buf
, buf
, comp
->pc
, op_flags
);
6342 auto aio_completion
= get_aio_completion(comp
);
6344 cmp_bl
.push_back(create_write_raw(ictx
, cmp_buf
, len
, aio_completion
));
6346 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
6347 librbd::api::Io
<>::aio_compare_and_write(
6348 *ictx
, aio_completion
, off
, len
, std::move(cmp_bl
), std::move(bl
),
6349 mismatch_off
, op_flags
, false);
6351 tracepoint(librbd
, aio_compare_and_write_exit
, 0);
6355 extern "C" int rbd_invalidate_cache(rbd_image_t image
)
6357 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6358 tracepoint(librbd
, invalidate_cache_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
6359 int r
= librbd::invalidate_cache(ictx
);
6360 tracepoint(librbd
, invalidate_cache_exit
, r
);
6364 extern "C" int rbd_poll_io_events(rbd_image_t image
, rbd_completion_t
*comps
, int numcomp
)
6366 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6367 librbd::io::AioCompletion
*cs
[numcomp
];
6368 tracepoint(librbd
, poll_io_events_enter
, ictx
, numcomp
);
6369 int r
= librbd::poll_io_events(ictx
, cs
, numcomp
);
6370 tracepoint(librbd
, poll_io_events_exit
, r
);
6372 for (int i
= 0; i
< r
; ++i
)
6373 comps
[i
] = cs
[i
]->rbd_comp
;
6378 extern "C" int rbd_metadata_get(rbd_image_t image
, const char *key
, char *value
, size_t *vallen
)
6380 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6382 tracepoint(librbd
, metadata_get_enter
, ictx
, key
);
6383 int r
= librbd::metadata_get(ictx
, key
, &val_s
);
6385 tracepoint(librbd
, metadata_get_exit
, r
, key
, NULL
);
6388 if (*vallen
< val_s
.size() + 1) {
6390 *vallen
= val_s
.size() + 1;
6391 tracepoint(librbd
, metadata_get_exit
, r
, key
, NULL
);
6393 strncpy(value
, val_s
.c_str(), val_s
.size() + 1);
6394 tracepoint(librbd
, metadata_get_exit
, r
, key
, value
);
6399 extern "C" int rbd_metadata_set(rbd_image_t image
, const char *key
, const char *value
)
6401 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6402 tracepoint(librbd
, metadata_set_enter
, ictx
, key
, value
);
6403 int r
= ictx
->operations
->metadata_set(key
, value
);
6404 tracepoint(librbd
, metadata_set_exit
, r
);
6408 extern "C" int rbd_metadata_remove(rbd_image_t image
, const char *key
)
6410 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6411 tracepoint(librbd
, metadata_remove_enter
, ictx
, key
);
6412 int r
= ictx
->operations
->metadata_remove(key
);
6413 tracepoint(librbd
, metadata_remove_exit
, r
);
6417 extern "C" int rbd_metadata_list(rbd_image_t image
, const char *start
, uint64_t max
,
6418 char *key
, size_t *key_len
, char *value
, size_t *val_len
)
6420 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6421 tracepoint(librbd
, metadata_list_enter
, ictx
);
6422 map
<string
, bufferlist
> pairs
;
6423 int r
= librbd::metadata_list(ictx
, start
, max
, &pairs
);
6424 size_t key_total_len
= 0, val_total_len
= 0;
6425 bool too_short
= false;
6426 for (map
<string
, bufferlist
>::iterator it
= pairs
.begin();
6427 it
!= pairs
.end(); ++it
) {
6428 key_total_len
+= it
->first
.size() + 1;
6429 val_total_len
+= it
->second
.length() + 1;
6431 if (*key_len
< key_total_len
|| *val_len
< val_total_len
)
6433 *key_len
= key_total_len
;
6434 *val_len
= val_total_len
;
6436 tracepoint(librbd
, metadata_list_exit
, -ERANGE
);
6440 char *key_p
= key
, *value_p
= value
;
6442 for (map
<string
, bufferlist
>::iterator it
= pairs
.begin();
6443 it
!= pairs
.end(); ++it
) {
6444 strncpy(key_p
, it
->first
.c_str(), it
->first
.size() + 1);
6445 key_p
+= it
->first
.size() + 1;
6446 strncpy(value_p
, it
->second
.c_str(), it
->second
.length());
6447 value_p
+= it
->second
.length();
6450 tracepoint(librbd
, metadata_list_entry
, it
->first
.c_str(), it
->second
.c_str());
6452 tracepoint(librbd
, metadata_list_exit
, r
);
6456 extern "C" int rbd_mirror_image_enable(rbd_image_t image
)
6458 return rbd_mirror_image_enable2(image
, RBD_MIRROR_IMAGE_MODE_JOURNAL
);
6461 extern "C" int rbd_mirror_image_enable2(rbd_image_t image
,
6462 rbd_mirror_image_mode_t mode
)
6464 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6465 return librbd::api::Mirror
<>::image_enable(ictx
, mode
, false);
6468 extern "C" int rbd_mirror_image_disable(rbd_image_t image
, bool force
)
6470 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6471 return librbd::api::Mirror
<>::image_disable(ictx
, force
);
6474 extern "C" int rbd_mirror_image_promote(rbd_image_t image
, bool force
)
6476 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6477 return librbd::api::Mirror
<>::image_promote(ictx
, force
);
6480 extern "C" int rbd_mirror_image_demote(rbd_image_t image
)
6482 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6483 return librbd::api::Mirror
<>::image_demote(ictx
);
6486 extern "C" int rbd_mirror_image_resync(rbd_image_t image
)
6488 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6489 return librbd::api::Mirror
<>::image_resync(ictx
);
6492 extern "C" int rbd_mirror_image_create_snapshot(rbd_image_t image
,
6495 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6496 auto flags
= librbd::util::get_default_snap_create_flags(ictx
);
6497 return librbd::api::Mirror
<>::image_snapshot_create(ictx
, flags
, snap_id
);
6500 extern "C" int rbd_mirror_image_create_snapshot2(rbd_image_t image
,
6504 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6505 return librbd::api::Mirror
<>::image_snapshot_create(ictx
, flags
, snap_id
);
6508 extern "C" int rbd_mirror_image_get_info(rbd_image_t image
,
6509 rbd_mirror_image_info_t
*mirror_image_info
,
6512 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6514 if (sizeof(rbd_mirror_image_info_t
) != info_size
) {
6518 librbd::mirror_image_info_t cpp_mirror_image
;
6519 int r
= librbd::api::Mirror
<>::image_get_info(ictx
, &cpp_mirror_image
);
6524 mirror_image_info_cpp_to_c(cpp_mirror_image
, mirror_image_info
);
6528 extern "C" void rbd_mirror_image_get_info_cleanup(
6529 rbd_mirror_image_info_t
*mirror_image_info
)
6531 free(mirror_image_info
->global_id
);
6534 extern "C" int rbd_mirror_image_get_mode(rbd_image_t image
,
6535 rbd_mirror_image_mode_t
*mode
)
6537 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6539 return librbd::api::Mirror
<>::image_get_mode(ictx
, mode
);
6542 extern "C" int rbd_mirror_image_get_global_status(
6543 rbd_image_t image
, rbd_mirror_image_global_status_t
*status
,
6546 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6548 if (sizeof(rbd_mirror_image_global_status_t
) != status_size
) {
6552 librbd::mirror_image_global_status_t cpp_status
;
6553 int r
= librbd::api::Mirror
<>::image_get_global_status(ictx
, &cpp_status
);
6558 mirror_image_global_status_cpp_to_c(cpp_status
, status
);
6562 #pragma GCC diagnostic push
6563 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6565 extern "C" int rbd_mirror_image_get_status(rbd_image_t image
,
6566 rbd_mirror_image_status_t
*status
,
6569 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6571 if (sizeof(rbd_mirror_image_status_t
) != status_size
) {
6575 librbd::mirror_image_global_status_t cpp_status
;
6576 int r
= librbd::api::Mirror
<>::image_get_global_status(ictx
, &cpp_status
);
6581 mirror_image_global_status_cpp_to_c(cpp_status
, status
);
6585 #pragma GCC diagnostic pop
6587 extern "C" int rbd_mirror_image_get_instance_id(rbd_image_t image
,
6589 size_t *instance_id_max_length
)
6591 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6593 std::string cpp_instance_id
;
6594 int r
= librbd::api::Mirror
<>::image_get_instance_id(ictx
, &cpp_instance_id
);
6599 if (cpp_instance_id
.size() >= *instance_id_max_length
) {
6600 *instance_id_max_length
= cpp_instance_id
.size() + 1;
6604 strcpy(instance_id
, cpp_instance_id
.c_str());
6605 *instance_id_max_length
= cpp_instance_id
.size() + 1;
6609 extern "C" int rbd_aio_mirror_image_promote(rbd_image_t image
, bool force
,
6610 rbd_completion_t c
) {
6611 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6612 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6613 librbd::api::Mirror
<>::image_promote(
6614 ictx
, force
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6615 get_aio_completion(comp
)));
6619 extern "C" int rbd_aio_mirror_image_demote(rbd_image_t image
,
6620 rbd_completion_t c
) {
6621 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6622 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6623 librbd::api::Mirror
<>::image_demote(
6624 ictx
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6625 get_aio_completion(comp
)));
6629 extern "C" int rbd_aio_mirror_image_get_info(rbd_image_t image
,
6630 rbd_mirror_image_info_t
*info
,
6632 rbd_completion_t c
) {
6633 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6634 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6636 if (sizeof(rbd_mirror_image_info_t
) != info_size
) {
6640 auto ctx
= new C_MirrorImageGetInfo(
6641 info
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6642 get_aio_completion(comp
)));
6643 librbd::api::Mirror
<>::image_get_info(
6644 ictx
, &ctx
->cpp_mirror_image_info
, ctx
);
6648 extern "C" int rbd_aio_mirror_image_get_mode(rbd_image_t image
,
6649 rbd_mirror_image_mode_t
*mode
,
6650 rbd_completion_t c
) {
6651 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6652 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6654 librbd::api::Mirror
<>::image_get_mode(
6655 ictx
, mode
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6656 get_aio_completion(comp
)));
6660 extern "C" int rbd_aio_mirror_image_get_global_status(
6661 rbd_image_t image
, rbd_mirror_image_global_status_t
*status
,
6662 size_t status_size
, rbd_completion_t c
) {
6663 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6664 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6666 if (sizeof(rbd_mirror_image_global_status_t
) != status_size
) {
6670 auto ctx
= new C_MirrorImageGetGlobalStatus(
6671 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6672 get_aio_completion(comp
)));
6673 librbd::api::Mirror
<>::image_get_global_status(
6674 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
6678 #pragma GCC diagnostic push
6679 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6681 extern "C" int rbd_aio_mirror_image_get_status(
6682 rbd_image_t image
, rbd_mirror_image_status_t
*status
, size_t status_size
,
6683 rbd_completion_t c
) {
6684 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6685 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6687 if (sizeof(rbd_mirror_image_status_t
) != status_size
) {
6691 auto ctx
= new C_MirrorImageGetStatus(
6692 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6693 get_aio_completion(comp
)));
6694 librbd::api::Mirror
<>::image_get_global_status(
6695 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
6699 #pragma GCC diagnostic pop
6701 extern "C" int rbd_aio_mirror_image_create_snapshot(rbd_image_t image
,
6704 rbd_completion_t c
) {
6705 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6706 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6708 librbd::api::Mirror
<>::image_snapshot_create(
6709 ictx
, flags
, snap_id
, new C_AioCompletion(ictx
,
6710 librbd::io::AIO_TYPE_GENERIC
,
6711 get_aio_completion(comp
)));
6715 extern "C" int rbd_update_watch(rbd_image_t image
, uint64_t *handle
,
6716 rbd_update_callback_t watch_cb
, void *arg
)
6718 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6719 C_UpdateWatchCB
*wctx
= new C_UpdateWatchCB(watch_cb
, arg
);
6720 tracepoint(librbd
, update_watch_enter
, ictx
, wctx
);
6721 int r
= ictx
->state
->register_update_watcher(wctx
, &wctx
->handle
);
6722 tracepoint(librbd
, update_watch_exit
, r
, wctx
->handle
);
6723 *handle
= reinterpret_cast<uint64_t>(wctx
);
6727 extern "C" int rbd_update_unwatch(rbd_image_t image
, uint64_t handle
)
6729 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6730 C_UpdateWatchCB
*wctx
= reinterpret_cast<C_UpdateWatchCB
*>(handle
);
6731 tracepoint(librbd
, update_unwatch_enter
, ictx
, wctx
->handle
);
6732 int r
= ictx
->state
->unregister_update_watcher(wctx
->handle
);
6734 tracepoint(librbd
, update_unwatch_exit
, r
);
6738 extern "C" int rbd_aio_is_complete(rbd_completion_t c
)
6740 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6741 return comp
->is_complete();
6744 extern "C" int rbd_aio_wait_for_complete(rbd_completion_t c
)
6746 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6747 return comp
->wait_for_complete();
6750 extern "C" ssize_t
rbd_aio_get_return_value(rbd_completion_t c
)
6752 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6753 return comp
->get_return_value();
6756 extern "C" void *rbd_aio_get_arg(rbd_completion_t c
)
6758 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6759 return comp
->get_arg();
6762 extern "C" void rbd_aio_release(rbd_completion_t c
)
6764 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6768 extern "C" int rbd_group_create(rados_ioctx_t p
, const char *name
)
6770 librados::IoCtx io_ctx
;
6771 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6772 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6773 tracepoint(librbd
, group_create_enter
, io_ctx
.get_pool_name().c_str(),
6774 io_ctx
.get_id(), name
);
6775 int r
= librbd::api::Group
<>::create(io_ctx
, name
);
6776 tracepoint(librbd
, group_create_exit
, r
);
6780 extern "C" int rbd_group_remove(rados_ioctx_t p
, const char *name
)
6782 librados::IoCtx io_ctx
;
6783 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6784 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6785 tracepoint(librbd
, group_remove_enter
, io_ctx
.get_pool_name().c_str(),
6786 io_ctx
.get_id(), name
);
6787 int r
= librbd::api::Group
<>::remove(io_ctx
, name
);
6788 tracepoint(librbd
, group_remove_exit
, r
);
6792 extern "C" int rbd_group_list(rados_ioctx_t p
, char *names
, size_t *size
)
6794 librados::IoCtx io_ctx
;
6795 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6796 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6797 tracepoint(librbd
, group_list_enter
, io_ctx
.get_pool_name().c_str(),
6800 vector
<string
> cpp_names
;
6801 int r
= librbd::api::Group
<>::list(io_ctx
, &cpp_names
);
6804 tracepoint(librbd
, group_list_exit
, r
);
6808 size_t expected_size
= 0;
6810 for (size_t i
= 0; i
< cpp_names
.size(); i
++) {
6811 expected_size
+= cpp_names
[i
].size() + 1;
6813 if (*size
< expected_size
) {
6814 *size
= expected_size
;
6815 tracepoint(librbd
, group_list_exit
, -ERANGE
);
6819 if (names
== NULL
) {
6820 tracepoint(librbd
, group_list_exit
, -EINVAL
);
6824 for (int i
= 0; i
< (int)cpp_names
.size(); i
++) {
6825 const char* name
= cpp_names
[i
].c_str();
6826 tracepoint(librbd
, group_list_entry
, name
);
6827 strcpy(names
, name
);
6828 names
+= strlen(names
) + 1;
6830 tracepoint(librbd
, group_list_exit
, (int)expected_size
);
6831 return (int)expected_size
;
6834 extern "C" int rbd_group_rename(rados_ioctx_t p
, const char *src_name
,
6835 const char *dest_name
)
6837 librados::IoCtx io_ctx
;
6838 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6839 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6840 tracepoint(librbd
, group_rename_enter
, io_ctx
.get_pool_name().c_str(),
6841 io_ctx
.get_id(), src_name
, dest_name
);
6842 int r
= librbd::api::Group
<>::rename(io_ctx
, src_name
, dest_name
);
6843 tracepoint(librbd
, group_rename_exit
, r
);
6847 extern "C" int rbd_group_image_add(rados_ioctx_t group_p
,
6848 const char *group_name
,
6849 rados_ioctx_t image_p
,
6850 const char *image_name
)
6852 librados::IoCtx group_ioctx
;
6853 librados::IoCtx image_ioctx
;
6855 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6856 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6858 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6859 tracepoint(librbd
, group_image_add_enter
, group_ioctx
.get_pool_name().c_str(),
6860 group_ioctx
.get_id(), group_name
, image_ioctx
.get_pool_name().c_str(),
6861 image_ioctx
.get_id(), image_name
);
6863 int r
= librbd::api::Group
<>::image_add(group_ioctx
, group_name
, image_ioctx
,
6866 tracepoint(librbd
, group_image_add_exit
, r
);
6870 extern "C" int rbd_group_image_remove(rados_ioctx_t group_p
,
6871 const char *group_name
,
6872 rados_ioctx_t image_p
,
6873 const char *image_name
)
6875 librados::IoCtx group_ioctx
;
6876 librados::IoCtx image_ioctx
;
6878 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6879 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6881 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6882 tracepoint(librbd
, group_image_remove_enter
, group_ioctx
.get_pool_name().c_str(),
6883 group_ioctx
.get_id(), group_name
, image_ioctx
.get_pool_name().c_str(),
6884 image_ioctx
.get_id(), image_name
);
6886 int r
= librbd::api::Group
<>::image_remove(group_ioctx
, group_name
,
6887 image_ioctx
, image_name
);
6889 tracepoint(librbd
, group_image_remove_exit
, r
);
6893 extern "C" int rbd_group_image_remove_by_id(rados_ioctx_t group_p
,
6894 const char *group_name
,
6895 rados_ioctx_t image_p
,
6896 const char *image_id
)
6898 librados::IoCtx group_ioctx
;
6899 librados::IoCtx image_ioctx
;
6901 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6902 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6904 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6905 tracepoint(librbd
, group_image_remove_by_id_enter
,
6906 group_ioctx
.get_pool_name().c_str(),
6907 group_ioctx
.get_id(), group_name
,
6908 image_ioctx
.get_pool_name().c_str(),
6909 image_ioctx
.get_id(), image_id
);
6911 int r
= librbd::api::Group
<>::image_remove_by_id(group_ioctx
, group_name
,
6912 image_ioctx
, image_id
);
6914 tracepoint(librbd
, group_image_remove_by_id_exit
, r
);
6918 extern "C" int rbd_group_image_list(rados_ioctx_t group_p
,
6919 const char *group_name
,
6920 rbd_group_image_info_t
*images
,
6921 size_t group_image_info_size
,
6924 librados::IoCtx group_ioctx
;
6925 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6927 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6928 tracepoint(librbd
, group_image_list_enter
,
6929 group_ioctx
.get_pool_name().c_str(),
6930 group_ioctx
.get_id(), group_name
);
6931 // FIPS zeroization audit 20191117: this memset is not security related.
6932 memset(images
, 0, sizeof(*images
) * *image_size
);
6934 if (group_image_info_size
!= sizeof(rbd_group_image_info_t
)) {
6936 tracepoint(librbd
, group_image_list_exit
, -ERANGE
);
6940 std::vector
<librbd::group_image_info_t
> cpp_images
;
6941 int r
= librbd::api::Group
<>::image_list(group_ioctx
, group_name
,
6945 tracepoint(librbd
, group_image_list_exit
, 0);
6951 tracepoint(librbd
, group_image_list_exit
, r
);
6955 if (*image_size
< cpp_images
.size()) {
6956 *image_size
= cpp_images
.size();
6957 tracepoint(librbd
, group_image_list_exit
, -ERANGE
);
6961 for (size_t i
= 0; i
< cpp_images
.size(); ++i
) {
6962 group_image_status_cpp_to_c(cpp_images
[i
], &images
[i
]);
6965 r
= *image_size
= cpp_images
.size();
6966 tracepoint(librbd
, group_image_list_exit
, r
);
6970 extern "C" int rbd_group_info_cleanup(rbd_group_info_t
*group_info
,
6971 size_t group_info_size
) {
6972 if (group_info_size
!= sizeof(rbd_group_info_t
)) {
6976 free(group_info
->name
);
6980 extern "C" int rbd_group_image_list_cleanup(rbd_group_image_info_t
*images
,
6981 size_t group_image_info_size
,
6983 if (group_image_info_size
!= sizeof(rbd_group_image_info_t
)) {
6987 for (size_t i
= 0; i
< len
; ++i
) {
6988 free(images
[i
].name
);
6993 extern "C" int rbd_group_snap_create(rados_ioctx_t group_p
,
6994 const char *group_name
,
6995 const char *snap_name
)
6997 librados::IoCtx group_ioctx
;
6998 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
7000 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
7001 tracepoint(librbd
, group_snap_create_enter
,
7002 group_ioctx
.get_pool_name().c_str(),
7003 group_ioctx
.get_id(), group_name
, snap_name
);
7005 int r
= librbd::api::Group
<>::snap_create(group_ioctx
, group_name
,
7007 tracepoint(librbd
, group_snap_create_exit
, r
);
7012 extern "C" int rbd_group_snap_create2(rados_ioctx_t group_p
,
7013 const char *group_name
,
7014 const char *snap_name
,
7017 librados::IoCtx group_ioctx
;
7018 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
7020 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
7021 tracepoint(librbd
, group_snap_create_enter
,
7022 group_ioctx
.get_pool_name().c_str(),
7023 group_ioctx
.get_id(), group_name
, snap_name
);
7025 int r
= librbd::api::Group
<>::snap_create(group_ioctx
, group_name
, snap_name
,
7027 tracepoint(librbd
, group_snap_create_exit
, r
);
7032 extern "C" int rbd_group_snap_remove(rados_ioctx_t group_p
,
7033 const char *group_name
,
7034 const char *snap_name
)
7036 librados::IoCtx group_ioctx
;
7037 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
7039 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
7040 tracepoint(librbd
, group_snap_remove_enter
,
7041 group_ioctx
.get_pool_name().c_str(),
7042 group_ioctx
.get_id(), group_name
, snap_name
);
7044 int r
= librbd::api::Group
<>::snap_remove(group_ioctx
, group_name
, snap_name
);
7046 tracepoint(librbd
, group_snap_remove_exit
, r
);
7051 extern "C" int rbd_group_snap_rename(rados_ioctx_t group_p
,
7052 const char *group_name
,
7053 const char *old_snap_name
,
7054 const char *new_snap_name
)
7056 librados::IoCtx group_ioctx
;
7057 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
7059 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
7060 tracepoint(librbd
, group_snap_rename_enter
,
7061 group_ioctx
.get_pool_name().c_str(), group_ioctx
.get_id(),
7062 group_name
, old_snap_name
, new_snap_name
);
7064 int r
= librbd::api::Group
<>::snap_rename(group_ioctx
, group_name
,
7065 old_snap_name
, new_snap_name
);
7067 tracepoint(librbd
, group_snap_list_exit
, r
);
7071 extern "C" int rbd_group_snap_list(rados_ioctx_t group_p
,
7072 const char *group_name
,
7073 rbd_group_snap_info_t
*snaps
,
7074 size_t group_snap_info_size
,
7077 librados::IoCtx group_ioctx
;
7078 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
7080 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
7081 tracepoint(librbd
, group_snap_list_enter
, group_ioctx
.get_pool_name().c_str(),
7082 group_ioctx
.get_id(), group_name
);
7083 // FIPS zeroization audit 20191117: this memset is not security related.
7084 memset(snaps
, 0, sizeof(*snaps
) * *snaps_size
);
7086 if (group_snap_info_size
!= sizeof(rbd_group_snap_info_t
)) {
7088 tracepoint(librbd
, group_snap_list_exit
, -ERANGE
);
7092 std::vector
<librbd::group_snap_info_t
> cpp_snaps
;
7093 int r
= librbd::api::Group
<>::snap_list(group_ioctx
, group_name
, &cpp_snaps
);
7097 tracepoint(librbd
, group_snap_list_exit
, 0);
7102 tracepoint(librbd
, group_snap_list_exit
, r
);
7106 if (*snaps_size
< cpp_snaps
.size()) {
7107 *snaps_size
= cpp_snaps
.size();
7108 tracepoint(librbd
, group_snap_list_exit
, -ERANGE
);
7112 for (size_t i
= 0; i
< cpp_snaps
.size(); ++i
) {
7113 group_snap_info_cpp_to_c(cpp_snaps
[i
], &snaps
[i
]);
7116 r
= *snaps_size
= cpp_snaps
.size();
7117 tracepoint(librbd
, group_snap_list_exit
, r
);
7121 extern "C" int rbd_group_snap_list_cleanup(rbd_group_snap_info_t
*snaps
,
7122 size_t group_snap_info_size
,
7124 if (group_snap_info_size
!= sizeof(rbd_group_snap_info_t
)) {
7128 for (size_t i
= 0; i
< len
; ++i
) {
7129 free(snaps
[i
].name
);
7134 extern "C" int rbd_group_snap_rollback(rados_ioctx_t group_p
,
7135 const char *group_name
,
7136 const char *snap_name
)
7138 librados::IoCtx group_ioctx
;
7139 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
7141 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
7142 tracepoint(librbd
, group_snap_rollback_enter
,
7143 group_ioctx
.get_pool_name().c_str(),
7144 group_ioctx
.get_id(), group_name
, snap_name
);
7146 librbd::NoOpProgressContext prog_ctx
;
7147 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
7148 snap_name
, prog_ctx
);
7150 tracepoint(librbd
, group_snap_rollback_exit
, r
);
7155 extern "C" int rbd_group_snap_rollback_with_progress(rados_ioctx_t group_p
,
7156 const char *group_name
,
7157 const char *snap_name
,
7158 librbd_progress_fn_t cb
,
7161 librados::IoCtx group_ioctx
;
7162 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
7164 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
7165 tracepoint(librbd
, group_snap_rollback_enter
,
7166 group_ioctx
.get_pool_name().c_str(),
7167 group_ioctx
.get_id(), group_name
, snap_name
);
7169 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
7170 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
7171 snap_name
, prog_ctx
);
7173 tracepoint(librbd
, group_snap_rollback_exit
, r
);
7178 extern "C" int rbd_snap_get_namespace_type(rbd_image_t image
,
7180 rbd_snap_namespace_type_t
*namespace_type
) {
7181 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7182 tracepoint(librbd
, snap_get_namespace_type_enter
, ictx
, ictx
->name
.c_str());
7183 int r
= librbd::api::Snapshot
<>::get_namespace_type(ictx
, snap_id
,
7185 tracepoint(librbd
, snap_get_namespace_type_exit
, r
);
7189 extern "C" int rbd_snap_get_group_namespace(rbd_image_t image
, uint64_t snap_id
,
7190 rbd_snap_group_namespace_t
*group_snap
,
7191 size_t snap_group_namespace_size
) {
7192 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7193 tracepoint(librbd
, snap_get_group_namespace_enter
, ictx
,
7194 ictx
->name
.c_str());
7196 if (snap_group_namespace_size
!= sizeof(rbd_snap_group_namespace_t
)) {
7197 tracepoint(librbd
, snap_get_group_namespace_exit
, -ERANGE
);
7201 librbd::snap_group_namespace_t group_namespace
;
7202 int r
= librbd::api::Snapshot
<>::get_group_namespace(ictx
, snap_id
,
7205 group_snap
->group_pool
= group_namespace
.group_pool
;
7206 group_snap
->group_name
= strdup(group_namespace
.group_name
.c_str());
7207 group_snap
->group_snap_name
=
7208 strdup(group_namespace
.group_snap_name
.c_str());
7211 tracepoint(librbd
, snap_get_group_namespace_exit
, r
);
7215 extern "C" int rbd_snap_group_namespace_cleanup(rbd_snap_group_namespace_t
*group_snap
,
7216 size_t snap_group_namespace_size
) {
7217 if (snap_group_namespace_size
!= sizeof(rbd_snap_group_namespace_t
)) {
7221 free(group_snap
->group_name
);
7222 free(group_snap
->group_snap_name
);
7226 extern "C" int rbd_snap_get_trash_namespace(rbd_image_t image
, uint64_t snap_id
,
7227 char *original_name
,
7228 size_t max_length
) {
7229 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7231 std::string cpp_original_name
;
7232 int r
= librbd::api::Snapshot
<>::get_trash_namespace(ictx
, snap_id
,
7233 &cpp_original_name
);
7238 if (cpp_original_name
.length() >= max_length
) {
7242 strcpy(original_name
, cpp_original_name
.c_str());
7246 extern "C" int rbd_snap_get_mirror_namespace(
7247 rbd_image_t image
, uint64_t snap_id
,
7248 rbd_snap_mirror_namespace_t
*mirror_snap
,
7249 size_t mirror_snap_size
) {
7250 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7252 if (mirror_snap_size
!= sizeof(rbd_snap_mirror_namespace_t
)) {
7256 librbd::snap_mirror_namespace_t mirror_namespace
;
7257 int r
= librbd::api::Snapshot
<>::get_mirror_namespace(
7258 ictx
, snap_id
, &mirror_namespace
);
7263 mirror_snap
->state
= mirror_namespace
.state
;
7264 mirror_snap
->primary_mirror_uuid
=
7265 strdup(mirror_namespace
.primary_mirror_uuid
.c_str());
7266 mirror_snap
->primary_snap_id
= mirror_namespace
.primary_snap_id
;
7267 mirror_snap
->mirror_peer_uuids_count
=
7268 mirror_namespace
.mirror_peer_uuids
.size();
7270 for (auto &peer
: mirror_namespace
.mirror_peer_uuids
) {
7271 len
+= peer
.size() + 1;
7273 mirror_snap
->mirror_peer_uuids
= (char *)malloc(len
);
7274 char *p
= mirror_snap
->mirror_peer_uuids
;
7275 for (auto &peer
: mirror_namespace
.mirror_peer_uuids
) {
7276 strncpy(p
, peer
.c_str(), peer
.size() + 1);
7277 p
+= peer
.size() + 1;
7279 mirror_snap
->complete
= mirror_namespace
.complete
;
7280 mirror_snap
->last_copied_object_number
=
7281 mirror_namespace
.last_copied_object_number
;
7286 extern "C" int rbd_snap_mirror_namespace_cleanup(
7287 rbd_snap_mirror_namespace_t
*mirror_snap
,
7288 size_t mirror_snap_size
) {
7289 if (mirror_snap_size
!= sizeof(rbd_snap_mirror_namespace_t
)) {
7293 free(mirror_snap
->primary_mirror_uuid
);
7294 free(mirror_snap
->mirror_peer_uuids
);
7298 extern "C" int rbd_watchers_list(rbd_image_t image
,
7299 rbd_image_watcher_t
*watchers
,
7300 size_t *max_watchers
) {
7301 std::list
<librbd::image_watcher_t
> watcher_list
;
7302 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7304 tracepoint(librbd
, list_watchers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
7305 // FIPS zeroization audit 20191117: this memset is not security related.
7306 memset(watchers
, 0, sizeof(*watchers
) * *max_watchers
);
7307 int r
= librbd::list_watchers(ictx
, watcher_list
);
7309 tracepoint(librbd
, list_watchers_exit
, r
, 0);
7313 if (watcher_list
.size() > *max_watchers
) {
7314 *max_watchers
= watcher_list
.size();
7315 tracepoint(librbd
, list_watchers_exit
, -ERANGE
, watcher_list
.size());
7320 for (auto &watcher
: watcher_list
) {
7321 tracepoint(librbd
, list_watchers_entry
, watcher
.addr
.c_str(), watcher
.id
, watcher
.cookie
);
7322 watchers
[*max_watchers
].addr
= strdup(watcher
.addr
.c_str());
7323 watchers
[*max_watchers
].id
= watcher
.id
;
7324 watchers
[*max_watchers
].cookie
= watcher
.cookie
;
7328 tracepoint(librbd
, list_watchers_exit
, r
, watcher_list
.size());
7332 extern "C" void rbd_watchers_list_cleanup(rbd_image_watcher_t
*watchers
,
7333 size_t num_watchers
) {
7334 for (size_t i
= 0; i
< num_watchers
; ++i
) {
7335 free(watchers
[i
].addr
);
7339 extern "C" int rbd_config_image_list(rbd_image_t image
,
7340 rbd_config_option_t
*options
,
7342 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7344 std::vector
<librbd::config_option_t
> option_vector
;
7345 int r
= librbd::api::Config
<>::list(ictx
, &option_vector
);
7350 if (*max_options
< static_cast<int>(option_vector
.size())) {
7351 *max_options
= static_cast<int>(option_vector
.size());
7355 for (int i
= 0; i
< static_cast<int>(option_vector
.size()); ++i
) {
7356 config_option_cpp_to_c(option_vector
[i
], &options
[i
]);
7358 *max_options
= static_cast<int>(option_vector
.size());
7362 extern "C" void rbd_config_image_list_cleanup(rbd_config_option_t
*options
,
7364 for (int i
= 0; i
< max_options
; ++i
) {
7365 config_option_cleanup(options
[i
]);
7369 extern "C" int rbd_quiesce_watch(rbd_image_t image
,
7370 rbd_update_callback_t quiesce_cb
,
7371 rbd_update_callback_t unquiesce_cb
,
7372 void *arg
, uint64_t *handle
)
7374 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7375 auto wctx
= new C_QuiesceWatchCB(quiesce_cb
, unquiesce_cb
, arg
);
7376 int r
= ictx
->state
->register_quiesce_watcher(wctx
, &wctx
->handle
);
7381 *handle
= reinterpret_cast<uint64_t>(wctx
);
7385 extern "C" int rbd_quiesce_unwatch(rbd_image_t image
, uint64_t handle
)
7387 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7388 auto *wctx
= reinterpret_cast<C_QuiesceWatchCB
*>(handle
);
7389 int r
= ictx
->state
->unregister_quiesce_watcher(wctx
->handle
);
7394 extern "C" void rbd_quiesce_complete(rbd_image_t image
, uint64_t handle
, int r
)
7396 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7397 ictx
->state
->quiesce_complete(handle
, r
);