1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "common/errno.h"
5 #include "common/Throttle.h"
6 #include "common/WorkQueue.h"
10 #include "rgw_frontend.h"
11 #include "rgw_request.h"
12 #include "rgw_process.h"
13 #include "rgw_loadgen.h"
14 #include "rgw_client_io.h"
15 #include "rgw_client_io_filters.h"
17 #define dout_subsys ceph_subsys_rgw
19 void RGWFCGXProcess::run()
26 conf->get_val("socket_path", "", &socket_path);
27 conf->get_val("socket_port", g_conf->rgw_port, &socket_port);
28 conf->get_val("socket_host", g_conf->rgw_host, &socket_host);
29 socket_backlog = g_conf->rgw_fcgi_socket_backlog;
31 if (socket_path.empty() && socket_port.empty() && socket_host.empty()) {
32 socket_path = g_conf->rgw_socket_path;
33 if (socket_path.empty()) {
34 dout(0) << "ERROR: no socket server point defined, cannot "
35 "start fcgi frontend" << dendl;
40 if (!socket_path.empty()) {
41 string path_str = socket_path;
43 /* this is necessary, as FCGX_OpenSocket might not return an
44 * error, but rather ungracefully exit */
45 int fd = open(path_str.c_str(), O_CREAT, 0644);
48 /* ENXIO is actually expected, we'll get that if we try to open
49 * a unix domain socket */
51 dout(0) << "ERROR: cannot create socket: path=" << path_str
52 << " error=" << cpp_strerror(err) << dendl;
59 const char *path = path_str.c_str();
60 sock_fd = FCGX_OpenSocket(path, socket_backlog);
62 dout(0) << "ERROR: FCGX_OpenSocket (" << path << ") returned "
66 if (chmod(path, 0777) < 0) {
67 dout(0) << "WARNING: couldn't set permissions on unix domain socket"
70 } else if (!socket_port.empty()) {
71 string bind = socket_host + ":" + socket_port;
72 sock_fd = FCGX_OpenSocket(bind.c_str(), socket_backlog);
74 dout(0) << "ERROR: FCGX_OpenSocket (" << bind.c_str() << ") returned "
82 FCGX_Request fcgx_reqs[max_connections];
84 QueueRing<FCGX_Request*> qr(max_connections);
85 for (int i = 0; i < max_connections; i++) {
86 FCGX_Request* fcgx = &fcgx_reqs[i];
87 FCGX_InitRequest(fcgx, sock_fd, 0);
92 RGWFCGXRequest* req = new RGWFCGXRequest(store->get_new_req_id(), &qr);
93 dout(10) << "allocated request req=" << hex << req << dec << dendl;
95 int ret = FCGX_Accept_r(req->fcgx);
98 dout(0) << "ERROR: FCGX_Accept_r returned " << ret << dendl;
108 dout(20) << "cleaning up fcgx connections" << dendl;
110 for (int i = 0; i < max_connections; i++) {
111 FCGX_Finish_r(&fcgx_reqs[i]);
113 } /* RGWFCGXProcess::run */
115 void RGWFCGXProcess::handle_request(RGWRequest* r)
117 RGWFCGXRequest* const req = static_cast<RGWFCGXRequest*>(r);
119 RGWFCGX fcgxfe(req->fcgx);
120 auto real_client_io = rgw::io::add_reordering(
121 rgw::io::add_buffering(cct,
122 rgw::io::add_chunking(
124 RGWRestfulIO client_io(cct, &real_client_io);
127 int ret = process_request(store, rest, req, uri_prefix,
128 *auth_registry, &client_io, olog);
130 /* we don't really care about return code */
131 dout(20) << "process_request() returned " << ret << dendl;
134 FCGX_Finish_r(req->fcgx);
137 } /* RGWFCGXProcess::handle_request */