]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_fcgi_process.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rgw / rgw_fcgi_process.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #include "common/errno.h"
5 #include "common/Throttle.h"
6 #include "common/WorkQueue.h"
7
8 #include "rgw_rest.h"
9 #include "rgw_frontend.h"
10 #include "rgw_request.h"
11 #include "rgw_process.h"
12 #include "rgw_loadgen.h"
13 #include "rgw_client_io.h"
14 #include "rgw_client_io_filters.h"
15
16 #define dout_subsys ceph_subsys_rgw
17
18 void RGWFCGXProcess::run()
19 {
20 string socket_path;
21 string socket_port;
22 string socket_host;
23 int socket_backlog;
24
25 conf->get_val("socket_path", "", &socket_path);
26 conf->get_val("socket_port", g_conf()->rgw_port, &socket_port);
27 conf->get_val("socket_host", g_conf()->rgw_host, &socket_host);
28 socket_backlog = g_conf()->rgw_fcgi_socket_backlog;
29
30 if (socket_path.empty() && socket_port.empty() && socket_host.empty()) {
31 socket_path = g_conf()->rgw_socket_path;
32 if (socket_path.empty()) {
33 dout(0) << "ERROR: no socket server point defined, cannot "
34 "start fcgi frontend" << dendl;
35 return;
36 }
37 }
38
39 if (!socket_path.empty()) {
40 string path_str = socket_path;
41
42 /* this is necessary, as FCGX_OpenSocket might not return an
43 * error, but rather ungracefully exit */
44 int fd = open(path_str.c_str(), O_CREAT, 0644);
45 if (fd < 0) {
46 int err = errno;
47 /* ENXIO is actually expected, we'll get that if we try to open
48 * a unix domain socket */
49 if (err != ENXIO) {
50 dout(0) << "ERROR: cannot create socket: path=" << path_str
51 << " error=" << cpp_strerror(err) << dendl;
52 return;
53 }
54 } else {
55 close(fd);
56 }
57
58 const char *path = path_str.c_str();
59 sock_fd = FCGX_OpenSocket(path, socket_backlog);
60 if (sock_fd < 0) {
61 dout(0) << "ERROR: FCGX_OpenSocket (" << path << ") returned "
62 << sock_fd << dendl;
63 return;
64 }
65 if (chmod(path, 0777) < 0) {
66 dout(0) << "WARNING: couldn't set permissions on unix domain socket"
67 << dendl;
68 }
69 } else if (!socket_port.empty()) {
70 string bind = socket_host + ":" + socket_port;
71 sock_fd = FCGX_OpenSocket(bind.c_str(), socket_backlog);
72 if (sock_fd < 0) {
73 dout(0) << "ERROR: FCGX_OpenSocket (" << bind.c_str() << ") returned "
74 << sock_fd << dendl;
75 return;
76 }
77 }
78
79 m_tp.start();
80
81 FCGX_Request fcgx_reqs[max_connections];
82
83 QueueRing<FCGX_Request*> qr(max_connections);
84 for (int i = 0; i < max_connections; i++) {
85 FCGX_Request* fcgx = &fcgx_reqs[i];
86 FCGX_InitRequest(fcgx, sock_fd, 0);
87 qr.enqueue(fcgx);
88 }
89
90 for (;;) {
91 RGWFCGXRequest* req = new RGWFCGXRequest(store->getRados()->get_new_req_id(), &qr);
92 dout(10) << "allocated request req=" << hex << req << dec << dendl;
93 req_throttle.get(1);
94 int ret = FCGX_Accept_r(req->fcgx);
95 if (ret < 0) {
96 delete req;
97 dout(0) << "ERROR: FCGX_Accept_r returned " << ret << dendl;
98 req_throttle.put(1);
99 break;
100 }
101 req_wq.queue(req);
102 }
103
104 m_tp.drain(&req_wq);
105 m_tp.stop();
106
107 dout(20) << "cleaning up fcgx connections" << dendl;
108
109 for (int i = 0; i < max_connections; i++) {
110 FCGX_Finish_r(&fcgx_reqs[i]);
111 }
112 } /* RGWFCGXProcess::run */
113
114 void RGWFCGXProcess::handle_request(RGWRequest* r)
115 {
116 RGWFCGXRequest* const req = static_cast<RGWFCGXRequest*>(r);
117
118 RGWFCGX fcgxfe(req->fcgx);
119 auto real_client_io = rgw::io::add_reordering(
120 rgw::io::add_buffering(cct,
121 rgw::io::add_chunking(
122 &fcgxfe)));
123 RGWRestfulIO client_io(cct, &real_client_io);
124
125
126 int ret = process_request(store, rest, req, uri_prefix,
127 *auth_registry, &client_io, olog,
128 null_yield, nullptr);
129 if (ret < 0) {
130 /* we don't really care about return code */
131 dout(20) << "process_request() returned " << ret << dendl;
132 }
133
134 FCGX_Finish_r(req->fcgx);
135
136 delete req;
137 } /* RGWFCGXProcess::handle_request */