Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / bench / rados_backend.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
3 #include "rados_backend.h"
4 #include <boost/tuple/tuple.hpp>
5
6 typedef boost::tuple<Context*, Context*, librados::AioCompletion*> arg_type;
7
8 void on_applied(void *completion, void *_arg) {
9   arg_type *arg = static_cast<arg_type*>(_arg);
10   arg->get<1>()->complete(0);
11 }
12
13 void on_complete(void *completion, void *_arg) {
14   arg_type *arg = static_cast<arg_type*>(_arg);
15   arg->get<0>()->complete(0);
16   arg->get<2>()->release();
17   delete arg;
18 }
19
20 void RadosBackend::write(
21   const string &oid,
22   uint64_t offset,
23   const bufferlist &bl,
24   Context *on_write_applied,
25   Context *on_commit)
26 {
27   librados::AioCompletion *completion = librados::Rados::aio_create_completion();
28
29
30   void *arg = static_cast<void *>(new arg_type(on_commit, on_write_applied,
31                                                completion));
32
33   completion->set_safe_callback(
34     arg,
35     on_complete);
36
37   completion->set_complete_callback(
38     arg,
39     on_applied);
40
41   ioctx->aio_write(oid, completion, bl, bl.length(), offset);
42 }
43
44 void RadosBackend::read(
45   const string &oid,
46   uint64_t offset,
47   uint64_t length,
48   bufferlist *bl,
49   Context *on_read_complete)
50 {
51   librados::AioCompletion *completion = librados::Rados::aio_create_completion();
52
53
54   void *arg = static_cast<void *>(new arg_type(on_read_complete, 0,
55                                                completion));
56
57   completion->set_complete_callback(
58     arg,
59     on_complete);
60
61   ioctx->aio_read(oid, completion, bl, length, offset);
62 }