]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_lib_frontend.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rgw / rgw_lib_frontend.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef RGW_LIB_FRONTEND_H
5 #define RGW_LIB_FRONTEND_H
6
7 #include <boost/container/flat_map.hpp>
8
9 #include <boost/container/flat_map.hpp>
10
11 #include "rgw_lib.h"
12 #include "rgw_file.h"
13
14 namespace rgw {
15
16 class RGWLibProcess : public RGWProcess {
17 RGWAccessKey access_key;
18 std::mutex mtx;
19 int gen;
20 bool shutdown;
21
22 typedef flat_map<RGWLibFS*, RGWLibFS*> FSMAP;
23 FSMAP mounted_fs;
24
25 using lock_guard = std::lock_guard<std::mutex>;
26 using unique_lock = std::unique_lock<std::mutex>;
27
28 public:
29 RGWLibProcess(CephContext* cct, RGWProcessEnv* pe, int num_threads,
30 RGWFrontendConfig* _conf) :
31 RGWProcess(cct, pe, num_threads, _conf), gen(0), shutdown(false) {}
32
33 void run() override;
34 void checkpoint();
35
36 void stop() {
37 shutdown = true;
38 for (const auto& fs: mounted_fs) {
39 fs.second->stop();
40 }
41 }
42
43 void register_fs(RGWLibFS* fs) {
44 lock_guard guard(mtx);
45 mounted_fs.insert(FSMAP::value_type(fs, fs));
46 ++gen;
47 }
48
49 void unregister_fs(RGWLibFS* fs) {
50 lock_guard guard(mtx);
51 FSMAP::iterator it = mounted_fs.find(fs);
52 if (it != mounted_fs.end()) {
53 mounted_fs.erase(it);
54 ++gen;
55 }
56 }
57
58 void enqueue_req(RGWLibRequest* req) {
59
60 lsubdout(g_ceph_context, rgw, 10)
61 << __func__ << " enqueue request req="
62 << hex << req << dec << dendl;
63
64 req_throttle.get(1);
65 req_wq.queue(req);
66 } /* enqueue_req */
67
68 /* "regular" requests */
69 void handle_request(RGWRequest* req) override; // async handler, deletes req
70 int process_request(RGWLibRequest* req);
71 int process_request(RGWLibRequest* req, RGWLibIO* io);
72 void set_access_key(RGWAccessKey& key) { access_key = key; }
73
74 /* requests w/continue semantics */
75 int start_request(RGWLibContinuedReq* req);
76 int finish_request(RGWLibContinuedReq* req);
77 }; /* RGWLibProcess */
78
79 class RGWLibFrontend : public RGWProcessFrontend {
80 public:
81 RGWLibFrontend(RGWProcessEnv& pe, RGWFrontendConfig *_conf)
82 : RGWProcessFrontend(pe, _conf) {}
83
84 int init() override;
85
86 void stop() override {
87 RGWProcessFrontend::stop();
88 get_process()->stop();
89 }
90
91 RGWLibProcess* get_process() {
92 return static_cast<RGWLibProcess*>(pprocess);
93 }
94
95 inline void enqueue_req(RGWLibRequest* req) {
96 static_cast<RGWLibProcess*>(pprocess)->enqueue_req(req); // async
97 }
98
99 inline int execute_req(RGWLibRequest* req) {
100 return static_cast<RGWLibProcess*>(pprocess)->process_request(req); // !async
101 }
102
103 inline int start_req(RGWLibContinuedReq* req) {
104 return static_cast<RGWLibProcess*>(pprocess)->start_request(req);
105 }
106
107 inline int finish_req(RGWLibContinuedReq* req) {
108 return static_cast<RGWLibProcess*>(pprocess)->finish_request(req);
109 }
110
111 }; /* RGWLibFrontend */
112
113 } /* namespace rgw */
114
115 #endif /* RGW_LIB_FRONTEND_H */