summaryrefslogtreecommitdiffstats
path: root/src/librbd/AsioEngine.cc
blob: 8e2beb49cfd91db696e689aeb280d8cf90086c83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "librbd/AsioEngine.h"
#include "include/Context.h"
#include "include/neorados/RADOS.hpp"
#include "include/rados/librados.hpp"
#include "common/dout.h"
#include "librbd/asio/ContextWQ.h"

#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
#define dout_prefix *_dout << "librbd::AsioEngine: " \
                           << this << " " << __func__ << ": "

namespace librbd {

AsioEngine::AsioEngine(std::shared_ptr<librados::Rados> rados)
  : m_rados_api(std::make_shared<neorados::RADOS>(
      neorados::RADOS::make_with_librados(*rados))),
    m_cct(m_rados_api->cct()),
    m_io_context(m_rados_api->get_io_context()),
    m_api_strand(std::make_unique<boost::asio::io_context::strand>(
      m_io_context)),
    m_context_wq(std::make_unique<asio::ContextWQ>(m_cct, m_io_context)) {
  ldout(m_cct, 20) << dendl;

  auto rados_threads = m_cct->_conf.get_val<uint64_t>("librados_thread_count");
  auto rbd_threads = m_cct->_conf.get_val<uint64_t>("rbd_op_threads");
  if (rbd_threads > rados_threads) {
    // inherit the librados thread count -- but increase it if librbd wants to
    // utilize more threads
    m_cct->_conf.set_val_or_die("librados_thread_count",
                                std::to_string(rbd_threads));
    m_cct->_conf.apply_changes(nullptr);
  }
}

AsioEngine::AsioEngine(librados::IoCtx& io_ctx)
  : AsioEngine(std::make_shared<librados::Rados>(io_ctx)) {
}

AsioEngine::~AsioEngine() {
  ldout(m_cct, 20) << dendl;
  m_api_strand.reset();
}

void AsioEngine::dispatch(Context* ctx, int r) {
  dispatch([ctx, r]() { ctx->complete(r); });
}

void AsioEngine::post(Context* ctx, int r) {
  post([ctx, r]() { ctx->complete(r); });
}

} // namespace librbd