]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_lib_frontend.h
import ceph pacific 16.2.5
[ceph.git] / ceph / src / rgw / rgw_lib_frontend.h
CommitLineData
7c673cae 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
7c673cae
FG
3
4#ifndef RGW_LIB_FRONTEND_H
5#define RGW_LIB_FRONTEND_H
6
7#include <boost/container/flat_map.hpp>
8
7c673cae
FG
9#include "rgw_lib.h"
10#include "rgw_file.h"
11
12namespace rgw {
13
14 class RGWLibProcess : public RGWProcess {
15 RGWAccessKey access_key;
16 std::mutex mtx;
f91f0fd5 17 std::condition_variable cv;
7c673cae
FG
18 int gen;
19 bool shutdown;
20
21 typedef flat_map<RGWLibFS*, RGWLibFS*> FSMAP;
22 FSMAP mounted_fs;
23
24 using lock_guard = std::lock_guard<std::mutex>;
25 using unique_lock = std::unique_lock<std::mutex>;
26
27 public:
28 RGWLibProcess(CephContext* cct, RGWProcessEnv* pe, int num_threads,
29 RGWFrontendConfig* _conf) :
30 RGWProcess(cct, pe, num_threads, _conf), gen(0), shutdown(false) {}
31
32 void run() override;
33 void checkpoint();
34
35 void stop() {
36 shutdown = true;
37 for (const auto& fs: mounted_fs) {
38 fs.second->stop();
39 }
f91f0fd5 40 cv.notify_all();
7c673cae
FG
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 */
b3b6e05e 69 void handle_request(const DoutPrefixProvider *dpp, RGWRequest* req) override; // async handler, deletes req
7c673cae
FG
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 */