]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_lib_frontend.h
update ceph source to reef 18.1.2
[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 3
1e59de90 4#pragma once
7c673cae
FG
5
6#include <boost/container/flat_map.hpp>
7
7c673cae
FG
8#include "rgw_lib.h"
9#include "rgw_file.h"
10
11namespace rgw {
12
13 class RGWLibProcess : public RGWProcess {
14 RGWAccessKey access_key;
15 std::mutex mtx;
f91f0fd5 16 std::condition_variable cv;
7c673cae
FG
17 int gen;
18 bool shutdown;
19
20 typedef flat_map<RGWLibFS*, RGWLibFS*> FSMAP;
21 FSMAP mounted_fs;
22
23 using lock_guard = std::lock_guard<std::mutex>;
24 using unique_lock = std::unique_lock<std::mutex>;
25
26 public:
1e59de90
TL
27 RGWLibProcess(CephContext* cct, RGWProcessEnv& pe, int num_threads,
28 std::string uri_prefix, RGWFrontendConfig* _conf) :
29 RGWProcess(cct, pe, num_threads, std::move(uri_prefix), _conf),
30 gen(0), shutdown(false) {}
7c673cae
FG
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="
20effc67 62 << std::hex << req << std::dec << dendl;
7c673cae
FG
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 */