From 7ddca28eb82991b35f3076261f70d52d375e6988 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 28 Aug 2017 02:33:20 -0700 Subject: [PATCH] rgw: create global http manager Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 2 ++ src/rgw/rgw_http_client.cc | 40 ++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_http_client.h | 9 +++++++++ src/rgw/rgw_main.cc | 4 +++- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 108ef379823..35e9cb0a14f 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1089,6 +1089,7 @@ public: explicit StoreDestructor(RGWRados *_s) : store(_s) {} ~StoreDestructor() { RGWStoreManager::close_storage(store); + rgw_http_client_cleanup(); } }; @@ -3108,6 +3109,7 @@ int main(int argc, const char **argv) rgw_bucket_init(store->meta_mgr); rgw_otp_init(store); + rgw_http_client_init(g_ceph_context); struct rgw_curl_setup { rgw_curl_setup() { diff --git a/src/rgw/rgw_http_client.cc b/src/rgw/rgw_http_client.cc index d0f90a5617d..32ca8613329 100644 --- a/src/rgw/rgw_http_client.cc +++ b/src/rgw/rgw_http_client.cc @@ -21,6 +21,8 @@ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rgw +RGWHTTPManager *rgw_http_manager; + struct rgw_http_req_data : public RefCountedObject { CURL *easy_handle{nullptr}; curl_slist *h{nullptr}; @@ -1240,4 +1242,42 @@ void *RGWHTTPManager::reqs_thread_entry() return 0; } +void rgw_http_client_init(CephContext *cct) +{ + curl_global_init(CURL_GLOBAL_ALL); + rgw_http_manager = new RGWHTTPManager(cct); + rgw_http_manager->set_threaded(); +} + +void rgw_http_client_cleanup() +{ + rgw_http_manager->stop(); + delete rgw_http_manager; + curl_global_cleanup(); +} + + +int RGWHTTP::send(RGWHTTPClient *req) { + if (!req) { + return 0; + } + int r = rgw_http_manager->add_request(req); + if (r < 0) { + return r; + } + + return 0; +} + +int RGWHTTP::process(RGWHTTPClient *req) { + if (!req) { + return 0; + } + int r = send(req); + if (r < 0) { + return r; + } + + return req->wait(); +} diff --git a/src/rgw/rgw_http_client.h b/src/rgw/rgw_http_client.h index a8bbaa17b96..fbe5d3626c0 100644 --- a/src/rgw/rgw_http_client.h +++ b/src/rgw/rgw_http_client.h @@ -14,6 +14,9 @@ using param_pair_t = pair; using param_vec_t = vector; +void rgw_http_client_init(CephContext *cct); +void rgw_http_client_cleanup(); + struct rgw_http_req_data; class RGWHTTPManager; @@ -317,4 +320,10 @@ public: int complete_requests(); }; +class RGWHTTP +{ +public: + static int send(RGWHTTPClient *req); + static int process(RGWHTTPClient *req); +}; #endif diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index ac8c6e3cd3c..1a050b5a1fd 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -298,7 +298,8 @@ int main(int argc, const char **argv) rgw_init_resolver(); rgw::curl::setup_curl(fe_map); - + rgw_http_client_init(g_ceph_context); + #if defined(WITH_RADOSGW_FCGI_FRONTEND) FCGX_Init(); #endif @@ -572,6 +573,7 @@ int main(int argc, const char **argv) rgw::auth::s3::LDAPEngine::shutdown(); rgw_tools_cleanup(); rgw_shutdown_resolver(); + rgw_http_client_cleanup(); rgw::curl::cleanup_curl(); rgw_perf_stop(g_ceph_context); -- 2.39.5