]>
Commit | Line | Data |
---|---|---|
f91f0fd5 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2012 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | ||
16 | #include <boost/system/system_error.hpp> | |
17 | ||
18 | #include "common/common_init.h" | |
19 | ||
20 | #include "global/global_init.h" | |
21 | ||
22 | #include "RADOSImpl.h" | |
23 | ||
24 | namespace neorados { | |
25 | namespace detail { | |
26 | ||
27 | RADOS::RADOS(boost::asio::io_context& ioctx, | |
28 | boost::intrusive_ptr<CephContext> cct) | |
29 | : Dispatcher(cct.get()), | |
30 | ioctx(ioctx), | |
31 | cct(cct), | |
32 | monclient(cct.get(), ioctx), | |
33 | mgrclient(cct.get(), nullptr, &monclient.monmap) { | |
34 | auto err = monclient.build_initial_monmap(); | |
35 | if (err < 0) | |
36 | throw std::system_error(ceph::to_error_code(err)); | |
37 | ||
38 | messenger.reset(Messenger::create_client_messenger(cct.get(), "radosclient")); | |
39 | if (!messenger) | |
40 | throw std::bad_alloc(); | |
41 | ||
42 | // Require OSDREPLYMUX feature. This means we will fail to talk to | |
43 | // old servers. This is necessary because otherwise we won't know | |
44 | // how to decompose the reply data into its constituent pieces. | |
45 | messenger->set_default_policy( | |
46 | Messenger::Policy::lossy_client(CEPH_FEATURE_OSDREPLYMUX)); | |
47 | ||
48 | objecter = std::make_unique<Objecter>(cct.get(), messenger.get(), &monclient, ioctx); | |
49 | ||
50 | objecter->set_balanced_budget(); | |
51 | monclient.set_messenger(messenger.get()); | |
52 | mgrclient.set_messenger(messenger.get()); | |
53 | objecter->init(); | |
54 | messenger->add_dispatcher_head(&mgrclient); | |
55 | messenger->add_dispatcher_tail(objecter.get()); | |
56 | messenger->start(); | |
57 | monclient.set_want_keys(CEPH_ENTITY_TYPE_MON | CEPH_ENTITY_TYPE_OSD | CEPH_ENTITY_TYPE_MGR); | |
58 | err = monclient.init(); | |
59 | if (err) { | |
60 | throw boost::system::system_error(ceph::to_error_code(err)); | |
61 | } | |
2a845540 | 62 | err = monclient.authenticate(std::chrono::duration<double>(cct->_conf.get_val<std::chrono::seconds>("client_mount_timeout")).count()); |
f91f0fd5 TL |
63 | if (err) { |
64 | throw boost::system::system_error(ceph::to_error_code(err)); | |
65 | } | |
66 | messenger->set_myname(entity_name_t::CLIENT(monclient.get_global_id())); | |
67 | // Detect older cluster, put mgrclient into compatible mode | |
68 | mgrclient.set_mgr_optional( | |
69 | !get_required_monitor_features().contains_all( | |
70 | ceph::features::mon::FEATURE_LUMINOUS)); | |
71 | ||
72 | // MgrClient needs this (it doesn't have MonClient reference itself) | |
73 | monclient.sub_want("mgrmap", 0, 0); | |
74 | monclient.renew_subs(); | |
75 | ||
76 | mgrclient.init(); | |
77 | objecter->set_client_incarnation(0); | |
78 | objecter->start(); | |
79 | ||
80 | messenger->add_dispatcher_tail(this); | |
81 | ||
82 | std::unique_lock l(lock); | |
83 | instance_id = monclient.get_global_id(); | |
84 | } | |
85 | ||
86 | RADOS::~RADOS() { | |
87 | if (objecter && objecter->initialized) { | |
88 | objecter->shutdown(); | |
89 | } | |
90 | ||
91 | mgrclient.shutdown(); | |
92 | monclient.shutdown(); | |
93 | ||
94 | if (messenger) { | |
95 | messenger->shutdown(); | |
96 | messenger->wait(); | |
97 | } | |
98 | } | |
99 | ||
100 | bool RADOS::ms_dispatch(Message *m) | |
101 | { | |
102 | switch (m->get_type()) { | |
103 | // OSD | |
104 | case CEPH_MSG_OSD_MAP: | |
105 | m->put(); | |
106 | return true; | |
107 | } | |
108 | return false; | |
109 | } | |
110 | ||
111 | void RADOS::ms_handle_connect(Connection *con) {} | |
112 | bool RADOS::ms_handle_reset(Connection *con) { | |
113 | return false; | |
114 | } | |
115 | void RADOS::ms_handle_remote_reset(Connection *con) {} | |
116 | bool RADOS::ms_handle_refused(Connection *con) { | |
117 | return false; | |
118 | } | |
119 | ||
120 | } // namespace detail | |
121 | } // namespace neorados |