summaryrefslogtreecommitdiffstats
path: root/src/neorados/RADOSImpl.h
blob: d45ca948123ed34cf7152049b74ed5819529ac72 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// -*- 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.
 *
 */
#ifndef CEPH_NEORADOS_RADOSIMPL_H
#define CEPH_NEORADOS_RADOSIMPL_H

#include <functional>
#include <memory>
#include <string>

#include <boost/asio.hpp>
#include <boost/intrusive_ptr.hpp>

#include "common/ceph_context.h"
#include "common/ceph_mutex.h"

#include "librados/RadosClient.h"

#include "mon/MonClient.h"

#include "mgr/MgrClient.h"

#include "osdc/Objecter.h"

namespace neorados {

class RADOS;

namespace detail {

class NeoClient;

class RADOS : public Dispatcher
{
  friend ::neorados::RADOS;
  friend NeoClient;

  boost::asio::io_context& ioctx;
  boost::intrusive_ptr<CephContext> cct;

  ceph::mutex lock = ceph::make_mutex("RADOS_unleashed::_::RADOSImpl");
  int instance_id = -1;

  std::unique_ptr<Messenger> messenger;

  MonClient monclient;
  MgrClient mgrclient;

  std::unique_ptr<Objecter> objecter;

public:

  RADOS(boost::asio::io_context& ioctx, boost::intrusive_ptr<CephContext> cct);
  ~RADOS();
  bool ms_dispatch(Message *m) override;
  void ms_handle_connect(Connection *con) override;
  bool ms_handle_reset(Connection *con) override;
  void ms_handle_remote_reset(Connection *con) override;
  bool ms_handle_refused(Connection *con) override;
  mon_feature_t get_required_monitor_features() const {
    return monclient.with_monmap(std::mem_fn(&MonMap::get_required_features));
  }
};

class Client {
public:
  Client(boost::asio::io_context& ioctx,
         boost::intrusive_ptr<CephContext> cct,
         MonClient& monclient, Objecter* objecter)
    : ioctx(ioctx), cct(cct), monclient(monclient), objecter(objecter) {
  }
  virtual ~Client() {}

  Client(const Client&) = delete;
  Client& operator=(const Client&) = delete;

  boost::asio::io_context& ioctx;

  boost::intrusive_ptr<CephContext> cct;
  MonClient& monclient;
  Objecter* objecter;

  mon_feature_t get_required_monitor_features() const {
    return monclient.with_monmap(std::mem_fn(&MonMap::get_required_features));
  }

  virtual int get_instance_id() const = 0;
};

class NeoClient : public Client {
public:
  NeoClient(std::unique_ptr<RADOS>&& rados)
    : Client(rados->ioctx, rados->cct, rados->monclient,
             rados->objecter.get()),
      rados(std::move(rados)) {
  }

  int get_instance_id() const override {
    return rados->instance_id;
  }

private:
  std::unique_ptr<RADOS> rados;
};

class RadosClient : public Client {
public:
  RadosClient(librados::RadosClient* rados_client)
    : Client(rados_client->poolctx, {rados_client->cct},
             rados_client->monclient, rados_client->objecter),
      rados_client(rados_client) {
  }

  int get_instance_id() const override {
    return rados_client->instance_id;
  }

public:
  librados::RadosClient* rados_client;
};

} // namespace detail
} // namespace neorados

#endif