]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/bench/rbd_backend.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / bench / rbd_backend.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
3 #include "rbd_backend.h"
4 #include <boost/tuple/tuple.hpp>
5
6 typedef boost::tuple<Context*, Context*> arg_type;
7
8 void on_complete(void *completion, void *_arg) {
9 arg_type *arg = static_cast<arg_type*>(_arg);
10 librbd::RBD::AioCompletion *comp =
11 static_cast<librbd::RBD::AioCompletion *>(completion);
12 ssize_t r = comp->get_return_value();
13 assert(r >= 0);
14 arg->get<0>()->complete(0);
15 if (arg->get<1>())
16 arg->get<1>()->complete(0);
17 comp->release();
18 delete arg;
19 }
20
21 void RBDBackend::write(
22 const string &oid,
23 uint64_t offset,
24 const bufferlist &bl,
25 Context *on_write_applied,
26 Context *on_commit)
27 {
28 bufferlist &bl_non_const = const_cast<bufferlist&>(bl);
29 ceph::shared_ptr<librbd::Image> image = (*m_images)[oid];
30 void *arg = static_cast<void *>(new arg_type(on_commit, on_write_applied));
31 librbd::RBD::AioCompletion *completion =
32 new librbd::RBD::AioCompletion(arg, on_complete);
33 int r = image->aio_write(offset, (size_t) bl_non_const.length(),
34 bl_non_const, completion);
35 assert(r >= 0);
36 }
37
38 void RBDBackend::read(
39 const string &oid,
40 uint64_t offset,
41 uint64_t length,
42 bufferlist *bl,
43 Context *on_read_complete)
44 {
45 ceph::shared_ptr<librbd::Image> image = (*m_images)[oid];
46 void *arg = static_cast<void *>(new arg_type(on_read_complete, NULL));
47 librbd::RBD::AioCompletion *completion =
48 new librbd::RBD::AioCompletion(arg, on_complete);
49 int r = image->aio_read(offset, (size_t) length, *bl, completion);
50 assert(r >= 0);
51 }