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
113
114
115
116
117
118
119
120
121
|
// -*- 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 neorados {
namespace detail {
RADOS::RADOS(boost::asio::io_context& ioctx,
boost::intrusive_ptr<CephContext> cct)
: Dispatcher(cct.get()),
ioctx(ioctx),
cct(cct),
monclient(cct.get(), ioctx),
mgrclient(cct.get(), nullptr, &monclient.monmap) {
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.get(), "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 = std::make_unique<Objecter>(cct.get(), messenger.get(), &monclient, ioctx);
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(std::chrono::duration<double>(cct->_conf.get_val<std::chrono::seconds>("client_mount_timeout")).count());
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();
}
RADOS::~RADOS() {
if (objecter && objecter->initialized) {
objecter->shutdown();
}
mgrclient.shutdown();
monclient.shutdown();
if (messenger) {
messenger->shutdown();
messenger->wait();
}
}
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;
}
} // namespace detail
} // namespace neorados
|