1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "test/librados_test_stub/LibradosTestStub.h"
5 #include "include/rados/librados.hpp"
6 #include "include/stringify.h"
7 #include "common/ceph_argparse.h"
8 #include "common/ceph_context.h"
9 #include "common/common_init.h"
10 #include "common/config.h"
11 #include "common/debug.h"
12 #include "common/snap_types.h"
13 #include "librados/AioCompletionImpl.h"
15 #include "test/librados_test_stub/TestClassHandler.h"
16 #include "test/librados_test_stub/TestIoCtxImpl.h"
17 #include "test/librados_test_stub/TestRadosClient.h"
18 #include "test/librados_test_stub/TestMemCluster.h"
19 #include "test/librados_test_stub/TestMemRadosClient.h"
20 #include "objclass/objclass.h"
21 #include "osd/osd_types.h"
22 #include <arpa/inet.h>
23 #include <boost/shared_ptr.hpp>
28 #include "include/ceph_assert.h"
29 #include "include/compat.h"
31 #define dout_context g_ceph_context
32 #define dout_subsys ceph_subsys_rados
38 MockTestMemIoCtxImpl
&get_mock_io_ctx(IoCtx
&ioctx
) {
39 MockTestMemIoCtxImpl
**mock
=
40 reinterpret_cast<MockTestMemIoCtxImpl
**>(&ioctx
);
44 } // namespace librados
46 namespace librados_test_stub
{
48 TestClusterRef
&cluster() {
49 static TestClusterRef s_cluster
;
53 void set_cluster(TestClusterRef cluster_ref
) {
54 cluster() = cluster_ref
;
57 TestClusterRef
get_cluster() {
58 auto &cluster_ref
= cluster();
59 if (cluster_ref
.get() == nullptr) {
60 cluster_ref
.reset(new librados::TestMemCluster());
65 librados::TestClassHandler
*get_class_handler() {
66 static boost::shared_ptr
<librados::TestClassHandler
> s_class_handler
;
67 if (!s_class_handler
) {
68 s_class_handler
.reset(new librados::TestClassHandler());
69 s_class_handler
->open_all_classes();
71 return s_class_handler
.get();
74 } // namespace librados_test_stub
78 void do_out_buffer(bufferlist
& outbl
, char **outbuf
, size_t *outbuflen
) {
80 if (outbl
.length() > 0) {
81 *outbuf
= (char *)malloc(outbl
.length());
82 memcpy(*outbuf
, outbl
.c_str(), outbl
.length());
88 *outbuflen
= outbl
.length();
92 void do_out_buffer(string
& outbl
, char **outbuf
, size_t *outbuflen
) {
94 if (outbl
.length() > 0) {
95 *outbuf
= (char *)malloc(outbl
.length());
96 memcpy(*outbuf
, outbl
.c_str(), outbl
.length());
102 *outbuflen
= outbl
.length();
106 librados::TestRadosClient
*create_rados_client() {
107 CephInitParameters
iparams(CEPH_ENTITY_TYPE_CLIENT
);
108 CephContext
*cct
= common_preinit(iparams
, CODE_ENVIRONMENT_LIBRARY
, 0);
109 cct
->_conf
.parse_env(cct
->get_module_type());
110 cct
->_conf
.apply_changes(nullptr);
114 librados_test_stub::get_cluster()->create_rados_client(cct
);
119 } // anonymous namespace
121 extern "C" int rados_aio_create_completion2(void *cb_arg
,
122 rados_callback_t cb_complete
,
123 rados_completion_t
*pc
)
125 librados::AioCompletionImpl
*c
= new librados::AioCompletionImpl
;
127 c
->set_complete_callback(cb_arg
, cb_complete
);
133 extern "C" int rados_aio_get_return_value(rados_completion_t c
) {
134 return reinterpret_cast<librados::AioCompletionImpl
*>(c
)->get_return_value();
137 extern "C" rados_config_t
rados_cct(rados_t cluster
)
139 librados::TestRadosClient
*client
=
140 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
141 return reinterpret_cast<rados_config_t
>(client
->cct());
144 extern "C" int rados_conf_set(rados_t cluster
, const char *option
,
146 librados::TestRadosClient
*impl
=
147 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
148 CephContext
*cct
= impl
->cct();
149 return cct
->_conf
.set_val(option
, value
);
152 extern "C" int rados_conf_parse_env(rados_t cluster
, const char *var
) {
153 librados::TestRadosClient
*client
=
154 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
155 auto& conf
= client
->cct()->_conf
;
156 conf
.parse_env(client
->cct()->get_module_type(), var
);
157 conf
.apply_changes(NULL
);
161 extern "C" int rados_conf_read_file(rados_t cluster
, const char *path
) {
162 librados::TestRadosClient
*client
=
163 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
164 auto& conf
= client
->cct()->_conf
;
165 int ret
= conf
.parse_config_files(path
, NULL
, 0);
167 conf
.parse_env(client
->cct()->get_module_type());
168 conf
.apply_changes(NULL
);
169 conf
.complain_about_parse_error(client
->cct());
170 } else if (ret
== -ENOENT
) {
171 // ignore missing client config
177 extern "C" int rados_connect(rados_t cluster
) {
178 librados::TestRadosClient
*client
=
179 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
180 return client
->connect();
183 extern "C" int rados_create(rados_t
*cluster
, const char * const id
) {
184 *cluster
= create_rados_client();
188 extern "C" int rados_create_with_context(rados_t
*cluster
,
189 rados_config_t cct_
) {
190 auto cct
= reinterpret_cast<CephContext
*>(cct_
);
191 *cluster
= librados_test_stub::get_cluster()->create_rados_client(cct
);
195 extern "C" rados_config_t
rados_ioctx_cct(rados_ioctx_t ioctx
)
197 librados::TestIoCtxImpl
*ctx
=
198 reinterpret_cast<librados::TestIoCtxImpl
*>(ioctx
);
199 return reinterpret_cast<rados_config_t
>(ctx
->get_rados_client()->cct());
202 extern "C" int rados_ioctx_create(rados_t cluster
, const char *pool_name
,
203 rados_ioctx_t
*ioctx
) {
204 librados::TestRadosClient
*client
=
205 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
207 int64_t pool_id
= client
->pool_lookup(pool_name
);
209 return static_cast<int>(pool_id
);
212 *ioctx
= reinterpret_cast<rados_ioctx_t
>(
213 client
->create_ioctx(pool_id
, pool_name
));
217 extern "C" int rados_ioctx_create2(rados_t cluster
, int64_t pool_id
,
218 rados_ioctx_t
*ioctx
)
220 librados::TestRadosClient
*client
=
221 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
223 std::list
<std::pair
<int64_t, std::string
> > pools
;
224 int r
= client
->pool_list(pools
);
229 for (std::list
<std::pair
<int64_t, std::string
> >::iterator it
=
230 pools
.begin(); it
!= pools
.end(); ++it
) {
231 if (it
->first
== pool_id
) {
232 *ioctx
= reinterpret_cast<rados_ioctx_t
>(
233 client
->create_ioctx(pool_id
, it
->second
));
240 extern "C" void rados_ioctx_destroy(rados_ioctx_t io
) {
241 librados::TestIoCtxImpl
*ctx
=
242 reinterpret_cast<librados::TestIoCtxImpl
*>(io
);
246 extern "C" rados_t
rados_ioctx_get_cluster(rados_ioctx_t io
) {
247 librados::TestIoCtxImpl
*ctx
=
248 reinterpret_cast<librados::TestIoCtxImpl
*>(io
);
249 return reinterpret_cast<rados_t
>(ctx
->get_rados_client());
252 extern "C" int rados_mon_command(rados_t cluster
, const char **cmd
,
253 size_t cmdlen
, const char *inbuf
,
254 size_t inbuflen
, char **outbuf
,
255 size_t *outbuflen
, char **outs
,
257 librados::TestRadosClient
*client
=
258 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
260 vector
<string
> cmdvec
;
261 for (size_t i
= 0; i
< cmdlen
; i
++) {
262 cmdvec
.push_back(cmd
[i
]);
266 inbl
.append(inbuf
, inbuflen
);
270 int ret
= client
->mon_command(cmdvec
, inbl
, &outbl
, &outstring
);
272 do_out_buffer(outbl
, outbuf
, outbuflen
);
273 do_out_buffer(outstring
, outs
, outslen
);
277 extern "C" int rados_nobjects_list_open(rados_ioctx_t io
,
278 rados_list_ctx_t
*ctx
) {
279 librados::TestIoCtxImpl
*io_ctx
=
280 reinterpret_cast<librados::TestIoCtxImpl
*>(io
);
281 librados::TestRadosClient
*client
= io_ctx
->get_rados_client();
283 std::list
<librados::TestRadosClient::Object
> *list
=
284 new std::list
<librados::TestRadosClient::Object
>();
286 client
->object_list(io_ctx
->get_id(), list
);
287 list
->push_front(librados::TestRadosClient::Object());
288 *ctx
= reinterpret_cast<rados_list_ctx_t
>(list
);
292 extern "C" int rados_nobjects_list_next(rados_list_ctx_t ctx
,
295 const char **nspace
) {
296 std::list
<librados::TestRadosClient::Object
> *list
=
297 reinterpret_cast<std::list
<librados::TestRadosClient::Object
> *>(ctx
);
298 if (!list
->empty()) {
305 librados::TestRadosClient::Object
&obj
= list
->front();
307 *entry
= obj
.oid
.c_str();
310 *key
= obj
.locator
.c_str();
312 if (nspace
!= NULL
) {
313 *nspace
= obj
.nspace
.c_str();
318 extern "C" void rados_nobjects_list_close(rados_list_ctx_t ctx
) {
319 std::list
<librados::TestRadosClient::Object
> *list
=
320 reinterpret_cast<std::list
<librados::TestRadosClient::Object
> *>(ctx
);
324 extern "C" int rados_pool_create(rados_t cluster
, const char *pool_name
) {
325 librados::TestRadosClient
*client
=
326 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
327 return client
->pool_create(pool_name
);
330 extern "C" int rados_pool_delete(rados_t cluster
, const char *pool_name
) {
331 librados::TestRadosClient
*client
=
332 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
333 return client
->pool_delete(pool_name
);
336 extern "C" void rados_shutdown(rados_t cluster
) {
337 librados::TestRadosClient
*client
=
338 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
342 extern "C" int rados_wait_for_latest_osdmap(rados_t cluster
) {
343 librados::TestRadosClient
*client
=
344 reinterpret_cast<librados::TestRadosClient
*>(cluster
);
345 return client
->wait_for_latest_osdmap();
348 using namespace std::placeholders
;
352 AioCompletion::~AioCompletion()
354 auto c
= reinterpret_cast<AioCompletionImpl
*>(pc
);
358 void AioCompletion::release() {
362 IoCtx::IoCtx() : io_ctx_impl(NULL
) {
369 IoCtx::IoCtx(const IoCtx
& rhs
) {
370 io_ctx_impl
= rhs
.io_ctx_impl
;
372 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
377 IoCtx::IoCtx(IoCtx
&& rhs
) noexcept
: io_ctx_impl(std::exchange(rhs
.io_ctx_impl
, nullptr))
381 IoCtx
& IoCtx::operator=(const IoCtx
& rhs
) {
383 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
387 io_ctx_impl
= rhs
.io_ctx_impl
;
389 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
395 librados::IoCtx
& librados::IoCtx::operator=(IoCtx
&& rhs
) noexcept
398 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
402 io_ctx_impl
= std::exchange(rhs
.io_ctx_impl
, nullptr);
406 int IoCtx::aio_flush() {
407 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
412 int IoCtx::aio_flush_async(AioCompletion
*c
) {
413 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
414 ctx
->aio_flush_async(c
->pc
);
418 int IoCtx::aio_notify(const std::string
& oid
, AioCompletion
*c
, bufferlist
& bl
,
419 uint64_t timeout_ms
, bufferlist
*pbl
) {
420 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
421 ctx
->aio_notify(oid
, c
->pc
, bl
, timeout_ms
, pbl
);
425 int IoCtx::aio_operate(const std::string
& oid
, AioCompletion
*c
,
426 ObjectReadOperation
*op
, bufferlist
*pbl
) {
427 return aio_operate(oid
, c
, op
, 0, pbl
);
430 int IoCtx::aio_operate(const std::string
& oid
, AioCompletion
*c
,
431 ObjectReadOperation
*op
, int flags
,
433 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
434 TestObjectOperationImpl
*ops
= reinterpret_cast<TestObjectOperationImpl
*>(op
->impl
);
435 return ctx
->aio_operate_read(oid
, *ops
, c
->pc
, flags
, pbl
,
436 ctx
->get_snap_read(), nullptr);
439 int IoCtx::aio_operate(const std::string
& oid
, AioCompletion
*c
,
440 ObjectReadOperation
*op
, int flags
,
441 bufferlist
*pbl
, const blkin_trace_info
*trace_info
) {
442 return aio_operate(oid
, c
, op
, flags
, pbl
);
445 int IoCtx::aio_operate(const std::string
& oid
, AioCompletion
*c
,
446 ObjectWriteOperation
*op
) {
447 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
448 TestObjectOperationImpl
*ops
= reinterpret_cast<TestObjectOperationImpl
*>(op
->impl
);
449 return ctx
->aio_operate(oid
, *ops
, c
->pc
, NULL
, 0);
452 int IoCtx::aio_operate(const std::string
& oid
, AioCompletion
*c
,
453 ObjectWriteOperation
*op
, snap_t seq
,
454 std::vector
<snap_t
>& snaps
, int flags
,
455 const blkin_trace_info
*trace_info
) {
456 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
457 TestObjectOperationImpl
*ops
= reinterpret_cast<TestObjectOperationImpl
*>(op
->impl
);
459 std::vector
<snapid_t
> snv
;
460 snv
.resize(snaps
.size());
461 for (size_t i
= 0; i
< snaps
.size(); ++i
)
463 SnapContext
snapc(seq
, snv
);
465 return ctx
->aio_operate(oid
, *ops
, c
->pc
, &snapc
, flags
);
468 int IoCtx::aio_operate(const std::string
& oid
, AioCompletion
*c
,
469 ObjectWriteOperation
*op
, snap_t seq
,
470 std::vector
<snap_t
>& snaps
) {
471 return aio_operate(oid
, c
, op
, seq
, snaps
, 0, nullptr);
474 int IoCtx::aio_operate(const std::string
& oid
, AioCompletion
*c
,
475 ObjectWriteOperation
*op
, snap_t seq
,
476 std::vector
<snap_t
>& snaps
,
477 const blkin_trace_info
*trace_info
) {
478 return aio_operate(oid
, c
, op
, seq
, snaps
, 0, trace_info
);
481 int IoCtx::aio_remove(const std::string
& oid
, AioCompletion
*c
) {
482 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
483 return ctx
->aio_remove(oid
, c
->pc
);
486 int IoCtx::aio_remove(const std::string
& oid
, AioCompletion
*c
, int flags
) {
487 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
488 return ctx
->aio_remove(oid
, c
->pc
, flags
);
491 int IoCtx::aio_watch(const std::string
& o
, AioCompletion
*c
, uint64_t *handle
,
492 librados::WatchCtx2
*watch_ctx
) {
493 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
494 return ctx
->aio_watch(o
, c
->pc
, handle
, watch_ctx
);
497 int IoCtx::aio_unwatch(uint64_t handle
, AioCompletion
*c
) {
498 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
499 return ctx
->aio_unwatch(handle
, c
->pc
);
502 config_t
IoCtx::cct() {
503 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
504 return reinterpret_cast<config_t
>(ctx
->get_rados_client()->cct());
507 void IoCtx::close() {
509 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
515 int IoCtx::create(const std::string
& oid
, bool exclusive
) {
516 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
517 return ctx
->execute_operation(
518 oid
, std::bind(&TestIoCtxImpl::create
, _1
, _2
, exclusive
,
519 ctx
->get_snap_context()));
522 void IoCtx::dup(const IoCtx
& rhs
) {
524 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(rhs
.io_ctx_impl
);
525 io_ctx_impl
= reinterpret_cast<IoCtxImpl
*>(ctx
->clone());
528 int IoCtx::exec(const std::string
& oid
, const char *cls
, const char *method
,
529 bufferlist
& inbl
, bufferlist
& outbl
) {
530 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
531 return ctx
->execute_operation(
532 oid
, std::bind(&TestIoCtxImpl::exec
, _1
, _2
,
533 librados_test_stub::get_class_handler(), cls
,
534 method
, inbl
, &outbl
, ctx
->get_snap_read(),
535 ctx
->get_snap_context()));
538 void IoCtx::from_rados_ioctx_t(rados_ioctx_t p
, IoCtx
&io
) {
539 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(p
);
543 io
.io_ctx_impl
= reinterpret_cast<IoCtxImpl
*>(ctx
);
546 uint64_t IoCtx::get_instance_id() const {
547 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
548 return ctx
->get_instance_id();
551 int64_t IoCtx::get_id() {
552 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
553 return ctx
->get_id();
556 uint64_t IoCtx::get_last_version() {
557 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
558 return ctx
->get_last_version();
561 std::string
IoCtx::get_pool_name() {
562 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
563 return ctx
->get_pool_name();
566 int IoCtx::list_snaps(const std::string
& o
, snap_set_t
*out_snaps
) {
567 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
568 return ctx
->execute_operation(
569 o
, std::bind(&TestIoCtxImpl::list_snaps
, _1
, _2
, out_snaps
));
572 int IoCtx::list_watchers(const std::string
& o
,
573 std::list
<obj_watch_t
> *out_watchers
) {
574 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
575 return ctx
->execute_operation(
576 o
, std::bind(&TestIoCtxImpl::list_watchers
, _1
, _2
, out_watchers
));
579 int IoCtx::notify(const std::string
& o
, uint64_t ver
, bufferlist
& bl
) {
580 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
581 return ctx
->notify(o
, bl
, 0, NULL
);
584 int IoCtx::notify2(const std::string
& o
, bufferlist
& bl
,
585 uint64_t timeout_ms
, bufferlist
*pbl
) {
586 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
587 return ctx
->notify(o
, bl
, timeout_ms
, pbl
);
590 void IoCtx::notify_ack(const std::string
& o
, uint64_t notify_id
,
591 uint64_t handle
, bufferlist
& bl
) {
592 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
593 ctx
->notify_ack(o
, notify_id
, handle
, bl
);
596 int IoCtx::omap_get_vals(const std::string
& oid
,
597 const std::string
& start_after
,
599 std::map
<std::string
, bufferlist
> *out_vals
) {
600 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
601 return ctx
->execute_operation(
602 oid
, std::bind(&TestIoCtxImpl::omap_get_vals
, _1
, _2
, start_after
, "",
603 max_return
, out_vals
));
606 int IoCtx::operate(const std::string
& oid
, ObjectWriteOperation
*op
) {
607 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
608 TestObjectOperationImpl
*ops
= reinterpret_cast<TestObjectOperationImpl
*>(op
->impl
);
609 return ctx
->operate(oid
, *ops
);
612 int IoCtx::operate(const std::string
& oid
, ObjectReadOperation
*op
,
614 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
615 TestObjectOperationImpl
*ops
= reinterpret_cast<TestObjectOperationImpl
*>(op
->impl
);
616 return ctx
->operate_read(oid
, *ops
, pbl
);
619 int IoCtx::read(const std::string
& oid
, bufferlist
& bl
, size_t len
,
621 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
622 return ctx
->execute_operation(
623 oid
, std::bind(&TestIoCtxImpl::read
, _1
, _2
, len
, off
, &bl
,
624 ctx
->get_snap_read(), nullptr));
627 int IoCtx::remove(const std::string
& oid
) {
628 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
629 return ctx
->execute_operation(
630 oid
, std::bind(&TestIoCtxImpl::remove
, _1
, _2
, ctx
->get_snap_context()));
633 int IoCtx::selfmanaged_snap_create(uint64_t *snapid
) {
634 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
635 return ctx
->selfmanaged_snap_create(snapid
);
638 void IoCtx::aio_selfmanaged_snap_create(uint64_t *snapid
, AioCompletion
* c
) {
639 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
640 return ctx
->aio_selfmanaged_snap_create(snapid
, c
->pc
);
643 int IoCtx::selfmanaged_snap_remove(uint64_t snapid
) {
644 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
645 return ctx
->selfmanaged_snap_remove(snapid
);
648 void IoCtx::aio_selfmanaged_snap_remove(uint64_t snapid
, AioCompletion
* c
) {
649 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
650 ctx
->aio_selfmanaged_snap_remove(snapid
, c
->pc
);
653 int IoCtx::selfmanaged_snap_rollback(const std::string
& oid
,
655 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
656 return ctx
->selfmanaged_snap_rollback(oid
, snapid
);
659 int IoCtx::selfmanaged_snap_set_write_ctx(snap_t seq
,
660 std::vector
<snap_t
>& snaps
) {
661 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
662 return ctx
->selfmanaged_snap_set_write_ctx(seq
, snaps
);
665 void IoCtx::snap_set_read(snap_t seq
) {
666 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
667 ctx
->set_snap_read(seq
);
670 int IoCtx::sparse_read(const std::string
& oid
, std::map
<uint64_t,uint64_t>& m
,
671 bufferlist
& bl
, size_t len
, uint64_t off
) {
672 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
673 return ctx
->execute_operation(
674 oid
, std::bind(&TestIoCtxImpl::sparse_read
, _1
, _2
, off
, len
, &m
, &bl
,
675 ctx
->get_snap_read()));
678 int IoCtx::stat(const std::string
& oid
, uint64_t *psize
, time_t *pmtime
) {
679 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
680 return ctx
->execute_operation(
681 oid
, std::bind(&TestIoCtxImpl::stat
, _1
, _2
, psize
, pmtime
));
684 int IoCtx::tmap_update(const std::string
& oid
, bufferlist
& cmdbl
) {
685 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
686 return ctx
->execute_operation(
687 oid
, std::bind(&TestIoCtxImpl::tmap_update
, _1
, _2
, cmdbl
));
690 int IoCtx::trunc(const std::string
& oid
, uint64_t off
) {
691 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
692 return ctx
->execute_operation(
693 oid
, std::bind(&TestIoCtxImpl::truncate
, _1
, _2
, off
,
694 ctx
->get_snap_context()));
697 int IoCtx::unwatch2(uint64_t handle
) {
698 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
699 return ctx
->unwatch(handle
);
702 int IoCtx::unwatch(const std::string
& o
, uint64_t handle
) {
703 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
704 return ctx
->unwatch(handle
);
707 int IoCtx::watch(const std::string
& o
, uint64_t ver
, uint64_t *handle
,
708 librados::WatchCtx
*wctx
) {
709 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
710 return ctx
->watch(o
, handle
, wctx
, NULL
);
713 int IoCtx::watch2(const std::string
& o
, uint64_t *handle
,
714 librados::WatchCtx2
*wctx
) {
715 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
716 return ctx
->watch(o
, handle
, NULL
, wctx
);
719 int IoCtx::write(const std::string
& oid
, bufferlist
& bl
, size_t len
,
721 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
722 return ctx
->execute_operation(
723 oid
, std::bind(&TestIoCtxImpl::write
, _1
, _2
, bl
, len
, off
,
724 ctx
->get_snap_context()));
727 int IoCtx::write_full(const std::string
& oid
, bufferlist
& bl
) {
728 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
729 return ctx
->execute_operation(
730 oid
, std::bind(&TestIoCtxImpl::write_full
, _1
, _2
, bl
,
731 ctx
->get_snap_context()));
734 int IoCtx::writesame(const std::string
& oid
, bufferlist
& bl
, size_t len
,
736 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
737 return ctx
->execute_operation(
738 oid
, std::bind(&TestIoCtxImpl::writesame
, _1
, _2
, bl
, len
, off
,
739 ctx
->get_snap_context()));
742 int IoCtx::cmpext(const std::string
& oid
, uint64_t off
, bufferlist
& cmp_bl
) {
743 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
744 return ctx
->execute_operation(
745 oid
, std::bind(&TestIoCtxImpl::cmpext
, _1
, _2
, off
, cmp_bl
,
746 ctx
->get_snap_read()));
749 int IoCtx::application_enable(const std::string
& app_name
, bool force
) {
753 int IoCtx::application_enable_async(const std::string
& app_name
,
754 bool force
, PoolAsyncCompletion
*c
) {
758 int IoCtx::application_list(std::set
<std::string
> *app_names
) {
762 int IoCtx::application_metadata_get(const std::string
& app_name
,
763 const std::string
&key
,
764 std::string
*value
) {
768 int IoCtx::application_metadata_set(const std::string
& app_name
,
769 const std::string
&key
,
770 const std::string
& value
) {
774 int IoCtx::application_metadata_remove(const std::string
& app_name
,
775 const std::string
&key
) {
779 int IoCtx::application_metadata_list(const std::string
& app_name
,
780 std::map
<std::string
, std::string
> *values
) {
784 void IoCtx::set_namespace(const std::string
& nspace
) {
785 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
786 ctx
->set_namespace(nspace
);
789 std::string
IoCtx::get_namespace() const {
790 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(io_ctx_impl
);
791 return ctx
->get_namespace();
794 void IoCtx::set_pool_full_try() {
797 bool IoCtx::get_pool_full_try() {
801 static int save_operation_result(int result
, int *pval
) {
808 ObjectOperation::ObjectOperation() {
809 TestObjectOperationImpl
*o
= new TestObjectOperationImpl();
811 impl
= reinterpret_cast<ObjectOperationImpl
*>(o
);
814 ObjectOperation::~ObjectOperation() {
815 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
822 void ObjectOperation::assert_exists() {
823 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
824 o
->ops
.push_back(std::bind(&TestIoCtxImpl::assert_exists
, _1
, _2
, _4
));
827 void ObjectOperation::assert_version(uint64_t ver
) {
828 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
829 o
->ops
.push_back(std::bind(&TestIoCtxImpl::assert_version
, _1
, _2
, ver
));
832 void ObjectOperation::exec(const char *cls
, const char *method
,
834 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
835 o
->ops
.push_back(std::bind(&TestIoCtxImpl::exec
, _1
, _2
,
836 librados_test_stub::get_class_handler(), cls
,
837 method
, inbl
, _3
, _4
, _5
));
840 void ObjectOperation::set_op_flags2(int flags
) {
843 size_t ObjectOperation::size() {
844 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
845 return o
->ops
.size();
848 void ObjectOperation::cmpext(uint64_t off
, const bufferlist
& cmp_bl
,
850 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
851 ObjectOperationTestImpl op
= std::bind(&TestIoCtxImpl::cmpext
, _1
, _2
, off
,
854 op
= std::bind(save_operation_result
,
855 std::bind(op
, _1
, _2
, _3
, _4
, _5
, _6
), prval
);
857 o
->ops
.push_back(op
);
860 void ObjectReadOperation::list_snaps(snap_set_t
*out_snaps
, int *prval
) {
861 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
863 ObjectOperationTestImpl op
= std::bind(&TestIoCtxImpl::list_snaps
, _1
, _2
,
866 op
= std::bind(save_operation_result
,
867 std::bind(op
, _1
, _2
, _3
, _4
, _5
, _6
), prval
);
869 o
->ops
.push_back(op
);
872 void ObjectReadOperation::list_watchers(std::list
<obj_watch_t
> *out_watchers
,
874 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
876 ObjectOperationTestImpl op
= std::bind(&TestIoCtxImpl::list_watchers
, _1
,
879 op
= std::bind(save_operation_result
,
880 std::bind(op
, _1
, _2
, _3
, _4
, _5
, _6
), prval
);
882 o
->ops
.push_back(op
);
885 void ObjectReadOperation::read(size_t off
, uint64_t len
, bufferlist
*pbl
,
887 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
889 ObjectOperationTestImpl op
;
891 op
= std::bind(&TestIoCtxImpl::read
, _1
, _2
, len
, off
, pbl
, _4
, nullptr);
893 op
= std::bind(&TestIoCtxImpl::read
, _1
, _2
, len
, off
, _3
, _4
, nullptr);
897 op
= std::bind(save_operation_result
,
898 std::bind(op
, _1
, _2
, _3
, _4
, _5
, _6
), prval
);
900 o
->ops
.push_back(op
);
903 void ObjectReadOperation::sparse_read(uint64_t off
, uint64_t len
,
904 std::map
<uint64_t,uint64_t> *m
,
905 bufferlist
*pbl
, int *prval
) {
906 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
908 ObjectOperationTestImpl op
;
910 op
= std::bind(&TestIoCtxImpl::sparse_read
, _1
, _2
, off
, len
, m
, pbl
, _4
);
912 op
= std::bind(&TestIoCtxImpl::sparse_read
, _1
, _2
, off
, len
, m
, _3
, _4
);
916 op
= std::bind(save_operation_result
,
917 std::bind(op
, _1
, _2
, _3
, _4
, _5
, _6
), prval
);
919 o
->ops
.push_back(op
);
922 void ObjectReadOperation::stat(uint64_t *psize
, time_t *pmtime
, int *prval
) {
923 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
925 ObjectOperationTestImpl op
= std::bind(&TestIoCtxImpl::stat
, _1
, _2
,
929 op
= std::bind(save_operation_result
,
930 std::bind(op
, _1
, _2
, _3
, _4
, _5
, _6
), prval
);
932 o
->ops
.push_back(op
);
935 void ObjectWriteOperation::append(const bufferlist
&bl
) {
936 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
937 o
->ops
.push_back(std::bind(&TestIoCtxImpl::append
, _1
, _2
, bl
, _5
));
940 void ObjectWriteOperation::create(bool exclusive
) {
941 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
942 o
->ops
.push_back(std::bind(&TestIoCtxImpl::create
, _1
, _2
, exclusive
, _5
));
945 void ObjectWriteOperation::omap_set(const std::map
<std::string
, bufferlist
> &map
) {
946 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
947 o
->ops
.push_back(std::bind(&TestIoCtxImpl::omap_set
, _1
, _2
, boost::ref(map
)));
950 void ObjectWriteOperation::remove() {
951 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
952 o
->ops
.push_back(std::bind(&TestIoCtxImpl::remove
, _1
, _2
, _5
));
955 void ObjectWriteOperation::selfmanaged_snap_rollback(uint64_t snapid
) {
956 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
957 o
->ops
.push_back(std::bind(&TestIoCtxImpl::selfmanaged_snap_rollback
,
961 void ObjectWriteOperation::set_alloc_hint(uint64_t expected_object_size
,
962 uint64_t expected_write_size
) {
963 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
964 o
->ops
.push_back(std::bind(&TestIoCtxImpl::set_alloc_hint
, _1
, _2
,
965 expected_object_size
, expected_write_size
, 0,
969 void ObjectWriteOperation::set_alloc_hint2(uint64_t expected_object_size
,
970 uint64_t expected_write_size
,
972 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
973 o
->ops
.push_back(std::bind(&TestIoCtxImpl::set_alloc_hint
, _1
, _2
,
974 expected_object_size
, expected_write_size
, flags
,
978 void ObjectWriteOperation::tmap_update(const bufferlist
& cmdbl
) {
979 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
980 o
->ops
.push_back(std::bind(&TestIoCtxImpl::tmap_update
, _1
, _2
,
984 void ObjectWriteOperation::truncate(uint64_t off
) {
985 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
986 o
->ops
.push_back(std::bind(&TestIoCtxImpl::truncate
, _1
, _2
, off
, _5
));
989 void ObjectWriteOperation::write(uint64_t off
, const bufferlist
& bl
) {
990 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
991 o
->ops
.push_back(std::bind(&TestIoCtxImpl::write
, _1
, _2
, bl
, bl
.length(),
995 void ObjectWriteOperation::write_full(const bufferlist
& bl
) {
996 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
997 o
->ops
.push_back(std::bind(&TestIoCtxImpl::write_full
, _1
, _2
, bl
, _5
));
1000 void ObjectWriteOperation::writesame(uint64_t off
, uint64_t len
,
1001 const bufferlist
& bl
) {
1002 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
1003 o
->ops
.push_back(std::bind(&TestIoCtxImpl::writesame
, _1
, _2
, bl
, len
,
1007 void ObjectWriteOperation::zero(uint64_t off
, uint64_t len
) {
1008 TestObjectOperationImpl
*o
= reinterpret_cast<TestObjectOperationImpl
*>(impl
);
1009 o
->ops
.push_back(std::bind(&TestIoCtxImpl::zero
, _1
, _2
, off
, len
, _5
));
1012 Rados::Rados() : client(NULL
) {
1015 Rados::Rados(IoCtx
& ioctx
) {
1016 TestIoCtxImpl
*ctx
= reinterpret_cast<TestIoCtxImpl
*>(ioctx
.io_ctx_impl
);
1017 TestRadosClient
*impl
= ctx
->get_rados_client();
1020 client
= reinterpret_cast<RadosClient
*>(impl
);
1021 ceph_assert(client
!= NULL
);
1028 void Rados::from_rados_t(rados_t p
, Rados
&rados
) {
1029 if (rados
.client
!= nullptr) {
1030 reinterpret_cast<TestRadosClient
*>(rados
.client
)->put();
1031 rados
.client
= nullptr;
1034 auto impl
= reinterpret_cast<TestRadosClient
*>(p
);
1037 rados
.client
= reinterpret_cast<RadosClient
*>(impl
);
1041 AioCompletion
*Rados::aio_create_completion(void *cb_arg
,
1042 callback_t cb_complete
) {
1043 AioCompletionImpl
*c
;
1044 int r
= rados_aio_create_completion2(cb_arg
, cb_complete
,
1045 reinterpret_cast<void**>(&c
));
1046 ceph_assert(r
== 0);
1047 return new AioCompletion(c
);
1050 int Rados::aio_watch_flush(AioCompletion
* c
) {
1051 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1052 return impl
->aio_watch_flush(c
->pc
);
1055 int Rados::blocklist_add(const std::string
& client_address
,
1056 uint32_t expire_seconds
) {
1057 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1058 return impl
->blocklist_add(client_address
, expire_seconds
);
1061 config_t
Rados::cct() {
1062 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1063 return reinterpret_cast<config_t
>(impl
->cct());
1066 int Rados::cluster_fsid(std::string
* fsid
) {
1067 *fsid
= "00000000-1111-2222-3333-444444444444";
1071 int Rados::conf_set(const char *option
, const char *value
) {
1072 return rados_conf_set(reinterpret_cast<rados_t
>(client
), option
, value
);
1075 int Rados::conf_get(const char *option
, std::string
&val
) {
1076 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1077 CephContext
*cct
= impl
->cct();
1080 int ret
= cct
->_conf
.get_val(option
, &str
, -1);
1091 int Rados::conf_parse_env(const char *env
) const {
1092 return rados_conf_parse_env(reinterpret_cast<rados_t
>(client
), env
);
1095 int Rados::conf_read_file(const char * const path
) const {
1096 return rados_conf_read_file(reinterpret_cast<rados_t
>(client
), path
);
1099 int Rados::connect() {
1100 return rados_connect(reinterpret_cast<rados_t
>(client
));
1103 uint64_t Rados::get_instance_id() {
1104 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1105 return impl
->get_instance_id();
1108 int Rados::get_min_compatible_osd(int8_t* require_osd_release
) {
1109 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1110 return impl
->get_min_compatible_osd(require_osd_release
);
1113 int Rados::get_min_compatible_client(int8_t* min_compat_client
,
1114 int8_t* require_min_compat_client
) {
1115 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1116 return impl
->get_min_compatible_client(min_compat_client
,
1117 require_min_compat_client
);
1120 int Rados::init(const char * const id
) {
1121 return rados_create(reinterpret_cast<rados_t
*>(&client
), id
);
1124 int Rados::init_with_context(config_t cct_
) {
1125 return rados_create_with_context(reinterpret_cast<rados_t
*>(&client
), cct_
);
1128 int Rados::ioctx_create(const char *name
, IoCtx
&io
) {
1130 int ret
= rados_ioctx_create(reinterpret_cast<rados_t
>(client
), name
, &p
);
1136 io
.io_ctx_impl
= reinterpret_cast<IoCtxImpl
*>(p
);
1140 int Rados::ioctx_create2(int64_t pool_id
, IoCtx
&io
)
1143 int ret
= rados_ioctx_create2(reinterpret_cast<rados_t
>(client
), pool_id
, &p
);
1149 io
.io_ctx_impl
= reinterpret_cast<IoCtxImpl
*>(p
);
1153 int Rados::mon_command(std::string cmd
, const bufferlist
& inbl
,
1154 bufferlist
*outbl
, std::string
*outs
) {
1155 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1157 std::vector
<std::string
> cmds
;
1158 cmds
.push_back(cmd
);
1159 return impl
->mon_command(cmds
, inbl
, outbl
, outs
);
1162 int Rados::service_daemon_register(const std::string
& service
,
1163 const std::string
& name
,
1164 const std::map
<std::string
,std::string
>& metadata
) {
1165 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1166 return impl
->service_daemon_register(service
, name
, metadata
);
1169 int Rados::service_daemon_update_status(std::map
<std::string
,std::string
>&& status
) {
1170 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1171 return impl
->service_daemon_update_status(std::move(status
));
1174 int Rados::pool_create(const char *name
) {
1175 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1176 return impl
->pool_create(name
);
1179 int Rados::pool_delete(const char *name
) {
1180 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1181 return impl
->pool_delete(name
);
1184 int Rados::pool_get_base_tier(int64_t pool
, int64_t* base_tier
) {
1185 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1186 return impl
->pool_get_base_tier(pool
, base_tier
);
1189 int Rados::pool_list(std::list
<std::string
>& v
) {
1190 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1191 std::list
<std::pair
<int64_t, std::string
> > pools
;
1192 int r
= impl
->pool_list(pools
);
1198 for (std::list
<std::pair
<int64_t, std::string
> >::iterator it
= pools
.begin();
1199 it
!= pools
.end(); ++it
) {
1200 v
.push_back(it
->second
);
1205 int Rados::pool_list2(std::list
<std::pair
<int64_t, std::string
> >& v
)
1207 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1208 return impl
->pool_list(v
);
1211 int64_t Rados::pool_lookup(const char *name
) {
1212 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1213 return impl
->pool_lookup(name
);
1216 int Rados::pool_reverse_lookup(int64_t id
, std::string
*name
) {
1217 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1218 return impl
->pool_reverse_lookup(id
, name
);
1221 void Rados::shutdown() {
1222 if (client
== NULL
) {
1225 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1230 void Rados::test_blocklist_self(bool set
) {
1233 int Rados::wait_for_latest_osdmap() {
1234 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1235 return impl
->wait_for_latest_osdmap();
1238 int Rados::watch_flush() {
1239 TestRadosClient
*impl
= reinterpret_cast<TestRadosClient
*>(client
);
1240 return impl
->watch_flush();
1243 WatchCtx::~WatchCtx() {
1246 WatchCtx2::~WatchCtx2() {
1249 } // namespace librados
1251 int cls_cxx_create(cls_method_context_t hctx
, bool exclusive
) {
1252 librados::TestClassHandler::MethodContext
*ctx
=
1253 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1254 return ctx
->io_ctx_impl
->create(ctx
->oid
, exclusive
, ctx
->snapc
);
1257 int cls_cxx_remove(cls_method_context_t hctx
) {
1258 librados::TestClassHandler::MethodContext
*ctx
=
1259 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1260 return ctx
->io_ctx_impl
->remove(ctx
->oid
, ctx
->io_ctx_impl
->get_snap_context());
1263 int cls_get_request_origin(cls_method_context_t hctx
, entity_inst_t
*origin
) {
1264 librados::TestClassHandler::MethodContext
*ctx
=
1265 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1267 librados::TestRadosClient
*rados_client
=
1268 ctx
->io_ctx_impl
->get_rados_client();
1270 struct sockaddr_in sin
;
1271 memset(&sin
, 0, sizeof(sin
));
1272 sin
.sin_family
= AF_INET
;
1274 inet_pton(AF_INET
, "127.0.0.1", &sin
.sin_addr
);
1276 entity_addr_t
entity_addr(entity_addr_t::TYPE_DEFAULT
,
1277 rados_client
->get_nonce());
1278 entity_addr
.in4_addr() = sin
;
1280 *origin
= entity_inst_t(
1281 entity_name_t::CLIENT(rados_client
->get_instance_id()),
1286 int cls_cxx_getxattr(cls_method_context_t hctx
, const char *name
,
1287 bufferlist
*outbl
) {
1288 std::map
<string
, bufferlist
> attrs
;
1289 int r
= cls_cxx_getxattrs(hctx
, &attrs
);
1294 std::map
<string
, bufferlist
>::iterator it
= attrs
.find(name
);
1295 if (it
== attrs
.end()) {
1298 *outbl
= it
->second
;
1302 int cls_cxx_getxattrs(cls_method_context_t hctx
, std::map
<string
, bufferlist
> *attrset
) {
1303 librados::TestClassHandler::MethodContext
*ctx
=
1304 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1305 return ctx
->io_ctx_impl
->xattr_get(ctx
->oid
, attrset
);
1308 int cls_cxx_map_get_keys(cls_method_context_t hctx
, const string
&start_obj
,
1309 uint64_t max_to_get
, std::set
<string
> *keys
, bool *more
) {
1310 librados::TestClassHandler::MethodContext
*ctx
=
1311 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1314 std::map
<string
, bufferlist
> vals
;
1315 int r
= ctx
->io_ctx_impl
->omap_get_vals2(ctx
->oid
, start_obj
, "", max_to_get
,
1321 for (std::map
<string
, bufferlist
>::iterator it
= vals
.begin();
1322 it
!= vals
.end(); ++it
) {
1323 keys
->insert(it
->first
);
1325 return keys
->size();
1328 int cls_cxx_map_get_val(cls_method_context_t hctx
, const string
&key
,
1329 bufferlist
*outbl
) {
1330 librados::TestClassHandler::MethodContext
*ctx
=
1331 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1333 std::map
<string
, bufferlist
> vals
;
1334 int r
= ctx
->io_ctx_impl
->omap_get_vals(ctx
->oid
, "", key
, 1024, &vals
);
1339 std::map
<string
, bufferlist
>::iterator it
= vals
.find(key
);
1340 if (it
== vals
.end()) {
1344 *outbl
= it
->second
;
1348 int cls_cxx_map_get_vals(cls_method_context_t hctx
, const string
&start_obj
,
1349 const string
&filter_prefix
, uint64_t max_to_get
,
1350 std::map
<string
, bufferlist
> *vals
, bool *more
) {
1351 librados::TestClassHandler::MethodContext
*ctx
=
1352 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1353 int r
= ctx
->io_ctx_impl
->omap_get_vals2(ctx
->oid
, start_obj
, filter_prefix
,
1354 max_to_get
, vals
, more
);
1358 return vals
->size();
1361 int cls_cxx_map_remove_key(cls_method_context_t hctx
, const string
&key
) {
1362 std::set
<std::string
> keys
;
1365 librados::TestClassHandler::MethodContext
*ctx
=
1366 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1367 return ctx
->io_ctx_impl
->omap_rm_keys(ctx
->oid
, keys
);
1370 int cls_cxx_map_set_val(cls_method_context_t hctx
, const string
&key
,
1372 std::map
<std::string
, bufferlist
> m
;
1374 return cls_cxx_map_set_vals(hctx
, &m
);
1377 int cls_cxx_map_set_vals(cls_method_context_t hctx
,
1378 const std::map
<string
, bufferlist
> *map
) {
1379 librados::TestClassHandler::MethodContext
*ctx
=
1380 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1381 return ctx
->io_ctx_impl
->omap_set(ctx
->oid
, *map
);
1384 int cls_cxx_read(cls_method_context_t hctx
, int ofs
, int len
,
1385 bufferlist
*outbl
) {
1386 return cls_cxx_read2(hctx
, ofs
, len
, outbl
, 0);
1389 int cls_cxx_read2(cls_method_context_t hctx
, int ofs
, int len
,
1390 bufferlist
*outbl
, uint32_t op_flags
) {
1391 librados::TestClassHandler::MethodContext
*ctx
=
1392 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1393 return ctx
->io_ctx_impl
->read(
1394 ctx
->oid
, len
, ofs
, outbl
, ctx
->snap_id
, nullptr);
1397 int cls_cxx_setxattr(cls_method_context_t hctx
, const char *name
,
1399 librados::TestClassHandler::MethodContext
*ctx
=
1400 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1401 return ctx
->io_ctx_impl
->xattr_set(ctx
->oid
, name
, *inbl
);
1404 int cls_cxx_stat(cls_method_context_t hctx
, uint64_t *size
, time_t *mtime
) {
1405 librados::TestClassHandler::MethodContext
*ctx
=
1406 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1407 return ctx
->io_ctx_impl
->stat(ctx
->oid
, size
, mtime
);
1410 int cls_cxx_write(cls_method_context_t hctx
, int ofs
, int len
,
1412 return cls_cxx_write2(hctx
, ofs
, len
, inbl
, 0);
1415 int cls_cxx_write2(cls_method_context_t hctx
, int ofs
, int len
,
1416 bufferlist
*inbl
, uint32_t op_flags
) {
1417 librados::TestClassHandler::MethodContext
*ctx
=
1418 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1419 return ctx
->io_ctx_impl
->write(ctx
->oid
, *inbl
, len
, ofs
, ctx
->snapc
);
1422 int cls_cxx_write_full(cls_method_context_t hctx
, bufferlist
*inbl
) {
1423 librados::TestClassHandler::MethodContext
*ctx
=
1424 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1425 return ctx
->io_ctx_impl
->write_full(ctx
->oid
, *inbl
, ctx
->snapc
);
1428 int cls_cxx_replace(cls_method_context_t hctx
, int ofs
, int len
,
1430 librados::TestClassHandler::MethodContext
*ctx
=
1431 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1432 int r
= ctx
->io_ctx_impl
->truncate(ctx
->oid
, 0, ctx
->snapc
);
1436 return ctx
->io_ctx_impl
->write(ctx
->oid
, *inbl
, len
, ofs
, ctx
->snapc
);
1439 int cls_cxx_truncate(cls_method_context_t hctx
, int ofs
) {
1440 librados::TestClassHandler::MethodContext
*ctx
=
1441 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1442 return ctx
->io_ctx_impl
->truncate(ctx
->oid
, ofs
, ctx
->snapc
);
1445 int cls_cxx_write_zero(cls_method_context_t hctx
, int ofs
, int len
) {
1446 librados::TestClassHandler::MethodContext
*ctx
=
1447 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1448 return ctx
->io_ctx_impl
->zero(ctx
->oid
, len
, ofs
, ctx
->snapc
);
1451 int cls_cxx_list_watchers(cls_method_context_t hctx
,
1452 obj_list_watch_response_t
*watchers
) {
1453 librados::TestClassHandler::MethodContext
*ctx
=
1454 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1456 std::list
<obj_watch_t
> obj_watchers
;
1457 int r
= ctx
->io_ctx_impl
->list_watchers(ctx
->oid
, &obj_watchers
);
1462 for (auto &w
: obj_watchers
) {
1463 watch_item_t watcher
;
1464 watcher
.name
= entity_name_t::CLIENT(w
.watcher_id
);
1465 watcher
.cookie
= w
.cookie
;
1466 watcher
.timeout_seconds
= w
.timeout_seconds
;
1467 watcher
.addr
.parse(w
.addr
);
1468 watchers
->entries
.push_back(watcher
);
1474 uint64_t cls_get_features(cls_method_context_t hctx
) {
1475 return CEPH_FEATURES_SUPPORTED_DEFAULT
;
1478 uint64_t cls_get_client_features(cls_method_context_t hctx
) {
1479 return CEPH_FEATURES_SUPPORTED_DEFAULT
;
1482 int cls_get_snapset_seq(cls_method_context_t hctx
, uint64_t *snap_seq
) {
1483 librados::TestClassHandler::MethodContext
*ctx
=
1484 reinterpret_cast<librados::TestClassHandler::MethodContext
*>(hctx
);
1485 librados::snap_set_t snapset
;
1486 int r
= ctx
->io_ctx_impl
->list_snaps(ctx
->oid
, &snapset
);
1491 *snap_seq
= snapset
.seq
;
1495 int cls_log(int level
, const char *format
, ...) {
1500 va_start(ap
, format
);
1501 int n
= vsnprintf(buf
, size
, format
, ap
);
1503 if ((n
> -1 && n
< size
) || size
> 8196) {
1504 dout(ceph::dout::need_dynamic(level
)) << buf
<< dendl
;
1512 int cls_register(const char *name
, cls_handle_t
*handle
) {
1513 librados::TestClassHandler
*cls
= librados_test_stub::get_class_handler();
1514 return cls
->create(name
, handle
);
1517 int cls_register_cxx_method(cls_handle_t hclass
, const char *method
,
1519 cls_method_cxx_call_t class_call
,
1520 cls_method_handle_t
*handle
) {
1521 librados::TestClassHandler
*cls
= librados_test_stub::get_class_handler();
1522 return cls
->create_method(hclass
, method
, class_call
, handle
);
1525 int cls_register_cxx_filter(cls_handle_t hclass
,
1526 const std::string
&filter_name
,
1527 cls_cxx_filter_factory_t fn
,
1528 cls_filter_handle_t
*)
1530 librados::TestClassHandler
*cls
= librados_test_stub::get_class_handler();
1531 return cls
->create_filter(hclass
, filter_name
, fn
);
1534 ceph_release_t
cls_get_required_osd_release(cls_handle_t hclass
) {
1535 return ceph_release_t::nautilus
;
1538 ceph_release_t
cls_get_min_compatible_client(cls_handle_t hclass
) {
1539 return ceph_release_t::nautilus
;
1542 // stubs to silence TestClassHandler::open_class()
1543 PGLSFilter::~PGLSFilter()
1546 int cls_gen_rand_base64(char *, int) {
1550 int cls_cxx_chunk_write_and_set(cls_method_handle_t
, int,
1552 uint32_t, bufferlist
*, int) {
1556 int cls_cxx_map_read_header(cls_method_handle_t
, bufferlist
*) {
1560 uint64_t cls_get_osd_min_alloc_size(cls_method_context_t hctx
) {
1564 uint64_t cls_get_pool_stripe_width(cls_method_context_t hctx
) {