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
&& bl
.is_zero()) {
2544 int r
= ictx
->io_work_queue
->write_zeroes(ofs
, len
, 0U, op_flags
);
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::write_zeroes(uint64_t ofs
, size_t len
, int zero_flags
,
2557 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2558 return ictx
->io_work_queue
->write_zeroes(ofs
, len
, zero_flags
, op_flags
);
2561 ssize_t
Image::compare_and_write(uint64_t ofs
, size_t len
,
2562 ceph::bufferlist
&cmp_bl
, ceph::bufferlist
& bl
,
2563 uint64_t *mismatch_off
, int op_flags
)
2565 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2566 tracepoint(librbd
, compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
2567 ictx
->snap_name
.c_str(),
2568 ictx
->read_only
, ofs
, len
, cmp_bl
.length() < len
? NULL
: cmp_bl
.c_str(),
2569 bl
.length() < len
? NULL
: bl
.c_str(), op_flags
);
2571 if (bl
.length() < len
) {
2572 tracepoint(librbd
, write_exit
, -EINVAL
);
2576 int r
= ictx
->io_work_queue
->compare_and_write(ofs
, len
, bufferlist
{cmp_bl
},
2577 bufferlist
{bl
}, mismatch_off
,
2580 tracepoint(librbd
, compare_and_write_exit
, r
);
2585 int Image::aio_write(uint64_t off
, size_t len
, bufferlist
& bl
,
2586 RBD::AioCompletion
*c
)
2588 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2589 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
);
2590 if (bl
.length() < len
) {
2591 tracepoint(librbd
, aio_write_exit
, -EINVAL
);
2594 ictx
->io_work_queue
->aio_write(get_aio_completion(c
), off
, len
,
2597 tracepoint(librbd
, aio_write_exit
, 0);
2601 int Image::aio_write2(uint64_t off
, size_t len
, bufferlist
& bl
,
2602 RBD::AioCompletion
*c
, int op_flags
)
2604 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2605 tracepoint(librbd
, aio_write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2606 ictx
->read_only
, off
, len
, bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
, op_flags
);
2607 if (bl
.length() < len
) {
2608 tracepoint(librbd
, aio_write_exit
, -EINVAL
);
2611 ictx
->io_work_queue
->aio_write(get_aio_completion(c
), off
, len
,
2612 bufferlist
{bl
}, op_flags
);
2614 tracepoint(librbd
, aio_write_exit
, 0);
2618 int Image::aio_discard(uint64_t off
, uint64_t len
, RBD::AioCompletion
*c
)
2620 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2621 tracepoint(librbd
, aio_discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, c
->pc
);
2622 ictx
->io_work_queue
->aio_discard(
2623 get_aio_completion(c
), off
, len
, ictx
->discard_granularity_bytes
);
2624 tracepoint(librbd
, aio_discard_exit
, 0);
2628 int Image::aio_read(uint64_t off
, size_t len
, bufferlist
& bl
,
2629 RBD::AioCompletion
*c
)
2631 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2632 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
);
2633 ldout(ictx
->cct
, 10) << "Image::aio_read() buf=" << (void *)bl
.c_str() << "~"
2634 << (void *)(bl
.c_str() + len
- 1) << dendl
;
2636 ictx
->io_work_queue
->aio_read(get_aio_completion(c
), off
, len
,
2637 io::ReadResult
{&bl
}, 0);
2638 tracepoint(librbd
, aio_read_exit
, 0);
2642 int Image::aio_read2(uint64_t off
, size_t len
, bufferlist
& bl
,
2643 RBD::AioCompletion
*c
, int op_flags
)
2645 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2646 tracepoint(librbd
, aio_read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2647 ictx
->read_only
, off
, len
, bl
.c_str(), c
->pc
, op_flags
);
2648 ldout(ictx
->cct
, 10) << "Image::aio_read() buf=" << (void *)bl
.c_str() << "~"
2649 << (void *)(bl
.c_str() + len
- 1) << dendl
;
2651 ictx
->io_work_queue
->aio_read(get_aio_completion(c
), off
, len
,
2652 io::ReadResult
{&bl
}, op_flags
);
2653 tracepoint(librbd
, aio_read_exit
, 0);
2659 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2660 tracepoint(librbd
, flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2661 int r
= ictx
->io_work_queue
->flush();
2662 tracepoint(librbd
, flush_exit
, r
);
2666 int Image::aio_flush(RBD::AioCompletion
*c
)
2668 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2669 tracepoint(librbd
, aio_flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, c
->pc
);
2670 ictx
->io_work_queue
->aio_flush(get_aio_completion(c
));
2671 tracepoint(librbd
, aio_flush_exit
, 0);
2675 int Image::aio_writesame(uint64_t off
, size_t len
, bufferlist
& bl
,
2676 RBD::AioCompletion
*c
, int op_flags
)
2678 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2679 tracepoint(librbd
, aio_writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
2680 ictx
->read_only
, off
, len
, bl
.length() <= len
? NULL
: bl
.c_str(), bl
.length(),
2682 if (bl
.length() <= 0 || len
% bl
.length()) {
2683 tracepoint(librbd
, aio_writesame_exit
, -EINVAL
);
2687 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
2688 if (discard_zero
&& bl
.is_zero()) {
2689 ictx
->io_work_queue
->aio_write_zeroes(get_aio_completion(c
), off
, len
, 0U,
2691 tracepoint(librbd
, aio_writesame_exit
, 0);
2695 ictx
->io_work_queue
->aio_writesame(get_aio_completion(c
), off
, len
,
2696 bufferlist
{bl
}, op_flags
);
2697 tracepoint(librbd
, aio_writesame_exit
, 0);
2701 int Image::aio_write_zeroes(uint64_t off
, size_t len
, RBD::AioCompletion
*c
,
2702 int zero_flags
, int op_flags
)
2704 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2705 ictx
->io_work_queue
->aio_write_zeroes(
2706 get_aio_completion(c
), off
, len
, zero_flags
, op_flags
, true);
2710 int Image::aio_compare_and_write(uint64_t off
, size_t len
,
2711 ceph::bufferlist
& cmp_bl
, ceph::bufferlist
& bl
,
2712 RBD::AioCompletion
*c
, uint64_t *mismatch_off
,
2715 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2716 tracepoint(librbd
, aio_compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
2717 ictx
->snap_name
.c_str(),
2718 ictx
->read_only
, off
, len
, cmp_bl
.length() < len
? NULL
: cmp_bl
.c_str(),
2719 bl
.length() < len
? NULL
: bl
.c_str(), c
->pc
, op_flags
);
2721 if (bl
.length() < len
) {
2722 tracepoint(librbd
, compare_and_write_exit
, -EINVAL
);
2726 ictx
->io_work_queue
->aio_compare_and_write(get_aio_completion(c
), off
, len
,
2727 bufferlist
{cmp_bl
}, bufferlist
{bl
},
2728 mismatch_off
, op_flags
, false);
2730 tracepoint(librbd
, aio_compare_and_write_exit
, 0);
2735 int Image::invalidate_cache()
2737 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2738 tracepoint(librbd
, invalidate_cache_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
2739 int r
= librbd::invalidate_cache(ictx
);
2740 tracepoint(librbd
, invalidate_cache_exit
, r
);
2744 int Image::poll_io_events(RBD::AioCompletion
**comps
, int numcomp
)
2746 io::AioCompletion
*cs
[numcomp
];
2747 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2748 tracepoint(librbd
, poll_io_events_enter
, ictx
, numcomp
);
2749 int r
= librbd::poll_io_events(ictx
, cs
, numcomp
);
2750 tracepoint(librbd
, poll_io_events_exit
, r
);
2752 for (int i
= 0; i
< r
; ++i
)
2753 comps
[i
] = (RBD::AioCompletion
*)cs
[i
]->rbd_comp
;
2758 int Image::metadata_get(const std::string
&key
, std::string
*value
)
2760 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2761 tracepoint(librbd
, metadata_get_enter
, ictx
, key
.c_str());
2762 int r
= librbd::metadata_get(ictx
, key
, value
);
2764 tracepoint(librbd
, metadata_get_exit
, r
, key
.c_str(), NULL
);
2766 tracepoint(librbd
, metadata_get_exit
, r
, key
.c_str(), value
->c_str());
2771 int Image::metadata_set(const std::string
&key
, const std::string
&value
)
2773 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2774 tracepoint(librbd
, metadata_set_enter
, ictx
, key
.c_str(), value
.c_str());
2775 int r
= ictx
->operations
->metadata_set(key
, value
);
2776 tracepoint(librbd
, metadata_set_exit
, r
);
2780 int Image::metadata_remove(const std::string
&key
)
2782 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2783 tracepoint(librbd
, metadata_remove_enter
, ictx
, key
.c_str());
2784 int r
= ictx
->operations
->metadata_remove(key
);
2785 tracepoint(librbd
, metadata_remove_exit
, r
);
2789 int Image::metadata_list(const std::string
&start
, uint64_t max
, map
<string
, bufferlist
> *pairs
)
2791 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2792 tracepoint(librbd
, metadata_list_enter
, ictx
);
2793 int r
= librbd::metadata_list(ictx
, start
, max
, pairs
);
2795 for (map
<string
, bufferlist
>::iterator it
= pairs
->begin();
2796 it
!= pairs
->end(); ++it
) {
2797 tracepoint(librbd
, metadata_list_entry
, it
->first
.c_str(), it
->second
.c_str());
2800 tracepoint(librbd
, metadata_list_exit
, r
);
2804 int Image::mirror_image_enable() {
2805 return mirror_image_enable2(RBD_MIRROR_IMAGE_MODE_JOURNAL
);
2808 int Image::mirror_image_enable2(mirror_image_mode_t mode
) {
2809 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2810 return librbd::api::Mirror
<>::image_enable(ictx
, mode
, false);
2813 int Image::mirror_image_disable(bool force
) {
2814 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2815 return librbd::api::Mirror
<>::image_disable(ictx
, force
);
2818 int Image::mirror_image_promote(bool force
) {
2819 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2820 return librbd::api::Mirror
<>::image_promote(ictx
, force
);
2823 int Image::mirror_image_demote() {
2824 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2825 return librbd::api::Mirror
<>::image_demote(ictx
);
2828 int Image::mirror_image_resync()
2830 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2831 return librbd::api::Mirror
<>::image_resync(ictx
);
2834 int Image::mirror_image_create_snapshot(uint64_t *snap_id
)
2836 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2837 return librbd::api::Mirror
<>::image_snapshot_create(ictx
, snap_id
);
2840 int Image::mirror_image_get_info(mirror_image_info_t
*mirror_image_info
,
2842 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2844 if (sizeof(mirror_image_info_t
) != info_size
) {
2848 return librbd::api::Mirror
<>::image_get_info(ictx
, mirror_image_info
);
2851 int Image::mirror_image_get_mode(mirror_image_mode_t
*mode
) {
2852 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2854 return librbd::api::Mirror
<>::image_get_mode(ictx
, mode
);
2857 int Image::mirror_image_get_global_status(
2858 mirror_image_global_status_t
*mirror_image_global_status
,
2859 size_t status_size
) {
2860 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2862 if (sizeof(mirror_image_global_status_t
) != status_size
) {
2866 return librbd::api::Mirror
<>::image_get_global_status(
2867 ictx
, mirror_image_global_status
);
2870 #pragma GCC diagnostic push
2871 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2873 int Image::mirror_image_get_status(mirror_image_status_t
*mirror_image_status
,
2874 size_t status_size
) {
2875 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2877 if (sizeof(mirror_image_status_t
) != status_size
) {
2881 mirror_image_global_status_t mirror_image_global_status
;
2882 int r
= librbd::api::Mirror
<>::image_get_global_status(
2883 ictx
, &mirror_image_global_status
);
2888 librbd::mirror_image_site_status_t local_status
;
2889 r
= get_local_mirror_image_site_status(mirror_image_global_status
,
2895 *mirror_image_status
= mirror_image_status_t
{
2896 mirror_image_global_status
.name
, mirror_image_global_status
.info
,
2897 local_status
.state
, local_status
.description
, local_status
.last_update
,
2902 #pragma GCC diagnostic pop
2904 int Image::mirror_image_get_instance_id(std::string
*instance_id
) {
2905 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2907 return librbd::api::Mirror
<>::image_get_instance_id(ictx
, instance_id
);
2910 int Image::aio_mirror_image_promote(bool force
, RBD::AioCompletion
*c
) {
2911 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2912 librbd::api::Mirror
<>::image_promote(
2913 ictx
, force
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2914 get_aio_completion(c
)));
2918 int Image::aio_mirror_image_demote(RBD::AioCompletion
*c
) {
2919 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2920 librbd::api::Mirror
<>::image_demote(
2921 ictx
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2922 get_aio_completion(c
)));
2926 int Image::aio_mirror_image_get_info(mirror_image_info_t
*mirror_image_info
,
2928 RBD::AioCompletion
*c
) {
2929 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2931 if (sizeof(mirror_image_info_t
) != info_size
) {
2935 librbd::api::Mirror
<>::image_get_info(
2936 ictx
, mirror_image_info
,
2937 new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2938 get_aio_completion(c
)));
2942 int Image::aio_mirror_image_get_mode(mirror_image_mode_t
*mode
,
2943 RBD::AioCompletion
*c
) {
2944 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2946 librbd::api::Mirror
<>::image_get_mode(
2947 ictx
, mode
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2948 get_aio_completion(c
)));
2952 int Image::aio_mirror_image_get_global_status(
2953 mirror_image_global_status_t
*status
, size_t status_size
,
2954 RBD::AioCompletion
*c
) {
2955 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2957 if (sizeof(mirror_image_global_status_t
) != status_size
) {
2961 librbd::api::Mirror
<>::image_get_global_status(
2962 ictx
, status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2963 get_aio_completion(c
)));
2967 #pragma GCC diagnostic push
2968 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2970 int Image::aio_mirror_image_get_status(mirror_image_status_t
*status
,
2972 RBD::AioCompletion
*c
) {
2973 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2975 if (sizeof(mirror_image_status_t
) != status_size
) {
2979 auto ctx
= new C_MirrorImageGetStatus(
2980 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
2981 get_aio_completion(c
)));
2982 librbd::api::Mirror
<>::image_get_global_status(
2983 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
2987 #pragma GCC diagnostic pop
2989 int Image::update_watch(UpdateWatchCtx
*wctx
, uint64_t *handle
) {
2990 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2991 tracepoint(librbd
, update_watch_enter
, ictx
, wctx
);
2992 int r
= ictx
->state
->register_update_watcher(wctx
, handle
);
2993 tracepoint(librbd
, update_watch_exit
, r
, *handle
);
2997 int Image::update_unwatch(uint64_t handle
) {
2998 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
2999 tracepoint(librbd
, update_unwatch_enter
, ictx
, handle
);
3000 int r
= ictx
->state
->unregister_update_watcher(handle
);
3001 tracepoint(librbd
, update_unwatch_exit
, r
);
3005 int Image::list_watchers(std::list
<librbd::image_watcher_t
> &watchers
) {
3006 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3007 tracepoint(librbd
, list_watchers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
3008 int r
= librbd::list_watchers(ictx
, watchers
);
3011 for (auto &watcher
: watchers
) {
3012 tracepoint(librbd
, list_watchers_entry
, watcher
.addr
.c_str(), watcher
.id
, watcher
.cookie
);
3016 tracepoint(librbd
, list_watchers_exit
, r
, watchers
.size());
3020 int Image::config_list(std::vector
<config_option_t
> *options
) {
3021 ImageCtx
*ictx
= (ImageCtx
*)ctx
;
3022 return librbd::api::Config
<>::list(ictx
, options
);
3025 } // namespace librbd
3027 extern "C" void rbd_version(int *major
, int *minor
, int *extra
)
3030 *major
= LIBRBD_VER_MAJOR
;
3032 *minor
= LIBRBD_VER_MINOR
;
3034 *extra
= LIBRBD_VER_EXTRA
;
3037 extern "C" void rbd_image_options_create(rbd_image_options_t
* opts
)
3039 librbd::image_options_create(opts
);
3042 extern "C" void rbd_image_options_destroy(rbd_image_options_t opts
)
3044 librbd::image_options_destroy(opts
);
3047 extern "C" int rbd_image_options_set_string(rbd_image_options_t opts
, int optname
,
3050 return librbd::image_options_set(opts
, optname
, optval
);
3053 extern "C" int rbd_image_options_set_uint64(rbd_image_options_t opts
, int optname
,
3056 return librbd::image_options_set(opts
, optname
, optval
);
3059 extern "C" int rbd_image_options_get_string(rbd_image_options_t opts
, int optname
,
3060 char* optval
, size_t maxlen
)
3062 std::string optval_
;
3064 int r
= librbd::image_options_get(opts
, optname
, &optval_
);
3070 if (optval_
.size() >= maxlen
) {
3074 strncpy(optval
, optval_
.c_str(), maxlen
);
3079 extern "C" int rbd_image_options_get_uint64(rbd_image_options_t opts
, int optname
,
3082 return librbd::image_options_get(opts
, optname
, optval
);
3085 extern "C" int rbd_image_options_is_set(rbd_image_options_t opts
, int optname
,
3088 return librbd::image_options_is_set(opts
, optname
, is_set
);
3091 extern "C" int rbd_image_options_unset(rbd_image_options_t opts
, int optname
)
3093 return librbd::image_options_unset(opts
, optname
);
3096 extern "C" void rbd_image_options_clear(rbd_image_options_t opts
)
3098 librbd::image_options_clear(opts
);
3101 extern "C" int rbd_image_options_is_empty(rbd_image_options_t opts
)
3103 return librbd::image_options_is_empty(opts
);
3106 /* pool mirroring */
3107 extern "C" int rbd_mirror_site_name_get(rados_t cluster
, char *name
,
3109 librados::Rados rados
;
3110 librados::Rados::from_rados_t(cluster
, rados
);
3112 std::string site_name
;
3113 int r
= librbd::api::Mirror
<>::site_name_get(rados
, &site_name
);
3118 auto total_len
= site_name
.size() + 1;
3119 if (*max_len
< total_len
) {
3120 *max_len
= total_len
;
3123 *max_len
= total_len
;
3125 strcpy(name
, site_name
.c_str());
3129 extern "C" int rbd_mirror_site_name_set(rados_t cluster
, const char *name
) {
3130 librados::Rados rados
;
3131 librados::Rados::from_rados_t(cluster
, rados
);
3132 return librbd::api::Mirror
<>::site_name_set(rados
, name
);
3135 extern "C" int rbd_mirror_mode_get(rados_ioctx_t p
,
3136 rbd_mirror_mode_t
*mirror_mode
) {
3137 librados::IoCtx io_ctx
;
3138 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3139 return librbd::api::Mirror
<>::mode_get(io_ctx
, mirror_mode
);
3142 extern "C" int rbd_mirror_mode_set(rados_ioctx_t p
,
3143 rbd_mirror_mode_t mirror_mode
) {
3144 librados::IoCtx io_ctx
;
3145 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3146 return librbd::api::Mirror
<>::mode_set(io_ctx
, mirror_mode
);
3149 extern "C" int rbd_mirror_uuid_get(rados_ioctx_t p
,
3150 char *mirror_uuid
, size_t *max_len
) {
3151 librados::IoCtx io_ctx
;
3152 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3154 std::string mirror_uuid_str
;
3155 int r
= librbd::api::Mirror
<>::uuid_get(io_ctx
, &mirror_uuid_str
);
3160 auto total_len
= mirror_uuid_str
.size() + 1;
3161 if (*max_len
< total_len
) {
3162 *max_len
= total_len
;
3165 *max_len
= total_len
;
3167 strcpy(mirror_uuid
, mirror_uuid_str
.c_str());
3171 extern "C" int rbd_mirror_peer_bootstrap_create(rados_ioctx_t p
, char *token
,
3173 librados::IoCtx io_ctx
;
3174 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3176 std::string token_str
;
3177 int r
= librbd::api::Mirror
<>::peer_bootstrap_create(io_ctx
, &token_str
);
3182 auto total_len
= token_str
.size() + 1;
3183 if (*max_len
< total_len
) {
3184 *max_len
= total_len
;
3187 *max_len
= total_len
;
3189 strcpy(token
, token_str
.c_str());
3193 extern "C" int rbd_mirror_peer_bootstrap_import(
3194 rados_ioctx_t p
, rbd_mirror_peer_direction_t direction
,
3195 const char *token
) {
3196 librados::IoCtx io_ctx
;
3197 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3199 return librbd::api::Mirror
<>::peer_bootstrap_import(io_ctx
, direction
, token
);
3202 extern "C" int rbd_mirror_peer_site_add(rados_ioctx_t p
, char *uuid
,
3203 size_t uuid_max_length
,
3204 rbd_mirror_peer_direction_t direction
,
3205 const char *site_name
,
3206 const char *client_name
) {
3207 static const std::size_t UUID_LENGTH
= 36;
3209 librados::IoCtx io_ctx
;
3210 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3212 if (uuid_max_length
< UUID_LENGTH
+ 1) {
3216 std::string uuid_str
;
3217 int r
= librbd::api::Mirror
<>::peer_site_add(io_ctx
, &uuid_str
, direction
,
3218 site_name
, client_name
);
3220 strncpy(uuid
, uuid_str
.c_str(), uuid_max_length
);
3221 uuid
[uuid_max_length
- 1] = '\0';
3226 extern "C" int rbd_mirror_peer_site_remove(rados_ioctx_t p
, const char *uuid
) {
3227 librados::IoCtx io_ctx
;
3228 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3229 int r
= librbd::api::Mirror
<>::peer_site_remove(io_ctx
, uuid
);
3233 extern "C" int rbd_mirror_peer_site_list(
3234 rados_ioctx_t p
, rbd_mirror_peer_site_t
*peers
, int *max_peers
) {
3235 librados::IoCtx io_ctx
;
3236 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3238 std::vector
<librbd::mirror_peer_site_t
> peer_vector
;
3239 int r
= librbd::api::Mirror
<>::peer_site_list(io_ctx
, &peer_vector
);
3244 if (*max_peers
< static_cast<int>(peer_vector
.size())) {
3245 *max_peers
= static_cast<int>(peer_vector
.size());
3249 for (int i
= 0; i
< static_cast<int>(peer_vector
.size()); ++i
) {
3250 peers
[i
].uuid
= strdup(peer_vector
[i
].uuid
.c_str());
3251 peers
[i
].direction
= peer_vector
[i
].direction
;
3252 peers
[i
].site_name
= strdup(peer_vector
[i
].site_name
.c_str());
3253 peers
[i
].mirror_uuid
= strdup(peer_vector
[i
].mirror_uuid
.c_str());
3254 peers
[i
].client_name
= strdup(peer_vector
[i
].client_name
.c_str());
3256 *max_peers
= static_cast<int>(peer_vector
.size());
3260 extern "C" void rbd_mirror_peer_site_list_cleanup(rbd_mirror_peer_site_t
*peers
,
3262 for (int i
= 0; i
< max_peers
; ++i
) {
3263 free(peers
[i
].uuid
);
3264 free(peers
[i
].site_name
);
3265 free(peers
[i
].mirror_uuid
);
3266 free(peers
[i
].client_name
);
3270 extern "C" int rbd_mirror_peer_site_set_client_name(
3271 rados_ioctx_t p
, const char *uuid
, const char *client_name
) {
3272 librados::IoCtx io_ctx
;
3273 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3274 return librbd::api::Mirror
<>::peer_site_set_client(io_ctx
, uuid
, client_name
);
3277 extern "C" int rbd_mirror_peer_site_set_name(
3278 rados_ioctx_t p
, const char *uuid
, const char *site_name
) {
3279 librados::IoCtx io_ctx
;
3280 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3281 return librbd::api::Mirror
<>::peer_site_set_name(io_ctx
, uuid
, site_name
);
3284 extern "C" int rbd_mirror_peer_site_set_direction(
3285 rados_ioctx_t p
, const char *uuid
, rbd_mirror_peer_direction_t direction
) {
3286 librados::IoCtx io_ctx
;
3287 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3288 return librbd::api::Mirror
<>::peer_site_set_direction(io_ctx
, uuid
,
3292 extern "C" int rbd_mirror_peer_site_get_attributes(
3293 rados_ioctx_t p
, const char *uuid
, char *keys
, size_t *max_key_len
,
3294 char *values
, size_t *max_val_len
, size_t *key_value_count
) {
3295 librados::IoCtx io_ctx
;
3296 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3298 std::map
<std::string
, std::string
> attributes
;
3299 int r
= librbd::api::Mirror
<>::peer_site_get_attributes(
3300 io_ctx
, uuid
, &attributes
);
3305 size_t key_total_len
= 0, val_total_len
= 0;
3306 for (auto& it
: attributes
) {
3307 key_total_len
+= it
.first
.size() + 1;
3308 val_total_len
+= it
.second
.length() + 1;
3311 bool too_short
= ((*max_key_len
< key_total_len
) ||
3312 (*max_val_len
< val_total_len
));
3314 *max_key_len
= key_total_len
;
3315 *max_val_len
= val_total_len
;
3316 *key_value_count
= attributes
.size();
3321 char *keys_p
= keys
;
3322 char *values_p
= values
;
3323 for (auto& it
: attributes
) {
3324 strncpy(keys_p
, it
.first
.c_str(), it
.first
.size() + 1);
3325 keys_p
+= it
.first
.size() + 1;
3327 strncpy(values_p
, it
.second
.c_str(), it
.second
.length() + 1);
3328 values_p
+= it
.second
.length() + 1;
3334 extern "C" int rbd_mirror_peer_site_set_attributes(
3335 rados_ioctx_t p
, const char *uuid
, const char *keys
, const char *values
,
3337 librados::IoCtx io_ctx
;
3338 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3340 std::map
<std::string
, std::string
> attributes
;
3342 for (size_t i
= 0; i
< count
; ++i
) {
3343 const char* key
= keys
;
3344 keys
+= strlen(key
) + 1;
3345 const char* value
= values
;
3346 values
+= strlen(value
) + 1;
3347 attributes
[key
] = value
;
3350 return librbd::api::Mirror
<>::peer_site_set_attributes(
3351 io_ctx
, uuid
, attributes
);
3354 extern "C" int rbd_mirror_image_global_status_list(rados_ioctx_t p
,
3355 const char *start_id
, size_t max
, char **image_ids
,
3356 rbd_mirror_image_global_status_t
*images
, size_t *len
) {
3357 librados::IoCtx io_ctx
;
3358 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3359 std::map
<std::string
, librbd::mirror_image_global_status_t
> cpp_images
;
3361 int r
= librbd::api::Mirror
<>::image_global_status_list(
3362 io_ctx
, start_id
, max
, &cpp_images
);
3368 for (auto &it
: cpp_images
) {
3369 ceph_assert(i
< max
);
3370 const std::string
&image_id
= it
.first
;
3371 image_ids
[i
] = strdup(image_id
.c_str());
3372 mirror_image_global_status_cpp_to_c(it
.second
, &images
[i
]);
3379 extern "C" void rbd_mirror_image_global_status_cleanup(
3380 rbd_mirror_image_global_status_t
*global_status
) {
3381 free(global_status
->name
);
3382 rbd_mirror_image_get_info_cleanup(&global_status
->info
);
3383 for (auto idx
= 0U; idx
< global_status
->site_statuses_count
; ++idx
) {
3384 free(global_status
->site_statuses
[idx
].mirror_uuid
);
3385 free(global_status
->site_statuses
[idx
].description
);
3387 free(global_status
->site_statuses
);
3390 extern "C" void rbd_mirror_image_global_status_list_cleanup(
3391 char **image_ids
, rbd_mirror_image_global_status_t
*images
, size_t len
) {
3392 for (size_t i
= 0; i
< len
; i
++) {
3394 rbd_mirror_image_global_status_cleanup(&images
[i
]);
3398 #pragma GCC diagnostic push
3399 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
3401 extern "C" int rbd_mirror_peer_add(rados_ioctx_t p
, char *uuid
,
3402 size_t uuid_max_length
,
3403 const char *cluster_name
,
3404 const char *client_name
) {
3405 return rbd_mirror_peer_site_add(
3406 p
, uuid
, uuid_max_length
, RBD_MIRROR_PEER_DIRECTION_RX_TX
, cluster_name
,
3410 extern "C" int rbd_mirror_peer_remove(rados_ioctx_t p
, const char *uuid
) {
3411 return rbd_mirror_peer_site_remove(p
, uuid
);
3414 extern "C" int rbd_mirror_peer_list(rados_ioctx_t p
,
3415 rbd_mirror_peer_t
*peers
, int *max_peers
) {
3416 librados::IoCtx io_ctx
;
3417 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3419 std::vector
<librbd::mirror_peer_site_t
> peer_vector
;
3420 int r
= librbd::api::Mirror
<>::peer_site_list(io_ctx
, &peer_vector
);
3425 if (*max_peers
< static_cast<int>(peer_vector
.size())) {
3426 *max_peers
= static_cast<int>(peer_vector
.size());
3430 for (int i
= 0; i
< static_cast<int>(peer_vector
.size()); ++i
) {
3431 peers
[i
].uuid
= strdup(peer_vector
[i
].uuid
.c_str());
3432 peers
[i
].cluster_name
= strdup(peer_vector
[i
].site_name
.c_str());
3433 peers
[i
].client_name
= strdup(peer_vector
[i
].client_name
.c_str());
3435 *max_peers
= static_cast<int>(peer_vector
.size());
3439 extern "C" void rbd_mirror_peer_list_cleanup(rbd_mirror_peer_t
*peers
,
3441 for (int i
= 0; i
< max_peers
; ++i
) {
3442 free(peers
[i
].uuid
);
3443 free(peers
[i
].cluster_name
);
3444 free(peers
[i
].client_name
);
3448 extern "C" int rbd_mirror_peer_set_client(rados_ioctx_t p
, const char *uuid
,
3449 const char *client_name
) {
3450 return rbd_mirror_peer_site_set_client_name(p
, uuid
, client_name
);
3453 extern "C" int rbd_mirror_peer_set_cluster(rados_ioctx_t p
, const char *uuid
,
3454 const char *cluster_name
) {
3455 return rbd_mirror_peer_site_set_name(p
, uuid
, cluster_name
);
3458 extern "C" int rbd_mirror_peer_get_attributes(
3459 rados_ioctx_t p
, const char *uuid
, char *keys
, size_t *max_key_len
,
3460 char *values
, size_t *max_val_len
, size_t *key_value_count
) {
3461 return rbd_mirror_peer_site_get_attributes(
3462 p
, uuid
, keys
, max_key_len
, values
, max_val_len
, key_value_count
);
3465 extern "C" int rbd_mirror_peer_set_attributes(
3466 rados_ioctx_t p
, const char *uuid
, const char *keys
, const char *values
,
3468 return rbd_mirror_peer_site_set_attributes(
3469 p
, uuid
, keys
, values
, count
);
3472 extern "C" int rbd_mirror_image_status_list(rados_ioctx_t p
,
3473 const char *start_id
, size_t max
, char **image_ids
,
3474 rbd_mirror_image_status_t
*images
, size_t *len
) {
3475 librados::IoCtx io_ctx
;
3476 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3477 std::map
<std::string
, librbd::mirror_image_global_status_t
> cpp_images
;
3479 int r
= librbd::api::Mirror
<>::image_global_status_list(
3480 io_ctx
, start_id
, max
, &cpp_images
);
3486 for (auto &it
: cpp_images
) {
3487 ceph_assert(i
< max
);
3488 const std::string
&image_id
= it
.first
;
3489 image_ids
[i
] = strdup(image_id
.c_str());
3490 mirror_image_global_status_cpp_to_c(it
.second
, &images
[i
]);
3497 extern "C" void rbd_mirror_image_status_list_cleanup(char **image_ids
,
3498 rbd_mirror_image_status_t
*images
, size_t len
) {
3499 for (size_t i
= 0; i
< len
; i
++) {
3501 free(images
[i
].name
);
3502 rbd_mirror_image_get_info_cleanup(&images
[i
].info
);
3503 free(images
[i
].description
);
3507 #pragma GCC diagnostic pop
3509 extern "C" int rbd_mirror_image_status_summary(rados_ioctx_t p
,
3510 rbd_mirror_image_status_state_t
*states
, int *counts
, size_t *maxlen
) {
3512 librados::IoCtx io_ctx
;
3513 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3515 std::map
<librbd::mirror_image_status_state_t
, int> states_
;
3516 int r
= librbd::api::Mirror
<>::image_status_summary(io_ctx
, &states_
);
3522 for (auto &it
: states_
) {
3526 states
[i
] = it
.first
;
3527 counts
[i
] = it
.second
;
3534 extern "C" int rbd_mirror_image_instance_id_list(
3535 rados_ioctx_t p
, const char *start_id
, size_t max
, char **image_ids
,
3536 char **instance_ids
, size_t *len
) {
3537 librados::IoCtx io_ctx
;
3538 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3539 std::map
<std::string
, std::string
> cpp_instance_ids
;
3541 int r
= librbd::api::Mirror
<>::image_instance_id_list(io_ctx
, start_id
, max
,
3548 for (auto &it
: cpp_instance_ids
) {
3549 ceph_assert(i
< max
);
3550 image_ids
[i
] = strdup(it
.first
.c_str());
3551 instance_ids
[i
] = strdup(it
.second
.c_str());
3558 extern "C" void rbd_mirror_image_instance_id_list_cleanup(
3559 char **image_ids
, char **instance_ids
, size_t len
) {
3560 for (size_t i
= 0; i
< len
; i
++) {
3562 free(instance_ids
[i
]);
3566 extern "C" int rbd_mirror_image_info_list(
3567 rados_ioctx_t p
, rbd_mirror_image_mode_t
*mode_filter
,
3568 const char *start_id
, size_t max
, char **image_ids
,
3569 rbd_mirror_image_mode_t
*mode_entries
,
3570 rbd_mirror_image_info_t
*info_entries
, size_t *num_entries
) {
3571 librados::IoCtx io_ctx
;
3572 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3573 std::map
<std::string
, std::pair
<librbd::mirror_image_mode_t
,
3574 librbd::mirror_image_info_t
>> cpp_entries
;
3576 int r
= librbd::api::Mirror
<>::image_info_list(io_ctx
, mode_filter
, start_id
,
3582 ceph_assert(cpp_entries
.size() <= max
);
3584 for (auto &it
: cpp_entries
) {
3585 *(image_ids
++) = strdup(it
.first
.c_str());
3586 *(mode_entries
++) = it
.second
.first
;
3587 mirror_image_info_cpp_to_c(it
.second
.second
, info_entries
++);
3589 *num_entries
= cpp_entries
.size();
3594 extern "C" void rbd_mirror_image_info_list_cleanup(
3595 char **image_ids
, rbd_mirror_image_info_t
*info_entries
,
3596 size_t num_entries
) {
3597 for (size_t i
= 0; i
< num_entries
; i
++) {
3598 free(*(image_ids
++));
3599 rbd_mirror_image_get_info_cleanup(info_entries
++);
3605 extern "C" void rbd_image_spec_cleanup(rbd_image_spec_t
*image
)
3611 extern "C" void rbd_image_spec_list_cleanup(rbd_image_spec_t
*images
,
3614 for (size_t idx
= 0; idx
< num_images
; ++idx
) {
3615 rbd_image_spec_cleanup(&images
[idx
]);
3619 extern "C" void rbd_linked_image_spec_cleanup(rbd_linked_image_spec_t
*image
)
3621 free(image
->pool_name
);
3622 free(image
->pool_namespace
);
3623 free(image
->image_id
);
3624 free(image
->image_name
);
3627 extern "C" void rbd_linked_image_spec_list_cleanup(
3628 rbd_linked_image_spec_t
*images
, size_t num_images
)
3630 for (size_t idx
= 0; idx
< num_images
; ++idx
) {
3631 rbd_linked_image_spec_cleanup(&images
[idx
]);
3635 extern "C" void rbd_snap_spec_cleanup(rbd_snap_spec_t
*snap
)
3641 extern "C" int rbd_list(rados_ioctx_t p
, char *names
, size_t *size
)
3643 librados::IoCtx io_ctx
;
3644 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3646 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3647 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(),
3649 std::vector
<librbd::image_spec_t
> cpp_image_specs
;
3650 int r
= librbd::api::Image
<>::list_images(io_ctx
, &cpp_image_specs
);
3652 tracepoint(librbd
, list_exit
, r
, *size
);
3656 size_t expected_size
= 0;
3658 for (auto& it
: cpp_image_specs
) {
3659 expected_size
+= it
.name
.size() + 1;
3661 if (*size
< expected_size
) {
3662 *size
= expected_size
;
3663 tracepoint(librbd
, list_exit
, -ERANGE
, *size
);
3667 if (names
== NULL
) {
3668 tracepoint(librbd
, list_exit
, -EINVAL
, *size
);
3672 for (auto& it
: cpp_image_specs
) {
3673 const char* name
= it
.name
.c_str();
3674 tracepoint(librbd
, list_entry
, name
);
3675 strcpy(names
, name
);
3676 names
+= strlen(names
) + 1;
3678 tracepoint(librbd
, list_exit
, (int)expected_size
, *size
);
3679 return (int)expected_size
;
3682 extern "C" int rbd_list2(rados_ioctx_t p
, rbd_image_spec_t
*images
,
3685 librados::IoCtx io_ctx
;
3686 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3688 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3689 tracepoint(librbd
, list_enter
, io_ctx
.get_pool_name().c_str(),
3691 // FIPS zeroization audit 20191117: this memset is not security related.
3692 memset(images
, 0, sizeof(*images
) * *size
);
3693 std::vector
<librbd::image_spec_t
> cpp_image_specs
;
3694 int r
= librbd::api::Image
<>::list_images(io_ctx
, &cpp_image_specs
);
3696 tracepoint(librbd
, list_exit
, r
, *size
);
3700 size_t expected_size
= cpp_image_specs
.size();
3701 if (*size
< expected_size
) {
3702 *size
= expected_size
;
3703 tracepoint(librbd
, list_exit
, -ERANGE
, *size
);
3707 *size
= expected_size
;
3708 for (size_t idx
= 0; idx
< expected_size
; ++idx
) {
3709 images
[idx
].id
= strdup(cpp_image_specs
[idx
].id
.c_str());
3710 images
[idx
].name
= strdup(cpp_image_specs
[idx
].name
.c_str());
3712 tracepoint(librbd
, list_exit
, 0, *size
);
3716 extern "C" int rbd_create(rados_ioctx_t p
, const char *name
, uint64_t size
, int *order
)
3718 librados::IoCtx io_ctx
;
3719 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3720 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3721 tracepoint(librbd
, create_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, *order
);
3722 int r
= librbd::create(io_ctx
, name
, size
, order
);
3723 tracepoint(librbd
, create_exit
, r
, *order
);
3727 extern "C" int rbd_create2(rados_ioctx_t p
, const char *name
,
3728 uint64_t size
, uint64_t features
,
3731 librados::IoCtx io_ctx
;
3732 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3733 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3734 tracepoint(librbd
, create2_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
);
3735 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
, 0, 0);
3736 tracepoint(librbd
, create2_exit
, r
, *order
);
3740 extern "C" int rbd_create3(rados_ioctx_t p
, const char *name
,
3741 uint64_t size
, uint64_t features
,
3743 uint64_t stripe_unit
, uint64_t stripe_count
)
3745 librados::IoCtx io_ctx
;
3746 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3747 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3748 tracepoint(librbd
, create3_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, features
, *order
, stripe_unit
, stripe_count
);
3749 int r
= librbd::create(io_ctx
, name
, size
, false, features
, order
,
3750 stripe_unit
, stripe_count
);
3751 tracepoint(librbd
, create3_exit
, r
, *order
);
3755 extern "C" int rbd_create4(rados_ioctx_t p
, const char *name
,
3756 uint64_t size
, rbd_image_options_t opts
)
3758 librados::IoCtx io_ctx
;
3759 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3760 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3761 tracepoint(librbd
, create4_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
, size
, opts
);
3762 librbd::ImageOptions
opts_(opts
);
3763 int r
= librbd::create(io_ctx
, name
, "", size
, opts_
, "", "", false);
3764 tracepoint(librbd
, create4_exit
, r
);
3768 extern "C" int rbd_clone(rados_ioctx_t p_ioctx
, const char *p_name
,
3769 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3770 const char *c_name
, uint64_t features
, int *c_order
)
3772 librados::IoCtx p_ioc
, c_ioc
;
3773 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3774 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3775 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3776 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
);
3777 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
,
3778 features
, c_order
, 0, 0);
3779 tracepoint(librbd
, clone_exit
, r
, *c_order
);
3783 extern "C" int rbd_clone2(rados_ioctx_t p_ioctx
, const char *p_name
,
3784 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3785 const char *c_name
, uint64_t features
, int *c_order
,
3786 uint64_t stripe_unit
, int stripe_count
)
3788 librados::IoCtx p_ioc
, c_ioc
;
3789 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3790 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3791 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3792 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
);
3793 int r
= librbd::clone(p_ioc
, p_name
, p_snap_name
, c_ioc
, c_name
,
3794 features
, c_order
, stripe_unit
, stripe_count
);
3795 tracepoint(librbd
, clone2_exit
, r
, *c_order
);
3799 extern "C" int rbd_clone3(rados_ioctx_t p_ioctx
, const char *p_name
,
3800 const char *p_snap_name
, rados_ioctx_t c_ioctx
,
3801 const char *c_name
, rbd_image_options_t c_opts
)
3803 librados::IoCtx p_ioc
, c_ioc
;
3804 librados::IoCtx::from_rados_ioctx_t(p_ioctx
, p_ioc
);
3805 librados::IoCtx::from_rados_ioctx_t(c_ioctx
, c_ioc
);
3806 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(p_ioc
));
3807 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
);
3808 librbd::ImageOptions
c_opts_(c_opts
);
3809 int r
= librbd::clone(p_ioc
, nullptr, p_name
, p_snap_name
, c_ioc
, nullptr,
3810 c_name
, c_opts_
, "", "");
3811 tracepoint(librbd
, clone3_exit
, r
);
3815 extern "C" int rbd_remove(rados_ioctx_t p
, const char *name
)
3817 librados::IoCtx io_ctx
;
3818 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3819 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3820 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
3821 librbd::NoOpProgressContext prog_ctx
;
3822 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, prog_ctx
);
3823 tracepoint(librbd
, remove_exit
, r
);
3827 extern "C" int rbd_remove_with_progress(rados_ioctx_t p
, const char *name
,
3828 librbd_progress_fn_t cb
, void *cbdata
)
3830 librados::IoCtx io_ctx
;
3831 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3832 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3833 tracepoint(librbd
, remove_enter
, io_ctx
.get_pool_name().c_str(), io_ctx
.get_id(), name
);
3834 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
3835 int r
= librbd::api::Image
<>::remove(io_ctx
, name
, prog_ctx
);
3836 tracepoint(librbd
, remove_exit
, r
);
3840 extern "C" int rbd_trash_move(rados_ioctx_t p
, const char *name
,
3842 librados::IoCtx io_ctx
;
3843 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3844 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3845 tracepoint(librbd
, trash_move_enter
, io_ctx
.get_pool_name().c_str(),
3846 io_ctx
.get_id(), name
);
3847 int r
= librbd::api::Trash
<>::move(io_ctx
, RBD_TRASH_IMAGE_SOURCE_USER
, name
,
3849 tracepoint(librbd
, trash_move_exit
, r
);
3853 extern "C" int rbd_trash_get(rados_ioctx_t io
, const char *id
,
3854 rbd_trash_image_info_t
*info
) {
3855 librados::IoCtx io_ctx
;
3856 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3858 librbd::trash_image_info_t cpp_info
;
3859 int r
= librbd::api::Trash
<>::get(io_ctx
, id
, &cpp_info
);
3864 trash_image_info_cpp_to_c(cpp_info
, info
);
3868 extern "C" void rbd_trash_get_cleanup(rbd_trash_image_info_t
*info
) {
3873 extern "C" int rbd_trash_list(rados_ioctx_t p
, rbd_trash_image_info_t
*entries
,
3874 size_t *num_entries
) {
3875 librados::IoCtx io_ctx
;
3876 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3877 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3878 tracepoint(librbd
, trash_list_enter
,
3879 io_ctx
.get_pool_name().c_str(), io_ctx
.get_id());
3880 // FIPS zeroization audit 20191117: this memset is not security related.
3881 memset(entries
, 0, sizeof(*entries
) * *num_entries
);
3883 vector
<librbd::trash_image_info_t
> cpp_entries
;
3884 int r
= librbd::api::Trash
<>::list(io_ctx
, cpp_entries
, true);
3886 tracepoint(librbd
, trash_list_exit
, r
, *num_entries
);
3890 if (*num_entries
< cpp_entries
.size()) {
3891 *num_entries
= cpp_entries
.size();
3892 tracepoint(librbd
, trash_list_exit
, -ERANGE
, *num_entries
);
3897 for (const auto &entry
: cpp_entries
) {
3898 trash_image_info_cpp_to_c(entry
, &entries
[i
++]);
3900 *num_entries
= cpp_entries
.size();
3902 return *num_entries
;
3905 extern "C" void rbd_trash_list_cleanup(rbd_trash_image_info_t
*entries
,
3906 size_t num_entries
) {
3907 for (size_t i
=0; i
< num_entries
; i
++) {
3908 rbd_trash_get_cleanup(&entries
[i
]);
3912 extern "C" int rbd_trash_purge(rados_ioctx_t io
, time_t expire_ts
,
3914 librados::IoCtx io_ctx
;
3915 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3916 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3917 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
3918 io_ctx
.get_id(), expire_ts
, threshold
);
3919 librbd::NoOpProgressContext nop_pctx
;
3920 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, nop_pctx
);
3921 tracepoint(librbd
, trash_purge_exit
, r
);
3925 extern "C" int rbd_trash_purge_with_progress(rados_ioctx_t io
, time_t expire_ts
,
3926 float threshold
, librbd_progress_fn_t cb
, void* cbdata
) {
3927 librados::IoCtx io_ctx
;
3928 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3929 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3930 tracepoint(librbd
, trash_purge_enter
, io_ctx
.get_pool_name().c_str(),
3931 io_ctx
.get_id(), expire_ts
, threshold
);
3932 librbd::CProgressContext
pctx(cb
, cbdata
);
3933 int r
= librbd::api::Trash
<>::purge(io_ctx
, expire_ts
, threshold
, pctx
);
3934 tracepoint(librbd
, trash_purge_exit
, r
);
3938 extern "C" int rbd_trash_remove(rados_ioctx_t p
, const char *image_id
,
3940 librados::IoCtx io_ctx
;
3941 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3942 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3943 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
3944 io_ctx
.get_id(), image_id
, force
);
3945 librbd::NoOpProgressContext prog_ctx
;
3946 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, prog_ctx
);
3947 tracepoint(librbd
, trash_remove_exit
, r
);
3951 extern "C" int rbd_trash_remove_with_progress(rados_ioctx_t p
,
3952 const char *image_id
,
3954 librbd_progress_fn_t cb
,
3956 librados::IoCtx io_ctx
;
3957 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3958 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3959 tracepoint(librbd
, trash_remove_enter
, io_ctx
.get_pool_name().c_str(),
3960 io_ctx
.get_id(), image_id
, force
);
3961 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
3962 int r
= librbd::api::Trash
<>::remove(io_ctx
, image_id
, force
, prog_ctx
);
3963 tracepoint(librbd
, trash_remove_exit
, r
);
3967 extern "C" int rbd_trash_restore(rados_ioctx_t p
, const char *id
,
3969 librados::IoCtx io_ctx
;
3970 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
3971 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
3972 tracepoint(librbd
, trash_undelete_enter
, io_ctx
.get_pool_name().c_str(),
3973 io_ctx
.get_id(), id
, name
);
3974 int r
= librbd::api::Trash
<>::restore(
3975 io_ctx
, librbd::api::Trash
<>::RESTORE_SOURCE_WHITELIST
, id
, name
);
3976 tracepoint(librbd
, trash_undelete_exit
, r
);
3980 extern "C" int rbd_namespace_create(rados_ioctx_t io
,
3981 const char *namespace_name
) {
3982 librados::IoCtx io_ctx
;
3983 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3985 return librbd::api::Namespace
<>::create(io_ctx
, namespace_name
);
3988 extern "C" int rbd_namespace_remove(rados_ioctx_t io
,
3989 const char *namespace_name
) {
3990 librados::IoCtx io_ctx
;
3991 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
3993 return librbd::api::Namespace
<>::remove(io_ctx
, namespace_name
);
3996 extern "C" int rbd_namespace_list(rados_ioctx_t io
, char *names
, size_t *size
) {
3997 librados::IoCtx io_ctx
;
3998 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4000 if (names
== nullptr || size
== nullptr) {
4004 std::vector
<std::string
> cpp_names
;
4005 int r
= librbd::api::Namespace
<>::list(io_ctx
, &cpp_names
);
4010 size_t expected_size
= 0;
4011 for (size_t i
= 0; i
< cpp_names
.size(); i
++) {
4012 expected_size
+= cpp_names
[i
].size() + 1;
4014 if (*size
< expected_size
) {
4015 *size
= expected_size
;
4019 *size
= expected_size
;
4020 for (int i
= 0; i
< (int)cpp_names
.size(); i
++) {
4021 const char* name
= cpp_names
[i
].c_str();
4022 strcpy(names
, name
);
4023 names
+= strlen(names
) + 1;
4026 return (int)expected_size
;
4029 extern "C" int rbd_namespace_exists(rados_ioctx_t io
,
4030 const char *namespace_name
,
4032 librados::IoCtx io_ctx
;
4033 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4035 return librbd::api::Namespace
<>::exists(io_ctx
, namespace_name
, exists
);
4038 extern "C" int rbd_pool_init(rados_ioctx_t io
, bool force
) {
4039 librados::IoCtx io_ctx
;
4040 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4042 return librbd::api::Pool
<>::init(io_ctx
, force
);
4045 extern "C" void rbd_pool_stats_create(rbd_pool_stats_t
*stats
) {
4046 *stats
= reinterpret_cast<rbd_pool_stats_t
>(
4047 new librbd::api::Pool
<>::StatOptions
{});
4050 extern "C" void rbd_pool_stats_destroy(rbd_pool_stats_t stats
) {
4051 auto pool_stat_options
=
4052 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(stats
);
4053 delete pool_stat_options
;
4056 extern "C" int rbd_pool_stats_option_add_uint64(rbd_pool_stats_t stats
,
4058 uint64_t* stat_val
) {
4059 auto pool_stat_options
=
4060 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(stats
);
4061 return librbd::api::Pool
<>::add_stat_option(
4062 pool_stat_options
, static_cast<rbd_pool_stat_option_t
>(stat_option
),
4066 extern "C" int rbd_pool_stats_get(
4067 rados_ioctx_t io
, rbd_pool_stats_t pool_stats
) {
4068 librados::IoCtx io_ctx
;
4069 librados::IoCtx::from_rados_ioctx_t(io
, io_ctx
);
4071 auto pool_stat_options
=
4072 reinterpret_cast<librbd::api::Pool
<>::StatOptions
*>(pool_stats
);
4073 return librbd::api::Pool
<>::get_stats(io_ctx
, pool_stat_options
);
4076 extern "C" int rbd_copy(rbd_image_t image
, rados_ioctx_t dest_p
,
4077 const char *destname
)
4079 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4080 librados::IoCtx dest_io_ctx
;
4081 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4082 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
);
4083 librbd::ImageOptions opts
;
4084 librbd::NoOpProgressContext prog_ctx
;
4085 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
4086 tracepoint(librbd
, copy_exit
, r
);
4090 extern "C" int rbd_copy2(rbd_image_t srcp
, rbd_image_t destp
)
4092 librbd::ImageCtx
*src
= (librbd::ImageCtx
*)srcp
;
4093 librbd::ImageCtx
*dest
= (librbd::ImageCtx
*)destp
;
4094 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
);
4095 librbd::NoOpProgressContext prog_ctx
;
4096 int r
= librbd::copy(src
, dest
, prog_ctx
, 0);
4097 tracepoint(librbd
, copy2_exit
, r
);
4101 extern "C" int rbd_copy3(rbd_image_t image
, rados_ioctx_t dest_p
,
4102 const char *destname
, rbd_image_options_t c_opts
)
4104 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4105 librados::IoCtx dest_io_ctx
;
4106 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4107 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
);
4108 librbd::ImageOptions
c_opts_(c_opts
);
4109 librbd::NoOpProgressContext prog_ctx
;
4110 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, c_opts_
, prog_ctx
, 0);
4111 tracepoint(librbd
, copy3_exit
, r
);
4115 extern "C" int rbd_copy4(rbd_image_t image
, rados_ioctx_t dest_p
,
4116 const char *destname
, rbd_image_options_t c_opts
, size_t sparse_size
)
4118 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4119 librados::IoCtx dest_io_ctx
;
4120 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4121 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
);
4122 librbd::ImageOptions
c_opts_(c_opts
);
4123 librbd::NoOpProgressContext prog_ctx
;
4124 int r
= librbd::copy(ictx
, dest_io_ctx
, destname
, c_opts_
, prog_ctx
, sparse_size
);
4125 tracepoint(librbd
, copy4_exit
, r
);
4129 extern "C" int rbd_copy_with_progress(rbd_image_t image
, rados_ioctx_t dest_p
,
4130 const char *destname
,
4131 librbd_progress_fn_t fn
, void *data
)
4133 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4134 librados::IoCtx dest_io_ctx
;
4135 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4136 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
);
4137 librbd::ImageOptions opts
;
4138 librbd::CProgressContext
prog_ctx(fn
, data
);
4139 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, opts
, prog_ctx
, 0);
4140 tracepoint(librbd
, copy_exit
, ret
);
4144 extern "C" int rbd_copy_with_progress2(rbd_image_t srcp
, rbd_image_t destp
,
4145 librbd_progress_fn_t fn
, void *data
)
4147 librbd::ImageCtx
*src
= (librbd::ImageCtx
*)srcp
;
4148 librbd::ImageCtx
*dest
= (librbd::ImageCtx
*)destp
;
4149 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
);
4150 librbd::CProgressContext
prog_ctx(fn
, data
);
4151 int ret
= librbd::copy(src
, dest
, prog_ctx
, 0);
4152 tracepoint(librbd
, copy2_exit
, ret
);
4156 extern "C" int rbd_copy_with_progress3(rbd_image_t image
, rados_ioctx_t dest_p
,
4157 const char *destname
,
4158 rbd_image_options_t dest_opts
,
4159 librbd_progress_fn_t fn
, void *data
)
4161 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4162 librados::IoCtx dest_io_ctx
;
4163 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4164 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
);
4165 librbd::ImageOptions
dest_opts_(dest_opts
);
4166 librbd::CProgressContext
prog_ctx(fn
, data
);
4167 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, dest_opts_
, prog_ctx
, 0);
4168 tracepoint(librbd
, copy3_exit
, ret
);
4172 extern "C" int rbd_copy_with_progress4(rbd_image_t image
, rados_ioctx_t dest_p
,
4173 const char *destname
,
4174 rbd_image_options_t dest_opts
,
4175 librbd_progress_fn_t fn
, void *data
, size_t sparse_size
)
4177 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4178 librados::IoCtx dest_io_ctx
;
4179 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4180 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
);
4181 librbd::ImageOptions
dest_opts_(dest_opts
);
4182 librbd::CProgressContext
prog_ctx(fn
, data
);
4183 int ret
= librbd::copy(ictx
, dest_io_ctx
, destname
, dest_opts_
, prog_ctx
, sparse_size
);
4184 tracepoint(librbd
, copy4_exit
, ret
);
4188 extern "C" int rbd_deep_copy(rbd_image_t image
, rados_ioctx_t dest_p
,
4189 const char *destname
, rbd_image_options_t c_opts
)
4191 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4192 librados::IoCtx dest_io_ctx
;
4193 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4194 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
4195 ictx
->snap_name
.c_str(), ictx
->read_only
,
4196 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
4198 librbd::ImageOptions
opts(c_opts
);
4199 librbd::NoOpProgressContext prog_ctx
;
4200 int r
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
4202 tracepoint(librbd
, deep_copy_exit
, r
);
4206 extern "C" int rbd_deep_copy_with_progress(rbd_image_t image
,
4207 rados_ioctx_t dest_p
,
4208 const char *destname
,
4209 rbd_image_options_t dest_opts
,
4210 librbd_progress_fn_t fn
, void *data
)
4212 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4213 librados::IoCtx dest_io_ctx
;
4214 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4215 tracepoint(librbd
, deep_copy_enter
, ictx
, ictx
->name
.c_str(),
4216 ictx
->snap_name
.c_str(), ictx
->read_only
,
4217 dest_io_ctx
.get_pool_name().c_str(), dest_io_ctx
.get_id(),
4218 destname
, dest_opts
);
4219 librbd::ImageOptions
opts(dest_opts
);
4220 librbd::CProgressContext
prog_ctx(fn
, data
);
4221 int ret
= librbd::api::Image
<>::deep_copy(ictx
, dest_io_ctx
, destname
, opts
,
4223 tracepoint(librbd
, deep_copy_exit
, ret
);
4227 extern "C" int rbd_flatten(rbd_image_t image
)
4229 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4230 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4231 librbd::NoOpProgressContext prog_ctx
;
4232 int r
= ictx
->operations
->flatten(prog_ctx
);
4233 tracepoint(librbd
, flatten_exit
, r
);
4237 extern "C" int rbd_flatten_with_progress(rbd_image_t image
,
4238 librbd_progress_fn_t cb
, void *cbdata
)
4240 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4241 tracepoint(librbd
, flatten_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4242 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4243 int r
= ictx
->operations
->flatten(prog_ctx
);
4244 tracepoint(librbd
, flatten_exit
, r
);
4248 extern "C" int rbd_sparsify(rbd_image_t image
, size_t sparse_size
)
4250 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4251 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
4253 librbd::NoOpProgressContext prog_ctx
;
4254 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
4255 tracepoint(librbd
, sparsify_exit
, r
);
4259 extern "C" int rbd_sparsify_with_progress(rbd_image_t image
, size_t sparse_size
,
4260 librbd_progress_fn_t cb
, void *cbdata
)
4262 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4263 tracepoint(librbd
, sparsify_enter
, ictx
, ictx
->name
.c_str(), sparse_size
,
4265 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4266 int r
= ictx
->operations
->sparsify(sparse_size
, prog_ctx
);
4267 tracepoint(librbd
, sparsify_exit
, r
);
4271 extern "C" int rbd_rename(rados_ioctx_t src_p
, const char *srcname
,
4272 const char *destname
)
4274 librados::IoCtx src_io_ctx
;
4275 librados::IoCtx::from_rados_ioctx_t(src_p
, src_io_ctx
);
4276 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(src_io_ctx
));
4277 tracepoint(librbd
, rename_enter
, src_io_ctx
.get_pool_name().c_str(), src_io_ctx
.get_id(), srcname
, destname
);
4278 int r
= librbd::rename(src_io_ctx
, srcname
, destname
);
4279 tracepoint(librbd
, rename_exit
, r
);
4283 extern "C" int rbd_migration_prepare(rados_ioctx_t p
, const char *image_name
,
4284 rados_ioctx_t dest_p
,
4285 const char *dest_image_name
,
4286 rbd_image_options_t opts_
)
4288 librados::IoCtx io_ctx
;
4289 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4290 librados::IoCtx dest_io_ctx
;
4291 librados::IoCtx::from_rados_ioctx_t(dest_p
, dest_io_ctx
);
4292 tracepoint(librbd
, migration_prepare_enter
, io_ctx
.get_pool_name().c_str(),
4293 io_ctx
.get_id(), image_name
, dest_io_ctx
.get_pool_name().c_str(),
4294 dest_io_ctx
.get_id(), dest_image_name
, opts_
);
4295 librbd::ImageOptions
opts(opts_
);
4296 int r
= librbd::api::Migration
<>::prepare(io_ctx
, image_name
, dest_io_ctx
,
4297 dest_image_name
, opts
);
4298 tracepoint(librbd
, migration_prepare_exit
, r
);
4302 extern "C" int rbd_migration_execute(rados_ioctx_t p
, const char *image_name
)
4304 librados::IoCtx io_ctx
;
4305 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4306 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4307 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
4308 io_ctx
.get_id(), image_name
);
4309 librbd::NoOpProgressContext prog_ctx
;
4310 int r
= librbd::api::Migration
<>::execute(io_ctx
, image_name
, prog_ctx
);
4311 tracepoint(librbd
, migration_execute_exit
, r
);
4315 extern "C" int rbd_migration_execute_with_progress(rados_ioctx_t p
,
4317 librbd_progress_fn_t fn
,
4320 librados::IoCtx io_ctx
;
4321 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4322 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4323 tracepoint(librbd
, migration_execute_enter
, io_ctx
.get_pool_name().c_str(),
4324 io_ctx
.get_id(), name
);
4325 librbd::CProgressContext
prog_ctx(fn
, data
);
4326 int r
= librbd::api::Migration
<>::execute(io_ctx
, name
, prog_ctx
);
4327 tracepoint(librbd
, migration_execute_exit
, r
);
4331 extern "C" int rbd_migration_abort(rados_ioctx_t p
, const char *image_name
)
4333 librados::IoCtx io_ctx
;
4334 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4335 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4336 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
4337 io_ctx
.get_id(), image_name
);
4338 librbd::NoOpProgressContext prog_ctx
;
4339 int r
= librbd::api::Migration
<>::abort(io_ctx
, image_name
, prog_ctx
);
4340 tracepoint(librbd
, migration_abort_exit
, r
);
4344 extern "C" int rbd_migration_abort_with_progress(rados_ioctx_t p
,
4346 librbd_progress_fn_t fn
,
4349 librados::IoCtx io_ctx
;
4350 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4351 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4352 tracepoint(librbd
, migration_abort_enter
, io_ctx
.get_pool_name().c_str(),
4353 io_ctx
.get_id(), name
);
4354 librbd::CProgressContext
prog_ctx(fn
, data
);
4355 int r
= librbd::api::Migration
<>::abort(io_ctx
, name
, prog_ctx
);
4356 tracepoint(librbd
, migration_abort_exit
, r
);
4360 extern "C" int rbd_migration_commit(rados_ioctx_t p
, const char *image_name
)
4362 librados::IoCtx io_ctx
;
4363 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4364 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4365 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
4366 io_ctx
.get_id(), image_name
);
4367 librbd::NoOpProgressContext prog_ctx
;
4368 int r
= librbd::api::Migration
<>::commit(io_ctx
, image_name
, prog_ctx
);
4369 tracepoint(librbd
, migration_commit_exit
, r
);
4373 extern "C" int rbd_migration_commit_with_progress(rados_ioctx_t p
,
4375 librbd_progress_fn_t fn
,
4378 librados::IoCtx io_ctx
;
4379 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4380 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4381 tracepoint(librbd
, migration_commit_enter
, io_ctx
.get_pool_name().c_str(),
4382 io_ctx
.get_id(), name
);
4383 librbd::CProgressContext
prog_ctx(fn
, data
);
4384 int r
= librbd::api::Migration
<>::commit(io_ctx
, name
, prog_ctx
);
4385 tracepoint(librbd
, migration_commit_exit
, r
);
4389 extern "C" int rbd_migration_status(rados_ioctx_t p
, const char *image_name
,
4390 rbd_image_migration_status_t
*status
,
4393 librados::IoCtx io_ctx
;
4394 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4395 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4396 tracepoint(librbd
, migration_status_enter
, io_ctx
.get_pool_name().c_str(),
4397 io_ctx
.get_id(), image_name
);
4399 if (status_size
!= sizeof(rbd_image_migration_status_t
)) {
4400 tracepoint(librbd
, migration_status_exit
, -ERANGE
);
4404 librbd::image_migration_status_t cpp_status
;
4405 int r
= librbd::api::Migration
<>::status(io_ctx
, image_name
, &cpp_status
);
4407 status
->source_pool_id
= cpp_status
.source_pool_id
;
4408 status
->source_pool_namespace
=
4409 strdup(cpp_status
.source_pool_namespace
.c_str());
4410 status
->source_image_name
= strdup(cpp_status
.source_image_name
.c_str());
4411 status
->source_image_id
= strdup(cpp_status
.source_image_id
.c_str());
4412 status
->dest_pool_id
= cpp_status
.dest_pool_id
;
4413 status
->dest_pool_namespace
=
4414 strdup(cpp_status
.dest_pool_namespace
.c_str());
4415 status
->dest_image_name
= strdup(cpp_status
.dest_image_name
.c_str());
4416 status
->dest_image_id
= strdup(cpp_status
.dest_image_id
.c_str());
4417 status
->state
= cpp_status
.state
;
4418 status
->state_description
= strdup(cpp_status
.state_description
.c_str());
4421 tracepoint(librbd
, migration_status_exit
, r
);
4425 extern "C" void rbd_migration_status_cleanup(rbd_image_migration_status_t
*s
)
4427 free(s
->source_pool_namespace
);
4428 free(s
->source_image_name
);
4429 free(s
->source_image_id
);
4430 free(s
->dest_pool_namespace
);
4431 free(s
->dest_image_name
);
4432 free(s
->dest_image_id
);
4433 free(s
->state_description
);
4436 extern "C" int rbd_pool_metadata_get(rados_ioctx_t p
, const char *key
,
4437 char *value
, size_t *vallen
)
4439 librados::IoCtx io_ctx
;
4440 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4442 int r
= librbd::api::PoolMetadata
<>::get(io_ctx
, key
, &val_s
);
4443 if (*vallen
< val_s
.size() + 1) {
4445 *vallen
= val_s
.size() + 1;
4447 strncpy(value
, val_s
.c_str(), val_s
.size() + 1);
4453 extern "C" int rbd_pool_metadata_set(rados_ioctx_t p
, const char *key
,
4456 librados::IoCtx io_ctx
;
4457 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4458 int r
= librbd::api::PoolMetadata
<>::set(io_ctx
, key
, value
);
4462 extern "C" int rbd_pool_metadata_remove(rados_ioctx_t p
, const char *key
)
4464 librados::IoCtx io_ctx
;
4465 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4466 int r
= librbd::api::PoolMetadata
<>::remove(io_ctx
, key
);
4470 extern "C" int rbd_pool_metadata_list(rados_ioctx_t p
, const char *start
,
4471 uint64_t max
, char *key
, size_t *key_len
,
4472 char *value
, size_t *val_len
)
4474 librados::IoCtx io_ctx
;
4475 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4476 map
<string
, bufferlist
> pairs
;
4477 int r
= librbd::api::PoolMetadata
<>::list(io_ctx
, start
, max
, &pairs
);
4481 size_t key_total_len
= 0, val_total_len
= 0;
4482 for (auto &it
: pairs
) {
4483 key_total_len
+= it
.first
.size() + 1;
4484 val_total_len
+= it
.second
.length() + 1;
4486 if (*key_len
< key_total_len
|| *val_len
< val_total_len
) {
4487 *key_len
= key_total_len
;
4488 *val_len
= val_total_len
;
4491 *key_len
= key_total_len
;
4492 *val_len
= val_total_len
;
4494 char *key_p
= key
, *value_p
= value
;
4495 for (auto &it
: pairs
) {
4496 strncpy(key_p
, it
.first
.c_str(), it
.first
.size() + 1);
4497 key_p
+= it
.first
.size() + 1;
4498 strncpy(value_p
, it
.second
.c_str(), it
.second
.length());
4499 value_p
+= it
.second
.length();
4506 extern "C" int rbd_config_pool_list(rados_ioctx_t p
,
4507 rbd_config_option_t
*options
,
4509 librados::IoCtx io_ctx
;
4510 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4512 std::vector
<librbd::config_option_t
> option_vector
;
4513 int r
= librbd::api::Config
<>::list(io_ctx
, &option_vector
);
4518 if (*max_options
< static_cast<int>(option_vector
.size())) {
4519 *max_options
= static_cast<int>(option_vector
.size());
4523 for (int i
= 0; i
< static_cast<int>(option_vector
.size()); ++i
) {
4524 config_option_cpp_to_c(option_vector
[i
], &options
[i
]);
4526 *max_options
= static_cast<int>(option_vector
.size());
4530 extern "C" void rbd_config_pool_list_cleanup(rbd_config_option_t
*options
,
4532 for (int i
= 0; i
< max_options
; ++i
) {
4533 config_option_cleanup(options
[i
]);
4537 extern "C" int rbd_open(rados_ioctx_t p
, const char *name
, rbd_image_t
*image
,
4538 const char *snap_name
)
4540 librados::IoCtx io_ctx
;
4541 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4542 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4543 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4545 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4547 int r
= ictx
->state
->open(0);
4549 *image
= (rbd_image_t
)ictx
;
4551 tracepoint(librbd
, open_image_exit
, r
);
4555 extern "C" int rbd_open_by_id(rados_ioctx_t p
, const char *id
,
4556 rbd_image_t
*image
, const char *snap_name
)
4558 librados::IoCtx io_ctx
;
4559 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4560 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4561 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4563 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(),
4564 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4566 int r
= ictx
->state
->open(0);
4568 *image
= (rbd_image_t
)ictx
;
4570 tracepoint(librbd
, open_image_exit
, r
);
4574 extern "C" int rbd_aio_open(rados_ioctx_t p
, const char *name
,
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(name
, "", 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(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
4585 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4587 tracepoint(librbd
, aio_open_image_exit
, 0);
4591 extern "C" int rbd_aio_open_by_id(rados_ioctx_t p
, const char *id
,
4592 rbd_image_t
*image
, const char *snap_name
,
4595 librados::IoCtx io_ctx
;
4596 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4597 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4598 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4600 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4601 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(),
4602 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
,
4604 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4606 tracepoint(librbd
, aio_open_image_exit
, 0);
4610 extern "C" int rbd_open_read_only(rados_ioctx_t p
, const char *name
,
4611 rbd_image_t
*image
, const char *snap_name
)
4613 librados::IoCtx io_ctx
;
4614 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4615 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4616 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4618 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4620 int r
= ictx
->state
->open(0);
4622 *image
= (rbd_image_t
)ictx
;
4624 tracepoint(librbd
, open_image_exit
, r
);
4628 extern "C" int rbd_open_by_id_read_only(rados_ioctx_t p
, const char *id
,
4629 rbd_image_t
*image
, const char *snap_name
)
4631 librados::IoCtx io_ctx
;
4632 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4633 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4634 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4636 tracepoint(librbd
, open_image_enter
, ictx
, ictx
->name
.c_str(),
4637 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4639 int r
= ictx
->state
->open(0);
4641 *image
= (rbd_image_t
)ictx
;
4643 tracepoint(librbd
, open_image_exit
, r
);
4647 extern "C" int rbd_aio_open_read_only(rados_ioctx_t p
, const char *name
,
4648 rbd_image_t
*image
, const char *snap_name
,
4651 librados::IoCtx io_ctx
;
4652 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4653 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4654 librbd::ImageCtx
*ictx
= new librbd::ImageCtx(name
, "", snap_name
, io_ctx
,
4656 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4657 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
);
4658 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4660 tracepoint(librbd
, aio_open_image_exit
, 0);
4664 extern "C" int rbd_aio_open_by_id_read_only(rados_ioctx_t p
, const char *id
,
4666 const char *snap_name
,
4669 librados::IoCtx io_ctx
;
4670 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
4671 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
4672 librbd::ImageCtx
*ictx
= new librbd::ImageCtx("", id
, snap_name
, io_ctx
,
4674 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4675 tracepoint(librbd
, aio_open_image_enter
, ictx
, ictx
->name
.c_str(),
4676 ictx
->id
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
4677 ictx
->state
->open(0, new C_OpenComplete(ictx
, get_aio_completion(comp
),
4679 tracepoint(librbd
, aio_open_image_exit
, 0);
4683 extern "C" int rbd_features_to_string(uint64_t features
, char *str_features
, size_t *size
)
4685 std::stringstream err
;
4686 std::string get_str_features
= librbd::rbd_features_to_string(features
, &err
);
4687 if (!err
.str().empty()) {
4690 uint64_t expected_size
= get_str_features
.size();
4691 if (*size
<= expected_size
) {
4692 *size
= expected_size
+ 1;
4695 strncpy(str_features
, get_str_features
.c_str(), expected_size
);
4696 str_features
[expected_size
] = '\0';
4697 *size
= expected_size
+ 1;
4701 extern "C" int rbd_features_from_string(const char *str_features
, uint64_t *features
)
4703 std::stringstream err
;
4704 *features
= librbd::rbd_features_from_string(str_features
, &err
);
4705 if (!err
.str().empty()) {
4712 extern "C" int rbd_close(rbd_image_t image
)
4714 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4715 tracepoint(librbd
, close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str());
4717 int r
= ictx
->state
->close();
4719 tracepoint(librbd
, close_image_exit
, r
);
4723 extern "C" int rbd_aio_close(rbd_image_t image
, rbd_completion_t c
)
4725 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4726 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
4727 tracepoint(librbd
, aio_close_image_enter
, ictx
, ictx
->name
.c_str(), ictx
->id
.c_str(), comp
->pc
);
4728 ictx
->state
->close(new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_CLOSE
,
4729 get_aio_completion(comp
)));
4730 tracepoint(librbd
, aio_close_image_exit
, 0);
4734 extern "C" int rbd_resize(rbd_image_t image
, uint64_t size
)
4736 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4737 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4738 librbd::NoOpProgressContext prog_ctx
;
4739 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
4740 tracepoint(librbd
, resize_exit
, r
);
4744 extern "C" int rbd_resize2(rbd_image_t image
, uint64_t size
, bool allow_shrink
,
4745 librbd_progress_fn_t cb
, void *cbdata
)
4747 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4748 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4749 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4750 int r
= ictx
->operations
->resize(size
, allow_shrink
, prog_ctx
);
4751 tracepoint(librbd
, resize_exit
, r
);
4755 extern "C" int rbd_resize_with_progress(rbd_image_t image
, uint64_t size
,
4756 librbd_progress_fn_t cb
, void *cbdata
)
4758 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4759 tracepoint(librbd
, resize_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, size
);
4760 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
4761 int r
= ictx
->operations
->resize(size
, true, prog_ctx
);
4762 tracepoint(librbd
, resize_exit
, r
);
4766 extern "C" int rbd_stat(rbd_image_t image
, rbd_image_info_t
*info
,
4769 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4770 tracepoint(librbd
, stat_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4771 int r
= librbd::info(ictx
, *info
, infosize
);
4772 tracepoint(librbd
, stat_exit
, r
, info
);
4776 extern "C" int rbd_get_old_format(rbd_image_t image
, uint8_t *old
)
4778 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4779 tracepoint(librbd
, get_old_format_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4780 int r
= librbd::get_old_format(ictx
, old
);
4781 tracepoint(librbd
, get_old_format_exit
, r
, *old
);
4785 extern "C" int rbd_get_size(rbd_image_t image
, uint64_t *size
)
4787 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4788 tracepoint(librbd
, get_size_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4789 int r
= librbd::get_size(ictx
, size
);
4790 tracepoint(librbd
, get_size_exit
, r
, *size
);
4794 extern "C" int rbd_get_features(rbd_image_t image
, uint64_t *features
)
4796 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4797 tracepoint(librbd
, get_features_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4798 int r
= librbd::get_features(ictx
, features
);
4799 tracepoint(librbd
, get_features_exit
, r
, *features
);
4803 extern "C" int rbd_update_features(rbd_image_t image
, uint64_t features
,
4806 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4807 bool features_enabled
= enabled
!= 0;
4808 tracepoint(librbd
, update_features_enter
, ictx
, features
, features_enabled
);
4809 int r
= ictx
->operations
->update_features(features
, features_enabled
);
4810 tracepoint(librbd
, update_features_exit
, r
);
4814 extern "C" int rbd_get_op_features(rbd_image_t image
, uint64_t *op_features
)
4816 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4817 return librbd::api::Image
<>::get_op_features(ictx
, op_features
);
4820 extern "C" int rbd_get_stripe_unit(rbd_image_t image
, uint64_t *stripe_unit
)
4822 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4823 tracepoint(librbd
, get_stripe_unit_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4824 *stripe_unit
= ictx
->get_stripe_unit();
4825 tracepoint(librbd
, get_stripe_unit_exit
, 0, *stripe_unit
);
4829 extern "C" int rbd_get_stripe_count(rbd_image_t image
, uint64_t *stripe_count
)
4831 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4832 tracepoint(librbd
, get_stripe_count_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4833 *stripe_count
= ictx
->get_stripe_count();
4834 tracepoint(librbd
, get_stripe_count_exit
, 0, *stripe_count
);
4838 extern "C" int rbd_get_create_timestamp(rbd_image_t image
,
4839 struct timespec
*timestamp
)
4841 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4842 tracepoint(librbd
, get_create_timestamp_enter
, ictx
, ictx
->name
.c_str(),
4844 utime_t time
= ictx
->get_create_timestamp();
4845 time
.to_timespec(timestamp
);
4846 tracepoint(librbd
, get_create_timestamp_exit
, 0, timestamp
);
4850 extern "C" int rbd_get_access_timestamp(rbd_image_t image
,
4851 struct timespec
*timestamp
)
4853 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4854 tracepoint(librbd
, get_access_timestamp_enter
, ictx
, ictx
->name
.c_str(),
4856 utime_t time
= ictx
->get_access_timestamp();
4857 time
.to_timespec(timestamp
);
4858 tracepoint(librbd
, get_access_timestamp_exit
, 0, timestamp
);
4862 extern "C" int rbd_get_modify_timestamp(rbd_image_t image
,
4863 struct timespec
*timestamp
)
4865 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4866 tracepoint(librbd
, get_modify_timestamp_enter
, ictx
, ictx
->name
.c_str(),
4868 utime_t time
= ictx
->get_modify_timestamp();
4869 time
.to_timespec(timestamp
);
4870 tracepoint(librbd
, get_modify_timestamp_exit
, 0, timestamp
);
4875 extern "C" int rbd_get_overlap(rbd_image_t image
, uint64_t *overlap
)
4877 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
4878 tracepoint(librbd
, get_overlap_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
4879 int r
= librbd::get_overlap(ictx
, overlap
);
4880 tracepoint(librbd
, get_overlap_exit
, r
, *overlap
);
4884 extern "C" int rbd_get_name(rbd_image_t image
, char *name
, size_t *name_len
)
4886 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4887 if (*name_len
<= ictx
->name
.size()) {
4888 *name_len
= ictx
->name
.size() + 1;
4892 strncpy(name
, ictx
->name
.c_str(), ictx
->name
.size());
4893 name
[ictx
->name
.size()] = '\0';
4894 *name_len
= ictx
->name
.size() + 1;
4898 extern "C" int rbd_get_id(rbd_image_t image
, char *id
, size_t id_len
)
4900 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4901 if (ictx
->old_format
) {
4904 if (ictx
->id
.size() >= id_len
) {
4908 strncpy(id
, ictx
->id
.c_str(), id_len
- 1);
4909 id
[id_len
- 1] = '\0';
4913 extern "C" int rbd_get_block_name_prefix(rbd_image_t image
, char *prefix
,
4916 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4917 if (ictx
->object_prefix
.size() >= prefix_len
) {
4921 strncpy(prefix
, ictx
->object_prefix
.c_str(), prefix_len
- 1);
4922 prefix
[prefix_len
- 1] = '\0';
4926 extern "C" int64_t rbd_get_data_pool_id(rbd_image_t image
)
4928 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4929 return librbd::api::Image
<>::get_data_pool_id(ictx
);
4932 extern "C" int rbd_get_parent_info(rbd_image_t image
,
4933 char *parent_pool_name
, size_t ppool_namelen
,
4934 char *parent_name
, size_t pnamelen
,
4935 char *parent_snap_name
, size_t psnap_namelen
)
4937 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4938 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
4939 ictx
->snap_name
.c_str(), ictx
->read_only
);
4941 librbd::linked_image_spec_t parent_image
;
4942 librbd::snap_spec_t parent_snap
;
4943 int r
= librbd::api::Image
<>::get_parent(ictx
, &parent_image
, &parent_snap
);
4945 if (parent_pool_name
) {
4946 if (parent_image
.pool_name
.length() + 1 > ppool_namelen
) {
4949 strcpy(parent_pool_name
, parent_image
.pool_name
.c_str());
4953 if (parent_image
.image_name
.length() + 1 > pnamelen
) {
4956 strcpy(parent_name
, parent_image
.image_name
.c_str());
4959 if (parent_snap_name
) {
4960 if (parent_snap
.name
.length() + 1 > psnap_namelen
) {
4963 strcpy(parent_snap_name
, parent_snap
.name
.c_str());
4969 tracepoint(librbd
, get_parent_info_exit
, r
, NULL
, NULL
, NULL
, NULL
);
4973 tracepoint(librbd
, get_parent_info_exit
, r
,
4974 parent_image
.pool_name
.c_str(),
4975 parent_image
.image_name
.c_str(),
4976 parent_image
.image_id
.c_str(),
4977 parent_snap
.name
.c_str());
4981 extern "C" int rbd_get_parent_info2(rbd_image_t image
,
4982 char *parent_pool_name
,
4983 size_t ppool_namelen
,
4984 char *parent_name
, size_t pnamelen
,
4985 char *parent_id
, size_t pidlen
,
4986 char *parent_snap_name
,
4987 size_t psnap_namelen
)
4989 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
4990 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
4991 ictx
->snap_name
.c_str(), ictx
->read_only
);
4993 librbd::linked_image_spec_t parent_image
;
4994 librbd::snap_spec_t parent_snap
;
4995 int r
= librbd::api::Image
<>::get_parent(ictx
, &parent_image
, &parent_snap
);
4997 if (parent_pool_name
) {
4998 if (parent_image
.pool_name
.length() + 1 > ppool_namelen
) {
5001 strcpy(parent_pool_name
, parent_image
.pool_name
.c_str());
5005 if (parent_image
.image_name
.length() + 1 > pnamelen
) {
5008 strcpy(parent_name
, parent_image
.image_name
.c_str());
5012 if (parent_image
.image_id
.length() + 1 > pidlen
) {
5015 strcpy(parent_id
, parent_image
.image_id
.c_str());
5018 if (parent_snap_name
) {
5019 if (parent_snap
.name
.length() + 1 > psnap_namelen
) {
5022 strcpy(parent_snap_name
, parent_snap
.name
.c_str());
5028 tracepoint(librbd
, get_parent_info_exit
, r
, NULL
, NULL
, NULL
, NULL
);
5032 tracepoint(librbd
, get_parent_info_exit
, r
,
5033 parent_image
.pool_name
.c_str(),
5034 parent_image
.image_name
.c_str(),
5035 parent_image
.image_id
.c_str(),
5036 parent_snap
.name
.c_str());
5040 extern "C" int rbd_get_parent(rbd_image_t image
,
5041 rbd_linked_image_spec_t
*parent_image
,
5042 rbd_snap_spec_t
*parent_snap
)
5044 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5045 tracepoint(librbd
, get_parent_info_enter
, ictx
, ictx
->name
.c_str(),
5046 ictx
->snap_name
.c_str(), ictx
->read_only
);
5048 librbd::linked_image_spec_t cpp_parent_image
;
5049 librbd::snap_spec_t cpp_parent_snap
;
5050 int r
= librbd::api::Image
<>::get_parent(ictx
, &cpp_parent_image
,
5053 // FIPS zeroization audit 20191117: these memsets are not security related.
5054 memset(parent_image
, 0, sizeof(rbd_linked_image_spec_t
));
5055 memset(parent_snap
, 0, sizeof(rbd_snap_spec_t
));
5058 .pool_id
= cpp_parent_image
.pool_id
,
5059 .pool_name
= strdup(cpp_parent_image
.pool_name
.c_str()),
5060 .pool_namespace
= strdup(cpp_parent_image
.pool_namespace
.c_str()),
5061 .image_id
= strdup(cpp_parent_image
.image_id
.c_str()),
5062 .image_name
= strdup(cpp_parent_image
.image_name
.c_str()),
5063 .trash
= cpp_parent_image
.trash
};
5065 .id
= cpp_parent_snap
.id
,
5066 .namespace_type
= cpp_parent_snap
.namespace_type
,
5067 .name
= strdup(cpp_parent_snap
.name
.c_str())};
5070 tracepoint(librbd
, get_parent_info_exit
, r
,
5071 parent_image
->pool_name
,
5072 parent_image
->image_name
,
5073 parent_image
->image_id
,
5078 extern "C" int rbd_get_flags(rbd_image_t image
, uint64_t *flags
)
5080 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5081 tracepoint(librbd
, get_flags_enter
, ictx
);
5082 int r
= librbd::get_flags(ictx
, flags
);
5083 tracepoint(librbd
, get_flags_exit
, ictx
, r
, *flags
);
5087 extern "C" int rbd_get_group(rbd_image_t image
, rbd_group_info_t
*group_info
,
5088 size_t group_info_size
)
5090 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5091 tracepoint(librbd
, image_get_group_enter
, ictx
->name
.c_str());
5093 if (group_info_size
!= sizeof(rbd_group_info_t
)) {
5094 tracepoint(librbd
, image_get_group_exit
, -ERANGE
);
5098 librbd::group_info_t cpp_group_info
;
5099 int r
= librbd::api::Group
<>::image_get_group(ictx
, &cpp_group_info
);
5101 group_info_cpp_to_c(cpp_group_info
, group_info
);
5103 group_info
->name
= NULL
;
5106 tracepoint(librbd
, image_get_group_exit
, r
);
5110 extern "C" int rbd_set_image_notification(rbd_image_t image
, int fd
, int type
)
5112 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5113 tracepoint(librbd
, set_image_notification_enter
, ictx
, fd
, type
);
5114 int r
= librbd::set_image_notification(ictx
, fd
, type
);
5115 tracepoint(librbd
, set_image_notification_exit
, ictx
, r
);
5119 extern "C" int rbd_is_exclusive_lock_owner(rbd_image_t image
, int *is_owner
)
5121 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5122 tracepoint(librbd
, is_exclusive_lock_owner_enter
, ictx
);
5124 int r
= librbd::is_exclusive_lock_owner(ictx
, &owner
);
5125 *is_owner
= owner
? 1 : 0;
5126 tracepoint(librbd
, is_exclusive_lock_owner_exit
, ictx
, r
, *is_owner
);
5130 extern "C" int rbd_lock_acquire(rbd_image_t image
, rbd_lock_mode_t lock_mode
)
5132 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5133 tracepoint(librbd
, lock_acquire_enter
, ictx
, lock_mode
);
5134 int r
= librbd::lock_acquire(ictx
, lock_mode
);
5135 tracepoint(librbd
, lock_acquire_exit
, ictx
, r
);
5139 extern "C" int rbd_lock_release(rbd_image_t image
)
5141 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5142 tracepoint(librbd
, lock_release_enter
, ictx
);
5143 int r
= librbd::lock_release(ictx
);
5144 tracepoint(librbd
, lock_release_exit
, ictx
, r
);
5148 extern "C" int rbd_lock_get_owners(rbd_image_t image
,
5149 rbd_lock_mode_t
*lock_mode
,
5151 size_t *max_lock_owners
)
5153 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5154 tracepoint(librbd
, lock_get_owners_enter
, ictx
);
5155 // FIPS zeroization audit 20191117: this memset is not security related.
5156 memset(lock_owners
, 0, sizeof(*lock_owners
) * *max_lock_owners
);
5157 std::list
<std::string
> lock_owner_list
;
5158 int r
= librbd::lock_get_owners(ictx
, lock_mode
, &lock_owner_list
);
5160 if (*max_lock_owners
>= lock_owner_list
.size()) {
5161 *max_lock_owners
= 0;
5162 for (auto &lock_owner
: lock_owner_list
) {
5163 lock_owners
[(*max_lock_owners
)++] = strdup(lock_owner
.c_str());
5166 *max_lock_owners
= lock_owner_list
.size();
5170 tracepoint(librbd
, lock_get_owners_exit
, ictx
, r
);
5174 extern "C" void rbd_lock_get_owners_cleanup(char **lock_owners
,
5175 size_t lock_owner_count
)
5177 for (size_t i
= 0; i
< lock_owner_count
; ++i
) {
5178 free(lock_owners
[i
]);
5182 extern "C" int rbd_lock_break(rbd_image_t image
, rbd_lock_mode_t lock_mode
,
5183 const char *lock_owner
)
5185 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5186 tracepoint(librbd
, lock_break_enter
, ictx
, lock_mode
, lock_owner
);
5187 int r
= librbd::lock_break(ictx
, lock_mode
, lock_owner
);
5188 tracepoint(librbd
, lock_break_exit
, ictx
, r
);
5192 extern "C" int rbd_rebuild_object_map(rbd_image_t image
,
5193 librbd_progress_fn_t cb
, void *cbdata
)
5195 librbd::ImageCtx
*ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5196 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5197 return ictx
->operations
->rebuild_object_map(prog_ctx
);
5201 extern "C" int rbd_snap_create(rbd_image_t image
, const char *snap_name
)
5203 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5204 tracepoint(librbd
, snap_create_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5205 int r
= ictx
->operations
->snap_create(cls::rbd::UserSnapshotNamespace(),
5207 tracepoint(librbd
, snap_create_exit
, r
);
5211 extern "C" int rbd_snap_rename(rbd_image_t image
, const char *srcname
, const char *dstname
)
5213 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5214 tracepoint(librbd
, snap_rename_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, srcname
, dstname
);
5215 int r
= ictx
->operations
->snap_rename(srcname
, dstname
);
5216 tracepoint(librbd
, snap_rename_exit
, r
);
5220 extern "C" int rbd_snap_remove(rbd_image_t image
, const char *snap_name
)
5222 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5223 tracepoint(librbd
, snap_remove_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5224 librbd::NoOpProgressContext prog_ctx
;
5225 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, 0, prog_ctx
);
5226 tracepoint(librbd
, snap_remove_exit
, r
);
5230 extern "C" int rbd_snap_remove2(rbd_image_t image
, const char *snap_name
, uint32_t flags
,
5231 librbd_progress_fn_t cb
, void *cbdata
)
5233 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5234 tracepoint(librbd
, snap_remove2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
, flags
);
5235 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5236 int r
= librbd::api::Snapshot
<>::remove(ictx
, snap_name
, flags
, prog_ctx
);
5237 tracepoint(librbd
, snap_remove_exit
, r
);
5241 extern "C" int rbd_snap_remove_by_id(rbd_image_t image
, uint64_t snap_id
)
5243 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5244 return librbd::api::Snapshot
<>::remove(ictx
, snap_id
);
5247 extern "C" int rbd_snap_rollback(rbd_image_t image
, const char *snap_name
)
5249 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5250 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5251 librbd::NoOpProgressContext prog_ctx
;
5252 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
5253 tracepoint(librbd
, snap_rollback_exit
, r
);
5257 extern "C" int rbd_snap_rollback_with_progress(rbd_image_t image
,
5258 const char *snap_name
,
5259 librbd_progress_fn_t cb
,
5262 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5263 tracepoint(librbd
, snap_rollback_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5264 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
5265 int r
= ictx
->operations
->snap_rollback(cls::rbd::UserSnapshotNamespace(), snap_name
, prog_ctx
);
5266 tracepoint(librbd
, snap_rollback_exit
, r
);
5270 extern "C" int rbd_snap_list(rbd_image_t image
, rbd_snap_info_t
*snaps
,
5273 vector
<librbd::snap_info_t
> cpp_snaps
;
5274 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5275 tracepoint(librbd
, snap_list_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snaps
);
5278 tracepoint(librbd
, snap_list_exit
, -EINVAL
, 0);
5281 // FIPS zeroization audit 20191117: this memset is not security related.
5282 memset(snaps
, 0, sizeof(*snaps
) * *max_snaps
);
5284 int r
= librbd::api::Snapshot
<>::list(ictx
, cpp_snaps
);
5286 tracepoint(librbd
, snap_list_exit
, 0, *max_snaps
);
5290 tracepoint(librbd
, snap_list_exit
, r
, *max_snaps
);
5293 if (*max_snaps
< (int)cpp_snaps
.size() + 1) {
5294 *max_snaps
= (int)cpp_snaps
.size() + 1;
5295 tracepoint(librbd
, snap_list_exit
, -ERANGE
, *max_snaps
);
5301 for (i
= 0; i
< (int)cpp_snaps
.size(); i
++) {
5302 snaps
[i
].id
= cpp_snaps
[i
].id
;
5303 snaps
[i
].size
= cpp_snaps
[i
].size
;
5304 snaps
[i
].name
= strdup(cpp_snaps
[i
].name
.c_str());
5305 if (!snaps
[i
].name
) {
5306 for (int j
= 0; j
< i
; j
++)
5307 free((void *)snaps
[j
].name
);
5308 tracepoint(librbd
, snap_list_exit
, -ENOMEM
, *max_snaps
);
5311 tracepoint(librbd
, snap_list_entry
, snaps
[i
].id
, snaps
[i
].size
, snaps
[i
].name
);
5315 snaps
[i
].name
= NULL
;
5317 r
= (int)cpp_snaps
.size();
5318 tracepoint(librbd
, snap_list_exit
, r
, *max_snaps
);
5322 extern "C" void rbd_snap_list_end(rbd_snap_info_t
*snaps
)
5324 tracepoint(librbd
, snap_list_end_enter
, snaps
);
5325 while (snaps
->name
) {
5326 free((void *)snaps
->name
);
5329 tracepoint(librbd
, snap_list_end_exit
);
5332 extern "C" int rbd_snap_protect(rbd_image_t image
, const char *snap_name
)
5334 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5335 tracepoint(librbd
, snap_protect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5336 int r
= ictx
->operations
->snap_protect(cls::rbd::UserSnapshotNamespace(), snap_name
);
5337 tracepoint(librbd
, snap_protect_exit
, r
);
5341 extern "C" int rbd_snap_unprotect(rbd_image_t image
, const char *snap_name
)
5343 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5344 tracepoint(librbd
, snap_unprotect_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5345 int r
= ictx
->operations
->snap_unprotect(cls::rbd::UserSnapshotNamespace(), snap_name
);
5346 tracepoint(librbd
, snap_unprotect_exit
, r
);
5350 extern "C" int rbd_snap_is_protected(rbd_image_t image
, const char *snap_name
,
5353 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5354 tracepoint(librbd
, snap_is_protected_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5355 bool protected_snap
;
5356 int r
= librbd::api::Snapshot
<>::is_protected(ictx
, snap_name
, &protected_snap
);
5358 tracepoint(librbd
, snap_is_protected_exit
, r
, *is_protected
? 1 : 0);
5361 *is_protected
= protected_snap
? 1 : 0;
5362 tracepoint(librbd
, snap_is_protected_exit
, 0, *is_protected
? 1 : 0);
5366 extern "C" int rbd_snap_get_limit(rbd_image_t image
, uint64_t *limit
)
5368 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5369 tracepoint(librbd
, snap_get_limit_enter
, ictx
, ictx
->name
.c_str());
5370 int r
= librbd::api::Snapshot
<>::get_limit(ictx
, limit
);
5371 tracepoint(librbd
, snap_get_limit_exit
, r
, *limit
);
5375 extern "C" int rbd_snap_exists(rbd_image_t image
, const char *snapname
, bool *exists
)
5377 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5378 tracepoint(librbd
, snap_exists_enter
, ictx
, ictx
->name
.c_str(),
5379 ictx
->snap_name
.c_str(), ictx
->read_only
, snapname
);
5380 int r
= librbd::api::Snapshot
<>::exists(ictx
, cls::rbd::UserSnapshotNamespace(), snapname
, exists
);
5381 tracepoint(librbd
, snap_exists_exit
, r
, *exists
);
5385 extern "C" int rbd_snap_get_timestamp(rbd_image_t image
, uint64_t snap_id
, struct timespec
*timestamp
)
5387 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5388 tracepoint(librbd
, snap_get_timestamp_enter
, ictx
, ictx
->name
.c_str());
5389 int r
= librbd::api::Snapshot
<>::get_timestamp(ictx
, snap_id
, timestamp
);
5390 tracepoint(librbd
, snap_get_timestamp_exit
, r
);
5394 extern "C" int rbd_snap_set_limit(rbd_image_t image
, uint64_t limit
)
5396 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5397 tracepoint(librbd
, snap_set_limit_enter
, ictx
, ictx
->name
.c_str(), limit
);
5398 int r
= librbd::api::Snapshot
<>::set_limit(ictx
, limit
);
5399 tracepoint(librbd
, snap_set_limit_exit
, r
);
5403 extern "C" int rbd_snap_set(rbd_image_t image
, const char *snap_name
)
5405 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5406 tracepoint(librbd
, snap_set_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, snap_name
);
5407 int r
= librbd::api::Image
<>::snap_set(
5408 ictx
, cls::rbd::UserSnapshotNamespace(), snap_name
);
5409 tracepoint(librbd
, snap_set_exit
, r
);
5413 extern "C" int rbd_snap_set_by_id(rbd_image_t image
, uint64_t snap_id
)
5415 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5416 return librbd::api::Image
<>::snap_set(ictx
, snap_id
);
5419 extern "C" int rbd_snap_get_name(rbd_image_t image
, uint64_t snap_id
, char *snapname
, size_t *name_len
)
5421 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5422 std::string snap_name
;
5423 int r
= librbd::api::Snapshot
<>::get_name(ictx
, snap_id
, &snap_name
);
5424 size_t expected_size
= snap_name
.size();
5425 if (*name_len
<= expected_size
) {
5426 *name_len
= expected_size
+ 1;
5429 strncpy(snapname
, snap_name
.c_str(), expected_size
);
5430 snapname
[expected_size
] = '\0';
5431 *name_len
= expected_size
+ 1;
5435 extern "C" int rbd_snap_get_id(rbd_image_t image
, const char *snapname
, uint64_t *snap_id
)
5437 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5438 return librbd::api::Snapshot
<>::get_id(ictx
, snapname
, snap_id
);
5441 extern "C" ssize_t
rbd_list_children(rbd_image_t image
, char *pools
,
5442 size_t *pools_len
, char *images
,
5445 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5446 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5447 ictx
->snap_name
.c_str(), ictx
->read_only
);
5449 std::vector
<librbd::linked_image_spec_t
> cpp_images
;
5450 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_images
);
5452 tracepoint(librbd
, list_children_exit
, r
);
5456 std::set
<std::pair
<std::string
, std::string
>> image_set
;
5457 for (auto& image
: cpp_images
) {
5459 image_set
.insert({image
.pool_name
, image
.image_name
});
5463 size_t pools_total
= 0;
5464 size_t images_total
= 0;
5465 for (auto it
: image_set
) {
5466 pools_total
+= it
.first
.length() + 1;
5467 images_total
+= it
.second
.length() + 1;
5470 bool too_short
= false;
5471 if (pools_total
> *pools_len
)
5473 if (images_total
> *images_len
)
5475 *pools_len
= pools_total
;
5476 *images_len
= images_total
;
5478 tracepoint(librbd
, list_children_exit
, -ERANGE
);
5482 char *pools_p
= pools
;
5483 char *images_p
= images
;
5484 for (auto it
: image_set
) {
5485 const char* pool
= it
.first
.c_str();
5486 strcpy(pools_p
, pool
);
5487 pools_p
+= it
.first
.length() + 1;
5488 const char* image
= it
.second
.c_str();
5489 strcpy(images_p
, image
);
5490 images_p
+= it
.second
.length() + 1;
5491 tracepoint(librbd
, list_children_entry
, pool
, image
);
5494 ssize_t ret
= image_set
.size();
5495 tracepoint(librbd
, list_children_exit
, ret
);
5499 extern "C" int rbd_list_children2(rbd_image_t image
,
5500 rbd_child_info_t
*children
,
5503 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5504 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5505 ictx
->snap_name
.c_str(), ictx
->read_only
);
5506 // FIPS zeroization audit 20191117: this memset is not security related.
5507 memset(children
, 0, sizeof(*children
) * *max_children
);
5509 if (!max_children
) {
5510 tracepoint(librbd
, list_children_exit
, -EINVAL
);
5514 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5515 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_children
);
5517 tracepoint(librbd
, list_children_exit
, r
);
5521 if (*max_children
< (int)cpp_children
.size() + 1) {
5522 *max_children
= (int)cpp_children
.size() + 1;
5523 tracepoint(librbd
, list_children_exit
, *max_children
);
5528 for (i
= 0; i
< (int)cpp_children
.size(); i
++) {
5529 children
[i
].pool_name
= strdup(cpp_children
[i
].pool_name
.c_str());
5530 children
[i
].image_name
= strdup(cpp_children
[i
].image_name
.c_str());
5531 children
[i
].image_id
= strdup(cpp_children
[i
].image_id
.c_str());
5532 children
[i
].trash
= cpp_children
[i
].trash
;
5533 tracepoint(librbd
, list_children_entry
, children
[i
].pool_name
,
5534 children
[i
].image_name
);
5536 children
[i
].pool_name
= NULL
;
5537 children
[i
].image_name
= NULL
;
5538 children
[i
].image_id
= NULL
;
5540 r
= (int)cpp_children
.size();
5541 tracepoint(librbd
, list_children_exit
, *max_children
);
5545 extern "C" void rbd_list_child_cleanup(rbd_child_info_t
*child
)
5547 free((void *)child
->pool_name
);
5548 free((void *)child
->image_name
);
5549 free((void *)child
->image_id
);
5552 extern "C" void rbd_list_children_cleanup(rbd_child_info_t
*children
,
5553 size_t num_children
)
5555 for (size_t i
=0; i
< num_children
; i
++) {
5556 free((void *)children
[i
].pool_name
);
5557 free((void *)children
[i
].image_name
);
5558 free((void *)children
[i
].image_id
);
5562 extern "C" int rbd_list_children3(rbd_image_t image
,
5563 rbd_linked_image_spec_t
*images
,
5566 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5567 tracepoint(librbd
, list_children_enter
, ictx
, ictx
->name
.c_str(),
5568 ictx
->snap_name
.c_str(), ictx
->read_only
);
5569 // FIPS zeroization audit 20191117: this memset is not security related.
5570 memset(images
, 0, sizeof(*images
) * *max_images
);
5572 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5573 int r
= librbd::api::Image
<>::list_children(ictx
, &cpp_children
);
5575 tracepoint(librbd
, list_children_exit
, r
);
5579 if (*max_images
< cpp_children
.size()) {
5580 *max_images
= cpp_children
.size();
5584 *max_images
= cpp_children
.size();
5585 for (size_t idx
= 0; idx
< cpp_children
.size(); ++idx
) {
5587 .pool_id
= cpp_children
[idx
].pool_id
,
5588 .pool_name
= strdup(cpp_children
[idx
].pool_name
.c_str()),
5589 .pool_namespace
= strdup(cpp_children
[idx
].pool_namespace
.c_str()),
5590 .image_id
= strdup(cpp_children
[idx
].image_id
.c_str()),
5591 .image_name
= strdup(cpp_children
[idx
].image_name
.c_str()),
5592 .trash
= cpp_children
[idx
].trash
};
5593 tracepoint(librbd
, list_children_entry
, images
[idx
].pool_name
,
5594 images
[idx
].image_name
);
5599 extern "C" int rbd_list_descendants(rbd_image_t image
,
5600 rbd_linked_image_spec_t
*images
,
5603 auto ictx
= reinterpret_cast<librbd::ImageCtx
*>(image
);
5604 // FIPS zeroization audit 20191117: this memset is not security related.
5605 memset(images
, 0, sizeof(*images
) * *max_images
);
5607 std::vector
<librbd::linked_image_spec_t
> cpp_children
;
5608 int r
= librbd::api::Image
<>::list_descendants(ictx
, {}, &cpp_children
);
5613 if (*max_images
< cpp_children
.size()) {
5614 *max_images
= cpp_children
.size();
5618 *max_images
= cpp_children
.size();
5619 for (size_t idx
= 0; idx
< cpp_children
.size(); ++idx
) {
5621 .pool_id
= cpp_children
[idx
].pool_id
,
5622 .pool_name
= strdup(cpp_children
[idx
].pool_name
.c_str()),
5623 .pool_namespace
= strdup(cpp_children
[idx
].pool_namespace
.c_str()),
5624 .image_id
= strdup(cpp_children
[idx
].image_id
.c_str()),
5625 .image_name
= strdup(cpp_children
[idx
].image_name
.c_str()),
5626 .trash
= cpp_children
[idx
].trash
};
5631 extern "C" ssize_t
rbd_list_lockers(rbd_image_t image
, int *exclusive
,
5632 char *tag
, size_t *tag_len
,
5633 char *clients
, size_t *clients_len
,
5634 char *cookies
, size_t *cookies_len
,
5635 char *addrs
, size_t *addrs_len
)
5637 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5638 tracepoint(librbd
, list_lockers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
5639 std::list
<librbd::locker_t
> lockers
;
5640 bool exclusive_bool
;
5643 int r
= list_lockers(ictx
, &lockers
, &exclusive_bool
, &tag_str
);
5645 tracepoint(librbd
, list_lockers_exit
, r
);
5649 ldout(ictx
->cct
, 20) << "list_lockers r = " << r
<< " lockers.size() = " << lockers
.size() << dendl
;
5651 *exclusive
= (int)exclusive_bool
;
5652 size_t clients_total
= 0;
5653 size_t cookies_total
= 0;
5654 size_t addrs_total
= 0;
5655 for (list
<librbd::locker_t
>::const_iterator it
= lockers
.begin();
5656 it
!= lockers
.end(); ++it
) {
5657 clients_total
+= it
->client
.length() + 1;
5658 cookies_total
+= it
->cookie
.length() + 1;
5659 addrs_total
+= it
->address
.length() + 1;
5662 bool too_short
= ((clients_total
> *clients_len
) ||
5663 (cookies_total
> *cookies_len
) ||
5664 (addrs_total
> *addrs_len
) ||
5665 (tag_str
.length() + 1 > *tag_len
));
5666 *clients_len
= clients_total
;
5667 *cookies_len
= cookies_total
;
5668 *addrs_len
= addrs_total
;
5669 *tag_len
= tag_str
.length() + 1;
5671 tracepoint(librbd
, list_lockers_exit
, -ERANGE
);
5675 strcpy(tag
, tag_str
.c_str());
5676 char *clients_p
= clients
;
5677 char *cookies_p
= cookies
;
5678 char *addrs_p
= addrs
;
5679 for (list
<librbd::locker_t
>::const_iterator it
= lockers
.begin();
5680 it
!= lockers
.end(); ++it
) {
5681 const char* client
= it
->client
.c_str();
5682 strcpy(clients_p
, client
);
5683 clients_p
+= it
->client
.length() + 1;
5684 const char* cookie
= it
->cookie
.c_str();
5685 strcpy(cookies_p
, cookie
);
5686 cookies_p
+= it
->cookie
.length() + 1;
5687 const char* address
= it
->address
.c_str();
5688 strcpy(addrs_p
, address
);
5689 addrs_p
+= it
->address
.length() + 1;
5690 tracepoint(librbd
, list_lockers_entry
, client
, cookie
, address
);
5693 ssize_t ret
= lockers
.size();
5694 tracepoint(librbd
, list_lockers_exit
, ret
);
5698 extern "C" int rbd_lock_exclusive(rbd_image_t image
, const char *cookie
)
5700 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5701 tracepoint(librbd
, lock_exclusive_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
);
5702 int r
= librbd::lock(ictx
, true, cookie
? cookie
: "", "");
5703 tracepoint(librbd
, lock_exclusive_exit
, r
);
5707 extern "C" int rbd_lock_shared(rbd_image_t image
, const char *cookie
,
5710 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5711 tracepoint(librbd
, lock_shared_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
, tag
);
5712 int r
= librbd::lock(ictx
, false, cookie
? cookie
: "", tag
? tag
: "");
5713 tracepoint(librbd
, lock_shared_exit
, r
);
5717 extern "C" int rbd_unlock(rbd_image_t image
, const char *cookie
)
5719 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5720 tracepoint(librbd
, unlock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, cookie
);
5721 int r
= librbd::unlock(ictx
, cookie
? cookie
: "");
5722 tracepoint(librbd
, unlock_exit
, r
);
5726 extern "C" int rbd_break_lock(rbd_image_t image
, const char *client
,
5729 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5730 tracepoint(librbd
, break_lock_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, client
, cookie
);
5731 int r
= librbd::break_lock(ictx
, client
, cookie
? cookie
: "");
5732 tracepoint(librbd
, break_lock_exit
, r
);
5737 extern "C" ssize_t
rbd_read(rbd_image_t image
, uint64_t ofs
, size_t len
,
5740 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5741 tracepoint(librbd
, read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5742 int r
= ictx
->io_work_queue
->read(ofs
, len
, librbd::io::ReadResult
{buf
, len
},
5744 tracepoint(librbd
, read_exit
, r
);
5748 extern "C" ssize_t
rbd_read2(rbd_image_t image
, uint64_t ofs
, size_t len
,
5749 char *buf
, int op_flags
)
5751 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5752 tracepoint(librbd
, read2_enter
, ictx
, ictx
->name
.c_str(),
5753 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, op_flags
);
5754 int r
= ictx
->io_work_queue
->read(ofs
, len
, librbd::io::ReadResult
{buf
, len
},
5756 tracepoint(librbd
, read_exit
, r
);
5761 extern "C" int64_t rbd_read_iterate(rbd_image_t image
, uint64_t ofs
, size_t len
,
5762 int (*cb
)(uint64_t, size_t, const char *, void *),
5765 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5766 tracepoint(librbd
, read_iterate_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5767 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
5768 tracepoint(librbd
, read_iterate_exit
, r
);
5772 extern "C" int rbd_read_iterate2(rbd_image_t image
, uint64_t ofs
, uint64_t len
,
5773 int (*cb
)(uint64_t, size_t, const char *, void *),
5776 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5777 tracepoint(librbd
, read_iterate2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5778 int64_t r
= librbd::read_iterate(ictx
, ofs
, len
, cb
, arg
);
5781 tracepoint(librbd
, read_iterate2_exit
, r
);
5785 extern "C" int rbd_diff_iterate(rbd_image_t image
,
5786 const char *fromsnapname
,
5787 uint64_t ofs
, uint64_t len
,
5788 int (*cb
)(uint64_t, size_t, int, void *),
5791 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5792 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
5793 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
5795 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
5796 cls::rbd::UserSnapshotNamespace(),
5797 fromsnapname
, ofs
, len
,
5798 true, false, cb
, arg
);
5799 tracepoint(librbd
, diff_iterate_exit
, r
);
5803 extern "C" int rbd_diff_iterate2(rbd_image_t image
, const char *fromsnapname
,
5804 uint64_t ofs
, uint64_t len
,
5805 uint8_t include_parent
, uint8_t whole_object
,
5806 int (*cb
)(uint64_t, size_t, int, void *),
5809 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5810 tracepoint(librbd
, diff_iterate_enter
, ictx
, ictx
->name
.c_str(),
5811 ictx
->snap_name
.c_str(), ictx
->read_only
, fromsnapname
, ofs
, len
,
5812 include_parent
!= 0, whole_object
!= 0);
5813 int r
= librbd::api::DiffIterate
<>::diff_iterate(ictx
,
5814 cls::rbd::UserSnapshotNamespace(),
5815 fromsnapname
, ofs
, len
,
5816 include_parent
, whole_object
,
5818 tracepoint(librbd
, diff_iterate_exit
, r
);
5822 extern "C" ssize_t
rbd_write(rbd_image_t image
, uint64_t ofs
, size_t len
,
5825 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5826 tracepoint(librbd
, write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, buf
);
5829 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
5830 int r
= ictx
->io_work_queue
->write(ofs
, len
, std::move(bl
), 0);
5831 tracepoint(librbd
, write_exit
, r
);
5835 extern "C" ssize_t
rbd_write2(rbd_image_t image
, uint64_t ofs
, size_t len
,
5836 const char *buf
, int op_flags
)
5838 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5839 tracepoint(librbd
, write2_enter
, ictx
, ictx
->name
.c_str(),
5840 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
, buf
, op_flags
);
5843 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
5844 int r
= ictx
->io_work_queue
->write(ofs
, len
, std::move(bl
), op_flags
);
5845 tracepoint(librbd
, write_exit
, r
);
5850 extern "C" int rbd_discard(rbd_image_t image
, uint64_t ofs
, uint64_t len
)
5852 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5853 tracepoint(librbd
, discard_enter
, ictx
, ictx
->name
.c_str(),
5854 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
, len
);
5855 if (len
> static_cast<uint64_t>(std::numeric_limits
<int>::max())) {
5856 tracepoint(librbd
, discard_exit
, -EINVAL
);
5860 int r
= ictx
->io_work_queue
->discard(
5861 ofs
, len
, ictx
->discard_granularity_bytes
);
5862 tracepoint(librbd
, discard_exit
, r
);
5866 extern "C" ssize_t
rbd_writesame(rbd_image_t image
, uint64_t ofs
, size_t len
,
5867 const char *buf
, size_t data_len
, int op_flags
)
5869 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5870 tracepoint(librbd
, writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
5871 ictx
->read_only
, ofs
, len
, data_len
== 0 ? NULL
: buf
, data_len
, op_flags
);
5873 if (data_len
== 0 || len
% data_len
||
5874 len
> static_cast<uint64_t>(std::numeric_limits
<int>::max())) {
5875 tracepoint(librbd
, writesame_exit
, -EINVAL
);
5879 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
5880 if (discard_zero
&& mem_is_zero(buf
, data_len
)) {
5881 int r
= ictx
->io_work_queue
->write_zeroes(ofs
, len
, 0, op_flags
);
5882 tracepoint(librbd
, writesame_exit
, r
);
5887 bl
.push_back(create_write_raw(ictx
, buf
, data_len
, nullptr));
5888 int r
= ictx
->io_work_queue
->writesame(ofs
, len
, std::move(bl
), op_flags
);
5889 tracepoint(librbd
, writesame_exit
, r
);
5893 extern "C" ssize_t
rbd_write_zeroes(rbd_image_t image
, uint64_t ofs
, size_t len
,
5894 int zero_flags
, int op_flags
)
5896 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5897 return ictx
->io_work_queue
->write_zeroes(ofs
, len
, zero_flags
, op_flags
);
5900 extern "C" ssize_t
rbd_compare_and_write(rbd_image_t image
,
5901 uint64_t ofs
, size_t len
,
5902 const char *cmp_buf
,
5904 uint64_t *mismatch_off
,
5907 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5908 tracepoint(librbd
, compare_and_write_enter
, ictx
, ictx
->name
.c_str(),
5909 ictx
->snap_name
.c_str(), ictx
->read_only
, ofs
,
5910 len
, cmp_buf
, buf
, op_flags
);
5913 cmp_bl
.push_back(create_write_raw(ictx
, cmp_buf
, len
, nullptr));
5915 bl
.push_back(create_write_raw(ictx
, buf
, len
, nullptr));
5917 int r
= ictx
->io_work_queue
->compare_and_write(ofs
, len
, std::move(cmp_bl
),
5918 std::move(bl
), mismatch_off
,
5920 tracepoint(librbd
, compare_and_write_exit
, r
);
5924 extern "C" int rbd_aio_create_completion(void *cb_arg
,
5925 rbd_callback_t complete_cb
,
5926 rbd_completion_t
*c
)
5928 librbd::RBD::AioCompletion
*rbd_comp
=
5929 new librbd::RBD::AioCompletion(cb_arg
, complete_cb
);
5930 *c
= (rbd_completion_t
) rbd_comp
;
5934 extern "C" int rbd_aio_write(rbd_image_t image
, uint64_t off
, size_t len
,
5935 const char *buf
, rbd_completion_t c
)
5937 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5938 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
5939 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, buf
, comp
->pc
);
5941 auto aio_completion
= get_aio_completion(comp
);
5943 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
5944 ictx
->io_work_queue
->aio_write(aio_completion
, off
, len
, std::move(bl
), 0);
5945 tracepoint(librbd
, aio_write_exit
, 0);
5949 extern "C" int rbd_aio_write2(rbd_image_t image
, uint64_t off
, size_t len
,
5950 const char *buf
, rbd_completion_t c
, int op_flags
)
5952 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5953 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
5954 tracepoint(librbd
, aio_write2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
5955 ictx
->read_only
, off
, len
, buf
, comp
->pc
, op_flags
);
5957 auto aio_completion
= get_aio_completion(comp
);
5959 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
5960 ictx
->io_work_queue
->aio_write(aio_completion
, off
, len
, std::move(bl
),
5962 tracepoint(librbd
, aio_write_exit
, 0);
5966 extern "C" int rbd_aio_writev(rbd_image_t image
, const struct iovec
*iov
,
5967 int iovcnt
, uint64_t off
, rbd_completion_t c
)
5969 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
5970 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
5972 // convert the scatter list into a bufferlist
5973 auto aio_completion
= get_aio_completion(comp
);
5976 for (int i
= 0; i
< iovcnt
; ++i
) {
5977 const struct iovec
&io
= iov
[i
];
5983 bl
.push_back(create_write_raw(ictx
, static_cast<char*>(io
.iov_base
),
5984 io
.iov_len
, aio_completion
));
5988 if (iovcnt
<= 0 || len
< 0) {
5992 tracepoint(librbd
, aio_write_enter
, ictx
, ictx
->name
.c_str(),
5993 ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, NULL
,
5996 ictx
->io_work_queue
->aio_write(aio_completion
, off
, len
, std::move(bl
), 0);
5998 tracepoint(librbd
, aio_write_exit
, r
);
6002 extern "C" int rbd_aio_discard(rbd_image_t image
, uint64_t off
, uint64_t len
,
6005 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6006 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6007 tracepoint(librbd
, aio_discard_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, comp
->pc
);
6008 ictx
->io_work_queue
->aio_discard(
6009 get_aio_completion(comp
), off
, len
, ictx
->discard_granularity_bytes
);
6010 tracepoint(librbd
, aio_discard_exit
, 0);
6014 extern "C" int rbd_aio_read(rbd_image_t image
, uint64_t off
, size_t len
,
6015 char *buf
, rbd_completion_t c
)
6017 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6018 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6019 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, buf
, comp
->pc
);
6020 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
6021 librbd::io::ReadResult
{buf
, len
}, 0);
6022 tracepoint(librbd
, aio_read_exit
, 0);
6026 extern "C" int rbd_aio_read2(rbd_image_t image
, uint64_t off
, size_t len
,
6027 char *buf
, rbd_completion_t c
, int op_flags
)
6029 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6030 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6031 tracepoint(librbd
, aio_read2_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6032 ictx
->read_only
, off
, len
, buf
, comp
->pc
, op_flags
);
6033 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
6034 librbd::io::ReadResult
{buf
, len
},op_flags
);
6035 tracepoint(librbd
, aio_read_exit
, 0);
6039 extern "C" int rbd_aio_readv(rbd_image_t image
, const struct iovec
*iov
,
6040 int iovcnt
, uint64_t off
, rbd_completion_t c
)
6042 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6043 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6046 for (int i
= 0; i
< iovcnt
; ++i
) {
6047 len
+= iov
[i
].iov_len
;
6054 if (iovcnt
== 0 || len
< 0) {
6058 tracepoint(librbd
, aio_read_enter
, ictx
, ictx
->name
.c_str(),
6059 ictx
->snap_name
.c_str(), ictx
->read_only
, off
, len
, NULL
,
6062 librbd::io::ReadResult read_result
;
6064 read_result
= librbd::io::ReadResult(
6065 static_cast<char *>(iov
[0].iov_base
), iov
[0].iov_len
);
6067 read_result
= librbd::io::ReadResult(iov
, iovcnt
);
6069 ictx
->io_work_queue
->aio_read(get_aio_completion(comp
), off
, len
,
6070 std::move(read_result
), 0);
6072 tracepoint(librbd
, aio_read_exit
, r
);
6076 extern "C" int rbd_flush(rbd_image_t image
)
6078 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6079 tracepoint(librbd
, flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
6080 int r
= ictx
->io_work_queue
->flush();
6081 tracepoint(librbd
, flush_exit
, r
);
6085 extern "C" int rbd_aio_flush(rbd_image_t image
, rbd_completion_t c
)
6087 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6088 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6089 tracepoint(librbd
, aio_flush_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
, comp
->pc
);
6090 ictx
->io_work_queue
->aio_flush(get_aio_completion(comp
));
6091 tracepoint(librbd
, aio_flush_exit
, 0);
6095 extern "C" int rbd_aio_writesame(rbd_image_t image
, uint64_t off
, size_t len
,
6096 const char *buf
, size_t data_len
, rbd_completion_t c
,
6099 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6100 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6101 tracepoint(librbd
, aio_writesame_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6102 ictx
->read_only
, off
, len
, data_len
== 0 ? NULL
: buf
, data_len
, comp
->pc
,
6105 if (data_len
== 0 || len
% data_len
) {
6106 tracepoint(librbd
, aio_writesame_exit
, -EINVAL
);
6110 bool discard_zero
= ictx
->config
.get_val
<bool>("rbd_discard_on_zeroed_write_same");
6111 if (discard_zero
&& mem_is_zero(buf
, data_len
)) {
6112 ictx
->io_work_queue
->aio_write_zeroes(get_aio_completion(comp
), off
, len
, 0,
6114 tracepoint(librbd
, aio_writesame_exit
, 0);
6118 auto aio_completion
= get_aio_completion(comp
);
6120 bl
.push_back(create_write_raw(ictx
, buf
, data_len
, aio_completion
));
6121 ictx
->io_work_queue
->aio_writesame(aio_completion
, off
, len
, std::move(bl
),
6123 tracepoint(librbd
, aio_writesame_exit
, 0);
6127 extern "C" int rbd_aio_write_zeroes(rbd_image_t image
, uint64_t off
, size_t len
,
6128 rbd_completion_t c
, int zero_flags
,
6131 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6132 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6134 ictx
->io_work_queue
->aio_write_zeroes(
6135 get_aio_completion(comp
), off
, len
, zero_flags
, op_flags
, true);
6139 extern "C" ssize_t
rbd_aio_compare_and_write(rbd_image_t image
, uint64_t off
,
6140 size_t len
, const char *cmp_buf
,
6141 const char *buf
, rbd_completion_t c
,
6142 uint64_t *mismatch_off
,
6145 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6146 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6147 tracepoint(librbd
, aio_compare_and_write_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(),
6148 ictx
->read_only
, off
, len
, cmp_buf
, buf
, comp
->pc
, op_flags
);
6150 auto aio_completion
= get_aio_completion(comp
);
6152 cmp_bl
.push_back(create_write_raw(ictx
, cmp_buf
, len
, aio_completion
));
6154 bl
.push_back(create_write_raw(ictx
, buf
, len
, aio_completion
));
6155 ictx
->io_work_queue
->aio_compare_and_write(aio_completion
, off
, len
,
6156 std::move(cmp_bl
), std::move(bl
),
6157 mismatch_off
, op_flags
, false);
6159 tracepoint(librbd
, aio_compare_and_write_exit
, 0);
6163 extern "C" int rbd_invalidate_cache(rbd_image_t image
)
6165 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6166 tracepoint(librbd
, invalidate_cache_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
6167 int r
= librbd::invalidate_cache(ictx
);
6168 tracepoint(librbd
, invalidate_cache_exit
, r
);
6172 extern "C" int rbd_poll_io_events(rbd_image_t image
, rbd_completion_t
*comps
, int numcomp
)
6174 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6175 librbd::io::AioCompletion
*cs
[numcomp
];
6176 tracepoint(librbd
, poll_io_events_enter
, ictx
, numcomp
);
6177 int r
= librbd::poll_io_events(ictx
, cs
, numcomp
);
6178 tracepoint(librbd
, poll_io_events_exit
, r
);
6180 for (int i
= 0; i
< r
; ++i
)
6181 comps
[i
] = cs
[i
]->rbd_comp
;
6186 extern "C" int rbd_metadata_get(rbd_image_t image
, const char *key
, char *value
, size_t *vallen
)
6188 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6190 tracepoint(librbd
, metadata_get_enter
, ictx
, key
);
6191 int r
= librbd::metadata_get(ictx
, key
, &val_s
);
6193 tracepoint(librbd
, metadata_get_exit
, r
, key
, NULL
);
6196 if (*vallen
< val_s
.size() + 1) {
6198 *vallen
= val_s
.size() + 1;
6199 tracepoint(librbd
, metadata_get_exit
, r
, key
, NULL
);
6201 strncpy(value
, val_s
.c_str(), val_s
.size() + 1);
6202 tracepoint(librbd
, metadata_get_exit
, r
, key
, value
);
6207 extern "C" int rbd_metadata_set(rbd_image_t image
, const char *key
, const char *value
)
6209 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6210 tracepoint(librbd
, metadata_set_enter
, ictx
, key
, value
);
6211 int r
= ictx
->operations
->metadata_set(key
, value
);
6212 tracepoint(librbd
, metadata_set_exit
, r
);
6216 extern "C" int rbd_metadata_remove(rbd_image_t image
, const char *key
)
6218 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6219 tracepoint(librbd
, metadata_remove_enter
, ictx
, key
);
6220 int r
= ictx
->operations
->metadata_remove(key
);
6221 tracepoint(librbd
, metadata_remove_exit
, r
);
6225 extern "C" int rbd_metadata_list(rbd_image_t image
, const char *start
, uint64_t max
,
6226 char *key
, size_t *key_len
, char *value
, size_t *val_len
)
6228 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6229 tracepoint(librbd
, metadata_list_enter
, ictx
);
6230 map
<string
, bufferlist
> pairs
;
6231 int r
= librbd::metadata_list(ictx
, start
, max
, &pairs
);
6232 size_t key_total_len
= 0, val_total_len
= 0;
6233 bool too_short
= false;
6234 for (map
<string
, bufferlist
>::iterator it
= pairs
.begin();
6235 it
!= pairs
.end(); ++it
) {
6236 key_total_len
+= it
->first
.size() + 1;
6237 val_total_len
+= it
->second
.length() + 1;
6239 if (*key_len
< key_total_len
|| *val_len
< val_total_len
)
6241 *key_len
= key_total_len
;
6242 *val_len
= val_total_len
;
6244 tracepoint(librbd
, metadata_list_exit
, -ERANGE
);
6248 char *key_p
= key
, *value_p
= value
;
6250 for (map
<string
, bufferlist
>::iterator it
= pairs
.begin();
6251 it
!= pairs
.end(); ++it
) {
6252 strncpy(key_p
, it
->first
.c_str(), it
->first
.size() + 1);
6253 key_p
+= it
->first
.size() + 1;
6254 strncpy(value_p
, it
->second
.c_str(), it
->second
.length());
6255 value_p
+= it
->second
.length();
6258 tracepoint(librbd
, metadata_list_entry
, it
->first
.c_str(), it
->second
.c_str());
6260 tracepoint(librbd
, metadata_list_exit
, r
);
6264 extern "C" int rbd_mirror_image_enable(rbd_image_t image
)
6266 return rbd_mirror_image_enable2(image
, RBD_MIRROR_IMAGE_MODE_JOURNAL
);
6269 extern "C" int rbd_mirror_image_enable2(rbd_image_t image
,
6270 rbd_mirror_image_mode_t mode
)
6272 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6273 return librbd::api::Mirror
<>::image_enable(ictx
, mode
, false);
6276 extern "C" int rbd_mirror_image_disable(rbd_image_t image
, bool force
)
6278 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6279 return librbd::api::Mirror
<>::image_disable(ictx
, force
);
6282 extern "C" int rbd_mirror_image_promote(rbd_image_t image
, bool force
)
6284 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6285 return librbd::api::Mirror
<>::image_promote(ictx
, force
);
6288 extern "C" int rbd_mirror_image_demote(rbd_image_t image
)
6290 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6291 return librbd::api::Mirror
<>::image_demote(ictx
);
6294 extern "C" int rbd_mirror_image_resync(rbd_image_t image
)
6296 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6297 return librbd::api::Mirror
<>::image_resync(ictx
);
6300 extern "C" int rbd_mirror_image_create_snapshot(rbd_image_t image
,
6303 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6304 return librbd::api::Mirror
<>::image_snapshot_create(ictx
, snap_id
);
6307 extern "C" int rbd_mirror_image_get_info(rbd_image_t image
,
6308 rbd_mirror_image_info_t
*mirror_image_info
,
6311 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6313 if (sizeof(rbd_mirror_image_info_t
) != info_size
) {
6317 librbd::mirror_image_info_t cpp_mirror_image
;
6318 int r
= librbd::api::Mirror
<>::image_get_info(ictx
, &cpp_mirror_image
);
6323 mirror_image_info_cpp_to_c(cpp_mirror_image
, mirror_image_info
);
6327 extern "C" void rbd_mirror_image_get_info_cleanup(
6328 rbd_mirror_image_info_t
*mirror_image_info
)
6330 free(mirror_image_info
->global_id
);
6333 extern "C" int rbd_mirror_image_get_mode(rbd_image_t image
,
6334 rbd_mirror_image_mode_t
*mode
)
6336 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6338 return librbd::api::Mirror
<>::image_get_mode(ictx
, mode
);
6341 extern "C" int rbd_mirror_image_get_global_status(
6342 rbd_image_t image
, rbd_mirror_image_global_status_t
*status
,
6345 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6347 if (sizeof(rbd_mirror_image_global_status_t
) != status_size
) {
6351 librbd::mirror_image_global_status_t cpp_status
;
6352 int r
= librbd::api::Mirror
<>::image_get_global_status(ictx
, &cpp_status
);
6357 mirror_image_global_status_cpp_to_c(cpp_status
, status
);
6361 #pragma GCC diagnostic push
6362 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6364 extern "C" int rbd_mirror_image_get_status(rbd_image_t image
,
6365 rbd_mirror_image_status_t
*status
,
6368 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6370 if (sizeof(rbd_mirror_image_status_t
) != status_size
) {
6374 librbd::mirror_image_global_status_t cpp_status
;
6375 int r
= librbd::api::Mirror
<>::image_get_global_status(ictx
, &cpp_status
);
6380 mirror_image_global_status_cpp_to_c(cpp_status
, status
);
6384 #pragma GCC diagnostic pop
6386 extern "C" int rbd_mirror_image_get_instance_id(rbd_image_t image
,
6388 size_t *instance_id_max_length
)
6390 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6392 std::string cpp_instance_id
;
6393 int r
= librbd::api::Mirror
<>::image_get_instance_id(ictx
, &cpp_instance_id
);
6398 if (cpp_instance_id
.size() >= *instance_id_max_length
) {
6399 *instance_id_max_length
= cpp_instance_id
.size() + 1;
6403 strcpy(instance_id
, cpp_instance_id
.c_str());
6404 *instance_id_max_length
= cpp_instance_id
.size() + 1;
6408 extern "C" int rbd_aio_mirror_image_promote(rbd_image_t image
, bool force
,
6409 rbd_completion_t c
) {
6410 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6411 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6412 librbd::api::Mirror
<>::image_promote(
6413 ictx
, force
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6414 get_aio_completion(comp
)));
6418 extern "C" int rbd_aio_mirror_image_demote(rbd_image_t image
,
6419 rbd_completion_t c
) {
6420 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6421 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6422 librbd::api::Mirror
<>::image_demote(
6423 ictx
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6424 get_aio_completion(comp
)));
6428 extern "C" int rbd_aio_mirror_image_get_info(rbd_image_t image
,
6429 rbd_mirror_image_info_t
*info
,
6431 rbd_completion_t c
) {
6432 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6433 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6435 if (sizeof(rbd_mirror_image_info_t
) != info_size
) {
6439 auto ctx
= new C_MirrorImageGetInfo(
6440 info
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6441 get_aio_completion(comp
)));
6442 librbd::api::Mirror
<>::image_get_info(
6443 ictx
, &ctx
->cpp_mirror_image_info
, ctx
);
6447 extern "C" int rbd_aio_mirror_image_get_mode(rbd_image_t image
,
6448 rbd_mirror_image_mode_t
*mode
,
6449 rbd_completion_t c
) {
6450 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6451 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6453 librbd::api::Mirror
<>::image_get_mode(
6454 ictx
, mode
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6455 get_aio_completion(comp
)));
6459 extern "C" int rbd_aio_mirror_image_get_global_status(
6460 rbd_image_t image
, rbd_mirror_image_global_status_t
*status
,
6461 size_t status_size
, rbd_completion_t c
) {
6462 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6463 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6465 if (sizeof(rbd_mirror_image_global_status_t
) != status_size
) {
6469 auto ctx
= new C_MirrorImageGetGlobalStatus(
6470 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6471 get_aio_completion(comp
)));
6472 librbd::api::Mirror
<>::image_get_global_status(
6473 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
6477 #pragma GCC diagnostic push
6478 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6480 extern "C" int rbd_aio_mirror_image_get_status(
6481 rbd_image_t image
, rbd_mirror_image_status_t
*status
, size_t status_size
,
6482 rbd_completion_t c
) {
6483 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6484 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6486 if (sizeof(rbd_mirror_image_status_t
) != status_size
) {
6490 auto ctx
= new C_MirrorImageGetStatus(
6491 status
, new C_AioCompletion(ictx
, librbd::io::AIO_TYPE_GENERIC
,
6492 get_aio_completion(comp
)));
6493 librbd::api::Mirror
<>::image_get_global_status(
6494 ictx
, &ctx
->cpp_mirror_image_global_status
, ctx
);
6498 #pragma GCC diagnostic pop
6500 extern "C" int rbd_update_watch(rbd_image_t image
, uint64_t *handle
,
6501 rbd_update_callback_t watch_cb
, void *arg
)
6503 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6504 C_UpdateWatchCB
*wctx
= new C_UpdateWatchCB(watch_cb
, arg
);
6505 tracepoint(librbd
, update_watch_enter
, ictx
, wctx
);
6506 int r
= ictx
->state
->register_update_watcher(wctx
, &wctx
->handle
);
6507 tracepoint(librbd
, update_watch_exit
, r
, wctx
->handle
);
6508 *handle
= reinterpret_cast<uint64_t>(wctx
);
6512 extern "C" int rbd_update_unwatch(rbd_image_t image
, uint64_t handle
)
6514 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6515 C_UpdateWatchCB
*wctx
= reinterpret_cast<C_UpdateWatchCB
*>(handle
);
6516 tracepoint(librbd
, update_unwatch_enter
, ictx
, wctx
->handle
);
6517 int r
= ictx
->state
->unregister_update_watcher(wctx
->handle
);
6519 tracepoint(librbd
, update_unwatch_exit
, r
);
6523 extern "C" int rbd_aio_is_complete(rbd_completion_t c
)
6525 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6526 return comp
->is_complete();
6529 extern "C" int rbd_aio_wait_for_complete(rbd_completion_t c
)
6531 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6532 return comp
->wait_for_complete();
6535 extern "C" ssize_t
rbd_aio_get_return_value(rbd_completion_t c
)
6537 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6538 return comp
->get_return_value();
6541 extern "C" void *rbd_aio_get_arg(rbd_completion_t c
)
6543 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6544 return comp
->get_arg();
6547 extern "C" void rbd_aio_release(rbd_completion_t c
)
6549 librbd::RBD::AioCompletion
*comp
= (librbd::RBD::AioCompletion
*)c
;
6553 extern "C" int rbd_group_create(rados_ioctx_t p
, const char *name
)
6555 librados::IoCtx io_ctx
;
6556 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6557 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6558 tracepoint(librbd
, group_create_enter
, io_ctx
.get_pool_name().c_str(),
6559 io_ctx
.get_id(), name
);
6560 int r
= librbd::api::Group
<>::create(io_ctx
, name
);
6561 tracepoint(librbd
, group_create_exit
, r
);
6565 extern "C" int rbd_group_remove(rados_ioctx_t p
, const char *name
)
6567 librados::IoCtx io_ctx
;
6568 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6569 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6570 tracepoint(librbd
, group_remove_enter
, io_ctx
.get_pool_name().c_str(),
6571 io_ctx
.get_id(), name
);
6572 int r
= librbd::api::Group
<>::remove(io_ctx
, name
);
6573 tracepoint(librbd
, group_remove_exit
, r
);
6577 extern "C" int rbd_group_list(rados_ioctx_t p
, char *names
, size_t *size
)
6579 librados::IoCtx io_ctx
;
6580 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6581 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6582 tracepoint(librbd
, group_list_enter
, io_ctx
.get_pool_name().c_str(),
6585 vector
<string
> cpp_names
;
6586 int r
= librbd::api::Group
<>::list(io_ctx
, &cpp_names
);
6589 tracepoint(librbd
, group_list_exit
, r
);
6593 size_t expected_size
= 0;
6595 for (size_t i
= 0; i
< cpp_names
.size(); i
++) {
6596 expected_size
+= cpp_names
[i
].size() + 1;
6598 if (*size
< expected_size
) {
6599 *size
= expected_size
;
6600 tracepoint(librbd
, group_list_exit
, -ERANGE
);
6604 if (names
== NULL
) {
6605 tracepoint(librbd
, group_list_exit
, -EINVAL
);
6609 for (int i
= 0; i
< (int)cpp_names
.size(); i
++) {
6610 const char* name
= cpp_names
[i
].c_str();
6611 tracepoint(librbd
, group_list_entry
, name
);
6612 strcpy(names
, name
);
6613 names
+= strlen(names
) + 1;
6615 tracepoint(librbd
, group_list_exit
, (int)expected_size
);
6616 return (int)expected_size
;
6619 extern "C" int rbd_group_rename(rados_ioctx_t p
, const char *src_name
,
6620 const char *dest_name
)
6622 librados::IoCtx io_ctx
;
6623 librados::IoCtx::from_rados_ioctx_t(p
, io_ctx
);
6624 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(io_ctx
));
6625 tracepoint(librbd
, group_rename_enter
, io_ctx
.get_pool_name().c_str(),
6626 io_ctx
.get_id(), src_name
, dest_name
);
6627 int r
= librbd::api::Group
<>::rename(io_ctx
, src_name
, dest_name
);
6628 tracepoint(librbd
, group_rename_exit
, r
);
6632 extern "C" int rbd_group_image_add(rados_ioctx_t group_p
,
6633 const char *group_name
,
6634 rados_ioctx_t image_p
,
6635 const char *image_name
)
6637 librados::IoCtx group_ioctx
;
6638 librados::IoCtx image_ioctx
;
6640 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6641 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6643 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6644 tracepoint(librbd
, group_image_add_enter
, group_ioctx
.get_pool_name().c_str(),
6645 group_ioctx
.get_id(), group_name
, image_ioctx
.get_pool_name().c_str(),
6646 image_ioctx
.get_id(), image_name
);
6648 int r
= librbd::api::Group
<>::image_add(group_ioctx
, group_name
, image_ioctx
,
6651 tracepoint(librbd
, group_image_add_exit
, r
);
6655 extern "C" int rbd_group_image_remove(rados_ioctx_t group_p
,
6656 const char *group_name
,
6657 rados_ioctx_t image_p
,
6658 const char *image_name
)
6660 librados::IoCtx group_ioctx
;
6661 librados::IoCtx image_ioctx
;
6663 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6664 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6666 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6667 tracepoint(librbd
, group_image_remove_enter
, group_ioctx
.get_pool_name().c_str(),
6668 group_ioctx
.get_id(), group_name
, image_ioctx
.get_pool_name().c_str(),
6669 image_ioctx
.get_id(), image_name
);
6671 int r
= librbd::api::Group
<>::image_remove(group_ioctx
, group_name
,
6672 image_ioctx
, image_name
);
6674 tracepoint(librbd
, group_image_remove_exit
, r
);
6678 extern "C" int rbd_group_image_remove_by_id(rados_ioctx_t group_p
,
6679 const char *group_name
,
6680 rados_ioctx_t image_p
,
6681 const char *image_id
)
6683 librados::IoCtx group_ioctx
;
6684 librados::IoCtx image_ioctx
;
6686 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6687 librados::IoCtx::from_rados_ioctx_t(image_p
, image_ioctx
);
6689 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6690 tracepoint(librbd
, group_image_remove_by_id_enter
,
6691 group_ioctx
.get_pool_name().c_str(),
6692 group_ioctx
.get_id(), group_name
,
6693 image_ioctx
.get_pool_name().c_str(),
6694 image_ioctx
.get_id(), image_id
);
6696 int r
= librbd::api::Group
<>::image_remove_by_id(group_ioctx
, group_name
,
6697 image_ioctx
, image_id
);
6699 tracepoint(librbd
, group_image_remove_by_id_exit
, r
);
6703 extern "C" int rbd_group_image_list(rados_ioctx_t group_p
,
6704 const char *group_name
,
6705 rbd_group_image_info_t
*images
,
6706 size_t group_image_info_size
,
6709 librados::IoCtx group_ioctx
;
6710 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6712 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6713 tracepoint(librbd
, group_image_list_enter
,
6714 group_ioctx
.get_pool_name().c_str(),
6715 group_ioctx
.get_id(), group_name
);
6716 // FIPS zeroization audit 20191117: this memset is not security related.
6717 memset(images
, 0, sizeof(*images
) * *image_size
);
6719 if (group_image_info_size
!= sizeof(rbd_group_image_info_t
)) {
6721 tracepoint(librbd
, group_image_list_exit
, -ERANGE
);
6725 std::vector
<librbd::group_image_info_t
> cpp_images
;
6726 int r
= librbd::api::Group
<>::image_list(group_ioctx
, group_name
,
6730 tracepoint(librbd
, group_image_list_exit
, 0);
6736 tracepoint(librbd
, group_image_list_exit
, r
);
6740 if (*image_size
< cpp_images
.size()) {
6741 *image_size
= cpp_images
.size();
6742 tracepoint(librbd
, group_image_list_exit
, -ERANGE
);
6746 for (size_t i
= 0; i
< cpp_images
.size(); ++i
) {
6747 group_image_status_cpp_to_c(cpp_images
[i
], &images
[i
]);
6750 r
= *image_size
= cpp_images
.size();
6751 tracepoint(librbd
, group_image_list_exit
, r
);
6755 extern "C" int rbd_group_info_cleanup(rbd_group_info_t
*group_info
,
6756 size_t group_info_size
) {
6757 if (group_info_size
!= sizeof(rbd_group_info_t
)) {
6761 free(group_info
->name
);
6765 extern "C" int rbd_group_image_list_cleanup(rbd_group_image_info_t
*images
,
6766 size_t group_image_info_size
,
6768 if (group_image_info_size
!= sizeof(rbd_group_image_info_t
)) {
6772 for (size_t i
= 0; i
< len
; ++i
) {
6773 free(images
[i
].name
);
6778 extern "C" int rbd_group_snap_create(rados_ioctx_t group_p
,
6779 const char *group_name
,
6780 const char *snap_name
)
6782 librados::IoCtx group_ioctx
;
6783 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6785 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6786 tracepoint(librbd
, group_snap_create_enter
,
6787 group_ioctx
.get_pool_name().c_str(),
6788 group_ioctx
.get_id(), group_name
, snap_name
);
6790 int r
= librbd::api::Group
<>::snap_create(group_ioctx
, group_name
, snap_name
);
6792 tracepoint(librbd
, group_snap_create_exit
, r
);
6797 extern "C" int rbd_group_snap_remove(rados_ioctx_t group_p
,
6798 const char *group_name
,
6799 const char *snap_name
)
6801 librados::IoCtx group_ioctx
;
6802 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6804 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6805 tracepoint(librbd
, group_snap_remove_enter
,
6806 group_ioctx
.get_pool_name().c_str(),
6807 group_ioctx
.get_id(), group_name
, snap_name
);
6809 int r
= librbd::api::Group
<>::snap_remove(group_ioctx
, group_name
, snap_name
);
6811 tracepoint(librbd
, group_snap_remove_exit
, r
);
6816 extern "C" int rbd_group_snap_rename(rados_ioctx_t group_p
,
6817 const char *group_name
,
6818 const char *old_snap_name
,
6819 const char *new_snap_name
)
6821 librados::IoCtx group_ioctx
;
6822 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6824 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6825 tracepoint(librbd
, group_snap_rename_enter
,
6826 group_ioctx
.get_pool_name().c_str(), group_ioctx
.get_id(),
6827 group_name
, old_snap_name
, new_snap_name
);
6829 int r
= librbd::api::Group
<>::snap_rename(group_ioctx
, group_name
,
6830 old_snap_name
, new_snap_name
);
6832 tracepoint(librbd
, group_snap_list_exit
, r
);
6836 extern "C" int rbd_group_snap_list(rados_ioctx_t group_p
,
6837 const char *group_name
,
6838 rbd_group_snap_info_t
*snaps
,
6839 size_t group_snap_info_size
,
6842 librados::IoCtx group_ioctx
;
6843 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6845 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6846 tracepoint(librbd
, group_snap_list_enter
, group_ioctx
.get_pool_name().c_str(),
6847 group_ioctx
.get_id(), group_name
);
6848 // FIPS zeroization audit 20191117: this memset is not security related.
6849 memset(snaps
, 0, sizeof(*snaps
) * *snaps_size
);
6851 if (group_snap_info_size
!= sizeof(rbd_group_snap_info_t
)) {
6853 tracepoint(librbd
, group_snap_list_exit
, -ERANGE
);
6857 std::vector
<librbd::group_snap_info_t
> cpp_snaps
;
6858 int r
= librbd::api::Group
<>::snap_list(group_ioctx
, group_name
, &cpp_snaps
);
6862 tracepoint(librbd
, group_snap_list_exit
, 0);
6867 tracepoint(librbd
, group_snap_list_exit
, r
);
6871 if (*snaps_size
< cpp_snaps
.size()) {
6872 *snaps_size
= cpp_snaps
.size();
6873 tracepoint(librbd
, group_snap_list_exit
, -ERANGE
);
6877 for (size_t i
= 0; i
< cpp_snaps
.size(); ++i
) {
6878 group_snap_info_cpp_to_c(cpp_snaps
[i
], &snaps
[i
]);
6881 r
= *snaps_size
= cpp_snaps
.size();
6882 tracepoint(librbd
, group_snap_list_exit
, r
);
6886 extern "C" int rbd_group_snap_list_cleanup(rbd_group_snap_info_t
*snaps
,
6887 size_t group_snap_info_size
,
6889 if (group_snap_info_size
!= sizeof(rbd_group_snap_info_t
)) {
6893 for (size_t i
= 0; i
< len
; ++i
) {
6894 free(snaps
[i
].name
);
6899 extern "C" int rbd_group_snap_rollback(rados_ioctx_t group_p
,
6900 const char *group_name
,
6901 const char *snap_name
)
6903 librados::IoCtx group_ioctx
;
6904 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6906 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6907 tracepoint(librbd
, group_snap_rollback_enter
,
6908 group_ioctx
.get_pool_name().c_str(),
6909 group_ioctx
.get_id(), group_name
, snap_name
);
6911 librbd::NoOpProgressContext prog_ctx
;
6912 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
6913 snap_name
, prog_ctx
);
6915 tracepoint(librbd
, group_snap_rollback_exit
, r
);
6920 extern "C" int rbd_group_snap_rollback_with_progress(rados_ioctx_t group_p
,
6921 const char *group_name
,
6922 const char *snap_name
,
6923 librbd_progress_fn_t cb
,
6926 librados::IoCtx group_ioctx
;
6927 librados::IoCtx::from_rados_ioctx_t(group_p
, group_ioctx
);
6929 TracepointProvider::initialize
<tracepoint_traits
>(get_cct(group_ioctx
));
6930 tracepoint(librbd
, group_snap_rollback_enter
,
6931 group_ioctx
.get_pool_name().c_str(),
6932 group_ioctx
.get_id(), group_name
, snap_name
);
6934 librbd::CProgressContext
prog_ctx(cb
, cbdata
);
6935 int r
= librbd::api::Group
<>::snap_rollback(group_ioctx
, group_name
,
6936 snap_name
, prog_ctx
);
6938 tracepoint(librbd
, group_snap_rollback_exit
, r
);
6943 extern "C" int rbd_snap_get_namespace_type(rbd_image_t image
,
6945 rbd_snap_namespace_type_t
*namespace_type
) {
6946 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6947 tracepoint(librbd
, snap_get_namespace_type_enter
, ictx
, ictx
->name
.c_str());
6948 int r
= librbd::api::Snapshot
<>::get_namespace_type(ictx
, snap_id
,
6950 tracepoint(librbd
, snap_get_namespace_type_exit
, r
);
6954 extern "C" int rbd_snap_get_group_namespace(rbd_image_t image
, uint64_t snap_id
,
6955 rbd_snap_group_namespace_t
*group_snap
,
6956 size_t snap_group_namespace_size
) {
6957 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6958 tracepoint(librbd
, snap_get_group_namespace_enter
, ictx
,
6959 ictx
->name
.c_str());
6961 if (snap_group_namespace_size
!= sizeof(rbd_snap_group_namespace_t
)) {
6962 tracepoint(librbd
, snap_get_group_namespace_exit
, -ERANGE
);
6966 librbd::snap_group_namespace_t group_namespace
;
6967 int r
= librbd::api::Snapshot
<>::get_group_namespace(ictx
, snap_id
,
6970 group_snap
->group_pool
= group_namespace
.group_pool
;
6971 group_snap
->group_name
= strdup(group_namespace
.group_name
.c_str());
6972 group_snap
->group_snap_name
=
6973 strdup(group_namespace
.group_snap_name
.c_str());
6976 tracepoint(librbd
, snap_get_group_namespace_exit
, r
);
6980 extern "C" int rbd_snap_group_namespace_cleanup(rbd_snap_group_namespace_t
*group_snap
,
6981 size_t snap_group_namespace_size
) {
6982 if (snap_group_namespace_size
!= sizeof(rbd_snap_group_namespace_t
)) {
6986 free(group_snap
->group_name
);
6987 free(group_snap
->group_snap_name
);
6991 extern "C" int rbd_snap_get_trash_namespace(rbd_image_t image
, uint64_t snap_id
,
6992 char *original_name
,
6993 size_t max_length
) {
6994 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
6996 std::string cpp_original_name
;
6997 int r
= librbd::api::Snapshot
<>::get_trash_namespace(ictx
, snap_id
,
6998 &cpp_original_name
);
7003 if (cpp_original_name
.length() >= max_length
) {
7007 strcpy(original_name
, cpp_original_name
.c_str());
7011 extern "C" int rbd_snap_get_mirror_namespace(
7012 rbd_image_t image
, uint64_t snap_id
,
7013 rbd_snap_mirror_namespace_t
*mirror_snap
,
7014 size_t mirror_snap_size
) {
7015 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7017 if (mirror_snap_size
!= sizeof(rbd_snap_mirror_namespace_t
)) {
7021 librbd::snap_mirror_namespace_t mirror_namespace
;
7022 int r
= librbd::api::Snapshot
<>::get_mirror_namespace(
7023 ictx
, snap_id
, &mirror_namespace
);
7028 mirror_snap
->state
= mirror_namespace
.state
;
7029 mirror_snap
->primary_mirror_uuid
=
7030 strdup(mirror_namespace
.primary_mirror_uuid
.c_str());
7031 mirror_snap
->primary_snap_id
= mirror_namespace
.primary_snap_id
;
7032 mirror_snap
->mirror_peer_uuids_count
=
7033 mirror_namespace
.mirror_peer_uuids
.size();
7035 for (auto &peer
: mirror_namespace
.mirror_peer_uuids
) {
7036 len
+= peer
.size() + 1;
7038 mirror_snap
->mirror_peer_uuids
= (char *)malloc(len
);
7039 char *p
= mirror_snap
->mirror_peer_uuids
;
7040 for (auto &peer
: mirror_namespace
.mirror_peer_uuids
) {
7041 strncpy(p
, peer
.c_str(), peer
.size() + 1);
7042 p
+= peer
.size() + 1;
7044 mirror_snap
->complete
= mirror_namespace
.complete
;
7045 mirror_snap
->last_copied_object_number
=
7046 mirror_namespace
.last_copied_object_number
;
7051 extern "C" int rbd_snap_mirror_namespace_cleanup(
7052 rbd_snap_mirror_namespace_t
*mirror_snap
,
7053 size_t mirror_snap_size
) {
7054 if (mirror_snap_size
!= sizeof(rbd_snap_mirror_namespace_t
)) {
7058 free(mirror_snap
->primary_mirror_uuid
);
7059 free(mirror_snap
->mirror_peer_uuids
);
7063 extern "C" int rbd_watchers_list(rbd_image_t image
,
7064 rbd_image_watcher_t
*watchers
,
7065 size_t *max_watchers
) {
7066 std::list
<librbd::image_watcher_t
> watcher_list
;
7067 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7069 tracepoint(librbd
, list_watchers_enter
, ictx
, ictx
->name
.c_str(), ictx
->snap_name
.c_str(), ictx
->read_only
);
7070 // FIPS zeroization audit 20191117: this memset is not security related.
7071 memset(watchers
, 0, sizeof(*watchers
) * *max_watchers
);
7072 int r
= librbd::list_watchers(ictx
, watcher_list
);
7074 tracepoint(librbd
, list_watchers_exit
, r
, 0);
7078 if (watcher_list
.size() > *max_watchers
) {
7079 *max_watchers
= watcher_list
.size();
7080 tracepoint(librbd
, list_watchers_exit
, -ERANGE
, watcher_list
.size());
7085 for (auto &watcher
: watcher_list
) {
7086 tracepoint(librbd
, list_watchers_entry
, watcher
.addr
.c_str(), watcher
.id
, watcher
.cookie
);
7087 watchers
[*max_watchers
].addr
= strdup(watcher
.addr
.c_str());
7088 watchers
[*max_watchers
].id
= watcher
.id
;
7089 watchers
[*max_watchers
].cookie
= watcher
.cookie
;
7093 tracepoint(librbd
, list_watchers_exit
, r
, watcher_list
.size());
7097 extern "C" void rbd_watchers_list_cleanup(rbd_image_watcher_t
*watchers
,
7098 size_t num_watchers
) {
7099 for (size_t i
= 0; i
< num_watchers
; ++i
) {
7100 free(watchers
[i
].addr
);
7104 extern "C" int rbd_config_image_list(rbd_image_t image
,
7105 rbd_config_option_t
*options
,
7107 librbd::ImageCtx
*ictx
= (librbd::ImageCtx
*)image
;
7109 std::vector
<librbd::config_option_t
> option_vector
;
7110 int r
= librbd::api::Config
<>::list(ictx
, &option_vector
);
7115 if (*max_options
< static_cast<int>(option_vector
.size())) {
7116 *max_options
= static_cast<int>(option_vector
.size());
7120 for (int i
= 0; i
< static_cast<int>(option_vector
.size()); ++i
) {
7121 config_option_cpp_to_c(option_vector
[i
], &options
[i
]);
7123 *max_options
= static_cast<int>(option_vector
.size());
7127 extern "C" void rbd_config_image_list_cleanup(rbd_config_option_t
*options
,
7129 for (int i
= 0; i
< max_options
; ++i
) {
7130 config_option_cleanup(options
[i
]);