]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/AsioEngine.cc
1a46b590479d69fa27a3db2f0266b087f5d2446e
[ceph.git] / ceph / src / librbd / AsioEngine.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "librbd/AsioEngine.h"
5 #include "include/Context.h"
6 #include "include/stringify.h"
7 #include "include/neorados/RADOS.hpp"
8 #include "include/rados/librados.hpp"
9 #include "common/dout.h"
10 #include "librbd/asio/ContextWQ.h"
11
12 #define dout_subsys ceph_subsys_rbd
13 #undef dout_prefix
14 #define dout_prefix *_dout << "librbd::AsioEngine: " \
15 << this << " " << __func__ << ": "
16
17 namespace librbd {
18
19 AsioEngine::AsioEngine(std::shared_ptr<librados::Rados> rados)
20 : m_rados_api(std::make_shared<neorados::RADOS>(
21 neorados::RADOS::make_with_librados(*rados))),
22 m_cct(m_rados_api->cct()),
23 m_io_context(m_rados_api->get_io_context()),
24 m_api_strand(std::make_unique<boost::asio::io_context::strand>(
25 m_io_context)),
26 m_context_wq(std::make_unique<asio::ContextWQ>(m_cct, m_io_context)) {
27 ldout(m_cct, 20) << dendl;
28
29 auto rados_threads = m_cct->_conf.get_val<uint64_t>("librados_thread_count");
30 auto rbd_threads = m_cct->_conf.get_val<uint64_t>("rbd_op_threads");
31 if (rbd_threads > rados_threads) {
32 // inherit the librados thread count -- but increase it if librbd wants to
33 // utilize more threads
34 m_cct->_conf.set_val("librados_thread_count", stringify(rbd_threads));
35 }
36 }
37
38 AsioEngine::AsioEngine(librados::IoCtx& io_ctx)
39 : AsioEngine(std::make_shared<librados::Rados>(io_ctx)) {
40 }
41
42 AsioEngine::~AsioEngine() {
43 ldout(m_cct, 20) << dendl;
44 m_api_strand.reset();
45 }
46
47 void AsioEngine::dispatch(Context* ctx, int r) {
48 dispatch([ctx, r]() { ctx->complete(r); });
49 }
50
51 void AsioEngine::post(Context* ctx, int r) {
52 post([ctx, r]() { ctx->complete(r); });
53 }
54
55 } // namespace librbd