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/api/Config.h"
32 #include "librbd/api/DiffIterate.h"
33 #include "librbd/api/Group.h"
34 #include "librbd/api/Image.h"
35 #include "librbd/api/Migration.h"
36 #include "librbd/api/Mirror.h"
37 #include "librbd/api/Namespace.h"
38 #include "librbd/api/Pool.h"
39 #include "librbd/api/PoolMetadata.h"
40 #include "librbd/api/Snapshot.h"
41 #include "librbd/api/Trash.h"
42 #include "librbd/io/AioCompletion.h"
43 #include "librbd/io/ImageRequestWQ.h"
44 #include "librbd/io/ReadResult.h"
50 #define TRACEPOINT_DEFINE
51 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
52 #include "tracing/librbd.h"
53 #undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
54 #undef TRACEPOINT_DEFINE
56 #define tracepoint(...)
59 #define dout_subsys ceph_subsys_rbd
61 #define dout_prefix *_dout << "librbd: "
66 using ceph::bufferlist
;
67 using librados::snap_t
;
68 using librados::IoCtx
;
72 TracepointProvider::Traits
tracepoint_traits("librbd_tp.so", "rbd_tracing");
74 struct UserBufferDeleter
: public deleter::impl
{
76 librbd::io::AioCompletion
* aio_completion
;
78 UserBufferDeleter(CephContext
* cct
, librbd::io::AioCompletion
* aio_completion
)
79 : deleter::impl(deleter()), cct(cct
), aio_completion(aio_completion
) {
80 aio_completion
->block(cct
);
83 ~UserBufferDeleter() override
{
84 aio_completion
->unblock(cct
);
88 static auto create_write_raw(librbd::ImageCtx
*ictx
, const char *buf
,
90 librbd::io::AioCompletion
* aio_completion
) {
91 if (ictx
->disable_zero_copy
|| aio_completion
== nullptr) {
92 // must copy the buffer if writeback/writearound cache is in-use (or using
94 return buffer::copy(buf
, len
);
97 // avoid copying memory for AIO operations, but possibly delay completions
98 // until the last reference to the user's memory has been released
99 return ceph::unique_leakable_ptr
<ceph::buffer::raw
>(
100 buffer::claim_buffer(
101 len
, const_cast<char*>(buf
),
102 deleter(new UserBufferDeleter(ictx
->cct
, aio_completion
))));
105 CephContext
* get_cct(IoCtx
&io_ctx
) {
106 return reinterpret_cast<CephContext
*>(io_ctx
.cct());
109 librbd::io::AioCompletion
* get_aio_completion(librbd::RBD::AioCompletion
*comp
) {
110 return reinterpret_cast<librbd::io::AioCompletion
*>(comp
->pc
);
113 struct C_AioCompletion
: public Context
{
115 librbd::io::aio_type_t aio_type
;
116 librbd::io::AioCompletion
* aio_comp
;
118 C_AioCompletion(librbd::ImageCtx
*ictx
, librbd::io::aio_type_t aio_type
,
119 librbd::io::AioCompletion
* aio_comp
)
120 : cct(ictx
->cct
), aio_type(aio_type
), aio_comp(aio_comp
) {
121 aio_comp
->init_time(ictx
, aio_type
);
124 virtual ~C_AioCompletion() {
128 void finish(int r
) override
{
129 ldout(cct
, 20) << "C_AioComplete::finish: r=" << r
<< dendl
;
133 aio_comp
->complete();
138 struct C_OpenComplete
: public C_AioCompletion
{
139 librbd::ImageCtx
*ictx
;
141 C_OpenComplete(librbd::ImageCtx
*ictx
, librbd::io::AioCompletion
* comp
,
143 : C_AioCompletion(ictx
, librbd::io::AIO_TYPE_OPEN
, comp
),
144 ictx(ictx
), ictxp(ictxp
) {
146 void finish(int r
) override
{
147 ldout(ictx
->cct
, 20) << "C_OpenComplete::finish: r=" << r
<< dendl
;
154 C_AioCompletion::finish(r
);
158 struct C_OpenAfterCloseComplete
: public Context
{
159 librbd::ImageCtx
*ictx
;
160 librbd::io::AioCompletion
* comp
;
162 C_OpenAfterCloseComplete(librbd::ImageCtx
*ictx
,
163 librbd::io::AioCompletion
* comp
,
165 : ictx(ictx
), comp(comp
), ictxp(ictxp
) {
167 void finish(int r
) override
{
168 ldout(ictx
->cct
, 20) << "C_OpenAfterCloseComplete::finish: r=" << r
170 delete reinterpret_cast<librbd::ImageCtx
*>(*ictxp
);
173 ictx
->state
->open(0, new C_OpenComplete(ictx
, comp
, ictxp
));
177 struct C_UpdateWatchCB
: public librbd::UpdateWatchCtx
{
178 rbd_update_callback_t watch_cb
;
182 C_UpdateWatchCB(rbd_update_callback_t watch_cb
, void *arg
) :
183 watch_cb(watch_cb
), arg(arg
) {
185 void handle_notify() override
{
190 void group_image_status_cpp_to_c(const librbd::group_image_info_t
&cpp_info
,
191 rbd_group_image_info_t
*c_info
) {
192 c_info
->name
= strdup(cpp_info
.name
.c_str());
193 c_info
->pool
= cpp_info
.pool
;
194 c_info
->state
= cpp_info
.state
;
197 void group_info_cpp_to_c(const librbd::group_info_t
&cpp_info
,
198 rbd_group_info_t
*c_info
) {
199 c_info
->name
= strdup(cpp_info
.name
.c_str());
200 c_info
->pool
= cpp_info
.pool
;
203 void group_snap_info_cpp_to_c(const librbd::group_snap_info_t
&cpp_info
,
204 rbd_group_snap_info_t
*c_info
) {
205 c_info
->name
= strdup(cpp_info
.name
.c_str());
206 c_info
->state
= cpp_info
.state
;
209 void mirror_image_info_cpp_to_c(const librbd::mirror_image_info_t
&cpp_info
,
210 rbd_mirror_image_info_t
*c_info
) {
211 c_info
->global_id
= strdup(cpp_info
.global_id
.c_str());
212 c_info
->state
= cpp_info
.state
;
213 c_info
->primary
= cpp_info
.primary
;
216 int get_local_mirror_image_site_status(
217 const librbd::mirror_image_global_status_t
& status
,
218 librbd::mirror_image_site_status_t
* local_status
) {
219 auto it
= std::find_if(status
.site_statuses
.begin(),
220 status
.site_statuses
.end(),
221 [](const librbd::mirror_image_site_status_t
& s
) {
222 return (s
.mirror_uuid
==
223 cls::rbd::MirrorImageSiteStatus::LOCAL_MIRROR_UUID
);
225 if (it
== status
.site_statuses
.end()) {
233 #pragma GCC diagnostic push
234 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
236 int mirror_image_global_status_cpp_to_c(
237 const librbd::mirror_image_global_status_t
&cpp_status
,
238 rbd_mirror_image_status_t
*c_status
) {
239 c_status
->name
= strdup(cpp_status
.name
.c_str());
240 mirror_image_info_cpp_to_c(cpp_status
.info
, &c_status
->info
);
242 librbd::mirror_image_site_status_t local_status
;
243 int r
= get_local_mirror_image_site_status(cpp_status
, &local_status
);
248 c_status
->state
= local_status
.state
;
249 c_status
->description
= strdup(local_status
.description
.c_str());
250 c_status
->last_update
= local_status
.last_update
;
251 c_status
->up
= local_status
.up
;
255 #pragma GCC diagnostic pop
257 void mirror_image_global_status_cpp_to_c(
258 const librbd::mirror_image_global_status_t
&cpp_status
,
259 rbd_mirror_image_global_status_t
*c_status
) {
260 c_status
->name
= strdup(cpp_status
.name
.c_str());
261 mirror_image_info_cpp_to_c(cpp_status
.info
, &c_status
->info
);
263 c_status
->site_statuses_count
= cpp_status
.site_statuses
.size();
264 c_status
->site_statuses
= (rbd_mirror_image_site_status_t
*)calloc(
265 cpp_status
.site_statuses
.size(), sizeof(rbd_mirror_image_site_status_t
));
268 for (auto it
= cpp_status
.site_statuses
.begin();
269 it
!= cpp_status
.site_statuses
.end(); ++it
) {
270 auto& s_status
= c_status
->site_statuses
[idx
++];
271 s_status
.mirror_uuid
= strdup(it
->mirror_uuid
.c_str());
272 s_status
.state
= it
->state
;
273 s_status
.description
= strdup(it
->description
.c_str());
274 s_status
.last_update
= it
->last_update
;
275 s_status
.up
= it
->up
;
279 void trash_image_info_cpp_to_c(const librbd::trash_image_info_t
&cpp_info
,
280 rbd_trash_image_info_t
*c_info
) {
281 c_info
->id
= strdup(cpp_info
.id
.c_str());
282 c_info
->name
= strdup(cpp_info
.name
.c_str());
283 c_info
->source
= cpp_info
.source
;
284 c_info
->deletion_time
= cpp_info
.deletion_time
;
285 c_info
->deferment_end_time
= cpp_info
.deferment_end_time
;
288 void config_option_cpp_to_c(const librbd::config_option_t
&cpp_option
,
289 rbd_config_option_t
*c_option
) {
290 c_option
->name
= strdup(cpp_option
.name
.c_str());
291 c_option
->value
= strdup(cpp_option
.value
.c_str());
292 c_option
->source
= cpp_option
.source
;
295 void config_option_cleanup(rbd_config_option_t
&option
) {
300 struct C_MirrorImageGetInfo
: public Context
{
301 rbd_mirror_image_info_t
*mirror_image_info
;
304 librbd::mirror_image_info_t cpp_mirror_image_info
;
306 C_MirrorImageGetInfo(rbd_mirror_image_info_t
*mirror_image_info
,
308 : mirror_image_info(mirror_image_info
), on_finish(on_finish
) {
311 void finish(int r
) override
{
313 on_finish
->complete(r
);
317 mirror_image_info_cpp_to_c(cpp_mirror_image_info
, mirror_image_info
);
318 on_finish
->complete(0);
322 struct C_MirrorImageGetGlobalStatus
: public Context
{
323 rbd_mirror_image_global_status_t
*mirror_image_global_status
;
326 librbd::mirror_image_global_status_t cpp_mirror_image_global_status
;
328 C_MirrorImageGetGlobalStatus(
329 rbd_mirror_image_global_status_t
*mirror_image_global_status
,
331 : mirror_image_global_status(mirror_image_global_status
),
332 on_finish(on_finish
) {
335 void finish(int r
) override
{
337 on_finish
->complete(r
);
341 mirror_image_global_status_cpp_to_c(cpp_mirror_image_global_status
,
342 mirror_image_global_status
);
343 on_finish
->complete(0);
347 #pragma GCC diagnostic push
348 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
350 struct C_MirrorImageGetStatus
: public Context
{
351 librbd::mirror_image_status_t
*mirror_image_status_cpp
= nullptr;
352 rbd_mirror_image_status_t
*mirror_image_status
= nullptr;
355 librbd::mirror_image_global_status_t cpp_mirror_image_global_status
;
357 C_MirrorImageGetStatus(rbd_mirror_image_status_t
*mirror_image_status
,
359 : mirror_image_status(mirror_image_status
), on_finish(on_finish
) {
361 C_MirrorImageGetStatus(librbd::mirror_image_status_t
*mirror_image_status
,
363 : mirror_image_status_cpp(mirror_image_status
), on_finish(on_finish
) {
367 void finish(int r
) override
{
369 on_finish
->complete(r
);
373 if (mirror_image_status
!= nullptr) {
374 r
= mirror_image_global_status_cpp_to_c(cpp_mirror_image_global_status
,
375 mirror_image_status
);
376 } else if (mirror_image_status_cpp
!= nullptr) {
377 librbd::mirror_image_site_status_t local_status
;
378 r
= get_local_mirror_image_site_status(cpp_mirror_image_global_status
,
381 *mirror_image_status_cpp
= {
382 cpp_mirror_image_global_status
.name
,
383 cpp_mirror_image_global_status
.info
,
384 local_status
.state
, local_status
.description
,
385 local_status
.last_update
, local_status
.up
};
388 on_finish
->complete(r
);
392 #pragma GCC diagnostic pop
394 } // anonymous namespace
397 ProgressContext::~ProgressContext()
401 class CProgressContext
: public ProgressContext
404 CProgressContext(librbd_progress_fn_t fn
, void *data
)
405 : m_fn(fn
), m_data(data
)
408 int update_progress(uint64_t offset
, uint64_t src_size
) override
410 return m_fn(offset
, src_size
, m_data
);
413 librbd_progress_fn_t m_fn
;
420 PoolStats::PoolStats() {
421 rbd_pool_stats_create(&pool_stats
);
424 PoolStats::~PoolStats() {
425 rbd_pool_stats_destroy(pool_stats
);
428 int PoolStats::add(rbd_pool_stat_option_t option
, uint64_t* opt_val
) {
429 return rbd_pool_stats_option_add_uint64(pool_stats
, option
, opt_val
);
443 void RBD::version(int *major
, int *minor
, int *extra
)
445 rbd_version(major
, minor
, extra
);
448 int RBD::open(IoCtx
& io_ctx
, Image
& image
, const char *name
)
450 return open(io_ctx
, image
, name
, NULL
);
453 int RBD::open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
)
455 return open_by_id(io_ctx
, image
, id
, nullptr);
458 int RBD::open(IoCtx
& io_ctx
, Image
& image
, const char *name
,
459 const char *snap_name
)
461 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, false);
462 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
463 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
465 if (image
.ctx
!= NULL
) {
466 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
470 int r
= ictx
->state
->open(0);
472 tracepoint(librbd
, open_image_exit
, r
);
476 image
.ctx
= (image_ctx_t
) ictx
;
477 tracepoint(librbd
, open_image_exit
, 0);
481 int RBD::open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
,
482 const char *snap_name
)
484 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, false);
485 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
486 tracepoint(librbd
, open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
487 ictx
->snap_name
.c_str(), ictx
->read_only
);
489 if (image
.ctx
!= nullptr) {
490 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
494 int r
= ictx
->state
->open(0);
496 tracepoint(librbd
, open_image_by_id_exit
, r
);
500 image
.ctx
= (image_ctx_t
) ictx
;
501 tracepoint(librbd
, open_image_by_id_exit
, 0);
505 int RBD::aio_open(IoCtx
& io_ctx
, Image
& image
, const char *name
,
506 const char *snap_name
, RBD::AioCompletion
*c
)
508 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, false);
509 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
510 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
);
512 if (image
.ctx
!= NULL
) {
513 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
514 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
516 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(c
),
519 tracepoint(librbd
, aio_open_image_exit
, 0);
523 int RBD::aio_open_by_id(IoCtx
& io_ctx
, Image
& image
, const char *id
,
524 const char *snap_name
, RBD::AioCompletion
*c
)
526 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, false);
527 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
528 tracepoint(librbd
, aio_open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
529 ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
531 if (image
.ctx
!= nullptr) {
532 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
533 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
535 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(c
),
538 tracepoint(librbd
, aio_open_image_by_id_exit
, 0);
542 int RBD::open_read_only(IoCtx
& io_ctx
, Image
& image
, const char *name
,
543 const char *snap_name
)
545 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, true);
546 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
547 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
549 if (image
.ctx
!= NULL
) {
550 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
554 int r
= ictx
->state
->open(0);
556 tracepoint(librbd
, open_image_exit
, r
);
560 image
.ctx
= (image_ctx_t
) ictx
;
561 tracepoint(librbd
, open_image_exit
, 0);
565 int RBD::open_by_id_read_only(IoCtx
& io_ctx
, Image
& image
, const char *id
,
566 const char *snap_name
)
568 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, true);
569 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
570 tracepoint(librbd
, open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
571 ictx
->snap_name
.c_str(), ictx
->read_only
);
573 if (image
.ctx
!= nullptr) {
574 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close();
578 int r
= ictx
->state
->open(0);
580 tracepoint(librbd
, open_image_by_id_exit
, r
);
584 image
.ctx
= (image_ctx_t
) ictx
;
585 tracepoint(librbd
, open_image_by_id_exit
, 0);
589 int RBD::aio_open_read_only(IoCtx
& io_ctx
, Image
& image
, const char *name
,
590 const char *snap_name
, RBD::AioCompletion
*c
)
592 ImageCtx
*ictx
= new ImageCtx(name
, "", snap_name
, io_ctx
, true);
593 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
594 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
);
596 if (image
.ctx
!= NULL
) {
597 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
598 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
600 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(c
),
603 tracepoint(librbd
, aio_open_image_exit
, 0);
607 int RBD::aio_open_by_id_read_only(IoCtx
& io_ctx
, Image
& image
, const char *id
,
608 const char *snap_name
, RBD::AioCompletion
*c
)
610 ImageCtx
*ictx
= new ImageCtx("", id
, snap_name
, io_ctx
, true);
611 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
612 tracepoint(librbd
, aio_open_image_by_id_enter
, ictx
, ictx
->id
.c_str(),
613 ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
615 if (image
.ctx
!= nullptr) {
616 reinterpret_cast<ImageCtx
*>(image
.ctx
)->state
->close(
617 new C_OpenAfterCloseComplete(ictx
, get_aio_completion(c
), &image
.ctx
));
619 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(c
),
622 tracepoint(librbd
, aio_open_image_by_id_exit
, 0);
626 int RBD::features_to_string(uint64_t features
, std::string
*str_features
)
628 std::stringstream err
;
629 *str_features
= librbd::rbd_features_to_string(features
, &err
);
630 if (!err
.str().empty()) {
637 int RBD::features_from_string(const std::string str_features
, uint64_t *features
)
639 std::stringstream err
;
640 *features
= librbd::rbd_features_from_string(str_features
, &err
);
641 if (!err
.str().empty()) {
648 int RBD::create(IoCtx
& io_ctx
, const char *name
, uint64_t size
, int *order
)
650 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
651 tracepoint(librbd
, create_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, *order
);
652 int r
= librbd::create(io_ctx
, name
, size
, order
);
653 tracepoint(librbd
, create_exit
, r
, *order
);
657 int RBD::create2(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
658 uint64_t features
, int *order
)
660 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
661 tracepoint(librbd
, create2_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
);
662 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
, 0, 0);
663 tracepoint(librbd
, create2_exit
, r
, *order
);
667 int RBD::create3(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
668 uint64_t features
, int *order
, uint64_t stripe_unit
,
669 uint64_t stripe_count
)
671 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
672 tracepoint(librbd
, create3_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
, stripe_unit
, stripe_count
);
673 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
,
674 stripe_unit
, stripe_count
);
675 tracepoint(librbd
, create3_exit
, r
, *order
);
679 int RBD::create4(IoCtx
& io_ctx
, const char *name
, uint64_t size
,
682 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
683 tracepoint(librbd
, create4_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, opts
.opts
);
684 int r
= librbd::create(io_ctx
, name
, "", size
, opts
, "", "", false);
685 tracepoint(librbd
, create4_exit
, r
);
689 int RBD::clone(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
690 IoCtx
& c_ioctx
, const char *c_name
, uint64_t features
,
693 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
694 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
);
695 int r
= librbd::clone(p_ioctx
, p_name
, p_snap_name
, c_ioctx
, c_name
,
696 features
, c_order
, 0, 0);
697 tracepoint(librbd
, clone_exit
, r
, *c_order
);
701 int RBD::clone2(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
702 IoCtx
& c_ioctx
, const char *c_name
, uint64_t features
,
703 int *c_order
, uint64_t stripe_unit
, int stripe_count
)
705 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
706 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
);
707 int r
= librbd::clone(p_ioctx
, p_name
, p_snap_name
, c_ioctx
, c_name
,
708 features
, c_order
, stripe_unit
, stripe_count
);
709 tracepoint(librbd
, clone2_exit
, r
, *c_order
);
713 int RBD::clone3(IoCtx
& p_ioctx
, const char *p_name
, const char *p_snap_name
,
714 IoCtx
& c_ioctx
, const char *c_name
, ImageOptions
& c_opts
)
716 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioctx
));
717 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
);
718 int r
= librbd::clone(p_ioctx
, nullptr, p_name
, p_snap_name
, c_ioctx
,
719 nullptr, c_name
, c_opts
, "", "");
720 tracepoint(librbd
, clone3_exit
, r
);
724 int RBD::remove(IoCtx
& io_ctx
, const char *name
)
726 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
727 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
728 librbd::NoOpProgressContext prog_ctx
;
729 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, prog_ctx
);
730 tracepoint(librbd
, remove_exit
, r
);
734 int RBD::remove_with_progress(IoCtx
& io_ctx
, const char *name
,
735 ProgressContext
& pctx
)
737 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
738 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
739 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, pctx
);
740 tracepoint(librbd
, remove_exit
, r
);
744 int RBD::trash_move(IoCtx
&io_ctx
, const char *name
, uint64_t delay
) {
745 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
746 tracepoint(librbd
, trash_move_enter
, io_ctx
.get_pool_name().c_str(),
747 io_ctx
.get_id(), name
);
748 int r
= librbd::api::Trash
<>::move(io_ctx
, RBD_TRASH_IMAGE_SOURCE_USER
,
750 tracepoint(librbd
, trash_move_exit
, r
);
754 int RBD::trash_get(IoCtx
&io_ctx
, const char *id
, trash_image_info_t
*info
) {
755 return librbd::api::Trash
<>::get(io_ctx
, id
, info
);
758 int RBD::trash_list(IoCtx
&io_ctx
, vector
<trash_image_info_t
> &entries
) {
759 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
760 tracepoint(librbd
, trash_list_enter
,
761 io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
762 int r
= librbd::api::Trash
<>::list(io_ctx
, entries
, true);
765 for (const auto& entry
: entries
) {
766 tracepoint(librbd
, trash_list_entry
, entry
.id
.c_str());
770 tracepoint(librbd
, trash_list_exit
, r
, r
);
774 int RBD::trash_remove(IoCtx
&io_ctx
, const char *image_id
, bool force
) {
775 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
776 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
777 io_ctx
.get_id(), image_id
, force
);
778 librbd::NoOpProgressContext prog_ctx
;
779 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, prog_ctx
);
780 tracepoint(librbd
, trash_remove_exit
, r
);
784 int RBD::trash_remove_with_progress(IoCtx
&io_ctx
, const char *image_id
,
785 bool force
, ProgressContext
&pctx
) {
786 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
787 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
788 io_ctx
.get_id(), image_id
, force
);
789 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, pctx
);
790 tracepoint(librbd
, trash_remove_exit
, r
);
794 int RBD::trash_restore(IoCtx
&io_ctx
, const char *id
, const char *name
) {
795 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
796 tracepoint(librbd
, trash_undelete_enter
, io_ctx
.get_pool_name().c_str(),
797 io_ctx
.get_id(), id
, name
);
798 int r
= librbd::api::Trash
<>::restore(
799 io_ctx
, librbd::api::Trash
<>::RESTORE_SOURCE_WHITELIST
, id
, name
);
800 tracepoint(librbd
, trash_undelete_exit
, r
);
804 int RBD::trash_purge(IoCtx
&io_ctx
, time_t expire_ts
, float threshold
) {
805 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
806 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
807 io_ctx
.get_id(), expire_ts
, threshold
);
808 NoOpProgressContext nop_pctx
;
809 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, nop_pctx
);
810 tracepoint(librbd
, trash_purge_exit
, r
);
814 int RBD::trash_purge_with_progress(IoCtx
&io_ctx
, time_t expire_ts
,
815 float threshold
, ProgressContext
&pctx
) {
816 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
817 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
818 io_ctx
.get_id(), expire_ts
, threshold
);
819 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, pctx
);
820 tracepoint(librbd
, trash_purge_exit
, r
);
824 int RBD::namespace_create(IoCtx
& io_ctx
, const char *namespace_name
) {
825 return librbd::api::Namespace
<>::create(io_ctx
, namespace_name
);
828 int RBD::namespace_remove(IoCtx
& io_ctx
, const char *namespace_name
) {
829 return librbd::api::Namespace
<>::remove(io_ctx
, namespace_name
);
832 int RBD::namespace_list(IoCtx
& io_ctx
,
833 std::vector
<std::string
>* namespace_names
) {
834 return librbd::api::Namespace
<>::list(io_ctx
, namespace_names
);
837 int RBD::namespace_exists(IoCtx
& io_ctx
, const char *namespace_name
,
839 return librbd::api::Namespace
<>::exists(io_ctx
, namespace_name
, exists
);
842 int RBD::pool_init(IoCtx
& io_ctx
, bool force
) {
843 return librbd::api::Pool
<>::init(io_ctx
, force
);
846 int RBD::pool_stats_get(IoCtx
& io_ctx
, PoolStats
* stats
) {
847 auto pool_stat_options
=
848 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(stats
->pool_stats
);
849 return librbd::api::Pool
<>::get_stats(io_ctx
, pool_stat_options
);
852 int RBD::list(IoCtx
& io_ctx
, vector
<string
>& names
)
854 std::vector
<image_spec_t
> image_specs
;
855 int r
= list2(io_ctx
, &image_specs
);
861 for (auto& it
: image_specs
) {
862 names
.push_back(it
.name
);
867 int RBD::list2(IoCtx
& io_ctx
, std::vector
<image_spec_t
> *images
)
869 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
870 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(),
873 int r
= librbd::api::Image
<>::list_images(io_ctx
, images
);
876 for (auto& it
: *images
) {
877 tracepoint(librbd
, list_entry
, it
.name
.c_str());
881 tracepoint(librbd
, list_exit
, r
, r
);
885 int RBD::rename(IoCtx
& src_io_ctx
, const char *srcname
, const char *destname
)
887 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(src_io_ctx
));
888 tracepoint(librbd
, rename_enter
, src_io_ctx
.get_pool_name().c_str(), src_io_ctx
.get_id(), srcname
, destname
);
889 int r
= librbd::rename(src_io_ctx
, srcname
, destname
);
890 tracepoint(librbd
, rename_exit
, r
);
894 int RBD::migration_prepare(IoCtx
& io_ctx
, const char *image_name
,
895 IoCtx
& dest_io_ctx
, const char *dest_image_name
,
898 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
899 tracepoint(librbd
, migration_prepare_enter
, io_ctx
.get_pool_name().c_str(),
900 io_ctx
.get_id(), image_name
, dest_io_ctx
.get_pool_name().c_str(),
901 dest_io_ctx
.get_id(), dest_image_name
, opts
.opts
);
902 int r
= librbd::api::Migration
<>::prepare(io_ctx
, image_name
, dest_io_ctx
,
903 dest_image_name
, opts
);
904 tracepoint(librbd
, migration_prepare_exit
, r
);
908 int RBD::migration_execute(IoCtx
& io_ctx
, const char *image_name
)
910 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
911 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
912 io_ctx
.get_id(), image_name
);
913 librbd::NoOpProgressContext prog_ctx
;
914 int r
= librbd::api::Migration
<>::execute(io_ctx
, image_name
, prog_ctx
);
915 tracepoint(librbd
, migration_execute_exit
, r
);
919 int RBD::migration_execute_with_progress(IoCtx
& io_ctx
,
920 const char *image_name
,
921 librbd::ProgressContext
&prog_ctx
)
923 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
924 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
925 io_ctx
.get_id(), image_name
);
926 int r
= librbd::api::Migration
<>::execute(io_ctx
, image_name
, prog_ctx
);
927 tracepoint(librbd
, migration_execute_exit
, r
);
931 int RBD::migration_abort(IoCtx
& io_ctx
, const char *image_name
)
933 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
934 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
935 io_ctx
.get_id(), image_name
);
936 librbd::NoOpProgressContext prog_ctx
;
937 int r
= librbd::api::Migration
<>::abort(io_ctx
, image_name
, prog_ctx
);
938 tracepoint(librbd
, migration_abort_exit
, r
);
942 int RBD::migration_abort_with_progress(IoCtx
& io_ctx
, const char *image_name
,
943 librbd::ProgressContext
&prog_ctx
)
945 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
946 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
947 io_ctx
.get_id(), image_name
);
948 int r
= librbd::api::Migration
<>::abort(io_ctx
, image_name
, prog_ctx
);
949 tracepoint(librbd
, migration_abort_exit
, r
);
953 int RBD::migration_commit(IoCtx
& io_ctx
, const char *image_name
)
955 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
956 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
957 io_ctx
.get_id(), image_name
);
958 librbd::NoOpProgressContext prog_ctx
;
959 int r
= librbd::api::Migration
<>::commit(io_ctx
, image_name
, prog_ctx
);
960 tracepoint(librbd
, migration_commit_exit
, r
);
964 int RBD::migration_commit_with_progress(IoCtx
& io_ctx
, const char *image_name
,
965 librbd::ProgressContext
&prog_ctx
)
967 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
968 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
969 io_ctx
.get_id(), image_name
);
970 int r
= librbd::api::Migration
<>::commit(io_ctx
, image_name
, prog_ctx
);
971 tracepoint(librbd
, migration_commit_exit
, r
);
975 int RBD::migration_status(IoCtx
& io_ctx
, const char *image_name
,
976 image_migration_status_t
*status
,
979 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
980 tracepoint(librbd
, migration_status_enter
, io_ctx
.get_pool_name().c_str(),
981 io_ctx
.get_id(), image_name
);
983 if (status_size
!= sizeof(image_migration_status_t
)) {
984 tracepoint(librbd
, migration_status_exit
, -ERANGE
);
988 int r
= librbd::api::Migration
<>::status(io_ctx
, image_name
, status
);
989 tracepoint(librbd
, migration_status_exit
, r
);
993 int RBD::mirror_mode_get(IoCtx
& io_ctx
, rbd_mirror_mode_t
*mirror_mode
) {
994 return librbd::api::Mirror
<>::mode_get(io_ctx
, mirror_mode
);
997 int RBD::mirror_mode_set(IoCtx
& io_ctx
, rbd_mirror_mode_t mirror_mode
) {
998 return librbd::api::Mirror
<>::mode_set(io_ctx
, mirror_mode
);
1001 int RBD::mirror_uuid_get(IoCtx
& io_ctx
, std::string
* mirror_uuid
) {
1002 return librbd::api::Mirror
<>::uuid_get(io_ctx
, mirror_uuid
);
1005 int RBD::mirror_site_name_get(librados::Rados
& rados
,
1006 std::string
* site_name
) {
1007 return librbd::api::Mirror
<>::site_name_get(rados
, site_name
);
1010 int RBD::mirror_site_name_set(librados::Rados
& rados
,
1011 const std::string
& site_name
) {
1012 return librbd::api::Mirror
<>::site_name_set(rados
, site_name
);
1015 int RBD::mirror_peer_bootstrap_create(IoCtx
& io_ctx
, std::string
* token
) {
1016 return librbd::api::Mirror
<>::peer_bootstrap_create(io_ctx
, token
);
1019 int RBD::mirror_peer_bootstrap_import(IoCtx
& io_ctx
,
1020 rbd_mirror_peer_direction_t direction
,
1021 const std::string
& token
) {
1022 return librbd::api::Mirror
<>::peer_bootstrap_import(io_ctx
, direction
,
1026 int RBD::mirror_peer_site_add(IoCtx
& io_ctx
, std::string
*uuid
,
1027 mirror_peer_direction_t direction
,
1028 const std::string
&site_name
,
1029 const std::string
&client_name
) {
1030 return librbd::api::Mirror
<>::peer_site_add(
1031 io_ctx
, uuid
, direction
, site_name
, client_name
);
1034 int RBD::mirror_peer_site_remove(IoCtx
& io_ctx
, const std::string
&uuid
) {
1035 return librbd::api::Mirror
<>::peer_site_remove(io_ctx
, uuid
);
1038 int RBD::mirror_peer_site_list(
1039 IoCtx
& io_ctx
, std::vector
<mirror_peer_site_t
> *peer_sites
) {
1040 return librbd::api::Mirror
<>::peer_site_list(io_ctx
, peer_sites
);
1043 int RBD::mirror_peer_site_set_client_name(
1044 IoCtx
& io_ctx
, const std::string
&uuid
, const std::string
&client_name
) {
1045 return librbd::api::Mirror
<>::peer_site_set_client(io_ctx
, uuid
,
1049 int RBD::mirror_peer_site_set_name(IoCtx
& io_ctx
, const std::string
&uuid
,
1050 const std::string
&site_name
) {
1051 return librbd::api::Mirror
<>::peer_site_set_name(io_ctx
, uuid
,
1055 int RBD::mirror_peer_site_set_direction(IoCtx
& io_ctx
,
1056 const std::string
& uuid
,
1057 mirror_peer_direction_t direction
) {
1058 return librbd::api::Mirror
<>::peer_site_set_direction(io_ctx
, uuid
,
1062 int RBD::mirror_peer_site_get_attributes(
1063 IoCtx
& io_ctx
, const std::string
&uuid
,
1064 std::map
<std::string
, std::string
> *key_vals
) {
1065 return librbd::api::Mirror
<>::peer_site_get_attributes(io_ctx
, uuid
,
1069 int RBD::mirror_peer_site_set_attributes(
1070 IoCtx
& io_ctx
, const std::string
&uuid
,
1071 const std::map
<std::string
, std::string
>& key_vals
) {
1072 return librbd::api::Mirror
<>::peer_site_set_attributes(io_ctx
, uuid
,
1076 int RBD::mirror_image_global_status_list(
1077 IoCtx
& io_ctx
, const std::string
&start_id
, size_t max
,
1078 std::map
<std::string
, mirror_image_global_status_t
> *global_statuses
) {
1079 return librbd::api::Mirror
<>::image_global_status_list(
1080 io_ctx
, start_id
, max
, global_statuses
);
1083 #pragma GCC diagnostic push
1084 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1086 int RBD::mirror_peer_add(IoCtx
& io_ctx
, std::string
*uuid
,
1087 const std::string
&cluster_name
,
1088 const std::string
&client_name
) {
1089 return librbd::api::Mirror
<>::peer_site_add(
1090 io_ctx
, uuid
, RBD_MIRROR_PEER_DIRECTION_RX_TX
, cluster_name
, client_name
);
1093 int RBD::mirror_peer_remove(IoCtx
& io_ctx
, const std::string
&uuid
) {
1094 return librbd::api::Mirror
<>::peer_site_remove(io_ctx
, uuid
);
1097 int RBD::mirror_peer_list(IoCtx
& io_ctx
, std::vector
<mirror_peer_t
> *peers
) {
1098 std::vector
<mirror_peer_site_t
> peer_sites
;
1099 int r
= librbd::api::Mirror
<>::peer_site_list(io_ctx
, &peer_sites
);
1105 peers
->reserve(peer_sites
.size());
1106 for (auto& peer_site
: peer_sites
) {
1107 peers
->push_back({peer_site
.uuid
, peer_site
.site_name
,
1108 peer_site
.client_name
});
1113 int RBD::mirror_peer_set_client(IoCtx
& io_ctx
, const std::string
&uuid
,
1114 const std::string
&client_name
) {
1115 return librbd::api::Mirror
<>::peer_site_set_client(io_ctx
, uuid
,
1119 int RBD::mirror_peer_set_cluster(IoCtx
& io_ctx
, const std::string
&uuid
,
1120 const std::string
&cluster_name
) {
1121 return librbd::api::Mirror
<>::peer_site_set_name(io_ctx
, uuid
,
1125 int RBD::mirror_peer_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_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_status_list(IoCtx
& io_ctx
, const std::string
&start_id
,
1140 size_t max
, std::map
<std::string
, mirror_image_status_t
> *images
) {
1141 std::map
<std::string
, mirror_image_global_status_t
> global_statuses
;
1143 int r
= librbd::api::Mirror
<>::image_global_status_list(
1144 io_ctx
, start_id
, max
, &global_statuses
);
1150 for (auto &[id
, global_status
] : global_statuses
) {
1151 if (global_status
.site_statuses
.empty() ||
1152 global_status
.site_statuses
[0].mirror_uuid
!=
1153 cls::rbd::MirrorImageSiteStatus::LOCAL_MIRROR_UUID
) {
1157 auto& site_status
= global_status
.site_statuses
[0];
1158 (*images
)[id
] = mirror_image_status_t
{
1159 global_status
.name
, global_status
.info
, site_status
.state
,
1160 site_status
.description
, site_status
.last_update
, site_status
.up
};
1166 #pragma GCC diagnostic pop
1168 int RBD::mirror_image_status_summary(IoCtx
& io_ctx
,
1169 std::map
<mirror_image_status_state_t
, int> *states
) {
1170 return librbd::api::Mirror
<>::image_status_summary(io_ctx
, states
);
1173 int RBD::mirror_image_instance_id_list(IoCtx
& io_ctx
,
1174 const std::string
&start_id
, size_t max
,
1175 std::map
<std::string
, std::string
> *instance_ids
) {
1176 return librbd::api::Mirror
<>::image_instance_id_list(io_ctx
, start_id
, max
,
1180 int RBD::mirror_image_info_list(
1181 IoCtx
& io_ctx
, mirror_image_mode_t
*mode_filter
,
1182 const std::string
&start_id
, size_t max
,
1183 std::map
<std::string
, std::pair
<mirror_image_mode_t
,
1184 mirror_image_info_t
>> *entries
) {
1185 return librbd::api::Mirror
<>::image_info_list(io_ctx
, mode_filter
, start_id
,
1189 int RBD::group_create(IoCtx
& io_ctx
, const char *group_name
)
1191 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1192 tracepoint(librbd
, group_create_enter
, io_ctx
.get_pool_name().c_str(),
1193 io_ctx
.get_id(), group_name
);
1194 int r
= librbd::api::Group
<>::create(io_ctx
, group_name
);
1195 tracepoint(librbd
, group_create_exit
, r
);
1199 int RBD::group_remove(IoCtx
& io_ctx
, const char *group_name
)
1201 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1202 tracepoint(librbd
, group_remove_enter
, io_ctx
.get_pool_name().c_str(),
1203 io_ctx
.get_id(), group_name
);
1204 int r
= librbd::api::Group
<>::remove(io_ctx
, group_name
);
1205 tracepoint(librbd
, group_remove_exit
, r
);
1209 int RBD::group_list(IoCtx
& io_ctx
, vector
<string
> *names
)
1211 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1212 tracepoint(librbd
, group_list_enter
, io_ctx
.get_pool_name().c_str(),
1215 int r
= librbd::api::Group
<>::list(io_ctx
, names
);
1217 for (auto itr
: *names
) {
1218 tracepoint(librbd
, group_list_entry
, itr
.c_str());
1221 tracepoint(librbd
, group_list_exit
, r
);
1225 int RBD::group_rename(IoCtx
& io_ctx
, const char *src_name
,
1226 const char *dest_name
)
1228 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
1229 tracepoint(librbd
, group_rename_enter
, io_ctx
.get_pool_name().c_str(),
1230 io_ctx
.get_id(), src_name
, dest_name
);
1231 int r
= librbd::api::Group
<>::rename(io_ctx
, src_name
, dest_name
);
1232 tracepoint(librbd
, group_rename_exit
, r
);
1236 int RBD::group_image_add(IoCtx
& group_ioctx
, const char *group_name
,
1237 IoCtx
& image_ioctx
, const char *image_name
)
1239 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1240 tracepoint(librbd
, group_image_add_enter
,
1241 group_ioctx
.get_pool_name().c_str(),
1242 group_ioctx
.get_id(), group_name
,
1243 image_ioctx
.get_pool_name().c_str(),
1244 image_ioctx
.get_id(), image_name
);
1245 int r
= librbd::api::Group
<>::image_add(group_ioctx
, group_name
,
1246 image_ioctx
, image_name
);
1247 tracepoint(librbd
, group_image_add_exit
, r
);
1251 int RBD::group_image_remove(IoCtx
& group_ioctx
, const char *group_name
,
1252 IoCtx
& image_ioctx
, const char *image_name
)
1254 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1255 tracepoint(librbd
, group_image_remove_enter
,
1256 group_ioctx
.get_pool_name().c_str(),
1257 group_ioctx
.get_id(), group_name
,
1258 image_ioctx
.get_pool_name().c_str(),
1259 image_ioctx
.get_id(), image_name
);
1260 int r
= librbd::api::Group
<>::image_remove(group_ioctx
, group_name
,
1261 image_ioctx
, image_name
);
1262 tracepoint(librbd
, group_image_remove_exit
, r
);
1266 int RBD::group_image_remove_by_id(IoCtx
& group_ioctx
, const char *group_name
,
1267 IoCtx
& image_ioctx
, const char *image_id
)
1269 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1270 tracepoint(librbd
, group_image_remove_by_id_enter
,
1271 group_ioctx
.get_pool_name().c_str(),
1272 group_ioctx
.get_id(), group_name
,
1273 image_ioctx
.get_pool_name().c_str(),
1274 image_ioctx
.get_id(), image_id
);
1275 int r
= librbd::api::Group
<>::image_remove_by_id(group_ioctx
, group_name
,
1276 image_ioctx
, image_id
);
1277 tracepoint(librbd
, group_image_remove_by_id_exit
, r
);
1281 int RBD::group_image_list(IoCtx
& group_ioctx
, const char *group_name
,
1282 std::vector
<group_image_info_t
> *images
,
1283 size_t group_image_info_size
)
1285 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1286 tracepoint(librbd
, group_image_list_enter
,
1287 group_ioctx
.get_pool_name().c_str(),
1288 group_ioctx
.get_id(), group_name
);
1290 if (group_image_info_size
!= sizeof(group_image_info_t
)) {
1291 tracepoint(librbd
, group_image_list_exit
, -ERANGE
);
1295 int r
= librbd::api::Group
<>::image_list(group_ioctx
, group_name
, images
);
1296 tracepoint(librbd
, group_image_list_exit
, r
);
1300 int RBD::group_snap_create(IoCtx
& group_ioctx
, const char *group_name
,
1301 const char *snap_name
) {
1302 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1303 tracepoint(librbd
, group_snap_create_enter
,
1304 group_ioctx
.get_pool_name().c_str(),
1305 group_ioctx
.get_id(), group_name
, snap_name
);
1306 int r
= librbd::api::Group
<>::snap_create(group_ioctx
, group_name
,
1308 tracepoint(librbd
, group_snap_create_exit
, r
);
1312 int RBD::group_snap_remove(IoCtx
& group_ioctx
, const char *group_name
,
1313 const char *snap_name
) {
1314 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1315 tracepoint(librbd
, group_snap_remove_enter
,
1316 group_ioctx
.get_pool_name().c_str(),
1317 group_ioctx
.get_id(), group_name
, snap_name
);
1318 int r
= librbd::api::Group
<>::snap_remove(group_ioctx
, group_name
,
1320 tracepoint(librbd
, group_snap_remove_exit
, r
);
1324 int RBD::group_snap_list(IoCtx
& group_ioctx
, const char *group_name
,
1325 std::vector
<group_snap_info_t
> *snaps
,
1326 size_t group_snap_info_size
)
1328 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1329 tracepoint(librbd
, group_snap_list_enter
,
1330 group_ioctx
.get_pool_name().c_str(),
1331 group_ioctx
.get_id(), group_name
);
1333 if (group_snap_info_size
!= sizeof(group_snap_info_t
)) {
1334 tracepoint(librbd
, group_snap_list_exit
, -ERANGE
);
1338 int r
= librbd::api::Group
<>::snap_list(group_ioctx
, group_name
, snaps
);
1339 tracepoint(librbd
, group_snap_list_exit
, r
);
1343 int RBD::group_snap_rename(IoCtx
& group_ioctx
, const char *group_name
,
1344 const char *old_snap_name
,
1345 const char *new_snap_name
)
1347 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1348 tracepoint(librbd
, group_snap_rename_enter
,
1349 group_ioctx
.get_pool_name().c_str(), group_ioctx
.get_id(),
1350 group_name
, old_snap_name
, new_snap_name
);
1351 int r
= librbd::api::Group
<>::snap_rename(group_ioctx
, group_name
,
1352 old_snap_name
, new_snap_name
);
1353 tracepoint(librbd
, group_snap_list_exit
, r
);
1357 int RBD::group_snap_rollback(IoCtx
& group_ioctx
, const char *group_name
,
1358 const char *snap_name
) {
1359 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1360 tracepoint(librbd
, group_snap_rollback_enter
,
1361 group_ioctx
.get_pool_name().c_str(),
1362 group_ioctx
.get_id(), group_name
, snap_name
);
1363 librbd::NoOpProgressContext prog_ctx
;
1364 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
1365 snap_name
, prog_ctx
);
1366 tracepoint(librbd
, group_snap_rollback_exit
, r
);
1370 int RBD::group_snap_rollback_with_progress(IoCtx
& group_ioctx
,
1371 const char *group_name
,
1372 const char *snap_name
,
1373 ProgressContext
& prog_ctx
) {
1374 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
1375 tracepoint(librbd
, group_snap_rollback_enter
,
1376 group_ioctx
.get_pool_name().c_str(),
1377 group_ioctx
.get_id(), group_name
, snap_name
);
1378 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
1379 snap_name
, prog_ctx
);
1380 tracepoint(librbd
, group_snap_rollback_exit
, r
);
1384 int RBD::pool_metadata_get(IoCtx
& ioctx
, const std::string
&key
,
1387 int r
= librbd::api::PoolMetadata
<>::get(ioctx
, key
, value
);
1391 int RBD::pool_metadata_set(IoCtx
& ioctx
, const std::string
&key
,
1392 const std::string
&value
)
1394 int r
= librbd::api::PoolMetadata
<>::set(ioctx
, key
, value
);
1398 int RBD::pool_metadata_remove(IoCtx
& ioctx
, const std::string
&key
)
1400 int r
= librbd::api::PoolMetadata
<>::remove(ioctx
, key
);
1404 int RBD::pool_metadata_list(IoCtx
& ioctx
, const std::string
&start
,
1405 uint64_t max
, map
<string
, bufferlist
> *pairs
)
1407 int r
= librbd::api::PoolMetadata
<>::list(ioctx
, start
, max
, pairs
);
1411 int RBD::config_list(IoCtx
& io_ctx
, std::vector
<config_option_t
> *options
) {
1412 return librbd::api::Config
<>::list(io_ctx
, options
);
1415 RBD::AioCompletion::AioCompletion(void *cb_arg
, callback_t complete_cb
)
1417 auto aio_comp
= librbd::io::AioCompletion::create(
1418 cb_arg
, complete_cb
, this);
1419 aio_comp
->external_callback
= true;
1420 pc
= reinterpret_cast<void*>(aio_comp
);
1423 bool RBD::AioCompletion::is_complete()
1425 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1426 return c
->is_complete();
1429 int RBD::AioCompletion::wait_for_complete()
1431 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1432 return c
->wait_for_complete();
1435 ssize_t
RBD::AioCompletion::get_return_value()
1437 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1438 return c
->get_return_value();
1441 void *RBD::AioCompletion::get_arg()
1443 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1444 return c
->get_arg();
1447 void RBD::AioCompletion::release()
1449 librbd::io::AioCompletion
*c
= (librbd::io::AioCompletion
*)pc
;
1458 ImageOptions::ImageOptions()
1460 librbd::image_options_create(&opts
);
1463 ImageOptions::ImageOptions(rbd_image_options_t opts_
)
1465 librbd::image_options_create_ref(&opts
, opts_
);
1468 ImageOptions::ImageOptions(const ImageOptions
&imgopts
)
1470 librbd::image_options_copy(&opts
, imgopts
);
1473 ImageOptions::~ImageOptions()
1475 librbd::image_options_destroy(opts
);
1478 int ImageOptions::set(int optname
, const std::string
& optval
)
1480 return librbd::image_options_set(opts
, optname
, optval
);
1483 int ImageOptions::set(int optname
, uint64_t optval
)
1485 return librbd::image_options_set(opts
, optname
, optval
);
1488 int ImageOptions::get(int optname
, std::string
* optval
) const
1490 return librbd::image_options_get(opts
, optname
, optval
);
1493 int ImageOptions::get(int optname
, uint64_t* optval
) const
1495 return librbd::image_options_get(opts
, optname
, optval
);
1498 int ImageOptions::is_set(int optname
, bool* is_set
)
1500 return librbd::image_options_is_set(opts
, optname
, is_set
);
1503 int ImageOptions::unset(int optname
)
1505 return librbd::image_options_unset(opts
, optname
);
1508 void ImageOptions::clear()
1510 librbd::image_options_clear(opts
);
1513 bool ImageOptions::empty() const
1515 return librbd::image_options_is_empty(opts
);
1522 Image::Image() : ctx(NULL
)
1535 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1536 tracepoint(librbd
, close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
1538 r
= ictx
->state
->close();
1541 tracepoint(librbd
, close_image_exit
, r
);
1546 int Image::aio_close(RBD::AioCompletion
*c
)
1552 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1553 tracepoint(librbd
, aio_close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), c
->pc
);
1555 ictx
->state
->close(new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_CLOSE
,
1556 get_aio_completion(c
)));
1559 tracepoint(librbd
, aio_close_image_exit
, 0);
1563 int Image::resize(uint64_t size
)
1565 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1566 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
1567 librbd::NoOpProgressContext prog_ctx
;
1568 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
1569 tracepoint(librbd
, resize_exit
, r
);
1573 int Image::resize2(uint64_t size
, bool allow_shrink
, librbd::ProgressContext
& pctx
)
1575 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1576 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
1577 int r
= ictx
->operations
->resize(size
, allow_shrink
, pctx
);
1578 tracepoint(librbd
, resize_exit
, r
);
1582 int Image::resize_with_progress(uint64_t size
, librbd::ProgressContext
& pctx
)
1584 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1585 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
1586 int r
= ictx
->operations
->resize(size
, true, pctx
);
1587 tracepoint(librbd
, resize_exit
, r
);
1591 int Image::stat(image_info_t
& info
, size_t infosize
)
1593 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1594 tracepoint(librbd
, stat_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1595 int r
= librbd::info(ictx
, info
, infosize
);
1596 tracepoint(librbd
, stat_exit
, r
, &info
);
1600 int Image::old_format(uint8_t *old
)
1602 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1603 tracepoint(librbd
, get_old_format_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1604 int r
= librbd::get_old_format(ictx
, old
);
1605 tracepoint(librbd
, get_old_format_exit
, r
, *old
);
1609 int Image::size(uint64_t *size
)
1611 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1612 tracepoint(librbd
, get_size_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1613 int r
= librbd::get_size(ictx
, size
);
1614 tracepoint(librbd
, get_size_exit
, r
, *size
);
1618 int Image::get_group(group_info_t
*group_info
, size_t group_info_size
)
1620 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1621 tracepoint(librbd
, image_get_group_enter
, ictx
->name
.c_str());
1623 if (group_info_size
!= sizeof(group_info_t
)) {
1624 tracepoint(librbd
, image_get_group_exit
, -ERANGE
);
1628 int r
= librbd::api::Group
<>::image_get_group(ictx
, group_info
);
1629 tracepoint(librbd
, image_get_group_exit
, r
);
1633 int Image::features(uint64_t *features
)
1635 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1636 tracepoint(librbd
, get_features_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1637 int r
= librbd::get_features(ictx
, features
);
1638 tracepoint(librbd
, get_features_exit
, r
, *features
);
1642 int Image::update_features(uint64_t features
, bool enabled
)
1644 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1645 tracepoint(librbd
, update_features_enter
, ictx
, features
, enabled
);
1646 int r
= ictx
->operations
->update_features(features
, enabled
);
1647 tracepoint(librbd
, update_features_exit
, r
);
1651 int Image::get_op_features(uint64_t *op_features
)
1653 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1654 return librbd::api::Image
<>::get_op_features(ictx
, op_features
);
1657 uint64_t Image::get_stripe_unit() const
1659 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1660 tracepoint(librbd
, get_stripe_unit_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1661 uint64_t stripe_unit
= ictx
->get_stripe_unit();
1662 tracepoint(librbd
, get_stripe_unit_exit
, 0, stripe_unit
);
1666 uint64_t Image::get_stripe_count() const
1668 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1669 tracepoint(librbd
, get_stripe_count_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1670 uint64_t stripe_count
= ictx
->get_stripe_count();
1671 tracepoint(librbd
, get_stripe_count_exit
, 0, stripe_count
);
1672 return stripe_count
;
1675 int Image::get_create_timestamp(struct timespec
*timestamp
)
1677 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1678 tracepoint(librbd
, get_create_timestamp_enter
, ictx
, ictx
->name
.c_str(),
1680 utime_t time
= ictx
->get_create_timestamp();
1681 time
.to_timespec(timestamp
);
1682 tracepoint(librbd
, get_create_timestamp_exit
, 0, timestamp
);
1686 int Image::get_access_timestamp(struct timespec
*timestamp
)
1688 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1689 tracepoint(librbd
, get_access_timestamp_enter
, ictx
, ictx
->name
.c_str(),
1692 std::shared_lock timestamp_locker
{ictx
->timestamp_lock
};
1693 utime_t time
= ictx
->get_access_timestamp();
1694 time
.to_timespec(timestamp
);
1696 tracepoint(librbd
, get_access_timestamp_exit
, 0, timestamp
);
1700 int Image::get_modify_timestamp(struct timespec
*timestamp
)
1702 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1703 tracepoint(librbd
, get_modify_timestamp_enter
, ictx
, ictx
->name
.c_str(),
1706 std::shared_lock timestamp_locker
{ictx
->timestamp_lock
};
1707 utime_t time
= ictx
->get_modify_timestamp();
1708 time
.to_timespec(timestamp
);
1710 tracepoint(librbd
, get_modify_timestamp_exit
, 0, timestamp
);
1714 int Image::overlap(uint64_t *overlap
)
1716 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1717 tracepoint(librbd
, get_overlap_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
1718 int r
= librbd::get_overlap(ictx
, overlap
);
1719 tracepoint(librbd
, get_overlap_exit
, r
, *overlap
);
1723 int Image::get_name(std::string
*name
)
1725 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1730 int Image::get_id(std::string
*id
)
1732 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1733 if (ictx
->old_format
) {
1740 std::string
Image::get_block_name_prefix()
1742 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1743 return ictx
->object_prefix
;
1746 int64_t Image::get_data_pool_id()
1748 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1749 return librbd::api::Image
<>::get_data_pool_id(ictx
);
1752 int Image::parent_info(string
*parent_pool_name
, string
*parent_name
,
1753 string
*parent_snap_name
)
1755 librbd::linked_image_spec_t parent_image
;
1756 librbd::snap_spec_t parent_snap
;
1757 int r
= get_parent(&parent_image
, &parent_snap
);
1759 if (parent_pool_name
!= nullptr) {
1760 *parent_pool_name
= parent_image
.pool_name
;
1762 if (parent_name
!= nullptr) {
1763 *parent_name
= parent_image
.image_name
;
1765 if (parent_snap_name
!= nullptr) {
1766 *parent_snap_name
= parent_snap
.name
;
1772 int Image::parent_info2(string
*parent_pool_name
, string
*parent_name
,
1773 string
*parent_id
, string
*parent_snap_name
)
1775 librbd::linked_image_spec_t parent_image
;
1776 librbd::snap_spec_t parent_snap
;
1777 int r
= get_parent(&parent_image
, &parent_snap
);
1779 if (parent_pool_name
!= nullptr) {
1780 *parent_pool_name
= parent_image
.pool_name
;
1782 if (parent_name
!= nullptr) {
1783 *parent_name
= parent_image
.image_name
;
1785 if (parent_id
!= nullptr) {
1786 *parent_id
= parent_image
.image_id
;
1788 if (parent_snap_name
!= nullptr) {
1789 *parent_snap_name
= parent_snap
.name
;
1795 int Image::get_parent(linked_image_spec_t
*parent_image
,
1796 snap_spec_t
*parent_snap
)
1798 auto ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1799 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
1800 ictx
->snap_name
.c_str(), ictx
->read_only
);
1802 int r
= librbd::api::Image
<>::get_parent(ictx
, parent_image
, parent_snap
);
1804 tracepoint(librbd
, get_parent_info_exit
, r
,
1805 parent_image
->pool_name
.c_str(),
1806 parent_image
->image_name
.c_str(),
1807 parent_image
->image_id
.c_str(),
1808 parent_snap
->name
.c_str());
1812 int Image::get_flags(uint64_t *flags
)
1814 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1815 tracepoint(librbd
, get_flags_enter
, ictx
);
1816 int r
= librbd::get_flags(ictx
, flags
);
1817 tracepoint(librbd
, get_flags_exit
, ictx
, r
, *flags
);
1821 int Image::set_image_notification(int fd
, int type
)
1823 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1824 tracepoint(librbd
, set_image_notification_enter
, ictx
, fd
, type
);
1825 int r
= librbd::set_image_notification(ictx
, fd
, type
);
1826 tracepoint(librbd
, set_image_notification_exit
, ictx
, r
);
1830 int Image::is_exclusive_lock_owner(bool *is_owner
)
1832 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1833 tracepoint(librbd
, is_exclusive_lock_owner_enter
, ictx
);
1834 int r
= librbd::is_exclusive_lock_owner(ictx
, is_owner
);
1835 tracepoint(librbd
, is_exclusive_lock_owner_exit
, ictx
, r
, *is_owner
);
1839 int Image::lock_acquire(rbd_lock_mode_t lock_mode
)
1841 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1842 tracepoint(librbd
, lock_acquire_enter
, ictx
, lock_mode
);
1843 int r
= librbd::lock_acquire(ictx
, lock_mode
);
1844 tracepoint(librbd
, lock_acquire_exit
, ictx
, r
);
1848 int Image::lock_release()
1850 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1851 tracepoint(librbd
, lock_release_enter
, ictx
);
1852 int r
= librbd::lock_release(ictx
);
1853 tracepoint(librbd
, lock_release_exit
, ictx
, r
);
1857 int Image::lock_get_owners(rbd_lock_mode_t
*lock_mode
,
1858 std::list
<std::string
> *lock_owners
)
1860 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1861 tracepoint(librbd
, lock_get_owners_enter
, ictx
);
1862 int r
= librbd::lock_get_owners(ictx
, lock_mode
, lock_owners
);
1863 tracepoint(librbd
, lock_get_owners_exit
, ictx
, r
);
1867 int Image::lock_break(rbd_lock_mode_t lock_mode
,
1868 const std::string
&lock_owner
)
1870 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1871 tracepoint(librbd
, lock_break_enter
, ictx
, lock_mode
, lock_owner
.c_str());
1872 int r
= librbd::lock_break(ictx
, lock_mode
, lock_owner
);
1873 tracepoint(librbd
, lock_break_exit
, ictx
, r
);
1877 int Image::rebuild_object_map(ProgressContext
&prog_ctx
)
1879 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1880 return ictx
->operations
->rebuild_object_map(prog_ctx
);
1883 int Image::check_object_map(ProgressContext
&prog_ctx
)
1885 ImageCtx
*ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
1886 return ictx
->operations
->check_object_map(prog_ctx
);
1889 int Image::copy(IoCtx
& dest_io_ctx
, const char *destname
)
1891 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1892 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
);
1894 librbd::NoOpProgressContext prog_ctx
;
1895 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
1896 tracepoint(librbd
, copy_exit
, r
);
1900 int Image::copy2(Image
& dest
)
1902 ImageCtx
*srcctx
= (ImageCtx
*)ctx
;
1903 ImageCtx
*destctx
= (ImageCtx
*)dest
.ctx
;
1904 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
);
1905 librbd::NoOpProgressContext prog_ctx
;
1906 int r
= librbd::copy(srcctx
, destctx
, prog_ctx
, 0);
1907 tracepoint(librbd
, copy2_exit
, r
);
1911 int Image::copy3(IoCtx
& dest_io_ctx
, const char *destname
, ImageOptions
& opts
)
1913 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1914 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
);
1915 librbd::NoOpProgressContext prog_ctx
;
1916 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
1917 tracepoint(librbd
, copy3_exit
, r
);
1921 int Image::copy4(IoCtx
& dest_io_ctx
, const char *destname
, ImageOptions
& opts
, size_t sparse_size
)
1923 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1924 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
);
1925 librbd::NoOpProgressContext prog_ctx
;
1926 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, sparse_size
);
1927 tracepoint(librbd
, copy4_exit
, r
);
1931 int Image::copy_with_progress(IoCtx
& dest_io_ctx
, const char *destname
,
1932 librbd::ProgressContext
&pctx
)
1934 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1935 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
);
1937 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, 0);
1938 tracepoint(librbd
, copy_exit
, r
);
1942 int Image::copy_with_progress2(Image
& dest
, librbd::ProgressContext
&pctx
)
1944 ImageCtx
*srcctx
= (ImageCtx
*)ctx
;
1945 ImageCtx
*destctx
= (ImageCtx
*)dest
.ctx
;
1946 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
);
1947 int r
= librbd::copy(srcctx
, destctx
, pctx
, 0);
1948 tracepoint(librbd
, copy2_exit
, r
);
1952 int Image::copy_with_progress3(IoCtx
& dest_io_ctx
, const char *destname
,
1954 librbd::ProgressContext
&pctx
)
1956 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1957 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
);
1958 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, 0);
1959 tracepoint(librbd
, copy3_exit
, r
);
1963 int Image::copy_with_progress4(IoCtx
& dest_io_ctx
, const char *destname
,
1965 librbd::ProgressContext
&pctx
,
1968 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1969 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
);
1970 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, pctx
, sparse_size
);
1971 tracepoint(librbd
, copy4_exit
, r
);
1975 int Image::deep_copy(IoCtx
& dest_io_ctx
, const char *destname
,
1978 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1979 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
1980 ictx
->snap_name
.c_str(), ictx
->read_only
,
1981 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
1982 destname
, opts
.opts
);
1983 librbd::NoOpProgressContext prog_ctx
;
1984 int r
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
1986 tracepoint(librbd
, deep_copy_exit
, r
);
1990 int Image::deep_copy_with_progress(IoCtx
& dest_io_ctx
, const char *destname
,
1992 librbd::ProgressContext
&prog_ctx
)
1994 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
1995 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
1996 ictx
->snap_name
.c_str(), ictx
->read_only
,
1997 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
1998 destname
, opts
.opts
);
1999 int r
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
2001 tracepoint(librbd
, deep_copy_exit
, r
);
2005 int Image::flatten()
2007 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2008 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
2009 librbd::NoOpProgressContext prog_ctx
;
2010 int r
= ictx
->operations
->flatten(prog_ctx
);
2011 tracepoint(librbd
, flatten_exit
, r
);
2015 int Image::flatten_with_progress(librbd::ProgressContext
& prog_ctx
)
2017 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2018 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
2019 int r
= ictx
->operations
->flatten(prog_ctx
);
2020 tracepoint(librbd
, flatten_exit
, r
);
2024 int Image::sparsify(size_t sparse_size
)
2026 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2027 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
2029 librbd::NoOpProgressContext prog_ctx
;
2030 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
2031 tracepoint(librbd
, sparsify_exit
, r
);
2035 int Image::sparsify_with_progress(size_t sparse_size
,
2036 librbd::ProgressContext
& prog_ctx
)
2038 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2039 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
2041 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
2042 tracepoint(librbd
, sparsify_exit
, r
);
2046 int Image::list_children(set
<pair
<string
, string
> > *children
)
2048 std::vector
<linked_image_spec_t
> images
;
2049 int r
= list_children3(&images
);
2054 for (auto& image
: images
) {
2056 children
->insert({image
.pool_name
, image
.image_name
});
2062 int Image::list_children2(vector
<librbd::child_info_t
> *children
)
2064 std::vector
<linked_image_spec_t
> images
;
2065 int r
= list_children3(&images
);
2070 for (auto& image
: images
) {
2071 children
->push_back({
2072 .pool_name
= image
.pool_name
,
2073 .image_name
= image
.image_name
,
2074 .image_id
= image
.image_id
,
2075 .trash
= image
.trash
});
2081 int Image::list_children3(std::vector
<linked_image_spec_t
> *images
)
2083 auto ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
2084 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
2085 ictx
->snap_name
.c_str(), ictx
->read_only
);
2087 int r
= librbd::api::Image
<>::list_children(ictx
, images
);
2090 for (auto& it
: *images
) {
2091 tracepoint(librbd
, list_children_entry
, it
.pool_name
.c_str(),
2092 it
.image_name
.c_str());
2096 tracepoint(librbd
, list_children_exit
, r
);
2100 int Image::list_descendants(std::vector
<linked_image_spec_t
> *images
)
2102 auto ictx
= reinterpret_cast<ImageCtx
*>(ctx
);
2105 int r
= librbd::api::Image
<>::list_descendants(ictx
, {}, images
);
2109 int Image::list_lockers(std::list
<librbd::locker_t
> *lockers
,
2110 bool *exclusive
, string
*tag
)
2112 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2113 tracepoint(librbd
, list_lockers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2114 int r
= librbd::list_lockers(ictx
, lockers
, exclusive
, tag
);
2116 for (std::list
<librbd::locker_t
>::const_iterator it
= lockers
->begin();
2117 it
!= lockers
->end(); ++it
) {
2118 tracepoint(librbd
, list_lockers_entry
, it
->client
.c_str(), it
->cookie
.c_str(), it
->address
.c_str());
2121 tracepoint(librbd
, list_lockers_exit
, r
);
2125 int Image::lock_exclusive(const string
& cookie
)
2127 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2128 tracepoint(librbd
, lock_exclusive_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str());
2129 int r
= librbd::lock(ictx
, true, cookie
, "");
2130 tracepoint(librbd
, lock_exclusive_exit
, r
);
2134 int Image::lock_shared(const string
& cookie
, const std::string
& tag
)
2136 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2137 tracepoint(librbd
, lock_shared_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str(), tag
.c_str());
2138 int r
= librbd::lock(ictx
, false, cookie
, tag
);
2139 tracepoint(librbd
, lock_shared_exit
, r
);
2143 int Image::unlock(const string
& cookie
)
2145 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2146 tracepoint(librbd
, unlock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
.c_str());
2147 int r
= librbd::unlock(ictx
, cookie
);
2148 tracepoint(librbd
, unlock_exit
, r
);
2152 int Image::break_lock(const string
& client
, const string
& cookie
)
2154 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2155 tracepoint(librbd
, break_lock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, client
.c_str(), cookie
.c_str());
2156 int r
= librbd::break_lock(ictx
, client
, cookie
);
2157 tracepoint(librbd
, break_lock_exit
, r
);
2161 int Image::snap_create(const char *snap_name
)
2163 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2164 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2165 int r
= ictx
->operations
->snap_create(cls::rbd::UserSnapshotNamespace(),
2167 tracepoint(librbd
, snap_create_exit
, r
);
2171 int Image::snap_remove(const char *snap_name
)
2173 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2174 tracepoint(librbd
, snap_remove_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2175 librbd::NoOpProgressContext prog_ctx
;
2176 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, 0, prog_ctx
);
2177 tracepoint(librbd
, snap_remove_exit
, r
);
2181 int Image::snap_remove2(const char *snap_name
, uint32_t flags
, ProgressContext
& pctx
)
2183 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2184 tracepoint(librbd
, snap_remove2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
, flags
);
2185 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, flags
, pctx
);
2186 tracepoint(librbd
, snap_remove_exit
, r
);
2190 int Image::snap_remove_by_id(uint64_t snap_id
)
2192 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2193 return librbd::api::Snapshot
<>::remove(ictx
, snap_id
);
2196 int Image::snap_rollback(const char *snap_name
)
2198 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2199 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2200 librbd::NoOpProgressContext prog_ctx
;
2201 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
2202 tracepoint(librbd
, snap_rollback_exit
, r
);
2206 int Image::snap_rename(const char *srcname
, const char *dstname
)
2208 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2209 tracepoint(librbd
, snap_rename_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, srcname
, dstname
);
2210 int r
= ictx
->operations
->snap_rename(srcname
, dstname
);
2211 tracepoint(librbd
, snap_rename_exit
, r
);
2215 int Image::snap_rollback_with_progress(const char *snap_name
,
2216 ProgressContext
& prog_ctx
)
2218 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2219 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2220 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
2221 tracepoint(librbd
, snap_rollback_exit
, r
);
2225 int Image::snap_protect(const char *snap_name
)
2227 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2228 tracepoint(librbd
, snap_protect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2229 int r
= ictx
->operations
->snap_protect(cls::rbd::UserSnapshotNamespace(), snap_name
);
2230 tracepoint(librbd
, snap_protect_exit
, r
);
2234 int Image::snap_unprotect(const char *snap_name
)
2236 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2237 tracepoint(librbd
, snap_unprotect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2238 int r
= ictx
->operations
->snap_unprotect(cls::rbd::UserSnapshotNamespace(), snap_name
);
2239 tracepoint(librbd
, snap_unprotect_exit
, r
);
2243 int Image::snap_is_protected(const char *snap_name
, bool *is_protected
)
2245 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2246 tracepoint(librbd
, snap_is_protected_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2247 int r
= librbd::api::Snapshot
<>::is_protected(ictx
, snap_name
, is_protected
);
2248 tracepoint(librbd
, snap_is_protected_exit
, r
, *is_protected
? 1 : 0);
2252 int Image::snap_list(vector
<librbd::snap_info_t
>& snaps
)
2254 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2255 tracepoint(librbd
, snap_list_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, &snaps
);
2256 int r
= librbd::api::Snapshot
<>::list(ictx
, snaps
);
2258 for (int i
= 0, n
= snaps
.size(); i
< n
; i
++) {
2259 tracepoint(librbd
, snap_list_entry
, snaps
[i
].id
, snaps
[i
].size
, snaps
[i
].name
.c_str());
2262 tracepoint(librbd
, snap_list_exit
, r
, snaps
.size());
2264 // A little ugly, but the C++ API doesn't need a Image::snap_list_end,
2265 // and we want the tracepoints to mirror the C API
2266 tracepoint(librbd
, snap_list_end_enter
, &snaps
);
2267 tracepoint(librbd
, snap_list_end_exit
);
2272 bool Image::snap_exists(const char *snap_name
)
2274 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2275 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
2276 ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2278 int r
= librbd::api::Snapshot
<>::exists(ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
, &exists
);
2279 tracepoint(librbd
, snap_exists_exit
, r
, exists
);
2281 // lie to caller since we don't know the real answer yet.
2287 // A safer verion of snap_exists.
2288 int Image::snap_exists2(const char *snap_name
, bool *exists
)
2290 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2291 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
2292 ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2293 int r
= librbd::api::Snapshot
<>::exists(ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
, exists
);
2294 tracepoint(librbd
, snap_exists_exit
, r
, *exists
);
2298 int Image::snap_get_timestamp(uint64_t snap_id
, struct timespec
*timestamp
)
2300 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2301 tracepoint(librbd
, snap_get_timestamp_enter
, ictx
, ictx
->name
.c_str());
2302 int r
= librbd::api::Snapshot
<>::get_timestamp(ictx
, snap_id
, timestamp
);
2303 tracepoint(librbd
, snap_get_timestamp_exit
, r
);
2307 int Image::snap_get_limit(uint64_t *limit
)
2309 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2310 tracepoint(librbd
, snap_get_limit_enter
, ictx
, ictx
->name
.c_str());
2311 int r
= librbd::api::Snapshot
<>::get_limit(ictx
, limit
);
2312 tracepoint(librbd
, snap_get_limit_exit
, r
, *limit
);
2316 int Image::snap_get_namespace_type(uint64_t snap_id
,
2317 snap_namespace_type_t
*namespace_type
) {
2318 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2319 tracepoint(librbd
, snap_get_namespace_type_enter
, ictx
, ictx
->name
.c_str());
2320 int r
= librbd::api::Snapshot
<>::get_namespace_type(ictx
, snap_id
, namespace_type
);
2321 tracepoint(librbd
, snap_get_namespace_type_exit
, r
);
2325 int Image::snap_get_group_namespace(uint64_t snap_id
,
2326 snap_group_namespace_t
*group_snap
,
2327 size_t group_snap_size
) {
2328 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2329 tracepoint(librbd
, snap_get_group_namespace_enter
, ictx
,
2330 ictx
->name
.c_str());
2332 if (group_snap_size
!= sizeof(snap_group_namespace_t
)) {
2333 tracepoint(librbd
, snap_get_group_namespace_exit
, -ERANGE
);
2337 int r
= librbd::api::Snapshot
<>::get_group_namespace(ictx
, snap_id
,
2339 tracepoint(librbd
, snap_get_group_namespace_exit
, r
);
2343 int Image::snap_get_trash_namespace(uint64_t snap_id
,
2344 std::string
* original_name
) {
2345 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2346 return librbd::api::Snapshot
<>::get_trash_namespace(ictx
, snap_id
,
2350 int Image::snap_get_mirror_namespace(
2351 uint64_t snap_id
, snap_mirror_namespace_t
*mirror_snap
,
2352 size_t mirror_snap_size
) {
2353 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2355 if (mirror_snap_size
!= sizeof(snap_mirror_namespace_t
)) {
2359 int r
= librbd::api::Snapshot
<>::get_mirror_namespace(
2360 ictx
, snap_id
, mirror_snap
);
2364 int Image::snap_set_limit(uint64_t limit
)
2366 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2368 tracepoint(librbd
, snap_set_limit_enter
, ictx
, ictx
->name
.c_str(), limit
);
2369 int r
= ictx
->operations
->snap_set_limit(limit
);
2370 tracepoint(librbd
, snap_set_limit_exit
, r
);
2374 int Image::snap_set(const char *snap_name
)
2376 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2377 tracepoint(librbd
, snap_set_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
2378 int r
= librbd::api::Image
<>::snap_set(
2379 ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
);
2380 tracepoint(librbd
, snap_set_exit
, r
);
2384 int Image::snap_set_by_id(uint64_t snap_id
)
2386 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2387 return librbd::api::Image
<>::snap_set(ictx
, snap_id
);
2390 int Image::snap_get_name(uint64_t snap_id
, std::string
*snap_name
)
2392 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2393 return librbd::api::Snapshot
<>::get_name(ictx
, snap_id
, snap_name
);
2396 int Image::snap_get_id(const std::string snap_name
, uint64_t *snap_id
)
2398 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2399 return librbd::api::Snapshot
<>::get_id(ictx
, snap_name
, snap_id
);
2402 ssize_t
Image::read(uint64_t ofs
, size_t len
, bufferlist
& bl
)
2404 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2405 tracepoint(librbd
, read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
2407 bl
.push_back(std::move(ptr
));
2409 int r
= ictx
->io_work_queue
->read(ofs
, len
, io::ReadResult
{&bl
}, 0);
2410 tracepoint(librbd
, read_exit
, r
);
2414 ssize_t
Image::read2(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
2416 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2417 tracepoint(librbd
, read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2418 ictx
->read_only
, ofs
, len
, op_flags
);
2420 bl
.push_back(std::move(ptr
));
2422 int r
= ictx
->io_work_queue
->read(ofs
, len
, io::ReadResult
{&bl
}, op_flags
);
2423 tracepoint(librbd
, read_exit
, r
);
2427 int64_t Image::read_iterate(uint64_t ofs
, size_t len
,
2428 int (*cb
)(uint64_t, size_t, const char *, void *),
2431 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2432 tracepoint(librbd
, read_iterate_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
2434 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
2435 tracepoint(librbd
, read_iterate_exit
, r
);
2439 int Image::read_iterate2(uint64_t ofs
, uint64_t len
,
2440 int (*cb
)(uint64_t, size_t, const char *, void *),
2443 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2444 tracepoint(librbd
, read_iterate2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
2446 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
2449 tracepoint(librbd
, read_iterate2_exit
, r
);
2453 int Image::diff_iterate(const char *fromsnapname
,
2454 uint64_t ofs
, uint64_t len
,
2455 int (*cb
)(uint64_t, size_t, int, void *),
2458 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2459 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
2460 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
2462 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
2463 cls::rbd::UserSnapshotNamespace(),
2465 len
, true, false, cb
, arg
);
2466 tracepoint(librbd
, diff_iterate_exit
, r
);
2470 int Image::diff_iterate2(const char *fromsnapname
, uint64_t ofs
, uint64_t len
,
2471 bool include_parent
, bool whole_object
,
2472 int (*cb
)(uint64_t, size_t, int, void *), void *arg
)
2474 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2475 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
2476 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
2477 include_parent
, whole_object
);
2478 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
2479 cls::rbd::UserSnapshotNamespace(),
2481 len
, include_parent
,
2482 whole_object
, cb
, arg
);
2483 tracepoint(librbd
, diff_iterate_exit
, r
);
2487 ssize_t
Image::write(uint64_t ofs
, size_t len
, bufferlist
& bl
)
2489 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2490 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());
2491 if (bl
.length() < len
) {
2492 tracepoint(librbd
, write_exit
, -EINVAL
);
2496 int r
= ictx
->io_work_queue
->write(ofs
, len
, bufferlist
{bl
}, 0);
2497 tracepoint(librbd
, write_exit
, r
);
2501 ssize_t
Image::write2(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
2503 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2504 tracepoint(librbd
, write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
,
2505 ofs
, len
, bl
.length() < len
? NULL
: bl
.c_str(), op_flags
);
2506 if (bl
.length() < len
) {
2507 tracepoint(librbd
, write_exit
, -EINVAL
);
2511 int r
= ictx
->io_work_queue
->write(ofs
, len
, bufferlist
{bl
}, op_flags
);
2512 tracepoint(librbd
, write_exit
, r
);
2516 int Image::discard(uint64_t ofs
, uint64_t len
)
2518 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2519 tracepoint(librbd
, discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
2520 if (len
> static_cast<uint64_t>(std::numeric_limits
<int32_t>::max())) {
2521 tracepoint(librbd
, discard_exit
, -EINVAL
);
2524 int r
= ictx
->io_work_queue
->discard(
2525 ofs
, len
, ictx
->discard_granularity_bytes
);
2526 tracepoint(librbd
, discard_exit
, r
);
2530 ssize_t
Image::writesame(uint64_t ofs
, size_t len
, bufferlist
& bl
, int op_flags
)
2532 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2533 tracepoint(librbd
, writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2534 ictx
->read_only
, ofs
, len
, bl
.length() <= 0 ? NULL
: bl
.c_str(), bl
.length(),
2536 if (bl
.length() <= 0 || len
% bl
.length() ||
2537 len
> static_cast<size_t>(std::numeric_limits
<int>::max())) {
2538 tracepoint(librbd
, writesame_exit
, -EINVAL
);
2542 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
2543 if (discard_zero
&& mem_is_zero(bl
.c_str(), bl
.length())) {
2544 int r
= ictx
->io_work_queue
->discard(ofs
, len
, 0);
2545 tracepoint(librbd
, writesame_exit
, r
);
2549 int r
= ictx
->io_work_queue
->writesame(ofs
, len
, bufferlist
{bl
}, op_flags
);
2550 tracepoint(librbd
, writesame_exit
, r
);
2554 ssize_t
Image::compare_and_write(uint64_t ofs
, size_t len
,
2555 ceph::bufferlist
&cmp_bl
, ceph::bufferlist
& bl
,
2556 uint64_t *mismatch_off
, int op_flags
)
2558 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2559 tracepoint(librbd
, compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
2560 ictx
->snap_name
.c_str(),
2561 ictx
->read_only
, ofs
, len
, cmp_bl
.length() < len
? NULL
: cmp_bl
.c_str(),
2562 bl
.length() < len
? NULL
: bl
.c_str(), op_flags
);
2564 if (bl
.length() < len
) {
2565 tracepoint(librbd
, write_exit
, -EINVAL
);
2569 int r
= ictx
->io_work_queue
->compare_and_write(ofs
, len
, bufferlist
{cmp_bl
},
2570 bufferlist
{bl
}, mismatch_off
,
2573 tracepoint(librbd
, compare_and_write_exit
, r
);
2578 int Image::aio_write(uint64_t off
, size_t len
, bufferlist
& bl
,
2579 RBD::AioCompletion
*c
)
2581 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2582 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
);
2583 if (bl
.length() < len
) {
2584 tracepoint(librbd
, aio_write_exit
, -EINVAL
);
2587 ictx
->io_work_queue
->aio_write(get_aio_completion(c
), off
, len
,
2590 tracepoint(librbd
, aio_write_exit
, 0);
2594 int Image::aio_write2(uint64_t off
, size_t len
, bufferlist
& bl
,
2595 RBD::AioCompletion
*c
, int op_flags
)
2597 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2598 tracepoint(librbd
, aio_write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2599 ictx
->read_only
, off
, len
, bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
, op_flags
);
2600 if (bl
.length() < len
) {
2601 tracepoint(librbd
, aio_write_exit
, -EINVAL
);
2604 ictx
->io_work_queue
->aio_write(get_aio_completion(c
), off
, len
,
2605 bufferlist
{bl
}, op_flags
);
2607 tracepoint(librbd
, aio_write_exit
, 0);
2611 int Image::aio_discard(uint64_t off
, uint64_t len
, RBD::AioCompletion
*c
)
2613 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2614 tracepoint(librbd
, aio_discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, c
->pc
);
2615 ictx
->io_work_queue
->aio_discard(
2616 get_aio_completion(c
), off
, len
, ictx
->discard_granularity_bytes
);
2617 tracepoint(librbd
, aio_discard_exit
, 0);
2621 int Image::aio_read(uint64_t off
, size_t len
, bufferlist
& bl
,
2622 RBD::AioCompletion
*c
)
2624 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2625 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
);
2626 ldout(ictx
->cct
, 10) << "Image::aio_read() buf=" << (void *)bl
.c_str() << "~"
2627 << (void *)(bl
.c_str() + len
- 1) << dendl
;
2629 ictx
->io_work_queue
->aio_read(get_aio_completion(c
), off
, len
,
2630 io::ReadResult
{&bl
}, 0);
2631 tracepoint(librbd
, aio_read_exit
, 0);
2635 int Image::aio_read2(uint64_t off
, size_t len
, bufferlist
& bl
,
2636 RBD::AioCompletion
*c
, int op_flags
)
2638 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2639 tracepoint(librbd
, aio_read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2640 ictx
->read_only
, off
, len
, bl
.c_str(), c
->pc
, op_flags
);
2641 ldout(ictx
->cct
, 10) << "Image::aio_read() buf=" << (void *)bl
.c_str() << "~"
2642 << (void *)(bl
.c_str() + len
- 1) << dendl
;
2644 ictx
->io_work_queue
->aio_read(get_aio_completion(c
), off
, len
,
2645 io::ReadResult
{&bl
}, op_flags
);
2646 tracepoint(librbd
, aio_read_exit
, 0);
2652 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2653 tracepoint(librbd
, flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2654 int r
= ictx
->io_work_queue
->flush();
2655 tracepoint(librbd
, flush_exit
, r
);
2659 int Image::aio_flush(RBD::AioCompletion
*c
)
2661 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2662 tracepoint(librbd
, aio_flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
2663 ictx
->io_work_queue
->aio_flush(get_aio_completion(c
));
2664 tracepoint(librbd
, aio_flush_exit
, 0);
2668 int Image::aio_writesame(uint64_t off
, size_t len
, bufferlist
& bl
,
2669 RBD::AioCompletion
*c
, int op_flags
)
2671 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2672 tracepoint(librbd
, aio_writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2673 ictx
->read_only
, off
, len
, bl
.length() <= len
? NULL
: bl
.c_str(), bl
.length(),
2675 if (bl
.length() <= 0 || len
% bl
.length()) {
2676 tracepoint(librbd
, aio_writesame_exit
, -EINVAL
);
2680 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
2681 if (discard_zero
&& mem_is_zero(bl
.c_str(), bl
.length())) {
2682 ictx
->io_work_queue
->aio_discard(get_aio_completion(c
), off
, len
, 0);
2683 tracepoint(librbd
, aio_writesame_exit
, 0);
2687 ictx
->io_work_queue
->aio_writesame(get_aio_completion(c
), off
, len
,
2688 bufferlist
{bl
}, op_flags
);
2689 tracepoint(librbd
, aio_writesame_exit
, 0);
2693 int Image::aio_compare_and_write(uint64_t off
, size_t len
,
2694 ceph::bufferlist
& cmp_bl
, ceph::bufferlist
& bl
,
2695 RBD::AioCompletion
*c
, uint64_t *mismatch_off
,
2698 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2699 tracepoint(librbd
, aio_compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
2700 ictx
->snap_name
.c_str(),
2701 ictx
->read_only
, off
, len
, cmp_bl
.length() < len
? NULL
: cmp_bl
.c_str(),
2702 bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
, op_flags
);
2704 if (bl
.length() < len
) {
2705 tracepoint(librbd
, compare_and_write_exit
, -EINVAL
);
2709 ictx
->io_work_queue
->aio_compare_and_write(get_aio_completion(c
), off
, len
,
2710 bufferlist
{cmp_bl
}, bufferlist
{bl
},
2711 mismatch_off
, op_flags
, false);
2713 tracepoint(librbd
, aio_compare_and_write_exit
, 0);
2718 int Image::invalidate_cache()
2720 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2721 tracepoint(librbd
, invalidate_cache_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2722 int r
= librbd::invalidate_cache(ictx
);
2723 tracepoint(librbd
, invalidate_cache_exit
, r
);
2727 int Image::poll_io_events(RBD::AioCompletion
**comps
, int numcomp
)
2729 io::AioCompletion
*cs
[numcomp
];
2730 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2731 tracepoint(librbd
, poll_io_events_enter
, ictx
, numcomp
);
2732 int r
= librbd::poll_io_events(ictx
, cs
, numcomp
);
2733 tracepoint(librbd
, poll_io_events_exit
, r
);
2735 for (int i
= 0; i
< r
; ++i
)
2736 comps
[i
] = (RBD::AioCompletion
*)cs
[i
]->rbd_comp
;
2741 int Image::metadata_get(const std::string
&key
, std::string
*value
)
2743 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2744 tracepoint(librbd
, metadata_get_enter
, ictx
, key
.c_str());
2745 int r
= librbd::metadata_get(ictx
, key
, value
);
2747 tracepoint(librbd
, metadata_get_exit
, r
, key
.c_str(), NULL
);
2749 tracepoint(librbd
, metadata_get_exit
, r
, key
.c_str(), value
->c_str());
2754 int Image::metadata_set(const std::string
&key
, const std::string
&value
)
2756 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2757 tracepoint(librbd
, metadata_set_enter
, ictx
, key
.c_str(), value
.c_str());
2758 int r
= ictx
->operations
->metadata_set(key
, value
);
2759 tracepoint(librbd
, metadata_set_exit
, r
);
2763 int Image::metadata_remove(const std::string
&key
)
2765 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2766 tracepoint(librbd
, metadata_remove_enter
, ictx
, key
.c_str());
2767 int r
= ictx
->operations
->metadata_remove(key
);
2768 tracepoint(librbd
, metadata_remove_exit
, r
);
2772 int Image::metadata_list(const std::string
&start
, uint64_t max
, map
<string
, bufferlist
> *pairs
)
2774 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2775 tracepoint(librbd
, metadata_list_enter
, ictx
);
2776 int r
= librbd::metadata_list(ictx
, start
, max
, pairs
);
2778 for (map
<string
, bufferlist
>::iterator it
= pairs
->begin();
2779 it
!= pairs
->end(); ++it
) {
2780 tracepoint(librbd
, metadata_list_entry
, it
->first
.c_str(), it
->second
.c_str());
2783 tracepoint(librbd
, metadata_list_exit
, r
);
2787 int Image::mirror_image_enable() {
2788 return mirror_image_enable2(RBD_MIRROR_IMAGE_MODE_JOURNAL
);
2791 int Image::mirror_image_enable2(mirror_image_mode_t mode
) {
2792 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2793 return librbd::api::Mirror
<>::image_enable(ictx
, mode
, false);
2796 int Image::mirror_image_disable(bool force
) {
2797 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2798 return librbd::api::Mirror
<>::image_disable(ictx
, force
);
2801 int Image::mirror_image_promote(bool force
) {
2802 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2803 return librbd::api::Mirror
<>::image_promote(ictx
, force
);
2806 int Image::mirror_image_demote() {
2807 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2808 return librbd::api::Mirror
<>::image_demote(ictx
);
2811 int Image::mirror_image_resync()
2813 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2814 return librbd::api::Mirror
<>::image_resync(ictx
);
2817 int Image::mirror_image_create_snapshot(uint64_t *snap_id
)
2819 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2820 return librbd::api::Mirror
<>::image_snapshot_create(ictx
, snap_id
);
2823 int Image::mirror_image_get_info(mirror_image_info_t
*mirror_image_info
,
2825 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2827 if (sizeof(mirror_image_info_t
) != info_size
) {
2831 return librbd::api::Mirror
<>::image_get_info(ictx
, mirror_image_info
);
2834 int Image::mirror_image_get_mode(mirror_image_mode_t
*mode
) {
2835 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2837 return librbd::api::Mirror
<>::image_get_mode(ictx
, mode
);
2840 int Image::mirror_image_get_global_status(
2841 mirror_image_global_status_t
*mirror_image_global_status
,
2842 size_t status_size
) {
2843 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2845 if (sizeof(mirror_image_global_status_t
) != status_size
) {
2849 return librbd::api::Mirror
<>::image_get_global_status(
2850 ictx
, mirror_image_global_status
);
2853 #pragma GCC diagnostic push
2854 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2856 int Image::mirror_image_get_status(mirror_image_status_t
*mirror_image_status
,
2857 size_t status_size
) {
2858 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2860 if (sizeof(mirror_image_status_t
) != status_size
) {
2864 mirror_image_global_status_t mirror_image_global_status
;
2865 int r
= librbd::api::Mirror
<>::image_get_global_status(
2866 ictx
, &mirror_image_global_status
);
2871 librbd::mirror_image_site_status_t local_status
;
2872 r
= get_local_mirror_image_site_status(mirror_image_global_status
,
2878 *mirror_image_status
= mirror_image_status_t
{
2879 mirror_image_global_status
.name
, mirror_image_global_status
.info
,
2880 local_status
.state
, local_status
.description
, local_status
.last_update
,
2885 #pragma GCC diagnostic pop
2887 int Image::mirror_image_get_instance_id(std::string
*instance_id
) {
2888 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2890 return librbd::api::Mirror
<>::image_get_instance_id(ictx
, instance_id
);
2893 int Image::aio_mirror_image_promote(bool force
, RBD::AioCompletion
*c
) {
2894 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2895 librbd::api::Mirror
<>::image_promote(
2896 ictx
, force
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2897 get_aio_completion(c
)));
2901 int Image::aio_mirror_image_demote(RBD::AioCompletion
*c
) {
2902 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2903 librbd::api::Mirror
<>::image_demote(
2904 ictx
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2905 get_aio_completion(c
)));
2909 int Image::aio_mirror_image_get_info(mirror_image_info_t
*mirror_image_info
,
2911 RBD::AioCompletion
*c
) {
2912 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2914 if (sizeof(mirror_image_info_t
) != info_size
) {
2918 librbd::api::Mirror
<>::image_get_info(
2919 ictx
, mirror_image_info
,
2920 new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2921 get_aio_completion(c
)));
2925 int Image::aio_mirror_image_get_mode(mirror_image_mode_t
*mode
,
2926 RBD::AioCompletion
*c
) {
2927 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2929 librbd::api::Mirror
<>::image_get_mode(
2930 ictx
, mode
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2931 get_aio_completion(c
)));
2935 int Image::aio_mirror_image_get_global_status(
2936 mirror_image_global_status_t
*status
, size_t status_size
,
2937 RBD::AioCompletion
*c
) {
2938 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2940 if (sizeof(mirror_image_global_status_t
) != status_size
) {
2944 librbd::api::Mirror
<>::image_get_global_status(
2945 ictx
, status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2946 get_aio_completion(c
)));
2950 #pragma GCC diagnostic push
2951 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2953 int Image::aio_mirror_image_get_status(mirror_image_status_t
*status
,
2955 RBD::AioCompletion
*c
) {
2956 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2958 if (sizeof(mirror_image_status_t
) != status_size
) {
2962 auto ctx
= new C_MirrorImageGetStatus(
2963 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2964 get_aio_completion(c
)));
2965 librbd::api::Mirror
<>::image_get_global_status(
2966 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
2970 #pragma GCC diagnostic pop
2972 int Image::update_watch(UpdateWatchCtx
*wctx
, uint64_t *handle
) {
2973 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2974 tracepoint(librbd
, update_watch_enter
, ictx
, wctx
);
2975 int r
= ictx
->state
->register_update_watcher(wctx
, handle
);
2976 tracepoint(librbd
, update_watch_exit
, r
, *handle
);
2980 int Image::update_unwatch(uint64_t handle
) {
2981 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2982 tracepoint(librbd
, update_unwatch_enter
, ictx
, handle
);
2983 int r
= ictx
->state
->unregister_update_watcher(handle
);
2984 tracepoint(librbd
, update_unwatch_exit
, r
);
2988 int Image::list_watchers(std::list
<librbd::image_watcher_t
> &watchers
) {
2989 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2990 tracepoint(librbd
, list_watchers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2991 int r
= librbd::list_watchers(ictx
, watchers
);
2994 for (auto &watcher
: watchers
) {
2995 tracepoint(librbd
, list_watchers_entry
, watcher
.addr
.c_str(), watcher
.id
, watcher
.cookie
);
2999 tracepoint(librbd
, list_watchers_exit
, r
, watchers
.size());
3003 int Image::config_list(std::vector
<config_option_t
> *options
) {
3004 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3005 return librbd::api::Config
<>::list(ictx
, options
);
3008 } // namespace librbd
3010 extern "C" void rbd_version(int *major
, int *minor
, int *extra
)
3013 *major
= LIBRBD_VER_MAJOR
;
3015 *minor
= LIBRBD_VER_MINOR
;
3017 *extra
= LIBRBD_VER_EXTRA
;
3020 extern "C" void rbd_image_options_create(rbd_image_options_t
* opts
)
3022 librbd::image_options_create(opts
);
3025 extern "C" void rbd_image_options_destroy(rbd_image_options_t opts
)
3027 librbd::image_options_destroy(opts
);
3030 extern "C" int rbd_image_options_set_string(rbd_image_options_t opts
, int optname
,
3033 return librbd::image_options_set(opts
, optname
, optval
);
3036 extern "C" int rbd_image_options_set_uint64(rbd_image_options_t opts
, int optname
,
3039 return librbd::image_options_set(opts
, optname
, optval
);
3042 extern "C" int rbd_image_options_get_string(rbd_image_options_t opts
, int optname
,
3043 char* optval
, size_t maxlen
)
3045 std::string optval_
;
3047 int r
= librbd::image_options_get(opts
, optname
, &optval_
);
3053 if (optval_
.size() >= maxlen
) {
3057 strncpy(optval
, optval_
.c_str(), maxlen
);
3062 extern "C" int rbd_image_options_get_uint64(rbd_image_options_t opts
, int optname
,
3065 return librbd::image_options_get(opts
, optname
, optval
);
3068 extern "C" int rbd_image_options_is_set(rbd_image_options_t opts
, int optname
,
3071 return librbd::image_options_is_set(opts
, optname
, is_set
);
3074 extern "C" int rbd_image_options_unset(rbd_image_options_t opts
, int optname
)
3076 return librbd::image_options_unset(opts
, optname
);
3079 extern "C" void rbd_image_options_clear(rbd_image_options_t opts
)
3081 librbd::image_options_clear(opts
);
3084 extern "C" int rbd_image_options_is_empty(rbd_image_options_t opts
)
3086 return librbd::image_options_is_empty(opts
);
3089 /* pool mirroring */
3090 extern "C" int rbd_mirror_site_name_get(rados_t cluster
, char *name
,
3092 librados::Rados rados
;
3093 librados::Rados::from_rados_t(cluster
, rados
);
3095 std::string site_name
;
3096 int r
= librbd::api::Mirror
<>::site_name_get(rados
, &site_name
);
3101 auto total_len
= site_name
.size() + 1;
3102 if (*max_len
< total_len
) {
3103 *max_len
= total_len
;
3106 *max_len
= total_len
;
3108 strcpy(name
, site_name
.c_str());
3112 extern "C" int rbd_mirror_site_name_set(rados_t cluster
, const char *name
) {
3113 librados::Rados rados
;
3114 librados::Rados::from_rados_t(cluster
, rados
);
3115 return librbd::api::Mirror
<>::site_name_set(rados
, name
);
3118 extern "C" int rbd_mirror_mode_get(rados_ioctx_t p
,
3119 rbd_mirror_mode_t
*mirror_mode
) {
3120 librados::IoCtx io_ctx
;
3121 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3122 return librbd::api::Mirror
<>::mode_get(io_ctx
, mirror_mode
);
3125 extern "C" int rbd_mirror_mode_set(rados_ioctx_t p
,
3126 rbd_mirror_mode_t mirror_mode
) {
3127 librados::IoCtx io_ctx
;
3128 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3129 return librbd::api::Mirror
<>::mode_set(io_ctx
, mirror_mode
);
3132 extern "C" int rbd_mirror_uuid_get(rados_ioctx_t p
,
3133 char *mirror_uuid
, size_t *max_len
) {
3134 librados::IoCtx io_ctx
;
3135 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3137 std::string mirror_uuid_str
;
3138 int r
= librbd::api::Mirror
<>::uuid_get(io_ctx
, &mirror_uuid_str
);
3143 auto total_len
= mirror_uuid_str
.size() + 1;
3144 if (*max_len
< total_len
) {
3145 *max_len
= total_len
;
3148 *max_len
= total_len
;
3150 strcpy(mirror_uuid
, mirror_uuid_str
.c_str());
3154 extern "C" int rbd_mirror_peer_bootstrap_create(rados_ioctx_t p
, char *token
,
3156 librados::IoCtx io_ctx
;
3157 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3159 std::string token_str
;
3160 int r
= librbd::api::Mirror
<>::peer_bootstrap_create(io_ctx
, &token_str
);
3165 auto total_len
= token_str
.size() + 1;
3166 if (*max_len
< total_len
) {
3167 *max_len
= total_len
;
3170 *max_len
= total_len
;
3172 strcpy(token
, token_str
.c_str());
3176 extern "C" int rbd_mirror_peer_bootstrap_import(
3177 rados_ioctx_t p
, rbd_mirror_peer_direction_t direction
,
3178 const char *token
) {
3179 librados::IoCtx io_ctx
;
3180 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3182 return librbd::api::Mirror
<>::peer_bootstrap_import(io_ctx
, direction
, token
);
3185 extern "C" int rbd_mirror_peer_site_add(rados_ioctx_t p
, char *uuid
,
3186 size_t uuid_max_length
,
3187 rbd_mirror_peer_direction_t direction
,
3188 const char *site_name
,
3189 const char *client_name
) {
3190 static const std::size_t UUID_LENGTH
= 36;
3192 librados::IoCtx io_ctx
;
3193 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3195 if (uuid_max_length
< UUID_LENGTH
+ 1) {
3199 std::string uuid_str
;
3200 int r
= librbd::api::Mirror
<>::peer_site_add(io_ctx
, &uuid_str
, direction
,
3201 site_name
, client_name
);
3203 strncpy(uuid
, uuid_str
.c_str(), uuid_max_length
);
3204 uuid
[uuid_max_length
- 1] = '\0';
3209 extern "C" int rbd_mirror_peer_site_remove(rados_ioctx_t p
, const char *uuid
) {
3210 librados::IoCtx io_ctx
;
3211 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3212 int r
= librbd::api::Mirror
<>::peer_site_remove(io_ctx
, uuid
);
3216 extern "C" int rbd_mirror_peer_site_list(
3217 rados_ioctx_t p
, rbd_mirror_peer_site_t
*peers
, int *max_peers
) {
3218 librados::IoCtx io_ctx
;
3219 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3221 std::vector
<librbd::mirror_peer_site_t
> peer_vector
;
3222 int r
= librbd::api::Mirror
<>::peer_site_list(io_ctx
, &peer_vector
);
3227 if (*max_peers
< static_cast<int>(peer_vector
.size())) {
3228 *max_peers
= static_cast<int>(peer_vector
.size());
3232 for (int i
= 0; i
< static_cast<int>(peer_vector
.size()); ++i
) {
3233 peers
[i
].uuid
= strdup(peer_vector
[i
].uuid
.c_str());
3234 peers
[i
].direction
= peer_vector
[i
].direction
;
3235 peers
[i
].site_name
= strdup(peer_vector
[i
].site_name
.c_str());
3236 peers
[i
].mirror_uuid
= strdup(peer_vector
[i
].mirror_uuid
.c_str());
3237 peers
[i
].client_name
= strdup(peer_vector
[i
].client_name
.c_str());
3239 *max_peers
= static_cast<int>(peer_vector
.size());
3243 extern "C" void rbd_mirror_peer_site_list_cleanup(rbd_mirror_peer_site_t
*peers
,
3245 for (int i
= 0; i
< max_peers
; ++i
) {
3246 free(peers
[i
].uuid
);
3247 free(peers
[i
].site_name
);
3248 free(peers
[i
].mirror_uuid
);
3249 free(peers
[i
].client_name
);
3253 extern "C" int rbd_mirror_peer_site_set_client_name(
3254 rados_ioctx_t p
, const char *uuid
, const char *client_name
) {
3255 librados::IoCtx io_ctx
;
3256 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3257 return librbd::api::Mirror
<>::peer_site_set_client(io_ctx
, uuid
, client_name
);
3260 extern "C" int rbd_mirror_peer_site_set_name(
3261 rados_ioctx_t p
, const char *uuid
, const char *site_name
) {
3262 librados::IoCtx io_ctx
;
3263 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3264 return librbd::api::Mirror
<>::peer_site_set_name(io_ctx
, uuid
, site_name
);
3267 extern "C" int rbd_mirror_peer_site_set_direction(
3268 rados_ioctx_t p
, const char *uuid
, rbd_mirror_peer_direction_t direction
) {
3269 librados::IoCtx io_ctx
;
3270 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3271 return librbd::api::Mirror
<>::peer_site_set_direction(io_ctx
, uuid
,
3275 extern "C" int rbd_mirror_peer_site_get_attributes(
3276 rados_ioctx_t p
, const char *uuid
, char *keys
, size_t *max_key_len
,
3277 char *values
, size_t *max_val_len
, size_t *key_value_count
) {
3278 librados::IoCtx io_ctx
;
3279 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3281 std::map
<std::string
, std::string
> attributes
;
3282 int r
= librbd::api::Mirror
<>::peer_site_get_attributes(
3283 io_ctx
, uuid
, &attributes
);
3288 size_t key_total_len
= 0, val_total_len
= 0;
3289 for (auto& it
: attributes
) {
3290 key_total_len
+= it
.first
.size() + 1;
3291 val_total_len
+= it
.second
.length() + 1;
3294 bool too_short
= ((*max_key_len
< key_total_len
) ||
3295 (*max_val_len
< val_total_len
));
3297 *max_key_len
= key_total_len
;
3298 *max_val_len
= val_total_len
;
3299 *key_value_count
= attributes
.size();
3304 char *keys_p
= keys
;
3305 char *values_p
= values
;
3306 for (auto& it
: attributes
) {
3307 strncpy(keys_p
, it
.first
.c_str(), it
.first
.size() + 1);
3308 keys_p
+= it
.first
.size() + 1;
3310 strncpy(values_p
, it
.second
.c_str(), it
.second
.length() + 1);
3311 values_p
+= it
.second
.length() + 1;
3317 extern "C" int rbd_mirror_peer_site_set_attributes(
3318 rados_ioctx_t p
, const char *uuid
, const char *keys
, const char *values
,
3320 librados::IoCtx io_ctx
;
3321 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3323 std::map
<std::string
, std::string
> attributes
;
3325 for (size_t i
= 0; i
< count
; ++i
) {
3326 const char* key
= keys
;
3327 keys
+= strlen(key
) + 1;
3328 const char* value
= values
;
3329 values
+= strlen(value
) + 1;
3330 attributes
[key
] = value
;
3333 return librbd::api::Mirror
<>::peer_site_set_attributes(
3334 io_ctx
, uuid
, attributes
);
3337 extern "C" int rbd_mirror_image_global_status_list(rados_ioctx_t p
,
3338 const char *start_id
, size_t max
, char **image_ids
,
3339 rbd_mirror_image_global_status_t
*images
, size_t *len
) {
3340 librados::IoCtx io_ctx
;
3341 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3342 std::map
<std::string
, librbd::mirror_image_global_status_t
> cpp_images
;
3344 int r
= librbd::api::Mirror
<>::image_global_status_list(
3345 io_ctx
, start_id
, max
, &cpp_images
);
3351 for (auto &it
: cpp_images
) {
3352 ceph_assert(i
< max
);
3353 const std::string
&image_id
= it
.first
;
3354 image_ids
[i
] = strdup(image_id
.c_str());
3355 mirror_image_global_status_cpp_to_c(it
.second
, &images
[i
]);
3362 extern "C" void rbd_mirror_image_global_status_cleanup(
3363 rbd_mirror_image_global_status_t
*global_status
) {
3364 free(global_status
->name
);
3365 rbd_mirror_image_get_info_cleanup(&global_status
->info
);
3366 for (auto idx
= 0U; idx
< global_status
->site_statuses_count
; ++idx
) {
3367 free(global_status
->site_statuses
[idx
].mirror_uuid
);
3368 free(global_status
->site_statuses
[idx
].description
);
3370 free(global_status
->site_statuses
);
3373 extern "C" void rbd_mirror_image_global_status_list_cleanup(
3374 char **image_ids
, rbd_mirror_image_global_status_t
*images
, size_t len
) {
3375 for (size_t i
= 0; i
< len
; i
++) {
3377 rbd_mirror_image_global_status_cleanup(&images
[i
]);
3381 #pragma GCC diagnostic push
3382 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
3384 extern "C" int rbd_mirror_peer_add(rados_ioctx_t p
, char *uuid
,
3385 size_t uuid_max_length
,
3386 const char *cluster_name
,
3387 const char *client_name
) {
3388 return rbd_mirror_peer_site_add(
3389 p
, uuid
, uuid_max_length
, RBD_MIRROR_PEER_DIRECTION_RX_TX
, cluster_name
,
3393 extern "C" int rbd_mirror_peer_remove(rados_ioctx_t p
, const char *uuid
) {
3394 return rbd_mirror_peer_site_remove(p
, uuid
);
3397 extern "C" int rbd_mirror_peer_list(rados_ioctx_t p
,
3398 rbd_mirror_peer_t
*peers
, int *max_peers
) {
3399 librados::IoCtx io_ctx
;
3400 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3402 std::vector
<librbd::mirror_peer_site_t
> peer_vector
;
3403 int r
= librbd::api::Mirror
<>::peer_site_list(io_ctx
, &peer_vector
);
3408 if (*max_peers
< static_cast<int>(peer_vector
.size())) {
3409 *max_peers
= static_cast<int>(peer_vector
.size());
3413 for (int i
= 0; i
< static_cast<int>(peer_vector
.size()); ++i
) {
3414 peers
[i
].uuid
= strdup(peer_vector
[i
].uuid
.c_str());
3415 peers
[i
].cluster_name
= strdup(peer_vector
[i
].site_name
.c_str());
3416 peers
[i
].client_name
= strdup(peer_vector
[i
].client_name
.c_str());
3418 *max_peers
= static_cast<int>(peer_vector
.size());
3422 extern "C" void rbd_mirror_peer_list_cleanup(rbd_mirror_peer_t
*peers
,
3424 for (int i
= 0; i
< max_peers
; ++i
) {
3425 free(peers
[i
].uuid
);
3426 free(peers
[i
].cluster_name
);
3427 free(peers
[i
].client_name
);
3431 extern "C" int rbd_mirror_peer_set_client(rados_ioctx_t p
, const char *uuid
,
3432 const char *client_name
) {
3433 return rbd_mirror_peer_site_set_client_name(p
, uuid
, client_name
);
3436 extern "C" int rbd_mirror_peer_set_cluster(rados_ioctx_t p
, const char *uuid
,
3437 const char *cluster_name
) {
3438 return rbd_mirror_peer_site_set_name(p
, uuid
, cluster_name
);
3441 extern "C" int rbd_mirror_peer_get_attributes(
3442 rados_ioctx_t p
, const char *uuid
, char *keys
, size_t *max_key_len
,
3443 char *values
, size_t *max_val_len
, size_t *key_value_count
) {
3444 return rbd_mirror_peer_site_get_attributes(
3445 p
, uuid
, keys
, max_key_len
, values
, max_val_len
, key_value_count
);
3448 extern "C" int rbd_mirror_peer_set_attributes(
3449 rados_ioctx_t p
, const char *uuid
, const char *keys
, const char *values
,
3451 return rbd_mirror_peer_site_set_attributes(
3452 p
, uuid
, keys
, values
, count
);
3455 extern "C" int rbd_mirror_image_status_list(rados_ioctx_t p
,
3456 const char *start_id
, size_t max
, char **image_ids
,
3457 rbd_mirror_image_status_t
*images
, size_t *len
) {
3458 librados::IoCtx io_ctx
;
3459 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3460 std::map
<std::string
, librbd::mirror_image_global_status_t
> cpp_images
;
3462 int r
= librbd::api::Mirror
<>::image_global_status_list(
3463 io_ctx
, start_id
, max
, &cpp_images
);
3469 for (auto &it
: cpp_images
) {
3470 ceph_assert(i
< max
);
3471 const std::string
&image_id
= it
.first
;
3472 image_ids
[i
] = strdup(image_id
.c_str());
3473 mirror_image_global_status_cpp_to_c(it
.second
, &images
[i
]);
3480 extern "C" void rbd_mirror_image_status_list_cleanup(char **image_ids
,
3481 rbd_mirror_image_status_t
*images
, size_t len
) {
3482 for (size_t i
= 0; i
< len
; i
++) {
3484 free(images
[i
].name
);
3485 rbd_mirror_image_get_info_cleanup(&images
[i
].info
);
3486 free(images
[i
].description
);
3490 #pragma GCC diagnostic pop
3492 extern "C" int rbd_mirror_image_status_summary(rados_ioctx_t p
,
3493 rbd_mirror_image_status_state_t
*states
, int *counts
, size_t *maxlen
) {
3495 librados::IoCtx io_ctx
;
3496 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3498 std::map
<librbd::mirror_image_status_state_t
, int> states_
;
3499 int r
= librbd::api::Mirror
<>::image_status_summary(io_ctx
, &states_
);
3505 for (auto &it
: states_
) {
3509 states
[i
] = it
.first
;
3510 counts
[i
] = it
.second
;
3517 extern "C" int rbd_mirror_image_instance_id_list(
3518 rados_ioctx_t p
, const char *start_id
, size_t max
, char **image_ids
,
3519 char **instance_ids
, size_t *len
) {
3520 librados::IoCtx io_ctx
;
3521 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3522 std::map
<std::string
, std::string
> cpp_instance_ids
;
3524 int r
= librbd::api::Mirror
<>::image_instance_id_list(io_ctx
, start_id
, max
,
3531 for (auto &it
: cpp_instance_ids
) {
3532 ceph_assert(i
< max
);
3533 image_ids
[i
] = strdup(it
.first
.c_str());
3534 instance_ids
[i
] = strdup(it
.second
.c_str());
3541 extern "C" void rbd_mirror_image_instance_id_list_cleanup(
3542 char **image_ids
, char **instance_ids
, size_t len
) {
3543 for (size_t i
= 0; i
< len
; i
++) {
3545 free(instance_ids
[i
]);
3549 extern "C" int rbd_mirror_image_info_list(
3550 rados_ioctx_t p
, rbd_mirror_image_mode_t
*mode_filter
,
3551 const char *start_id
, size_t max
, char **image_ids
,
3552 rbd_mirror_image_mode_t
*mode_entries
,
3553 rbd_mirror_image_info_t
*info_entries
, size_t *num_entries
) {
3554 librados::IoCtx io_ctx
;
3555 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3556 std::map
<std::string
, std::pair
<librbd::mirror_image_mode_t
,
3557 librbd::mirror_image_info_t
>> cpp_entries
;
3559 int r
= librbd::api::Mirror
<>::image_info_list(io_ctx
, mode_filter
, start_id
,
3565 ceph_assert(cpp_entries
.size() <= max
);
3567 for (auto &it
: cpp_entries
) {
3568 *(image_ids
++) = strdup(it
.first
.c_str());
3569 *(mode_entries
++) = it
.second
.first
;
3570 mirror_image_info_cpp_to_c(it
.second
.second
, info_entries
++);
3572 *num_entries
= cpp_entries
.size();
3577 extern "C" void rbd_mirror_image_info_list_cleanup(
3578 char **image_ids
, rbd_mirror_image_info_t
*info_entries
,
3579 size_t num_entries
) {
3580 for (size_t i
= 0; i
< num_entries
; i
++) {
3581 free(*(image_ids
++));
3582 rbd_mirror_image_get_info_cleanup(info_entries
++);
3588 extern "C" void rbd_image_spec_cleanup(rbd_image_spec_t
*image
)
3594 extern "C" void rbd_image_spec_list_cleanup(rbd_image_spec_t
*images
,
3597 for (size_t idx
= 0; idx
< num_images
; ++idx
) {
3598 rbd_image_spec_cleanup(&images
[idx
]);
3602 extern "C" void rbd_linked_image_spec_cleanup(rbd_linked_image_spec_t
*image
)
3604 free(image
->pool_name
);
3605 free(image
->pool_namespace
);
3606 free(image
->image_id
);
3607 free(image
->image_name
);
3610 extern "C" void rbd_linked_image_spec_list_cleanup(
3611 rbd_linked_image_spec_t
*images
, size_t num_images
)
3613 for (size_t idx
= 0; idx
< num_images
; ++idx
) {
3614 rbd_linked_image_spec_cleanup(&images
[idx
]);
3618 extern "C" void rbd_snap_spec_cleanup(rbd_snap_spec_t
*snap
)
3624 extern "C" int rbd_list(rados_ioctx_t p
, char *names
, size_t *size
)
3626 librados::IoCtx io_ctx
;
3627 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3629 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3630 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(),
3632 std::vector
<librbd::image_spec_t
> cpp_image_specs
;
3633 int r
= librbd::api::Image
<>::list_images(io_ctx
, &cpp_image_specs
);
3635 tracepoint(librbd
, list_exit
, r
, *size
);
3639 size_t expected_size
= 0;
3641 for (auto& it
: cpp_image_specs
) {
3642 expected_size
+= it
.name
.size() + 1;
3644 if (*size
< expected_size
) {
3645 *size
= expected_size
;
3646 tracepoint(librbd
, list_exit
, -ERANGE
, *size
);
3650 if (names
== NULL
) {
3651 tracepoint(librbd
, list_exit
, -EINVAL
, *size
);
3655 for (auto& it
: cpp_image_specs
) {
3656 const char* name
= it
.name
.c_str();
3657 tracepoint(librbd
, list_entry
, name
);
3658 strcpy(names
, name
);
3659 names
+= strlen(names
) + 1;
3661 tracepoint(librbd
, list_exit
, (int)expected_size
, *size
);
3662 return (int)expected_size
;
3665 extern "C" int rbd_list2(rados_ioctx_t p
, rbd_image_spec_t
*images
,
3668 librados::IoCtx io_ctx
;
3669 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3671 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3672 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(),
3674 // FIPS zeroization audit 20191117: this memset is not security related.
3675 memset(images
, 0, sizeof(*images
) * *size
);
3676 std::vector
<librbd::image_spec_t
> cpp_image_specs
;
3677 int r
= librbd::api::Image
<>::list_images(io_ctx
, &cpp_image_specs
);
3679 tracepoint(librbd
, list_exit
, r
, *size
);
3683 size_t expected_size
= cpp_image_specs
.size();
3684 if (*size
< expected_size
) {
3685 *size
= expected_size
;
3686 tracepoint(librbd
, list_exit
, -ERANGE
, *size
);
3690 *size
= expected_size
;
3691 for (size_t idx
= 0; idx
< expected_size
; ++idx
) {
3692 images
[idx
].id
= strdup(cpp_image_specs
[idx
].id
.c_str());
3693 images
[idx
].name
= strdup(cpp_image_specs
[idx
].name
.c_str());
3695 tracepoint(librbd
, list_exit
, 0, *size
);
3699 extern "C" int rbd_create(rados_ioctx_t p
, const char *name
, uint64_t size
, int *order
)
3701 librados::IoCtx io_ctx
;
3702 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3703 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3704 tracepoint(librbd
, create_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, *order
);
3705 int r
= librbd::create(io_ctx
, name
, size
, order
);
3706 tracepoint(librbd
, create_exit
, r
, *order
);
3710 extern "C" int rbd_create2(rados_ioctx_t p
, const char *name
,
3711 uint64_t size
, uint64_t features
,
3714 librados::IoCtx io_ctx
;
3715 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3716 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3717 tracepoint(librbd
, create2_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
);
3718 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
, 0, 0);
3719 tracepoint(librbd
, create2_exit
, r
, *order
);
3723 extern "C" int rbd_create3(rados_ioctx_t p
, const char *name
,
3724 uint64_t size
, uint64_t features
,
3726 uint64_t stripe_unit
, uint64_t stripe_count
)
3728 librados::IoCtx io_ctx
;
3729 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3730 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3731 tracepoint(librbd
, create3_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
, stripe_unit
, stripe_count
);
3732 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
,
3733 stripe_unit
, stripe_count
);
3734 tracepoint(librbd
, create3_exit
, r
, *order
);
3738 extern "C" int rbd_create4(rados_ioctx_t p
, const char *name
,
3739 uint64_t size
, rbd_image_options_t opts
)
3741 librados::IoCtx io_ctx
;
3742 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3743 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3744 tracepoint(librbd
, create4_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, opts
);
3745 librbd::ImageOptions
opts_(opts
);
3746 int r
= librbd::create(io_ctx
, name
, "", size
, opts_
, "", "", false);
3747 tracepoint(librbd
, create4_exit
, r
);
3751 extern "C" int rbd_clone(rados_ioctx_t p_ioctx
, const char *p_name
,
3752 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3753 const char *c_name
, uint64_t features
, int *c_order
)
3755 librados::IoCtx p_ioc
, c_ioc
;
3756 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3757 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3758 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3759 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
);
3760 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
,
3761 features
, c_order
, 0, 0);
3762 tracepoint(librbd
, clone_exit
, r
, *c_order
);
3766 extern "C" int rbd_clone2(rados_ioctx_t p_ioctx
, const char *p_name
,
3767 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3768 const char *c_name
, uint64_t features
, int *c_order
,
3769 uint64_t stripe_unit
, int stripe_count
)
3771 librados::IoCtx p_ioc
, c_ioc
;
3772 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3773 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3774 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3775 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
);
3776 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
,
3777 features
, c_order
, stripe_unit
, stripe_count
);
3778 tracepoint(librbd
, clone2_exit
, r
, *c_order
);
3782 extern "C" int rbd_clone3(rados_ioctx_t p_ioctx
, const char *p_name
,
3783 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3784 const char *c_name
, rbd_image_options_t c_opts
)
3786 librados::IoCtx p_ioc
, c_ioc
;
3787 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3788 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3789 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3790 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
);
3791 librbd::ImageOptions
c_opts_(c_opts
);
3792 int r
= librbd::clone(p_ioc
, nullptr, p_name
, p_snap_name
, c_ioc
, nullptr,
3793 c_name
, c_opts_
, "", "");
3794 tracepoint(librbd
, clone3_exit
, r
);
3798 extern "C" int rbd_remove(rados_ioctx_t p
, const char *name
)
3800 librados::IoCtx io_ctx
;
3801 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3802 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3803 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
3804 librbd::NoOpProgressContext prog_ctx
;
3805 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, prog_ctx
);
3806 tracepoint(librbd
, remove_exit
, r
);
3810 extern "C" int rbd_remove_with_progress(rados_ioctx_t p
, const char *name
,
3811 librbd_progress_fn_t cb
, void *cbdata
)
3813 librados::IoCtx io_ctx
;
3814 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3815 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3816 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
3817 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
3818 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, prog_ctx
);
3819 tracepoint(librbd
, remove_exit
, r
);
3823 extern "C" int rbd_trash_move(rados_ioctx_t p
, const char *name
,
3825 librados::IoCtx io_ctx
;
3826 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3827 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3828 tracepoint(librbd
, trash_move_enter
, io_ctx
.get_pool_name().c_str(),
3829 io_ctx
.get_id(), name
);
3830 int r
= librbd::api::Trash
<>::move(io_ctx
, RBD_TRASH_IMAGE_SOURCE_USER
, name
,
3832 tracepoint(librbd
, trash_move_exit
, r
);
3836 extern "C" int rbd_trash_get(rados_ioctx_t io
, const char *id
,
3837 rbd_trash_image_info_t
*info
) {
3838 librados::IoCtx io_ctx
;
3839 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3841 librbd::trash_image_info_t cpp_info
;
3842 int r
= librbd::api::Trash
<>::get(io_ctx
, id
, &cpp_info
);
3847 trash_image_info_cpp_to_c(cpp_info
, info
);
3851 extern "C" void rbd_trash_get_cleanup(rbd_trash_image_info_t
*info
) {
3856 extern "C" int rbd_trash_list(rados_ioctx_t p
, rbd_trash_image_info_t
*entries
,
3857 size_t *num_entries
) {
3858 librados::IoCtx io_ctx
;
3859 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3860 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3861 tracepoint(librbd
, trash_list_enter
,
3862 io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
3863 // FIPS zeroization audit 20191117: this memset is not security related.
3864 memset(entries
, 0, sizeof(*entries
) * *num_entries
);
3866 vector
<librbd::trash_image_info_t
> cpp_entries
;
3867 int r
= librbd::api::Trash
<>::list(io_ctx
, cpp_entries
, true);
3869 tracepoint(librbd
, trash_list_exit
, r
, *num_entries
);
3873 if (*num_entries
< cpp_entries
.size()) {
3874 *num_entries
= cpp_entries
.size();
3875 tracepoint(librbd
, trash_list_exit
, -ERANGE
, *num_entries
);
3880 for (const auto &entry
: cpp_entries
) {
3881 trash_image_info_cpp_to_c(entry
, &entries
[i
++]);
3883 *num_entries
= cpp_entries
.size();
3885 return *num_entries
;
3888 extern "C" void rbd_trash_list_cleanup(rbd_trash_image_info_t
*entries
,
3889 size_t num_entries
) {
3890 for (size_t i
=0; i
< num_entries
; i
++) {
3891 rbd_trash_get_cleanup(&entries
[i
]);
3895 extern "C" int rbd_trash_purge(rados_ioctx_t io
, time_t expire_ts
,
3897 librados::IoCtx io_ctx
;
3898 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3899 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3900 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
3901 io_ctx
.get_id(), expire_ts
, threshold
);
3902 librbd::NoOpProgressContext nop_pctx
;
3903 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, nop_pctx
);
3904 tracepoint(librbd
, trash_purge_exit
, r
);
3908 extern "C" int rbd_trash_purge_with_progress(rados_ioctx_t io
, time_t expire_ts
,
3909 float threshold
, librbd_progress_fn_t cb
, void* cbdata
) {
3910 librados::IoCtx io_ctx
;
3911 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3912 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3913 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
3914 io_ctx
.get_id(), expire_ts
, threshold
);
3915 librbd::CProgressContext
pctx(cb
, cbdata
);
3916 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, pctx
);
3917 tracepoint(librbd
, trash_purge_exit
, r
);
3921 extern "C" int rbd_trash_remove(rados_ioctx_t p
, const char *image_id
,
3923 librados::IoCtx io_ctx
;
3924 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3925 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3926 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
3927 io_ctx
.get_id(), image_id
, force
);
3928 librbd::NoOpProgressContext prog_ctx
;
3929 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, prog_ctx
);
3930 tracepoint(librbd
, trash_remove_exit
, r
);
3934 extern "C" int rbd_trash_remove_with_progress(rados_ioctx_t p
,
3935 const char *image_id
,
3937 librbd_progress_fn_t cb
,
3939 librados::IoCtx io_ctx
;
3940 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3941 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3942 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
3943 io_ctx
.get_id(), image_id
, force
);
3944 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
3945 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, prog_ctx
);
3946 tracepoint(librbd
, trash_remove_exit
, r
);
3950 extern "C" int rbd_trash_restore(rados_ioctx_t p
, const char *id
,
3952 librados::IoCtx io_ctx
;
3953 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3954 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3955 tracepoint(librbd
, trash_undelete_enter
, io_ctx
.get_pool_name().c_str(),
3956 io_ctx
.get_id(), id
, name
);
3957 int r
= librbd::api::Trash
<>::restore(
3958 io_ctx
, librbd::api::Trash
<>::RESTORE_SOURCE_WHITELIST
, id
, name
);
3959 tracepoint(librbd
, trash_undelete_exit
, r
);
3963 extern "C" int rbd_namespace_create(rados_ioctx_t io
,
3964 const char *namespace_name
) {
3965 librados::IoCtx io_ctx
;
3966 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3968 return librbd::api::Namespace
<>::create(io_ctx
, namespace_name
);
3971 extern "C" int rbd_namespace_remove(rados_ioctx_t io
,
3972 const char *namespace_name
) {
3973 librados::IoCtx io_ctx
;
3974 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3976 return librbd::api::Namespace
<>::remove(io_ctx
, namespace_name
);
3979 extern "C" int rbd_namespace_list(rados_ioctx_t io
, char *names
, size_t *size
) {
3980 librados::IoCtx io_ctx
;
3981 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3983 if (names
== nullptr || size
== nullptr) {
3987 std::vector
<std::string
> cpp_names
;
3988 int r
= librbd::api::Namespace
<>::list(io_ctx
, &cpp_names
);
3993 size_t expected_size
= 0;
3994 for (size_t i
= 0; i
< cpp_names
.size(); i
++) {
3995 expected_size
+= cpp_names
[i
].size() + 1;
3997 if (*size
< expected_size
) {
3998 *size
= expected_size
;
4002 *size
= expected_size
;
4003 for (int i
= 0; i
< (int)cpp_names
.size(); i
++) {
4004 const char* name
= cpp_names
[i
].c_str();
4005 strcpy(names
, name
);
4006 names
+= strlen(names
) + 1;
4009 return (int)expected_size
;
4012 extern "C" int rbd_namespace_exists(rados_ioctx_t io
,
4013 const char *namespace_name
,
4015 librados::IoCtx io_ctx
;
4016 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4018 return librbd::api::Namespace
<>::exists(io_ctx
, namespace_name
, exists
);
4021 extern "C" int rbd_pool_init(rados_ioctx_t io
, bool force
) {
4022 librados::IoCtx io_ctx
;
4023 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4025 return librbd::api::Pool
<>::init(io_ctx
, force
);
4028 extern "C" void rbd_pool_stats_create(rbd_pool_stats_t
*stats
) {
4029 *stats
= reinterpret_cast<rbd_pool_stats_t
>(
4030 new librbd::api::Pool
<>::StatOptions
{});
4033 extern "C" void rbd_pool_stats_destroy(rbd_pool_stats_t stats
) {
4034 auto pool_stat_options
=
4035 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(stats
);
4036 delete pool_stat_options
;
4039 extern "C" int rbd_pool_stats_option_add_uint64(rbd_pool_stats_t stats
,
4041 uint64_t* stat_val
) {
4042 auto pool_stat_options
=
4043 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(stats
);
4044 return librbd::api::Pool
<>::add_stat_option(
4045 pool_stat_options
, static_cast<rbd_pool_stat_option_t
>(stat_option
),
4049 extern "C" int rbd_pool_stats_get(
4050 rados_ioctx_t io
, rbd_pool_stats_t pool_stats
) {
4051 librados::IoCtx io_ctx
;
4052 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4054 auto pool_stat_options
=
4055 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(pool_stats
);
4056 return librbd::api::Pool
<>::get_stats(io_ctx
, pool_stat_options
);
4059 extern "C" int rbd_copy(rbd_image_t image
, rados_ioctx_t dest_p
,
4060 const char *destname
)
4062 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4063 librados::IoCtx dest_io_ctx
;
4064 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4065 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
);
4066 librbd::ImageOptions opts
;
4067 librbd::NoOpProgressContext prog_ctx
;
4068 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
4069 tracepoint(librbd
, copy_exit
, r
);
4073 extern "C" int rbd_copy2(rbd_image_t srcp
, rbd_image_t destp
)
4075 librbd::ImageCtx
*src
= (librbd::ImageCtx
*)srcp
;
4076 librbd::ImageCtx
*dest
= (librbd::ImageCtx
*)destp
;
4077 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
);
4078 librbd::NoOpProgressContext prog_ctx
;
4079 int r
= librbd::copy(src
, dest
, prog_ctx
, 0);
4080 tracepoint(librbd
, copy2_exit
, r
);
4084 extern "C" int rbd_copy3(rbd_image_t image
, rados_ioctx_t dest_p
,
4085 const char *destname
, rbd_image_options_t c_opts
)
4087 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4088 librados::IoCtx dest_io_ctx
;
4089 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4090 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
);
4091 librbd::ImageOptions
c_opts_(c_opts
);
4092 librbd::NoOpProgressContext prog_ctx
;
4093 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, c_opts_
, prog_ctx
, 0);
4094 tracepoint(librbd
, copy3_exit
, r
);
4098 extern "C" int rbd_copy4(rbd_image_t image
, rados_ioctx_t dest_p
,
4099 const char *destname
, rbd_image_options_t c_opts
, size_t sparse_size
)
4101 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4102 librados::IoCtx dest_io_ctx
;
4103 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4104 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
);
4105 librbd::ImageOptions
c_opts_(c_opts
);
4106 librbd::NoOpProgressContext prog_ctx
;
4107 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, c_opts_
, prog_ctx
, sparse_size
);
4108 tracepoint(librbd
, copy4_exit
, r
);
4112 extern "C" int rbd_copy_with_progress(rbd_image_t image
, rados_ioctx_t dest_p
,
4113 const char *destname
,
4114 librbd_progress_fn_t fn
, void *data
)
4116 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4117 librados::IoCtx dest_io_ctx
;
4118 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4119 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
);
4120 librbd::ImageOptions opts
;
4121 librbd::CProgressContext
prog_ctx(fn
, data
);
4122 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
4123 tracepoint(librbd
, copy_exit
, ret
);
4127 extern "C" int rbd_copy_with_progress2(rbd_image_t srcp
, rbd_image_t destp
,
4128 librbd_progress_fn_t fn
, void *data
)
4130 librbd::ImageCtx
*src
= (librbd::ImageCtx
*)srcp
;
4131 librbd::ImageCtx
*dest
= (librbd::ImageCtx
*)destp
;
4132 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
);
4133 librbd::CProgressContext
prog_ctx(fn
, data
);
4134 int ret
= librbd::copy(src
, dest
, prog_ctx
, 0);
4135 tracepoint(librbd
, copy2_exit
, ret
);
4139 extern "C" int rbd_copy_with_progress3(rbd_image_t image
, rados_ioctx_t dest_p
,
4140 const char *destname
,
4141 rbd_image_options_t dest_opts
,
4142 librbd_progress_fn_t fn
, void *data
)
4144 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4145 librados::IoCtx dest_io_ctx
;
4146 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4147 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
);
4148 librbd::ImageOptions
dest_opts_(dest_opts
);
4149 librbd::CProgressContext
prog_ctx(fn
, data
);
4150 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, dest_opts_
, prog_ctx
, 0);
4151 tracepoint(librbd
, copy3_exit
, ret
);
4155 extern "C" int rbd_copy_with_progress4(rbd_image_t image
, rados_ioctx_t dest_p
,
4156 const char *destname
,
4157 rbd_image_options_t dest_opts
,
4158 librbd_progress_fn_t fn
, void *data
, size_t sparse_size
)
4160 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4161 librados::IoCtx dest_io_ctx
;
4162 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4163 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
);
4164 librbd::ImageOptions
dest_opts_(dest_opts
);
4165 librbd::CProgressContext
prog_ctx(fn
, data
);
4166 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, dest_opts_
, prog_ctx
, sparse_size
);
4167 tracepoint(librbd
, copy4_exit
, ret
);
4171 extern "C" int rbd_deep_copy(rbd_image_t image
, rados_ioctx_t dest_p
,
4172 const char *destname
, rbd_image_options_t c_opts
)
4174 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4175 librados::IoCtx dest_io_ctx
;
4176 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4177 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
4178 ictx
->snap_name
.c_str(), ictx
->read_only
,
4179 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
4181 librbd::ImageOptions
opts(c_opts
);
4182 librbd::NoOpProgressContext prog_ctx
;
4183 int r
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
4185 tracepoint(librbd
, deep_copy_exit
, r
);
4189 extern "C" int rbd_deep_copy_with_progress(rbd_image_t image
,
4190 rados_ioctx_t dest_p
,
4191 const char *destname
,
4192 rbd_image_options_t dest_opts
,
4193 librbd_progress_fn_t fn
, void *data
)
4195 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4196 librados::IoCtx dest_io_ctx
;
4197 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4198 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
4199 ictx
->snap_name
.c_str(), ictx
->read_only
,
4200 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
4201 destname
, dest_opts
);
4202 librbd::ImageOptions
opts(dest_opts
);
4203 librbd::CProgressContext
prog_ctx(fn
, data
);
4204 int ret
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
4206 tracepoint(librbd
, deep_copy_exit
, ret
);
4210 extern "C" int rbd_flatten(rbd_image_t image
)
4212 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4213 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4214 librbd::NoOpProgressContext prog_ctx
;
4215 int r
= ictx
->operations
->flatten(prog_ctx
);
4216 tracepoint(librbd
, flatten_exit
, r
);
4220 extern "C" int rbd_flatten_with_progress(rbd_image_t image
,
4221 librbd_progress_fn_t cb
, void *cbdata
)
4223 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4224 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4225 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4226 int r
= ictx
->operations
->flatten(prog_ctx
);
4227 tracepoint(librbd
, flatten_exit
, r
);
4231 extern "C" int rbd_sparsify(rbd_image_t image
, size_t sparse_size
)
4233 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4234 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
4236 librbd::NoOpProgressContext prog_ctx
;
4237 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
4238 tracepoint(librbd
, sparsify_exit
, r
);
4242 extern "C" int rbd_sparsify_with_progress(rbd_image_t image
, size_t sparse_size
,
4243 librbd_progress_fn_t cb
, void *cbdata
)
4245 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4246 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
4248 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4249 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
4250 tracepoint(librbd
, sparsify_exit
, r
);
4254 extern "C" int rbd_rename(rados_ioctx_t src_p
, const char *srcname
,
4255 const char *destname
)
4257 librados::IoCtx src_io_ctx
;
4258 librados::IoCtx::from_rados_ioctx_t(src_p
, src_io_ctx
);
4259 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(src_io_ctx
));
4260 tracepoint(librbd
, rename_enter
, src_io_ctx
.get_pool_name().c_str(), src_io_ctx
.get_id(), srcname
, destname
);
4261 int r
= librbd::rename(src_io_ctx
, srcname
, destname
);
4262 tracepoint(librbd
, rename_exit
, r
);
4266 extern "C" int rbd_migration_prepare(rados_ioctx_t p
, const char *image_name
,
4267 rados_ioctx_t dest_p
,
4268 const char *dest_image_name
,
4269 rbd_image_options_t opts_
)
4271 librados::IoCtx io_ctx
;
4272 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4273 librados::IoCtx dest_io_ctx
;
4274 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4275 tracepoint(librbd
, migration_prepare_enter
, io_ctx
.get_pool_name().c_str(),
4276 io_ctx
.get_id(), image_name
, dest_io_ctx
.get_pool_name().c_str(),
4277 dest_io_ctx
.get_id(), dest_image_name
, opts_
);
4278 librbd::ImageOptions
opts(opts_
);
4279 int r
= librbd::api::Migration
<>::prepare(io_ctx
, image_name
, dest_io_ctx
,
4280 dest_image_name
, opts
);
4281 tracepoint(librbd
, migration_prepare_exit
, r
);
4285 extern "C" int rbd_migration_execute(rados_ioctx_t p
, const char *image_name
)
4287 librados::IoCtx io_ctx
;
4288 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4289 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4290 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
4291 io_ctx
.get_id(), image_name
);
4292 librbd::NoOpProgressContext prog_ctx
;
4293 int r
= librbd::api::Migration
<>::execute(io_ctx
, image_name
, prog_ctx
);
4294 tracepoint(librbd
, migration_execute_exit
, r
);
4298 extern "C" int rbd_migration_execute_with_progress(rados_ioctx_t p
,
4300 librbd_progress_fn_t fn
,
4303 librados::IoCtx io_ctx
;
4304 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4305 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4306 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
4307 io_ctx
.get_id(), name
);
4308 librbd::CProgressContext
prog_ctx(fn
, data
);
4309 int r
= librbd::api::Migration
<>::execute(io_ctx
, name
, prog_ctx
);
4310 tracepoint(librbd
, migration_execute_exit
, r
);
4314 extern "C" int rbd_migration_abort(rados_ioctx_t p
, const char *image_name
)
4316 librados::IoCtx io_ctx
;
4317 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4318 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4319 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
4320 io_ctx
.get_id(), image_name
);
4321 librbd::NoOpProgressContext prog_ctx
;
4322 int r
= librbd::api::Migration
<>::abort(io_ctx
, image_name
, prog_ctx
);
4323 tracepoint(librbd
, migration_abort_exit
, r
);
4327 extern "C" int rbd_migration_abort_with_progress(rados_ioctx_t p
,
4329 librbd_progress_fn_t fn
,
4332 librados::IoCtx io_ctx
;
4333 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4334 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4335 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
4336 io_ctx
.get_id(), name
);
4337 librbd::CProgressContext
prog_ctx(fn
, data
);
4338 int r
= librbd::api::Migration
<>::abort(io_ctx
, name
, prog_ctx
);
4339 tracepoint(librbd
, migration_abort_exit
, r
);
4343 extern "C" int rbd_migration_commit(rados_ioctx_t p
, const char *image_name
)
4345 librados::IoCtx io_ctx
;
4346 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4347 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4348 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
4349 io_ctx
.get_id(), image_name
);
4350 librbd::NoOpProgressContext prog_ctx
;
4351 int r
= librbd::api::Migration
<>::commit(io_ctx
, image_name
, prog_ctx
);
4352 tracepoint(librbd
, migration_commit_exit
, r
);
4356 extern "C" int rbd_migration_commit_with_progress(rados_ioctx_t p
,
4358 librbd_progress_fn_t fn
,
4361 librados::IoCtx io_ctx
;
4362 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4363 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4364 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
4365 io_ctx
.get_id(), name
);
4366 librbd::CProgressContext
prog_ctx(fn
, data
);
4367 int r
= librbd::api::Migration
<>::commit(io_ctx
, name
, prog_ctx
);
4368 tracepoint(librbd
, migration_commit_exit
, r
);
4372 extern "C" int rbd_migration_status(rados_ioctx_t p
, const char *image_name
,
4373 rbd_image_migration_status_t
*status
,
4376 librados::IoCtx io_ctx
;
4377 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4378 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4379 tracepoint(librbd
, migration_status_enter
, io_ctx
.get_pool_name().c_str(),
4380 io_ctx
.get_id(), image_name
);
4382 if (status_size
!= sizeof(rbd_image_migration_status_t
)) {
4383 tracepoint(librbd
, migration_status_exit
, -ERANGE
);
4387 librbd::image_migration_status_t cpp_status
;
4388 int r
= librbd::api::Migration
<>::status(io_ctx
, image_name
, &cpp_status
);
4390 status
->source_pool_id
= cpp_status
.source_pool_id
;
4391 status
->source_pool_namespace
=
4392 strdup(cpp_status
.source_pool_namespace
.c_str());
4393 status
->source_image_name
= strdup(cpp_status
.source_image_name
.c_str());
4394 status
->source_image_id
= strdup(cpp_status
.source_image_id
.c_str());
4395 status
->dest_pool_id
= cpp_status
.dest_pool_id
;
4396 status
->dest_pool_namespace
=
4397 strdup(cpp_status
.dest_pool_namespace
.c_str());
4398 status
->dest_image_name
= strdup(cpp_status
.dest_image_name
.c_str());
4399 status
->dest_image_id
= strdup(cpp_status
.dest_image_id
.c_str());
4400 status
->state
= cpp_status
.state
;
4401 status
->state_description
= strdup(cpp_status
.state_description
.c_str());
4404 tracepoint(librbd
, migration_status_exit
, r
);
4408 extern "C" void rbd_migration_status_cleanup(rbd_image_migration_status_t
*s
)
4410 free(s
->source_pool_namespace
);
4411 free(s
->source_image_name
);
4412 free(s
->source_image_id
);
4413 free(s
->dest_pool_namespace
);
4414 free(s
->dest_image_name
);
4415 free(s
->dest_image_id
);
4416 free(s
->state_description
);
4419 extern "C" int rbd_pool_metadata_get(rados_ioctx_t p
, const char *key
,
4420 char *value
, size_t *vallen
)
4422 librados::IoCtx io_ctx
;
4423 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4425 int r
= librbd::api::PoolMetadata
<>::get(io_ctx
, key
, &val_s
);
4426 if (*vallen
< val_s
.size() + 1) {
4428 *vallen
= val_s
.size() + 1;
4430 strncpy(value
, val_s
.c_str(), val_s
.size() + 1);
4436 extern "C" int rbd_pool_metadata_set(rados_ioctx_t p
, const char *key
,
4439 librados::IoCtx io_ctx
;
4440 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4441 int r
= librbd::api::PoolMetadata
<>::set(io_ctx
, key
, value
);
4445 extern "C" int rbd_pool_metadata_remove(rados_ioctx_t p
, const char *key
)
4447 librados::IoCtx io_ctx
;
4448 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4449 int r
= librbd::api::PoolMetadata
<>::remove(io_ctx
, key
);
4453 extern "C" int rbd_pool_metadata_list(rados_ioctx_t p
, const char *start
,
4454 uint64_t max
, char *key
, size_t *key_len
,
4455 char *value
, size_t *val_len
)
4457 librados::IoCtx io_ctx
;
4458 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4459 map
<string
, bufferlist
> pairs
;
4460 int r
= librbd::api::PoolMetadata
<>::list(io_ctx
, start
, max
, &pairs
);
4464 size_t key_total_len
= 0, val_total_len
= 0;
4465 for (auto &it
: pairs
) {
4466 key_total_len
+= it
.first
.size() + 1;
4467 val_total_len
+= it
.second
.length() + 1;
4469 if (*key_len
< key_total_len
|| *val_len
< val_total_len
) {
4470 *key_len
= key_total_len
;
4471 *val_len
= val_total_len
;
4474 *key_len
= key_total_len
;
4475 *val_len
= val_total_len
;
4477 char *key_p
= key
, *value_p
= value
;
4478 for (auto &it
: pairs
) {
4479 strncpy(key_p
, it
.first
.c_str(), it
.first
.size() + 1);
4480 key_p
+= it
.first
.size() + 1;
4481 strncpy(value_p
, it
.second
.c_str(), it
.second
.length());
4482 value_p
+= it
.second
.length();
4489 extern "C" int rbd_config_pool_list(rados_ioctx_t p
,
4490 rbd_config_option_t
*options
,
4492 librados::IoCtx io_ctx
;
4493 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4495 std::vector
<librbd::config_option_t
> option_vector
;
4496 int r
= librbd::api::Config
<>::list(io_ctx
, &option_vector
);
4501 if (*max_options
< static_cast<int>(option_vector
.size())) {
4502 *max_options
= static_cast<int>(option_vector
.size());
4506 for (int i
= 0; i
< static_cast<int>(option_vector
.size()); ++i
) {
4507 config_option_cpp_to_c(option_vector
[i
], &options
[i
]);
4509 *max_options
= static_cast<int>(option_vector
.size());
4513 extern "C" void rbd_config_pool_list_cleanup(rbd_config_option_t
*options
,
4515 for (int i
= 0; i
< max_options
; ++i
) {
4516 config_option_cleanup(options
[i
]);
4520 extern "C" int rbd_open(rados_ioctx_t p
, const char *name
, rbd_image_t
*image
,
4521 const char *snap_name
)
4523 librados::IoCtx io_ctx
;
4524 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4525 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4526 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4528 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4530 int r
= ictx
->state
->open(0);
4532 *image
= (rbd_image_t
)ictx
;
4534 tracepoint(librbd
, open_image_exit
, r
);
4538 extern "C" int rbd_open_by_id(rados_ioctx_t p
, const char *id
,
4539 rbd_image_t
*image
, const char *snap_name
)
4541 librados::IoCtx io_ctx
;
4542 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4543 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4544 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4546 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(),
4547 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4549 int r
= ictx
->state
->open(0);
4551 *image
= (rbd_image_t
)ictx
;
4553 tracepoint(librbd
, open_image_exit
, r
);
4557 extern "C" int rbd_aio_open(rados_ioctx_t p
, const char *name
,
4558 rbd_image_t
*image
, const char *snap_name
,
4561 librados::IoCtx io_ctx
;
4562 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4563 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4564 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4566 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4567 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
);
4568 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4570 tracepoint(librbd
, aio_open_image_exit
, 0);
4574 extern "C" int rbd_aio_open_by_id(rados_ioctx_t p
, const char *id
,
4575 rbd_image_t
*image
, const char *snap_name
,
4578 librados::IoCtx io_ctx
;
4579 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4580 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4581 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4583 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4584 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(),
4585 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
,
4587 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4589 tracepoint(librbd
, aio_open_image_exit
, 0);
4593 extern "C" int rbd_open_read_only(rados_ioctx_t p
, const char *name
,
4594 rbd_image_t
*image
, const char *snap_name
)
4596 librados::IoCtx io_ctx
;
4597 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4598 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4599 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4601 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4603 int r
= ictx
->state
->open(0);
4605 *image
= (rbd_image_t
)ictx
;
4607 tracepoint(librbd
, open_image_exit
, r
);
4611 extern "C" int rbd_open_by_id_read_only(rados_ioctx_t p
, const char *id
,
4612 rbd_image_t
*image
, const char *snap_name
)
4614 librados::IoCtx io_ctx
;
4615 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4616 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4617 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4619 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(),
4620 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4622 int r
= ictx
->state
->open(0);
4624 *image
= (rbd_image_t
)ictx
;
4626 tracepoint(librbd
, open_image_exit
, r
);
4630 extern "C" int rbd_aio_open_read_only(rados_ioctx_t p
, const char *name
,
4631 rbd_image_t
*image
, const char *snap_name
,
4634 librados::IoCtx io_ctx
;
4635 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4636 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4637 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4639 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4640 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
);
4641 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4643 tracepoint(librbd
, aio_open_image_exit
, 0);
4647 extern "C" int rbd_aio_open_by_id_read_only(rados_ioctx_t p
, const char *id
,
4649 const char *snap_name
,
4652 librados::IoCtx io_ctx
;
4653 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4654 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4655 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4657 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4658 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(),
4659 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
4660 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4662 tracepoint(librbd
, aio_open_image_exit
, 0);
4666 extern "C" int rbd_features_to_string(uint64_t features
, char *str_features
, size_t *size
)
4668 std::stringstream err
;
4669 std::string get_str_features
= librbd::rbd_features_to_string(features
, &err
);
4670 if (!err
.str().empty()) {
4673 uint64_t expected_size
= get_str_features
.size();
4674 if (*size
<= expected_size
) {
4675 *size
= expected_size
+ 1;
4678 strncpy(str_features
, get_str_features
.c_str(), expected_size
);
4679 str_features
[expected_size
] = '\0';
4680 *size
= expected_size
+ 1;
4684 extern "C" int rbd_features_from_string(const char *str_features
, uint64_t *features
)
4686 std::stringstream err
;
4687 *features
= librbd::rbd_features_from_string(str_features
, &err
);
4688 if (!err
.str().empty()) {
4695 extern "C" int rbd_close(rbd_image_t image
)
4697 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4698 tracepoint(librbd
, close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4700 int r
= ictx
->state
->close();
4702 tracepoint(librbd
, close_image_exit
, r
);
4706 extern "C" int rbd_aio_close(rbd_image_t image
, rbd_completion_t c
)
4708 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4709 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4710 tracepoint(librbd
, aio_close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), comp
->pc
);
4711 ictx
->state
->close(new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_CLOSE
,
4712 get_aio_completion(comp
)));
4713 tracepoint(librbd
, aio_close_image_exit
, 0);
4717 extern "C" int rbd_resize(rbd_image_t image
, uint64_t size
)
4719 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4720 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4721 librbd::NoOpProgressContext prog_ctx
;
4722 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
4723 tracepoint(librbd
, resize_exit
, r
);
4727 extern "C" int rbd_resize2(rbd_image_t image
, uint64_t size
, bool allow_shrink
,
4728 librbd_progress_fn_t cb
, void *cbdata
)
4730 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4731 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4732 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4733 int r
= ictx
->operations
->resize(size
, allow_shrink
, prog_ctx
);
4734 tracepoint(librbd
, resize_exit
, r
);
4738 extern "C" int rbd_resize_with_progress(rbd_image_t image
, uint64_t size
,
4739 librbd_progress_fn_t cb
, void *cbdata
)
4741 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4742 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4743 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4744 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
4745 tracepoint(librbd
, resize_exit
, r
);
4749 extern "C" int rbd_stat(rbd_image_t image
, rbd_image_info_t
*info
,
4752 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4753 tracepoint(librbd
, stat_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4754 int r
= librbd::info(ictx
, *info
, infosize
);
4755 tracepoint(librbd
, stat_exit
, r
, info
);
4759 extern "C" int rbd_get_old_format(rbd_image_t image
, uint8_t *old
)
4761 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4762 tracepoint(librbd
, get_old_format_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4763 int r
= librbd::get_old_format(ictx
, old
);
4764 tracepoint(librbd
, get_old_format_exit
, r
, *old
);
4768 extern "C" int rbd_get_size(rbd_image_t image
, uint64_t *size
)
4770 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4771 tracepoint(librbd
, get_size_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4772 int r
= librbd::get_size(ictx
, size
);
4773 tracepoint(librbd
, get_size_exit
, r
, *size
);
4777 extern "C" int rbd_get_features(rbd_image_t image
, uint64_t *features
)
4779 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4780 tracepoint(librbd
, get_features_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4781 int r
= librbd::get_features(ictx
, features
);
4782 tracepoint(librbd
, get_features_exit
, r
, *features
);
4786 extern "C" int rbd_update_features(rbd_image_t image
, uint64_t features
,
4789 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4790 bool features_enabled
= enabled
!= 0;
4791 tracepoint(librbd
, update_features_enter
, ictx
, features
, features_enabled
);
4792 int r
= ictx
->operations
->update_features(features
, features_enabled
);
4793 tracepoint(librbd
, update_features_exit
, r
);
4797 extern "C" int rbd_get_op_features(rbd_image_t image
, uint64_t *op_features
)
4799 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4800 return librbd::api::Image
<>::get_op_features(ictx
, op_features
);
4803 extern "C" int rbd_get_stripe_unit(rbd_image_t image
, uint64_t *stripe_unit
)
4805 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4806 tracepoint(librbd
, get_stripe_unit_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4807 *stripe_unit
= ictx
->get_stripe_unit();
4808 tracepoint(librbd
, get_stripe_unit_exit
, 0, *stripe_unit
);
4812 extern "C" int rbd_get_stripe_count(rbd_image_t image
, uint64_t *stripe_count
)
4814 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4815 tracepoint(librbd
, get_stripe_count_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4816 *stripe_count
= ictx
->get_stripe_count();
4817 tracepoint(librbd
, get_stripe_count_exit
, 0, *stripe_count
);
4821 extern "C" int rbd_get_create_timestamp(rbd_image_t image
,
4822 struct timespec
*timestamp
)
4824 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4825 tracepoint(librbd
, get_create_timestamp_enter
, ictx
, ictx
->name
.c_str(),
4827 utime_t time
= ictx
->get_create_timestamp();
4828 time
.to_timespec(timestamp
);
4829 tracepoint(librbd
, get_create_timestamp_exit
, 0, timestamp
);
4833 extern "C" int rbd_get_access_timestamp(rbd_image_t image
,
4834 struct timespec
*timestamp
)
4836 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4837 tracepoint(librbd
, get_access_timestamp_enter
, ictx
, ictx
->name
.c_str(),
4839 utime_t time
= ictx
->get_access_timestamp();
4840 time
.to_timespec(timestamp
);
4841 tracepoint(librbd
, get_access_timestamp_exit
, 0, timestamp
);
4845 extern "C" int rbd_get_modify_timestamp(rbd_image_t image
,
4846 struct timespec
*timestamp
)
4848 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4849 tracepoint(librbd
, get_modify_timestamp_enter
, ictx
, ictx
->name
.c_str(),
4851 utime_t time
= ictx
->get_modify_timestamp();
4852 time
.to_timespec(timestamp
);
4853 tracepoint(librbd
, get_modify_timestamp_exit
, 0, timestamp
);
4858 extern "C" int rbd_get_overlap(rbd_image_t image
, uint64_t *overlap
)
4860 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4861 tracepoint(librbd
, get_overlap_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4862 int r
= librbd::get_overlap(ictx
, overlap
);
4863 tracepoint(librbd
, get_overlap_exit
, r
, *overlap
);
4867 extern "C" int rbd_get_name(rbd_image_t image
, char *name
, size_t *name_len
)
4869 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4870 if (*name_len
<= ictx
->name
.size()) {
4871 *name_len
= ictx
->name
.size() + 1;
4875 strncpy(name
, ictx
->name
.c_str(), ictx
->name
.size());
4876 name
[ictx
->name
.size()] = '\0';
4877 *name_len
= ictx
->name
.size() + 1;
4881 extern "C" int rbd_get_id(rbd_image_t image
, char *id
, size_t id_len
)
4883 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4884 if (ictx
->old_format
) {
4887 if (ictx
->id
.size() >= id_len
) {
4891 strncpy(id
, ictx
->id
.c_str(), id_len
- 1);
4892 id
[id_len
- 1] = '\0';
4896 extern "C" int rbd_get_block_name_prefix(rbd_image_t image
, char *prefix
,
4899 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4900 if (ictx
->object_prefix
.size() >= prefix_len
) {
4904 strncpy(prefix
, ictx
->object_prefix
.c_str(), prefix_len
- 1);
4905 prefix
[prefix_len
- 1] = '\0';
4909 extern "C" int64_t rbd_get_data_pool_id(rbd_image_t image
)
4911 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4912 return librbd::api::Image
<>::get_data_pool_id(ictx
);
4915 extern "C" int rbd_get_parent_info(rbd_image_t image
,
4916 char *parent_pool_name
, size_t ppool_namelen
,
4917 char *parent_name
, size_t pnamelen
,
4918 char *parent_snap_name
, size_t psnap_namelen
)
4920 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4921 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
4922 ictx
->snap_name
.c_str(), ictx
->read_only
);
4924 librbd::linked_image_spec_t parent_image
;
4925 librbd::snap_spec_t parent_snap
;
4926 int r
= librbd::api::Image
<>::get_parent(ictx
, &parent_image
, &parent_snap
);
4928 if (parent_pool_name
) {
4929 if (parent_image
.pool_name
.length() + 1 > ppool_namelen
) {
4932 strcpy(parent_pool_name
, parent_image
.pool_name
.c_str());
4936 if (parent_image
.image_name
.length() + 1 > pnamelen
) {
4939 strcpy(parent_name
, parent_image
.image_name
.c_str());
4942 if (parent_snap_name
) {
4943 if (parent_snap
.name
.length() + 1 > psnap_namelen
) {
4946 strcpy(parent_snap_name
, parent_snap
.name
.c_str());
4952 tracepoint(librbd
, get_parent_info_exit
, r
, NULL
, NULL
, NULL
, NULL
);
4956 tracepoint(librbd
, get_parent_info_exit
, r
,
4957 parent_image
.pool_name
.c_str(),
4958 parent_image
.image_name
.c_str(),
4959 parent_image
.image_id
.c_str(),
4960 parent_snap
.name
.c_str());
4964 extern "C" int rbd_get_parent_info2(rbd_image_t image
,
4965 char *parent_pool_name
,
4966 size_t ppool_namelen
,
4967 char *parent_name
, size_t pnamelen
,
4968 char *parent_id
, size_t pidlen
,
4969 char *parent_snap_name
,
4970 size_t psnap_namelen
)
4972 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4973 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
4974 ictx
->snap_name
.c_str(), ictx
->read_only
);
4976 librbd::linked_image_spec_t parent_image
;
4977 librbd::snap_spec_t parent_snap
;
4978 int r
= librbd::api::Image
<>::get_parent(ictx
, &parent_image
, &parent_snap
);
4980 if (parent_pool_name
) {
4981 if (parent_image
.pool_name
.length() + 1 > ppool_namelen
) {
4984 strcpy(parent_pool_name
, parent_image
.pool_name
.c_str());
4988 if (parent_image
.image_name
.length() + 1 > pnamelen
) {
4991 strcpy(parent_name
, parent_image
.image_name
.c_str());
4995 if (parent_image
.image_id
.length() + 1 > pidlen
) {
4998 strcpy(parent_id
, parent_image
.image_id
.c_str());
5001 if (parent_snap_name
) {
5002 if (parent_snap
.name
.length() + 1 > psnap_namelen
) {
5005 strcpy(parent_snap_name
, parent_snap
.name
.c_str());
5011 tracepoint(librbd
, get_parent_info_exit
, r
, NULL
, NULL
, NULL
, NULL
);
5015 tracepoint(librbd
, get_parent_info_exit
, r
,
5016 parent_image
.pool_name
.c_str(),
5017 parent_image
.image_name
.c_str(),
5018 parent_image
.image_id
.c_str(),
5019 parent_snap
.name
.c_str());
5023 extern "C" int rbd_get_parent(rbd_image_t image
,
5024 rbd_linked_image_spec_t
*parent_image
,
5025 rbd_snap_spec_t
*parent_snap
)
5027 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5028 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
5029 ictx
->snap_name
.c_str(), ictx
->read_only
);
5031 librbd::linked_image_spec_t cpp_parent_image
;
5032 librbd::snap_spec_t cpp_parent_snap
;
5033 int r
= librbd::api::Image
<>::get_parent(ictx
, &cpp_parent_image
,
5036 // FIPS zeroization audit 20191117: these memsets are not security related.
5037 memset(parent_image
, 0, sizeof(rbd_linked_image_spec_t
));
5038 memset(parent_snap
, 0, sizeof(rbd_snap_spec_t
));
5041 .pool_id
= cpp_parent_image
.pool_id
,
5042 .pool_name
= strdup(cpp_parent_image
.pool_name
.c_str()),
5043 .pool_namespace
= strdup(cpp_parent_image
.pool_namespace
.c_str()),
5044 .image_id
= strdup(cpp_parent_image
.image_id
.c_str()),
5045 .image_name
= strdup(cpp_parent_image
.image_name
.c_str()),
5046 .trash
= cpp_parent_image
.trash
};
5048 .id
= cpp_parent_snap
.id
,
5049 .namespace_type
= cpp_parent_snap
.namespace_type
,
5050 .name
= strdup(cpp_parent_snap
.name
.c_str())};
5053 tracepoint(librbd
, get_parent_info_exit
, r
,
5054 parent_image
->pool_name
,
5055 parent_image
->image_name
,
5056 parent_image
->image_id
,
5061 extern "C" int rbd_get_flags(rbd_image_t image
, uint64_t *flags
)
5063 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5064 tracepoint(librbd
, get_flags_enter
, ictx
);
5065 int r
= librbd::get_flags(ictx
, flags
);
5066 tracepoint(librbd
, get_flags_exit
, ictx
, r
, *flags
);
5070 extern "C" int rbd_get_group(rbd_image_t image
, rbd_group_info_t
*group_info
,
5071 size_t group_info_size
)
5073 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5074 tracepoint(librbd
, image_get_group_enter
, ictx
->name
.c_str());
5076 if (group_info_size
!= sizeof(rbd_group_info_t
)) {
5077 tracepoint(librbd
, image_get_group_exit
, -ERANGE
);
5081 librbd::group_info_t cpp_group_info
;
5082 int r
= librbd::api::Group
<>::image_get_group(ictx
, &cpp_group_info
);
5084 group_info_cpp_to_c(cpp_group_info
, group_info
);
5086 group_info
->name
= NULL
;
5089 tracepoint(librbd
, image_get_group_exit
, r
);
5093 extern "C" int rbd_set_image_notification(rbd_image_t image
, int fd
, int type
)
5095 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5096 tracepoint(librbd
, set_image_notification_enter
, ictx
, fd
, type
);
5097 int r
= librbd::set_image_notification(ictx
, fd
, type
);
5098 tracepoint(librbd
, set_image_notification_exit
, ictx
, r
);
5102 extern "C" int rbd_is_exclusive_lock_owner(rbd_image_t image
, int *is_owner
)
5104 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5105 tracepoint(librbd
, is_exclusive_lock_owner_enter
, ictx
);
5107 int r
= librbd::is_exclusive_lock_owner(ictx
, &owner
);
5108 *is_owner
= owner
? 1 : 0;
5109 tracepoint(librbd
, is_exclusive_lock_owner_exit
, ictx
, r
, *is_owner
);
5113 extern "C" int rbd_lock_acquire(rbd_image_t image
, rbd_lock_mode_t lock_mode
)
5115 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5116 tracepoint(librbd
, lock_acquire_enter
, ictx
, lock_mode
);
5117 int r
= librbd::lock_acquire(ictx
, lock_mode
);
5118 tracepoint(librbd
, lock_acquire_exit
, ictx
, r
);
5122 extern "C" int rbd_lock_release(rbd_image_t image
)
5124 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5125 tracepoint(librbd
, lock_release_enter
, ictx
);
5126 int r
= librbd::lock_release(ictx
);
5127 tracepoint(librbd
, lock_release_exit
, ictx
, r
);
5131 extern "C" int rbd_lock_get_owners(rbd_image_t image
,
5132 rbd_lock_mode_t
*lock_mode
,
5134 size_t *max_lock_owners
)
5136 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5137 tracepoint(librbd
, lock_get_owners_enter
, ictx
);
5138 // FIPS zeroization audit 20191117: this memset is not security related.
5139 memset(lock_owners
, 0, sizeof(*lock_owners
) * *max_lock_owners
);
5140 std::list
<std::string
> lock_owner_list
;
5141 int r
= librbd::lock_get_owners(ictx
, lock_mode
, &lock_owner_list
);
5143 if (*max_lock_owners
>= lock_owner_list
.size()) {
5144 *max_lock_owners
= 0;
5145 for (auto &lock_owner
: lock_owner_list
) {
5146 lock_owners
[(*max_lock_owners
)++] = strdup(lock_owner
.c_str());
5149 *max_lock_owners
= lock_owner_list
.size();
5153 tracepoint(librbd
, lock_get_owners_exit
, ictx
, r
);
5157 extern "C" void rbd_lock_get_owners_cleanup(char **lock_owners
,
5158 size_t lock_owner_count
)
5160 for (size_t i
= 0; i
< lock_owner_count
; ++i
) {
5161 free(lock_owners
[i
]);
5165 extern "C" int rbd_lock_break(rbd_image_t image
, rbd_lock_mode_t lock_mode
,
5166 const char *lock_owner
)
5168 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5169 tracepoint(librbd
, lock_break_enter
, ictx
, lock_mode
, lock_owner
);
5170 int r
= librbd::lock_break(ictx
, lock_mode
, lock_owner
);
5171 tracepoint(librbd
, lock_break_exit
, ictx
, r
);
5175 extern "C" int rbd_rebuild_object_map(rbd_image_t image
,
5176 librbd_progress_fn_t cb
, void *cbdata
)
5178 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5179 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5180 return ictx
->operations
->rebuild_object_map(prog_ctx
);
5184 extern "C" int rbd_snap_create(rbd_image_t image
, const char *snap_name
)
5186 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5187 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5188 int r
= ictx
->operations
->snap_create(cls::rbd::UserSnapshotNamespace(),
5190 tracepoint(librbd
, snap_create_exit
, r
);
5194 extern "C" int rbd_snap_rename(rbd_image_t image
, const char *srcname
, const char *dstname
)
5196 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5197 tracepoint(librbd
, snap_rename_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, srcname
, dstname
);
5198 int r
= ictx
->operations
->snap_rename(srcname
, dstname
);
5199 tracepoint(librbd
, snap_rename_exit
, r
);
5203 extern "C" int rbd_snap_remove(rbd_image_t image
, const char *snap_name
)
5205 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5206 tracepoint(librbd
, snap_remove_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5207 librbd::NoOpProgressContext prog_ctx
;
5208 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, 0, prog_ctx
);
5209 tracepoint(librbd
, snap_remove_exit
, r
);
5213 extern "C" int rbd_snap_remove2(rbd_image_t image
, const char *snap_name
, uint32_t flags
,
5214 librbd_progress_fn_t cb
, void *cbdata
)
5216 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5217 tracepoint(librbd
, snap_remove2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
, flags
);
5218 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5219 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, flags
, prog_ctx
);
5220 tracepoint(librbd
, snap_remove_exit
, r
);
5224 extern "C" int rbd_snap_remove_by_id(rbd_image_t image
, uint64_t snap_id
)
5226 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5227 return librbd::api::Snapshot
<>::remove(ictx
, snap_id
);
5230 extern "C" int rbd_snap_rollback(rbd_image_t image
, const char *snap_name
)
5232 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5233 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5234 librbd::NoOpProgressContext prog_ctx
;
5235 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
5236 tracepoint(librbd
, snap_rollback_exit
, r
);
5240 extern "C" int rbd_snap_rollback_with_progress(rbd_image_t image
,
5241 const char *snap_name
,
5242 librbd_progress_fn_t cb
,
5245 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5246 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5247 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5248 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
5249 tracepoint(librbd
, snap_rollback_exit
, r
);
5253 extern "C" int rbd_snap_list(rbd_image_t image
, rbd_snap_info_t
*snaps
,
5256 vector
<librbd::snap_info_t
> cpp_snaps
;
5257 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5258 tracepoint(librbd
, snap_list_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snaps
);
5261 tracepoint(librbd
, snap_list_exit
, -EINVAL
, 0);
5264 // FIPS zeroization audit 20191117: this memset is not security related.
5265 memset(snaps
, 0, sizeof(*snaps
) * *max_snaps
);
5267 int r
= librbd::api::Snapshot
<>::list(ictx
, cpp_snaps
);
5269 tracepoint(librbd
, snap_list_exit
, 0, *max_snaps
);
5273 tracepoint(librbd
, snap_list_exit
, r
, *max_snaps
);
5276 if (*max_snaps
< (int)cpp_snaps
.size() + 1) {
5277 *max_snaps
= (int)cpp_snaps
.size() + 1;
5278 tracepoint(librbd
, snap_list_exit
, -ERANGE
, *max_snaps
);
5284 for (i
= 0; i
< (int)cpp_snaps
.size(); i
++) {
5285 snaps
[i
].id
= cpp_snaps
[i
].id
;
5286 snaps
[i
].size
= cpp_snaps
[i
].size
;
5287 snaps
[i
].name
= strdup(cpp_snaps
[i
].name
.c_str());
5288 if (!snaps
[i
].name
) {
5289 for (int j
= 0; j
< i
; j
++)
5290 free((void *)snaps
[j
].name
);
5291 tracepoint(librbd
, snap_list_exit
, -ENOMEM
, *max_snaps
);
5294 tracepoint(librbd
, snap_list_entry
, snaps
[i
].id
, snaps
[i
].size
, snaps
[i
].name
);
5298 snaps
[i
].name
= NULL
;
5300 r
= (int)cpp_snaps
.size();
5301 tracepoint(librbd
, snap_list_exit
, r
, *max_snaps
);
5305 extern "C" void rbd_snap_list_end(rbd_snap_info_t
*snaps
)
5307 tracepoint(librbd
, snap_list_end_enter
, snaps
);
5308 while (snaps
->name
) {
5309 free((void *)snaps
->name
);
5312 tracepoint(librbd
, snap_list_end_exit
);
5315 extern "C" int rbd_snap_protect(rbd_image_t image
, const char *snap_name
)
5317 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5318 tracepoint(librbd
, snap_protect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5319 int r
= ictx
->operations
->snap_protect(cls::rbd::UserSnapshotNamespace(), snap_name
);
5320 tracepoint(librbd
, snap_protect_exit
, r
);
5324 extern "C" int rbd_snap_unprotect(rbd_image_t image
, const char *snap_name
)
5326 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5327 tracepoint(librbd
, snap_unprotect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5328 int r
= ictx
->operations
->snap_unprotect(cls::rbd::UserSnapshotNamespace(), snap_name
);
5329 tracepoint(librbd
, snap_unprotect_exit
, r
);
5333 extern "C" int rbd_snap_is_protected(rbd_image_t image
, const char *snap_name
,
5336 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5337 tracepoint(librbd
, snap_is_protected_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5338 bool protected_snap
;
5339 int r
= librbd::api::Snapshot
<>::is_protected(ictx
, snap_name
, &protected_snap
);
5341 tracepoint(librbd
, snap_is_protected_exit
, r
, *is_protected
? 1 : 0);
5344 *is_protected
= protected_snap
? 1 : 0;
5345 tracepoint(librbd
, snap_is_protected_exit
, 0, *is_protected
? 1 : 0);
5349 extern "C" int rbd_snap_get_limit(rbd_image_t image
, uint64_t *limit
)
5351 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5352 tracepoint(librbd
, snap_get_limit_enter
, ictx
, ictx
->name
.c_str());
5353 int r
= librbd::api::Snapshot
<>::get_limit(ictx
, limit
);
5354 tracepoint(librbd
, snap_get_limit_exit
, r
, *limit
);
5358 extern "C" int rbd_snap_exists(rbd_image_t image
, const char *snapname
, bool *exists
)
5360 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5361 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
5362 ictx
->snap_name
.c_str(), ictx
->read_only
, snapname
);
5363 int r
= librbd::api::Snapshot
<>::exists(ictx
, cls::rbd::UserSnapshotNamespace(), snapname
, exists
);
5364 tracepoint(librbd
, snap_exists_exit
, r
, *exists
);
5368 extern "C" int rbd_snap_get_timestamp(rbd_image_t image
, uint64_t snap_id
, struct timespec
*timestamp
)
5370 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5371 tracepoint(librbd
, snap_get_timestamp_enter
, ictx
, ictx
->name
.c_str());
5372 int r
= librbd::api::Snapshot
<>::get_timestamp(ictx
, snap_id
, timestamp
);
5373 tracepoint(librbd
, snap_get_timestamp_exit
, r
);
5377 extern "C" int rbd_snap_set_limit(rbd_image_t image
, uint64_t limit
)
5379 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5380 tracepoint(librbd
, snap_set_limit_enter
, ictx
, ictx
->name
.c_str(), limit
);
5381 int r
= librbd::api::Snapshot
<>::set_limit(ictx
, limit
);
5382 tracepoint(librbd
, snap_set_limit_exit
, r
);
5386 extern "C" int rbd_snap_set(rbd_image_t image
, const char *snap_name
)
5388 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5389 tracepoint(librbd
, snap_set_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5390 int r
= librbd::api::Image
<>::snap_set(
5391 ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
);
5392 tracepoint(librbd
, snap_set_exit
, r
);
5396 extern "C" int rbd_snap_set_by_id(rbd_image_t image
, uint64_t snap_id
)
5398 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5399 return librbd::api::Image
<>::snap_set(ictx
, snap_id
);
5402 extern "C" int rbd_snap_get_name(rbd_image_t image
, uint64_t snap_id
, char *snapname
, size_t *name_len
)
5404 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5405 std::string snap_name
;
5406 int r
= librbd::api::Snapshot
<>::get_name(ictx
, snap_id
, &snap_name
);
5407 size_t expected_size
= snap_name
.size();
5408 if (*name_len
<= expected_size
) {
5409 *name_len
= expected_size
+ 1;
5412 strncpy(snapname
, snap_name
.c_str(), expected_size
);
5413 snapname
[expected_size
] = '\0';
5414 *name_len
= expected_size
+ 1;
5418 extern "C" int rbd_snap_get_id(rbd_image_t image
, const char *snapname
, uint64_t *snap_id
)
5420 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5421 return librbd::api::Snapshot
<>::get_id(ictx
, snapname
, snap_id
);
5424 extern "C" ssize_t
rbd_list_children(rbd_image_t image
, char *pools
,
5425 size_t *pools_len
, char *images
,
5428 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5429 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5430 ictx
->snap_name
.c_str(), ictx
->read_only
);
5432 std::vector
<librbd::linked_image_spec_t
> cpp_images
;
5433 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_images
);
5435 tracepoint(librbd
, list_children_exit
, r
);
5439 std::set
<std::pair
<std::string
, std::string
>> image_set
;
5440 for (auto& image
: cpp_images
) {
5442 image_set
.insert({image
.pool_name
, image
.image_name
});
5446 size_t pools_total
= 0;
5447 size_t images_total
= 0;
5448 for (auto it
: image_set
) {
5449 pools_total
+= it
.first
.length() + 1;
5450 images_total
+= it
.second
.length() + 1;
5453 bool too_short
= false;
5454 if (pools_total
> *pools_len
)
5456 if (images_total
> *images_len
)
5458 *pools_len
= pools_total
;
5459 *images_len
= images_total
;
5461 tracepoint(librbd
, list_children_exit
, -ERANGE
);
5465 char *pools_p
= pools
;
5466 char *images_p
= images
;
5467 for (auto it
: image_set
) {
5468 const char* pool
= it
.first
.c_str();
5469 strcpy(pools_p
, pool
);
5470 pools_p
+= it
.first
.length() + 1;
5471 const char* image
= it
.second
.c_str();
5472 strcpy(images_p
, image
);
5473 images_p
+= it
.second
.length() + 1;
5474 tracepoint(librbd
, list_children_entry
, pool
, image
);
5477 ssize_t ret
= image_set
.size();
5478 tracepoint(librbd
, list_children_exit
, ret
);
5482 extern "C" int rbd_list_children2(rbd_image_t image
,
5483 rbd_child_info_t
*children
,
5486 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5487 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5488 ictx
->snap_name
.c_str(), ictx
->read_only
);
5489 // FIPS zeroization audit 20191117: this memset is not security related.
5490 memset(children
, 0, sizeof(*children
) * *max_children
);
5492 if (!max_children
) {
5493 tracepoint(librbd
, list_children_exit
, -EINVAL
);
5497 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5498 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_children
);
5500 tracepoint(librbd
, list_children_exit
, r
);
5504 if (*max_children
< (int)cpp_children
.size() + 1) {
5505 *max_children
= (int)cpp_children
.size() + 1;
5506 tracepoint(librbd
, list_children_exit
, *max_children
);
5511 for (i
= 0; i
< (int)cpp_children
.size(); i
++) {
5512 children
[i
].pool_name
= strdup(cpp_children
[i
].pool_name
.c_str());
5513 children
[i
].image_name
= strdup(cpp_children
[i
].image_name
.c_str());
5514 children
[i
].image_id
= strdup(cpp_children
[i
].image_id
.c_str());
5515 children
[i
].trash
= cpp_children
[i
].trash
;
5516 tracepoint(librbd
, list_children_entry
, children
[i
].pool_name
,
5517 children
[i
].image_name
);
5519 children
[i
].pool_name
= NULL
;
5520 children
[i
].image_name
= NULL
;
5521 children
[i
].image_id
= NULL
;
5523 r
= (int)cpp_children
.size();
5524 tracepoint(librbd
, list_children_exit
, *max_children
);
5528 extern "C" void rbd_list_child_cleanup(rbd_child_info_t
*child
)
5530 free((void *)child
->pool_name
);
5531 free((void *)child
->image_name
);
5532 free((void *)child
->image_id
);
5535 extern "C" void rbd_list_children_cleanup(rbd_child_info_t
*children
,
5536 size_t num_children
)
5538 for (size_t i
=0; i
< num_children
; i
++) {
5539 free((void *)children
[i
].pool_name
);
5540 free((void *)children
[i
].image_name
);
5541 free((void *)children
[i
].image_id
);
5545 extern "C" int rbd_list_children3(rbd_image_t image
,
5546 rbd_linked_image_spec_t
*images
,
5549 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5550 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5551 ictx
->snap_name
.c_str(), ictx
->read_only
);
5552 // FIPS zeroization audit 20191117: this memset is not security related.
5553 memset(images
, 0, sizeof(*images
) * *max_images
);
5555 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5556 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_children
);
5558 tracepoint(librbd
, list_children_exit
, r
);
5562 if (*max_images
< cpp_children
.size()) {
5563 *max_images
= cpp_children
.size();
5567 *max_images
= cpp_children
.size();
5568 for (size_t idx
= 0; idx
< cpp_children
.size(); ++idx
) {
5570 .pool_id
= cpp_children
[idx
].pool_id
,
5571 .pool_name
= strdup(cpp_children
[idx
].pool_name
.c_str()),
5572 .pool_namespace
= strdup(cpp_children
[idx
].pool_namespace
.c_str()),
5573 .image_id
= strdup(cpp_children
[idx
].image_id
.c_str()),
5574 .image_name
= strdup(cpp_children
[idx
].image_name
.c_str()),
5575 .trash
= cpp_children
[idx
].trash
};
5576 tracepoint(librbd
, list_children_entry
, images
[idx
].pool_name
,
5577 images
[idx
].image_name
);
5582 extern "C" int rbd_list_descendants(rbd_image_t image
,
5583 rbd_linked_image_spec_t
*images
,
5586 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5587 // FIPS zeroization audit 20191117: this memset is not security related.
5588 memset(images
, 0, sizeof(*images
) * *max_images
);
5590 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5591 int r
= librbd::api::Image
<>::list_descendants(ictx
, {}, &cpp_children
);
5596 if (*max_images
< cpp_children
.size()) {
5597 *max_images
= cpp_children
.size();
5601 *max_images
= cpp_children
.size();
5602 for (size_t idx
= 0; idx
< cpp_children
.size(); ++idx
) {
5604 .pool_id
= cpp_children
[idx
].pool_id
,
5605 .pool_name
= strdup(cpp_children
[idx
].pool_name
.c_str()),
5606 .pool_namespace
= strdup(cpp_children
[idx
].pool_namespace
.c_str()),
5607 .image_id
= strdup(cpp_children
[idx
].image_id
.c_str()),
5608 .image_name
= strdup(cpp_children
[idx
].image_name
.c_str()),
5609 .trash
= cpp_children
[idx
].trash
};
5614 extern "C" ssize_t
rbd_list_lockers(rbd_image_t image
, int *exclusive
,
5615 char *tag
, size_t *tag_len
,
5616 char *clients
, size_t *clients_len
,
5617 char *cookies
, size_t *cookies_len
,
5618 char *addrs
, size_t *addrs_len
)
5620 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5621 tracepoint(librbd
, list_lockers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
5622 std::list
<librbd::locker_t
> lockers
;
5623 bool exclusive_bool
;
5626 int r
= list_lockers(ictx
, &lockers
, &exclusive_bool
, &tag_str
);
5628 tracepoint(librbd
, list_lockers_exit
, r
);
5632 ldout(ictx
->cct
, 20) << "list_lockers r = " << r
<< " lockers.size() = " << lockers
.size() << dendl
;
5634 *exclusive
= (int)exclusive_bool
;
5635 size_t clients_total
= 0;
5636 size_t cookies_total
= 0;
5637 size_t addrs_total
= 0;
5638 for (list
<librbd::locker_t
>::const_iterator it
= lockers
.begin();
5639 it
!= lockers
.end(); ++it
) {
5640 clients_total
+= it
->client
.length() + 1;
5641 cookies_total
+= it
->cookie
.length() + 1;
5642 addrs_total
+= it
->address
.length() + 1;
5645 bool too_short
= ((clients_total
> *clients_len
) ||
5646 (cookies_total
> *cookies_len
) ||
5647 (addrs_total
> *addrs_len
) ||
5648 (tag_str
.length() + 1 > *tag_len
));
5649 *clients_len
= clients_total
;
5650 *cookies_len
= cookies_total
;
5651 *addrs_len
= addrs_total
;
5652 *tag_len
= tag_str
.length() + 1;
5654 tracepoint(librbd
, list_lockers_exit
, -ERANGE
);
5658 strcpy(tag
, tag_str
.c_str());
5659 char *clients_p
= clients
;
5660 char *cookies_p
= cookies
;
5661 char *addrs_p
= addrs
;
5662 for (list
<librbd::locker_t
>::const_iterator it
= lockers
.begin();
5663 it
!= lockers
.end(); ++it
) {
5664 const char* client
= it
->client
.c_str();
5665 strcpy(clients_p
, client
);
5666 clients_p
+= it
->client
.length() + 1;
5667 const char* cookie
= it
->cookie
.c_str();
5668 strcpy(cookies_p
, cookie
);
5669 cookies_p
+= it
->cookie
.length() + 1;
5670 const char* address
= it
->address
.c_str();
5671 strcpy(addrs_p
, address
);
5672 addrs_p
+= it
->address
.length() + 1;
5673 tracepoint(librbd
, list_lockers_entry
, client
, cookie
, address
);
5676 ssize_t ret
= lockers
.size();
5677 tracepoint(librbd
, list_lockers_exit
, ret
);
5681 extern "C" int rbd_lock_exclusive(rbd_image_t image
, const char *cookie
)
5683 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5684 tracepoint(librbd
, lock_exclusive_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
);
5685 int r
= librbd::lock(ictx
, true, cookie
? cookie
: "", "");
5686 tracepoint(librbd
, lock_exclusive_exit
, r
);
5690 extern "C" int rbd_lock_shared(rbd_image_t image
, const char *cookie
,
5693 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5694 tracepoint(librbd
, lock_shared_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
, tag
);
5695 int r
= librbd::lock(ictx
, false, cookie
? cookie
: "", tag
? tag
: "");
5696 tracepoint(librbd
, lock_shared_exit
, r
);
5700 extern "C" int rbd_unlock(rbd_image_t image
, const char *cookie
)
5702 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5703 tracepoint(librbd
, unlock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
);
5704 int r
= librbd::unlock(ictx
, cookie
? cookie
: "");
5705 tracepoint(librbd
, unlock_exit
, r
);
5709 extern "C" int rbd_break_lock(rbd_image_t image
, const char *client
,
5712 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5713 tracepoint(librbd
, break_lock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, client
, cookie
);
5714 int r
= librbd::break_lock(ictx
, client
, cookie
? cookie
: "");
5715 tracepoint(librbd
, break_lock_exit
, r
);
5720 extern "C" ssize_t
rbd_read(rbd_image_t image
, uint64_t ofs
, size_t len
,
5723 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5724 tracepoint(librbd
, read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5725 int r
= ictx
->io_work_queue
->read(ofs
, len
, librbd::io::ReadResult
{buf
, len
},
5727 tracepoint(librbd
, read_exit
, r
);
5731 extern "C" ssize_t
rbd_read2(rbd_image_t image
, uint64_t ofs
, size_t len
,
5732 char *buf
, int op_flags
)
5734 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5735 tracepoint(librbd
, read2_enter
, ictx
, ictx
->name
.c_str(),
5736 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, op_flags
);
5737 int r
= ictx
->io_work_queue
->read(ofs
, len
, librbd::io::ReadResult
{buf
, len
},
5739 tracepoint(librbd
, read_exit
, r
);
5744 extern "C" int64_t rbd_read_iterate(rbd_image_t image
, uint64_t ofs
, size_t len
,
5745 int (*cb
)(uint64_t, size_t, const char *, void *),
5748 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5749 tracepoint(librbd
, read_iterate_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5750 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
5751 tracepoint(librbd
, read_iterate_exit
, r
);
5755 extern "C" int rbd_read_iterate2(rbd_image_t image
, uint64_t ofs
, uint64_t len
,
5756 int (*cb
)(uint64_t, size_t, const char *, void *),
5759 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5760 tracepoint(librbd
, read_iterate2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5761 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
5764 tracepoint(librbd
, read_iterate2_exit
, r
);
5768 extern "C" int rbd_diff_iterate(rbd_image_t image
,
5769 const char *fromsnapname
,
5770 uint64_t ofs
, uint64_t len
,
5771 int (*cb
)(uint64_t, size_t, int, void *),
5774 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5775 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
5776 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
5778 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
5779 cls::rbd::UserSnapshotNamespace(),
5780 fromsnapname
, ofs
, len
,
5781 true, false, cb
, arg
);
5782 tracepoint(librbd
, diff_iterate_exit
, r
);
5786 extern "C" int rbd_diff_iterate2(rbd_image_t image
, const char *fromsnapname
,
5787 uint64_t ofs
, uint64_t len
,
5788 uint8_t include_parent
, uint8_t whole_object
,
5789 int (*cb
)(uint64_t, size_t, int, void *),
5792 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5793 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
5794 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
5795 include_parent
!= 0, whole_object
!= 0);
5796 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
5797 cls::rbd::UserSnapshotNamespace(),
5798 fromsnapname
, ofs
, len
,
5799 include_parent
, whole_object
,
5801 tracepoint(librbd
, diff_iterate_exit
, r
);
5805 extern "C" ssize_t
rbd_write(rbd_image_t image
, uint64_t ofs
, size_t len
,
5808 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5809 tracepoint(librbd
, write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, buf
);
5812 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
5813 int r
= ictx
->io_work_queue
->write(ofs
, len
, std::move(bl
), 0);
5814 tracepoint(librbd
, write_exit
, r
);
5818 extern "C" ssize_t
rbd_write2(rbd_image_t image
, uint64_t ofs
, size_t len
,
5819 const char *buf
, int op_flags
)
5821 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5822 tracepoint(librbd
, write2_enter
, ictx
, ictx
->name
.c_str(),
5823 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, buf
, op_flags
);
5826 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
5827 int r
= ictx
->io_work_queue
->write(ofs
, len
, std::move(bl
), op_flags
);
5828 tracepoint(librbd
, write_exit
, r
);
5833 extern "C" int rbd_discard(rbd_image_t image
, uint64_t ofs
, uint64_t len
)
5835 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5836 tracepoint(librbd
, discard_enter
, ictx
, ictx
->name
.c_str(),
5837 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5838 if (len
> static_cast<uint64_t>(std::numeric_limits
<int>::max())) {
5839 tracepoint(librbd
, discard_exit
, -EINVAL
);
5843 int r
= ictx
->io_work_queue
->discard(
5844 ofs
, len
, ictx
->discard_granularity_bytes
);
5845 tracepoint(librbd
, discard_exit
, r
);
5849 extern "C" ssize_t
rbd_writesame(rbd_image_t image
, uint64_t ofs
, size_t len
,
5850 const char *buf
, size_t data_len
, int op_flags
)
5852 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5853 tracepoint(librbd
, writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
5854 ictx
->read_only
, ofs
, len
, data_len
== 0 ? NULL
: buf
, data_len
, op_flags
);
5856 if (data_len
== 0 || len
% data_len
||
5857 len
> static_cast<uint64_t>(std::numeric_limits
<int>::max())) {
5858 tracepoint(librbd
, writesame_exit
, -EINVAL
);
5862 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
5863 if (discard_zero
&& mem_is_zero(buf
, data_len
)) {
5864 int r
= ictx
->io_work_queue
->discard(ofs
, len
, 0);
5865 tracepoint(librbd
, writesame_exit
, r
);
5870 bl
.push_back(create_write_raw(ictx
, buf
, data_len
, nullptr));
5871 int r
= ictx
->io_work_queue
->writesame(ofs
, len
, std::move(bl
), op_flags
);
5872 tracepoint(librbd
, writesame_exit
, r
);
5876 extern "C" ssize_t
rbd_compare_and_write(rbd_image_t image
,
5877 uint64_t ofs
, size_t len
,
5878 const char *cmp_buf
,
5880 uint64_t *mismatch_off
,
5883 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5884 tracepoint(librbd
, compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
5885 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
,
5886 len
, cmp_buf
, buf
, op_flags
);
5889 cmp_bl
.push_back(create_write_raw(ictx
, cmp_buf
, len
, nullptr));
5891 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
5893 int r
= ictx
->io_work_queue
->compare_and_write(ofs
, len
, std::move(cmp_bl
),
5894 std::move(bl
), mismatch_off
,
5896 tracepoint(librbd
, compare_and_write_exit
, r
);
5900 extern "C" int rbd_aio_create_completion(void *cb_arg
,
5901 rbd_callback_t complete_cb
,
5902 rbd_completion_t
*c
)
5904 librbd::RBD::AioCompletion
*rbd_comp
=
5905 new librbd::RBD::AioCompletion(cb_arg
, complete_cb
);
5906 *c
= (rbd_completion_t
) rbd_comp
;
5910 extern "C" int rbd_aio_write(rbd_image_t image
, uint64_t off
, size_t len
,
5911 const char *buf
, rbd_completion_t c
)
5913 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5914 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
5915 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, buf
, comp
->pc
);
5917 auto aio_completion
= get_aio_completion(comp
);
5919 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
5920 ictx
->io_work_queue
->aio_write(aio_completion
, off
, len
, std::move(bl
), 0);
5921 tracepoint(librbd
, aio_write_exit
, 0);
5925 extern "C" int rbd_aio_write2(rbd_image_t image
, uint64_t off
, size_t len
,
5926 const char *buf
, rbd_completion_t c
, int op_flags
)
5928 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5929 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
5930 tracepoint(librbd
, aio_write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
5931 ictx
->read_only
, off
, len
, buf
, comp
->pc
, op_flags
);
5933 auto aio_completion
= get_aio_completion(comp
);
5935 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
5936 ictx
->io_work_queue
->aio_write(aio_completion
, off
, len
, std::move(bl
),
5938 tracepoint(librbd
, aio_write_exit
, 0);
5942 extern "C" int rbd_aio_writev(rbd_image_t image
, const struct iovec
*iov
,
5943 int iovcnt
, uint64_t off
, rbd_completion_t c
)
5945 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5946 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
5948 // convert the scatter list into a bufferlist
5949 auto aio_completion
= get_aio_completion(comp
);
5952 for (int i
= 0; i
< iovcnt
; ++i
) {
5953 const struct iovec
&io
= iov
[i
];
5959 bl
.push_back(create_write_raw(ictx
, static_cast<char*>(io
.iov_base
),
5960 io
.iov_len
, aio_completion
));
5964 if (iovcnt
<= 0 || len
< 0) {
5968 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(),
5969 ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, NULL
,
5972 ictx
->io_work_queue
->aio_write(aio_completion
, off
, len
, std::move(bl
), 0);
5974 tracepoint(librbd
, aio_write_exit
, r
);
5978 extern "C" int rbd_aio_discard(rbd_image_t image
, uint64_t off
, uint64_t len
,
5981 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5982 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
5983 tracepoint(librbd
, aio_discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, comp
->pc
);
5984 ictx
->io_work_queue
->aio_discard(
5985 get_aio_completion(comp
), off
, len
, ictx
->discard_granularity_bytes
);
5986 tracepoint(librbd
, aio_discard_exit
, 0);
5990 extern "C" int rbd_aio_read(rbd_image_t image
, uint64_t off
, size_t len
,
5991 char *buf
, rbd_completion_t c
)
5993 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5994 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
5995 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, buf
, comp
->pc
);
5996 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
5997 librbd::io::ReadResult
{buf
, len
}, 0);
5998 tracepoint(librbd
, aio_read_exit
, 0);
6002 extern "C" int rbd_aio_read2(rbd_image_t image
, uint64_t off
, size_t len
,
6003 char *buf
, rbd_completion_t c
, int op_flags
)
6005 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6006 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6007 tracepoint(librbd
, aio_read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6008 ictx
->read_only
, off
, len
, buf
, comp
->pc
, op_flags
);
6009 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
6010 librbd::io::ReadResult
{buf
, len
},op_flags
);
6011 tracepoint(librbd
, aio_read_exit
, 0);
6015 extern "C" int rbd_aio_readv(rbd_image_t image
, const struct iovec
*iov
,
6016 int iovcnt
, uint64_t off
, rbd_completion_t c
)
6018 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6019 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6022 for (int i
= 0; i
< iovcnt
; ++i
) {
6023 len
+= iov
[i
].iov_len
;
6030 if (iovcnt
== 0 || len
< 0) {
6034 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(),
6035 ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, NULL
,
6038 librbd::io::ReadResult read_result
;
6040 read_result
= librbd::io::ReadResult(
6041 static_cast<char *>(iov
[0].iov_base
), iov
[0].iov_len
);
6043 read_result
= librbd::io::ReadResult(iov
, iovcnt
);
6045 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
6046 std::move(read_result
), 0);
6048 tracepoint(librbd
, aio_read_exit
, r
);
6052 extern "C" int rbd_flush(rbd_image_t image
)
6054 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6055 tracepoint(librbd
, flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
6056 int r
= ictx
->io_work_queue
->flush();
6057 tracepoint(librbd
, flush_exit
, r
);
6061 extern "C" int rbd_aio_flush(rbd_image_t image
, rbd_completion_t c
)
6063 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6064 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6065 tracepoint(librbd
, aio_flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
6066 ictx
->io_work_queue
->aio_flush(get_aio_completion(comp
));
6067 tracepoint(librbd
, aio_flush_exit
, 0);
6071 extern "C" int rbd_aio_writesame(rbd_image_t image
, uint64_t off
, size_t len
,
6072 const char *buf
, size_t data_len
, rbd_completion_t c
,
6075 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6076 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6077 tracepoint(librbd
, aio_writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6078 ictx
->read_only
, off
, len
, data_len
== 0 ? NULL
: buf
, data_len
, comp
->pc
,
6081 if (data_len
== 0 || len
% data_len
) {
6082 tracepoint(librbd
, aio_writesame_exit
, -EINVAL
);
6086 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
6087 if (discard_zero
&& mem_is_zero(buf
, data_len
)) {
6088 ictx
->io_work_queue
->aio_discard(get_aio_completion(comp
), off
, len
, 0);
6089 tracepoint(librbd
, aio_writesame_exit
, 0);
6093 auto aio_completion
= get_aio_completion(comp
);
6095 bl
.push_back(create_write_raw(ictx
, buf
, data_len
, aio_completion
));
6096 ictx
->io_work_queue
->aio_writesame(aio_completion
, off
, len
, std::move(bl
),
6098 tracepoint(librbd
, aio_writesame_exit
, 0);
6102 extern "C" ssize_t
rbd_aio_compare_and_write(rbd_image_t image
, uint64_t off
,
6103 size_t len
, const char *cmp_buf
,
6104 const char *buf
, rbd_completion_t c
,
6105 uint64_t *mismatch_off
,
6108 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6109 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6110 tracepoint(librbd
, aio_compare_and_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6111 ictx
->read_only
, off
, len
, cmp_buf
, buf
, comp
->pc
, op_flags
);
6113 auto aio_completion
= get_aio_completion(comp
);
6115 cmp_bl
.push_back(create_write_raw(ictx
, cmp_buf
, len
, aio_completion
));
6117 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
6118 ictx
->io_work_queue
->aio_compare_and_write(aio_completion
, off
, len
,
6119 std::move(cmp_bl
), std::move(bl
),
6120 mismatch_off
, op_flags
, false);
6122 tracepoint(librbd
, aio_compare_and_write_exit
, 0);
6126 extern "C" int rbd_invalidate_cache(rbd_image_t image
)
6128 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6129 tracepoint(librbd
, invalidate_cache_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
6130 int r
= librbd::invalidate_cache(ictx
);
6131 tracepoint(librbd
, invalidate_cache_exit
, r
);
6135 extern "C" int rbd_poll_io_events(rbd_image_t image
, rbd_completion_t
*comps
, int numcomp
)
6137 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6138 librbd::io::AioCompletion
*cs
[numcomp
];
6139 tracepoint(librbd
, poll_io_events_enter
, ictx
, numcomp
);
6140 int r
= librbd::poll_io_events(ictx
, cs
, numcomp
);
6141 tracepoint(librbd
, poll_io_events_exit
, r
);
6143 for (int i
= 0; i
< r
; ++i
)
6144 comps
[i
] = cs
[i
]->rbd_comp
;
6149 extern "C" int rbd_metadata_get(rbd_image_t image
, const char *key
, char *value
, size_t *vallen
)
6151 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6153 tracepoint(librbd
, metadata_get_enter
, ictx
, key
);
6154 int r
= librbd::metadata_get(ictx
, key
, &val_s
);
6156 tracepoint(librbd
, metadata_get_exit
, r
, key
, NULL
);
6159 if (*vallen
< val_s
.size() + 1) {
6161 *vallen
= val_s
.size() + 1;
6162 tracepoint(librbd
, metadata_get_exit
, r
, key
, NULL
);
6164 strncpy(value
, val_s
.c_str(), val_s
.size() + 1);
6165 tracepoint(librbd
, metadata_get_exit
, r
, key
, value
);
6170 extern "C" int rbd_metadata_set(rbd_image_t image
, const char *key
, const char *value
)
6172 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6173 tracepoint(librbd
, metadata_set_enter
, ictx
, key
, value
);
6174 int r
= ictx
->operations
->metadata_set(key
, value
);
6175 tracepoint(librbd
, metadata_set_exit
, r
);
6179 extern "C" int rbd_metadata_remove(rbd_image_t image
, const char *key
)
6181 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6182 tracepoint(librbd
, metadata_remove_enter
, ictx
, key
);
6183 int r
= ictx
->operations
->metadata_remove(key
);
6184 tracepoint(librbd
, metadata_remove_exit
, r
);
6188 extern "C" int rbd_metadata_list(rbd_image_t image
, const char *start
, uint64_t max
,
6189 char *key
, size_t *key_len
, char *value
, size_t *val_len
)
6191 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6192 tracepoint(librbd
, metadata_list_enter
, ictx
);
6193 map
<string
, bufferlist
> pairs
;
6194 int r
= librbd::metadata_list(ictx
, start
, max
, &pairs
);
6195 size_t key_total_len
= 0, val_total_len
= 0;
6196 bool too_short
= false;
6197 for (map
<string
, bufferlist
>::iterator it
= pairs
.begin();
6198 it
!= pairs
.end(); ++it
) {
6199 key_total_len
+= it
->first
.size() + 1;
6200 val_total_len
+= it
->second
.length() + 1;
6202 if (*key_len
< key_total_len
|| *val_len
< val_total_len
)
6204 *key_len
= key_total_len
;
6205 *val_len
= val_total_len
;
6207 tracepoint(librbd
, metadata_list_exit
, -ERANGE
);
6211 char *key_p
= key
, *value_p
= value
;
6213 for (map
<string
, bufferlist
>::iterator it
= pairs
.begin();
6214 it
!= pairs
.end(); ++it
) {
6215 strncpy(key_p
, it
->first
.c_str(), it
->first
.size() + 1);
6216 key_p
+= it
->first
.size() + 1;
6217 strncpy(value_p
, it
->second
.c_str(), it
->second
.length());
6218 value_p
+= it
->second
.length();
6221 tracepoint(librbd
, metadata_list_entry
, it
->first
.c_str(), it
->second
.c_str());
6223 tracepoint(librbd
, metadata_list_exit
, r
);
6227 extern "C" int rbd_mirror_image_enable(rbd_image_t image
)
6229 return rbd_mirror_image_enable2(image
, RBD_MIRROR_IMAGE_MODE_JOURNAL
);
6232 extern "C" int rbd_mirror_image_enable2(rbd_image_t image
,
6233 rbd_mirror_image_mode_t mode
)
6235 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6236 return librbd::api::Mirror
<>::image_enable(ictx
, mode
, false);
6239 extern "C" int rbd_mirror_image_disable(rbd_image_t image
, bool force
)
6241 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6242 return librbd::api::Mirror
<>::image_disable(ictx
, force
);
6245 extern "C" int rbd_mirror_image_promote(rbd_image_t image
, bool force
)
6247 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6248 return librbd::api::Mirror
<>::image_promote(ictx
, force
);
6251 extern "C" int rbd_mirror_image_demote(rbd_image_t image
)
6253 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6254 return librbd::api::Mirror
<>::image_demote(ictx
);
6257 extern "C" int rbd_mirror_image_resync(rbd_image_t image
)
6259 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6260 return librbd::api::Mirror
<>::image_resync(ictx
);
6263 extern "C" int rbd_mirror_image_create_snapshot(rbd_image_t image
,
6266 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6267 return librbd::api::Mirror
<>::image_snapshot_create(ictx
, snap_id
);
6270 extern "C" int rbd_mirror_image_get_info(rbd_image_t image
,
6271 rbd_mirror_image_info_t
*mirror_image_info
,
6274 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6276 if (sizeof(rbd_mirror_image_info_t
) != info_size
) {
6280 librbd::mirror_image_info_t cpp_mirror_image
;
6281 int r
= librbd::api::Mirror
<>::image_get_info(ictx
, &cpp_mirror_image
);
6286 mirror_image_info_cpp_to_c(cpp_mirror_image
, mirror_image_info
);
6290 extern "C" void rbd_mirror_image_get_info_cleanup(
6291 rbd_mirror_image_info_t
*mirror_image_info
)
6293 free(mirror_image_info
->global_id
);
6296 extern "C" int rbd_mirror_image_get_mode(rbd_image_t image
,
6297 rbd_mirror_image_mode_t
*mode
)
6299 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6301 return librbd::api::Mirror
<>::image_get_mode(ictx
, mode
);
6304 extern "C" int rbd_mirror_image_get_global_status(
6305 rbd_image_t image
, rbd_mirror_image_global_status_t
*status
,
6308 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6310 if (sizeof(rbd_mirror_image_global_status_t
) != status_size
) {
6314 librbd::mirror_image_global_status_t cpp_status
;
6315 int r
= librbd::api::Mirror
<>::image_get_global_status(ictx
, &cpp_status
);
6320 mirror_image_global_status_cpp_to_c(cpp_status
, status
);
6324 #pragma GCC diagnostic push
6325 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6327 extern "C" int rbd_mirror_image_get_status(rbd_image_t image
,
6328 rbd_mirror_image_status_t
*status
,
6331 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6333 if (sizeof(rbd_mirror_image_status_t
) != status_size
) {
6337 librbd::mirror_image_global_status_t cpp_status
;
6338 int r
= librbd::api::Mirror
<>::image_get_global_status(ictx
, &cpp_status
);
6343 mirror_image_global_status_cpp_to_c(cpp_status
, status
);
6347 #pragma GCC diagnostic pop
6349 extern "C" int rbd_mirror_image_get_instance_id(rbd_image_t image
,
6351 size_t *instance_id_max_length
)
6353 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6355 std::string cpp_instance_id
;
6356 int r
= librbd::api::Mirror
<>::image_get_instance_id(ictx
, &cpp_instance_id
);
6361 if (cpp_instance_id
.size() >= *instance_id_max_length
) {
6362 *instance_id_max_length
= cpp_instance_id
.size() + 1;
6366 strcpy(instance_id
, cpp_instance_id
.c_str());
6367 *instance_id_max_length
= cpp_instance_id
.size() + 1;
6371 extern "C" int rbd_aio_mirror_image_promote(rbd_image_t image
, bool force
,
6372 rbd_completion_t c
) {
6373 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6374 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6375 librbd::api::Mirror
<>::image_promote(
6376 ictx
, force
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6377 get_aio_completion(comp
)));
6381 extern "C" int rbd_aio_mirror_image_demote(rbd_image_t image
,
6382 rbd_completion_t c
) {
6383 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6384 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6385 librbd::api::Mirror
<>::image_demote(
6386 ictx
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6387 get_aio_completion(comp
)));
6391 extern "C" int rbd_aio_mirror_image_get_info(rbd_image_t image
,
6392 rbd_mirror_image_info_t
*info
,
6394 rbd_completion_t c
) {
6395 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6396 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6398 if (sizeof(rbd_mirror_image_info_t
) != info_size
) {
6402 auto ctx
= new C_MirrorImageGetInfo(
6403 info
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6404 get_aio_completion(comp
)));
6405 librbd::api::Mirror
<>::image_get_info(
6406 ictx
, &ctx
->cpp_mirror_image_info
, ctx
);
6410 extern "C" int rbd_aio_mirror_image_get_mode(rbd_image_t image
,
6411 rbd_mirror_image_mode_t
*mode
,
6412 rbd_completion_t c
) {
6413 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6414 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6416 librbd::api::Mirror
<>::image_get_mode(
6417 ictx
, mode
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6418 get_aio_completion(comp
)));
6422 extern "C" int rbd_aio_mirror_image_get_global_status(
6423 rbd_image_t image
, rbd_mirror_image_global_status_t
*status
,
6424 size_t status_size
, rbd_completion_t c
) {
6425 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6426 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6428 if (sizeof(rbd_mirror_image_global_status_t
) != status_size
) {
6432 auto ctx
= new C_MirrorImageGetGlobalStatus(
6433 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6434 get_aio_completion(comp
)));
6435 librbd::api::Mirror
<>::image_get_global_status(
6436 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
6440 #pragma GCC diagnostic push
6441 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6443 extern "C" int rbd_aio_mirror_image_get_status(
6444 rbd_image_t image
, rbd_mirror_image_status_t
*status
, size_t status_size
,
6445 rbd_completion_t c
) {
6446 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6447 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6449 if (sizeof(rbd_mirror_image_status_t
) != status_size
) {
6453 auto ctx
= new C_MirrorImageGetStatus(
6454 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6455 get_aio_completion(comp
)));
6456 librbd::api::Mirror
<>::image_get_global_status(
6457 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
6461 #pragma GCC diagnostic pop
6463 extern "C" int rbd_update_watch(rbd_image_t image
, uint64_t *handle
,
6464 rbd_update_callback_t watch_cb
, void *arg
)
6466 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6467 C_UpdateWatchCB
*wctx
= new C_UpdateWatchCB(watch_cb
, arg
);
6468 tracepoint(librbd
, update_watch_enter
, ictx
, wctx
);
6469 int r
= ictx
->state
->register_update_watcher(wctx
, &wctx
->handle
);
6470 tracepoint(librbd
, update_watch_exit
, r
, wctx
->handle
);
6471 *handle
= reinterpret_cast<uint64_t>(wctx
);
6475 extern "C" int rbd_update_unwatch(rbd_image_t image
, uint64_t handle
)
6477 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6478 C_UpdateWatchCB
*wctx
= reinterpret_cast<C_UpdateWatchCB
*>(handle
);
6479 tracepoint(librbd
, update_unwatch_enter
, ictx
, wctx
->handle
);
6480 int r
= ictx
->state
->unregister_update_watcher(wctx
->handle
);
6482 tracepoint(librbd
, update_unwatch_exit
, r
);
6486 extern "C" int rbd_aio_is_complete(rbd_completion_t c
)
6488 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6489 return comp
->is_complete();
6492 extern "C" int rbd_aio_wait_for_complete(rbd_completion_t c
)
6494 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6495 return comp
->wait_for_complete();
6498 extern "C" ssize_t
rbd_aio_get_return_value(rbd_completion_t c
)
6500 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6501 return comp
->get_return_value();
6504 extern "C" void *rbd_aio_get_arg(rbd_completion_t c
)
6506 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6507 return comp
->get_arg();
6510 extern "C" void rbd_aio_release(rbd_completion_t c
)
6512 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6516 extern "C" int rbd_group_create(rados_ioctx_t p
, const char *name
)
6518 librados::IoCtx io_ctx
;
6519 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6520 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6521 tracepoint(librbd
, group_create_enter
, io_ctx
.get_pool_name().c_str(),
6522 io_ctx
.get_id(), name
);
6523 int r
= librbd::api::Group
<>::create(io_ctx
, name
);
6524 tracepoint(librbd
, group_create_exit
, r
);
6528 extern "C" int rbd_group_remove(rados_ioctx_t p
, const char *name
)
6530 librados::IoCtx io_ctx
;
6531 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6532 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6533 tracepoint(librbd
, group_remove_enter
, io_ctx
.get_pool_name().c_str(),
6534 io_ctx
.get_id(), name
);
6535 int r
= librbd::api::Group
<>::remove(io_ctx
, name
);
6536 tracepoint(librbd
, group_remove_exit
, r
);
6540 extern "C" int rbd_group_list(rados_ioctx_t p
, char *names
, size_t *size
)
6542 librados::IoCtx io_ctx
;
6543 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6544 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6545 tracepoint(librbd
, group_list_enter
, io_ctx
.get_pool_name().c_str(),
6548 vector
<string
> cpp_names
;
6549 int r
= librbd::api::Group
<>::list(io_ctx
, &cpp_names
);
6552 tracepoint(librbd
, group_list_exit
, r
);
6556 size_t expected_size
= 0;
6558 for (size_t i
= 0; i
< cpp_names
.size(); i
++) {
6559 expected_size
+= cpp_names
[i
].size() + 1;
6561 if (*size
< expected_size
) {
6562 *size
= expected_size
;
6563 tracepoint(librbd
, group_list_exit
, -ERANGE
);
6567 if (names
== NULL
) {
6568 tracepoint(librbd
, group_list_exit
, -EINVAL
);
6572 for (int i
= 0; i
< (int)cpp_names
.size(); i
++) {
6573 const char* name
= cpp_names
[i
].c_str();
6574 tracepoint(librbd
, group_list_entry
, name
);
6575 strcpy(names
, name
);
6576 names
+= strlen(names
) + 1;
6578 tracepoint(librbd
, group_list_exit
, (int)expected_size
);
6579 return (int)expected_size
;
6582 extern "C" int rbd_group_rename(rados_ioctx_t p
, const char *src_name
,
6583 const char *dest_name
)
6585 librados::IoCtx io_ctx
;
6586 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6587 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6588 tracepoint(librbd
, group_rename_enter
, io_ctx
.get_pool_name().c_str(),
6589 io_ctx
.get_id(), src_name
, dest_name
);
6590 int r
= librbd::api::Group
<>::rename(io_ctx
, src_name
, dest_name
);
6591 tracepoint(librbd
, group_rename_exit
, r
);
6595 extern "C" int rbd_group_image_add(rados_ioctx_t group_p
,
6596 const char *group_name
,
6597 rados_ioctx_t image_p
,
6598 const char *image_name
)
6600 librados::IoCtx group_ioctx
;
6601 librados::IoCtx image_ioctx
;
6603 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6604 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6606 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6607 tracepoint(librbd
, group_image_add_enter
, group_ioctx
.get_pool_name().c_str(),
6608 group_ioctx
.get_id(), group_name
, image_ioctx
.get_pool_name().c_str(),
6609 image_ioctx
.get_id(), image_name
);
6611 int r
= librbd::api::Group
<>::image_add(group_ioctx
, group_name
, image_ioctx
,
6614 tracepoint(librbd
, group_image_add_exit
, r
);
6618 extern "C" int rbd_group_image_remove(rados_ioctx_t group_p
,
6619 const char *group_name
,
6620 rados_ioctx_t image_p
,
6621 const char *image_name
)
6623 librados::IoCtx group_ioctx
;
6624 librados::IoCtx image_ioctx
;
6626 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6627 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6629 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6630 tracepoint(librbd
, group_image_remove_enter
, group_ioctx
.get_pool_name().c_str(),
6631 group_ioctx
.get_id(), group_name
, image_ioctx
.get_pool_name().c_str(),
6632 image_ioctx
.get_id(), image_name
);
6634 int r
= librbd::api::Group
<>::image_remove(group_ioctx
, group_name
,
6635 image_ioctx
, image_name
);
6637 tracepoint(librbd
, group_image_remove_exit
, r
);
6641 extern "C" int rbd_group_image_remove_by_id(rados_ioctx_t group_p
,
6642 const char *group_name
,
6643 rados_ioctx_t image_p
,
6644 const char *image_id
)
6646 librados::IoCtx group_ioctx
;
6647 librados::IoCtx image_ioctx
;
6649 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6650 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6652 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6653 tracepoint(librbd
, group_image_remove_by_id_enter
,
6654 group_ioctx
.get_pool_name().c_str(),
6655 group_ioctx
.get_id(), group_name
,
6656 image_ioctx
.get_pool_name().c_str(),
6657 image_ioctx
.get_id(), image_id
);
6659 int r
= librbd::api::Group
<>::image_remove_by_id(group_ioctx
, group_name
,
6660 image_ioctx
, image_id
);
6662 tracepoint(librbd
, group_image_remove_by_id_exit
, r
);
6666 extern "C" int rbd_group_image_list(rados_ioctx_t group_p
,
6667 const char *group_name
,
6668 rbd_group_image_info_t
*images
,
6669 size_t group_image_info_size
,
6672 librados::IoCtx group_ioctx
;
6673 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6675 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6676 tracepoint(librbd
, group_image_list_enter
,
6677 group_ioctx
.get_pool_name().c_str(),
6678 group_ioctx
.get_id(), group_name
);
6679 // FIPS zeroization audit 20191117: this memset is not security related.
6680 memset(images
, 0, sizeof(*images
) * *image_size
);
6682 if (group_image_info_size
!= sizeof(rbd_group_image_info_t
)) {
6684 tracepoint(librbd
, group_image_list_exit
, -ERANGE
);
6688 std::vector
<librbd::group_image_info_t
> cpp_images
;
6689 int r
= librbd::api::Group
<>::image_list(group_ioctx
, group_name
,
6693 tracepoint(librbd
, group_image_list_exit
, 0);
6699 tracepoint(librbd
, group_image_list_exit
, r
);
6703 if (*image_size
< cpp_images
.size()) {
6704 *image_size
= cpp_images
.size();
6705 tracepoint(librbd
, group_image_list_exit
, -ERANGE
);
6709 for (size_t i
= 0; i
< cpp_images
.size(); ++i
) {
6710 group_image_status_cpp_to_c(cpp_images
[i
], &images
[i
]);
6713 r
= *image_size
= cpp_images
.size();
6714 tracepoint(librbd
, group_image_list_exit
, r
);
6718 extern "C" int rbd_group_info_cleanup(rbd_group_info_t
*group_info
,
6719 size_t group_info_size
) {
6720 if (group_info_size
!= sizeof(rbd_group_info_t
)) {
6724 free(group_info
->name
);
6728 extern "C" int rbd_group_image_list_cleanup(rbd_group_image_info_t
*images
,
6729 size_t group_image_info_size
,
6731 if (group_image_info_size
!= sizeof(rbd_group_image_info_t
)) {
6735 for (size_t i
= 0; i
< len
; ++i
) {
6736 free(images
[i
].name
);
6741 extern "C" int rbd_group_snap_create(rados_ioctx_t group_p
,
6742 const char *group_name
,
6743 const char *snap_name
)
6745 librados::IoCtx group_ioctx
;
6746 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6748 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6749 tracepoint(librbd
, group_snap_create_enter
,
6750 group_ioctx
.get_pool_name().c_str(),
6751 group_ioctx
.get_id(), group_name
, snap_name
);
6753 int r
= librbd::api::Group
<>::snap_create(group_ioctx
, group_name
, snap_name
);
6755 tracepoint(librbd
, group_snap_create_exit
, r
);
6760 extern "C" int rbd_group_snap_remove(rados_ioctx_t group_p
,
6761 const char *group_name
,
6762 const char *snap_name
)
6764 librados::IoCtx group_ioctx
;
6765 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6767 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6768 tracepoint(librbd
, group_snap_remove_enter
,
6769 group_ioctx
.get_pool_name().c_str(),
6770 group_ioctx
.get_id(), group_name
, snap_name
);
6772 int r
= librbd::api::Group
<>::snap_remove(group_ioctx
, group_name
, snap_name
);
6774 tracepoint(librbd
, group_snap_remove_exit
, r
);
6779 extern "C" int rbd_group_snap_rename(rados_ioctx_t group_p
,
6780 const char *group_name
,
6781 const char *old_snap_name
,
6782 const char *new_snap_name
)
6784 librados::IoCtx group_ioctx
;
6785 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6787 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6788 tracepoint(librbd
, group_snap_rename_enter
,
6789 group_ioctx
.get_pool_name().c_str(), group_ioctx
.get_id(),
6790 group_name
, old_snap_name
, new_snap_name
);
6792 int r
= librbd::api::Group
<>::snap_rename(group_ioctx
, group_name
,
6793 old_snap_name
, new_snap_name
);
6795 tracepoint(librbd
, group_snap_list_exit
, r
);
6799 extern "C" int rbd_group_snap_list(rados_ioctx_t group_p
,
6800 const char *group_name
,
6801 rbd_group_snap_info_t
*snaps
,
6802 size_t group_snap_info_size
,
6805 librados::IoCtx group_ioctx
;
6806 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6808 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6809 tracepoint(librbd
, group_snap_list_enter
, group_ioctx
.get_pool_name().c_str(),
6810 group_ioctx
.get_id(), group_name
);
6811 // FIPS zeroization audit 20191117: this memset is not security related.
6812 memset(snaps
, 0, sizeof(*snaps
) * *snaps_size
);
6814 if (group_snap_info_size
!= sizeof(rbd_group_snap_info_t
)) {
6816 tracepoint(librbd
, group_snap_list_exit
, -ERANGE
);
6820 std::vector
<librbd::group_snap_info_t
> cpp_snaps
;
6821 int r
= librbd::api::Group
<>::snap_list(group_ioctx
, group_name
, &cpp_snaps
);
6825 tracepoint(librbd
, group_snap_list_exit
, 0);
6830 tracepoint(librbd
, group_snap_list_exit
, r
);
6834 if (*snaps_size
< cpp_snaps
.size()) {
6835 *snaps_size
= cpp_snaps
.size();
6836 tracepoint(librbd
, group_snap_list_exit
, -ERANGE
);
6840 for (size_t i
= 0; i
< cpp_snaps
.size(); ++i
) {
6841 group_snap_info_cpp_to_c(cpp_snaps
[i
], &snaps
[i
]);
6844 r
= *snaps_size
= cpp_snaps
.size();
6845 tracepoint(librbd
, group_snap_list_exit
, r
);
6849 extern "C" int rbd_group_snap_list_cleanup(rbd_group_snap_info_t
*snaps
,
6850 size_t group_snap_info_size
,
6852 if (group_snap_info_size
!= sizeof(rbd_group_snap_info_t
)) {
6856 for (size_t i
= 0; i
< len
; ++i
) {
6857 free(snaps
[i
].name
);
6862 extern "C" int rbd_group_snap_rollback(rados_ioctx_t group_p
,
6863 const char *group_name
,
6864 const char *snap_name
)
6866 librados::IoCtx group_ioctx
;
6867 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6869 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6870 tracepoint(librbd
, group_snap_rollback_enter
,
6871 group_ioctx
.get_pool_name().c_str(),
6872 group_ioctx
.get_id(), group_name
, snap_name
);
6874 librbd::NoOpProgressContext prog_ctx
;
6875 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
6876 snap_name
, prog_ctx
);
6878 tracepoint(librbd
, group_snap_rollback_exit
, r
);
6883 extern "C" int rbd_group_snap_rollback_with_progress(rados_ioctx_t group_p
,
6884 const char *group_name
,
6885 const char *snap_name
,
6886 librbd_progress_fn_t cb
,
6889 librados::IoCtx group_ioctx
;
6890 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6892 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6893 tracepoint(librbd
, group_snap_rollback_enter
,
6894 group_ioctx
.get_pool_name().c_str(),
6895 group_ioctx
.get_id(), group_name
, snap_name
);
6897 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
6898 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
6899 snap_name
, prog_ctx
);
6901 tracepoint(librbd
, group_snap_rollback_exit
, r
);
6906 extern "C" int rbd_snap_get_namespace_type(rbd_image_t image
,
6908 rbd_snap_namespace_type_t
*namespace_type
) {
6909 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6910 tracepoint(librbd
, snap_get_namespace_type_enter
, ictx
, ictx
->name
.c_str());
6911 int r
= librbd::api::Snapshot
<>::get_namespace_type(ictx
, snap_id
,
6913 tracepoint(librbd
, snap_get_namespace_type_exit
, r
);
6917 extern "C" int rbd_snap_get_group_namespace(rbd_image_t image
, uint64_t snap_id
,
6918 rbd_snap_group_namespace_t
*group_snap
,
6919 size_t snap_group_namespace_size
) {
6920 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6921 tracepoint(librbd
, snap_get_group_namespace_enter
, ictx
,
6922 ictx
->name
.c_str());
6924 if (snap_group_namespace_size
!= sizeof(rbd_snap_group_namespace_t
)) {
6925 tracepoint(librbd
, snap_get_group_namespace_exit
, -ERANGE
);
6929 librbd::snap_group_namespace_t group_namespace
;
6930 int r
= librbd::api::Snapshot
<>::get_group_namespace(ictx
, snap_id
,
6933 group_snap
->group_pool
= group_namespace
.group_pool
;
6934 group_snap
->group_name
= strdup(group_namespace
.group_name
.c_str());
6935 group_snap
->group_snap_name
=
6936 strdup(group_namespace
.group_snap_name
.c_str());
6939 tracepoint(librbd
, snap_get_group_namespace_exit
, r
);
6943 extern "C" int rbd_snap_group_namespace_cleanup(rbd_snap_group_namespace_t
*group_snap
,
6944 size_t snap_group_namespace_size
) {
6945 if (snap_group_namespace_size
!= sizeof(rbd_snap_group_namespace_t
)) {
6949 free(group_snap
->group_name
);
6950 free(group_snap
->group_snap_name
);
6954 extern "C" int rbd_snap_get_trash_namespace(rbd_image_t image
, uint64_t snap_id
,
6955 char *original_name
,
6956 size_t max_length
) {
6957 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6959 std::string cpp_original_name
;
6960 int r
= librbd::api::Snapshot
<>::get_trash_namespace(ictx
, snap_id
,
6961 &cpp_original_name
);
6966 if (cpp_original_name
.length() >= max_length
) {
6970 strcpy(original_name
, cpp_original_name
.c_str());
6974 extern "C" int rbd_snap_get_mirror_namespace(
6975 rbd_image_t image
, uint64_t snap_id
,
6976 rbd_snap_mirror_namespace_t
*mirror_snap
,
6977 size_t mirror_snap_size
) {
6978 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6980 if (mirror_snap_size
!= sizeof(rbd_snap_mirror_namespace_t
)) {
6984 librbd::snap_mirror_namespace_t mirror_namespace
;
6985 int r
= librbd::api::Snapshot
<>::get_mirror_namespace(
6986 ictx
, snap_id
, &mirror_namespace
);
6991 mirror_snap
->state
= mirror_namespace
.state
;
6992 mirror_snap
->primary_mirror_uuid
=
6993 strdup(mirror_namespace
.primary_mirror_uuid
.c_str());
6994 mirror_snap
->primary_snap_id
= mirror_namespace
.primary_snap_id
;
6995 mirror_snap
->mirror_peer_uuids_count
=
6996 mirror_namespace
.mirror_peer_uuids
.size();
6998 for (auto &peer
: mirror_namespace
.mirror_peer_uuids
) {
6999 len
+= peer
.size() + 1;
7001 mirror_snap
->mirror_peer_uuids
= (char *)malloc(len
);
7002 char *p
= mirror_snap
->mirror_peer_uuids
;
7003 for (auto &peer
: mirror_namespace
.mirror_peer_uuids
) {
7004 strncpy(p
, peer
.c_str(), peer
.size() + 1);
7005 p
+= peer
.size() + 1;
7007 mirror_snap
->complete
= mirror_namespace
.complete
;
7008 mirror_snap
->last_copied_object_number
=
7009 mirror_namespace
.last_copied_object_number
;
7014 extern "C" int rbd_snap_mirror_namespace_cleanup(
7015 rbd_snap_mirror_namespace_t
*mirror_snap
,
7016 size_t mirror_snap_size
) {
7017 if (mirror_snap_size
!= sizeof(rbd_snap_mirror_namespace_t
)) {
7021 free(mirror_snap
->primary_mirror_uuid
);
7022 free(mirror_snap
->mirror_peer_uuids
);
7026 extern "C" int rbd_watchers_list(rbd_image_t image
,
7027 rbd_image_watcher_t
*watchers
,
7028 size_t *max_watchers
) {
7029 std::list
<librbd::image_watcher_t
> watcher_list
;
7030 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7032 tracepoint(librbd
, list_watchers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
7033 // FIPS zeroization audit 20191117: this memset is not security related.
7034 memset(watchers
, 0, sizeof(*watchers
) * *max_watchers
);
7035 int r
= librbd::list_watchers(ictx
, watcher_list
);
7037 tracepoint(librbd
, list_watchers_exit
, r
, 0);
7041 if (watcher_list
.size() > *max_watchers
) {
7042 *max_watchers
= watcher_list
.size();
7043 tracepoint(librbd
, list_watchers_exit
, -ERANGE
, watcher_list
.size());
7048 for (auto &watcher
: watcher_list
) {
7049 tracepoint(librbd
, list_watchers_entry
, watcher
.addr
.c_str(), watcher
.id
, watcher
.cookie
);
7050 watchers
[*max_watchers
].addr
= strdup(watcher
.addr
.c_str());
7051 watchers
[*max_watchers
].id
= watcher
.id
;
7052 watchers
[*max_watchers
].cookie
= watcher
.cookie
;
7056 tracepoint(librbd
, list_watchers_exit
, r
, watcher_list
.size());
7060 extern "C" void rbd_watchers_list_cleanup(rbd_image_watcher_t
*watchers
,
7061 size_t num_watchers
) {
7062 for (size_t i
= 0; i
< num_watchers
; ++i
) {
7063 free(watchers
[i
].addr
);
7067 extern "C" int rbd_config_image_list(rbd_image_t image
,
7068 rbd_config_option_t
*options
,
7070 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7072 std::vector
<librbd::config_option_t
> option_vector
;
7073 int r
= librbd::api::Config
<>::list(ictx
, &option_vector
);
7078 if (*max_options
< static_cast<int>(option_vector
.size())) {
7079 *max_options
= static_cast<int>(option_vector
.size());
7083 for (int i
= 0; i
< static_cast<int>(option_vector
.size()); ++i
) {
7084 config_option_cpp_to_c(option_vector
[i
], &options
[i
]);
7086 *max_options
= static_cast<int>(option_vector
.size());
7090 extern "C" void rbd_config_image_list_cleanup(rbd_config_option_t
*options
,
7092 for (int i
= 0; i
< max_options
; ++i
) {
7093 config_option_cleanup(options
[i
]);