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
136
137
138
139
140
141
142
143
|
// -*- 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) 2011 New Dream Network
*
* 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_CEPHCONTEXT_H
#define CEPH_CEPHCONTEXT_H
#include <iostream>
#include <stdint.h>
#include "include/buffer.h"
#include "include/atomic.h"
class AdminSocket;
class CephContextServiceThread;
class PerfCountersCollection;
class md_config_obs_t;
struct md_config_t;
class CephContextHook;
class CryptoNone;
class CryptoAES;
class CryptoHandler;
namespace ceph {
class HeartbeatMap;
namespace log {
class Log;
}
}
using ceph::bufferlist;
/* A CephContext represents the context held by a single library user.
* There can be multiple CephContexts in the same process.
*
* For daemons and utility programs, there will be only one CephContext. The
* CephContext contains the configuration, the dout object, and anything else
* that you might want to pass to libcommon with every function call.
*/
class CephContext {
public:
CephContext(uint32_t module_type_);
// ref count!
private:
~CephContext();
atomic_t nref;
public:
CephContext *get() {
nref.inc();
return this;
}
void put() {
if (nref.dec() == 0)
delete this;
}
md_config_t *_conf;
ceph::log::Log *_log;
/* Start the Ceph Context's service thread */
void start_service_thread();
/* Reopen the log files */
void reopen_logs();
/* Get the module type (client, mon, osd, mds, etc.) */
uint32_t get_module_type() const;
/* Get the PerfCountersCollection of this CephContext */
PerfCountersCollection *get_perfcounters_collection();
ceph::HeartbeatMap *get_heartbeat_map() {
return _heartbeat_map;
}
/**
* Get the admin socket associated with this CephContext.
*
* Currently there is always an admin socket object,
* so this will never return NULL.
*
* @return the admin socket
*/
AdminSocket *get_admin_socket();
/**
* process an admin socket command
*/
void do_command(std::string command, std::string args, bufferlist *out);
/**
* get a crypto handler
*/
CryptoHandler *get_crypto_handler(int type);
private:
CephContext(const CephContext &rhs);
CephContext &operator=(const CephContext &rhs);
/* Stop and join the Ceph Context's service thread */
void join_service_thread();
uint32_t _module_type;
/* libcommon service thread.
* SIGHUP wakes this thread, which then reopens logfiles */
friend class CephContextServiceThread;
CephContextServiceThread *_service_thread;
md_config_obs_t *_log_obs;
/* The admin socket associated with this context */
AdminSocket *_admin_socket;
/* lock which protects service thread creation, destruction, etc. */
pthread_spinlock_t _service_thread_lock;
/* The collection of profiling loggers associated with this context */
PerfCountersCollection *_perf_counters_collection;
md_config_obs_t *_perf_counters_conf_obs;
CephContextHook *_admin_hook;
ceph::HeartbeatMap *_heartbeat_map;
// crypto
CryptoNone *_crypto_none;
CryptoAES *_crypto_aes;
};
#endif
|