summaryrefslogtreecommitdiffstats
path: root/src/RADOS/RADOSImpl.cc
blob: 4dd816da5190de159b901f7ce7d985de8e02a191 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2012 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */


#include <boost/system/system_error.hpp>

#include "common/common_init.h"

#include "global/global_init.h"

#include "RADOSImpl.h"

namespace RADOS {
namespace detail {

RADOS::RADOS(boost::asio::io_context& ioctx,
	     boost::intrusive_ptr<CephContext> _cct)
  : Dispatcher(_cct.detach()),
    ioctx(ioctx),
    monclient(cct, ioctx),
    moncsd(monclient),
    mgrclient(cct, nullptr, &monclient.monmap),
    mgrcsd(mgrclient) {
  auto err = monclient.build_initial_monmap();
  if (err < 0)
    throw std::system_error(ceph::to_error_code(err));

  messenger.reset(Messenger::create_client_messenger(cct, "radosclient"));
  if (!messenger)
    throw std::bad_alloc();

  // require OSDREPLYMUX feature.  this means we will fail to talk to
  // old servers.  this is necessary because otherwise we won't know
  // how to decompose the reply data into its constituent pieces.
  messenger->set_default_policy(
    Messenger::Policy::lossy_client(CEPH_FEATURE_OSDREPLYMUX));

  objecter.reset(new Objecter(cct, messenger.get(), &monclient,
			      ioctx,
			      cct->_conf->rados_mon_op_timeout,
			      cct->_conf->rados_osd_op_timeout));

  objecter->set_balanced_budget();
  monclient.set_messenger(messenger.get());
  mgrclient.set_messenger(messenger.get());
  objecter->init();
  messenger->add_dispatcher_head(&mgrclient);
  messenger->add_dispatcher_tail(objecter.get());
  messenger->start();
  monclient.set_want_keys(CEPH_ENTITY_TYPE_MON | CEPH_ENTITY_TYPE_OSD | CEPH_ENTITY_TYPE_MGR);
  err = monclient.init();
  if (err) {
    throw boost::system::system_error(ceph::to_error_code(err));
  }
  err = monclient.authenticate(cct->_conf->client_mount_timeout);
  if (err) {
    throw boost::system::system_error(ceph::to_error_code(err));
  }
  messenger->set_myname(entity_name_t::CLIENT(monclient.get_global_id()));
  // Detect older cluster, put mgrclient into compatible mode
  mgrclient.set_mgr_optional(
      !get_required_monitor_features().contains_all(
        ceph::features::mon::FEATURE_LUMINOUS));

  // MgrClient needs this (it doesn't have MonClient reference itself)
  monclient.sub_want("mgrmap", 0, 0);
  monclient.renew_subs();

  mgrclient.init();
  objecter->set_client_incarnation(0);
  objecter->start();

  messenger->add_dispatcher_tail(this);

  std::unique_lock l(lock);
  instance_id = monclient.get_global_id();
}

bool RADOS::ms_dispatch(Message *m)
{
  switch (m->get_type()) {
  // OSD
  case CEPH_MSG_OSD_MAP:
    m->put();
    return true;
  }
  return false;
}

void RADOS::ms_handle_connect(Connection *con) {}
bool RADOS::ms_handle_reset(Connection *con) {
  return false;
}
void RADOS::ms_handle_remote_reset(Connection *con) {}
bool RADOS::ms_handle_refused(Connection *con) {
  return false;
}

RADOS::~RADOS() = default;
}
}