-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rgw: move all curl related global init to one place
since libcurl needs to setup the various ssl libraries based on backends, moving all the global init to one place. A TODO is to use std::call_once on the global_init and similarly the init functions of libopenssl. A further TODO is to implement locking primitives for gnutls Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
- Loading branch information
1 parent
4f083be
commit 5d9b884
Showing
5 changed files
with
121 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
extern "C" { | ||
#include <curl/curl.h> | ||
} | ||
|
||
#include "rgw_http_client_curl.h" | ||
#include <mutex> | ||
#include <vector> | ||
|
||
#include "rgw_common.h" | ||
#define dout_context g_ceph_context | ||
#define dout_subsys ceph_subsys_rgw | ||
|
||
#ifdef WITH_RADOSGW_OPENSSL_LOCK_COMPAT | ||
#include <openssl/crypto.h> | ||
#endif | ||
|
||
namespace rgw { | ||
namespace curl { | ||
|
||
#ifdef HAVE_CURL_MULTI_WAIT | ||
static void check_curl() | ||
{ | ||
} | ||
#else | ||
static void check_curl() | ||
{ | ||
derr << "WARNING: libcurl doesn't support curl_multi_wait()" << dendl; | ||
derr << "WARNING: cross zone / region transfer performance may be affected" << dendl; | ||
} | ||
#endif | ||
|
||
void init_ssl(){ | ||
#ifdef WITH_RADOSGW_OPENSSL_LOCK_COMPAT | ||
rgw::curl::openssl::init_ssl(); | ||
#endif | ||
} | ||
|
||
std::once_flag curl_init_flag; | ||
|
||
void setup_curl(){ | ||
check_curl(); | ||
init_ssl(); | ||
std::call_once(curl_init_flag, curl_global_init, CURL_GLOBAL_ALL); | ||
} | ||
|
||
void cleanup_curl(){ | ||
curl_global_cleanup(); | ||
} | ||
|
||
|
||
namespace openssl { | ||
|
||
class RGWSSLSetup | ||
{ | ||
std::vector <std::mutex> locks; | ||
public: | ||
RGWSSLSetup(int n) : locks (n){} | ||
|
||
void set_lock(int id){ | ||
try { | ||
locks.at(id).lock(); | ||
} catch (std::out_of_range& e) { | ||
dout(0) << __func__ << "failed to set locks" << dendl; | ||
} | ||
} | ||
|
||
void clear_lock(int id){ | ||
try { | ||
locks.at(id).unlock(); | ||
} catch (std::out_of_range& e) { | ||
dout(0) << __func__ << "failed to unlock" << dendl; | ||
} | ||
} | ||
}; | ||
|
||
|
||
#ifdef WITH_RADOSGW_OPENSSL_LOCK_COMPAT | ||
void rgw_ssl_locking_callback(int mode, int id, const char *file, int line) | ||
{ | ||
static RGWSSLSetup locks(CRYPTO_num_locks()); | ||
if (mode & CRYPTO_LOCK) | ||
locks.set_lock(id); | ||
else | ||
locks.clear_lock(id); | ||
} | ||
|
||
unsigned long rgw_ssl_thread_id_callback(){ | ||
return (unsigned long)pthread_self(); | ||
} | ||
|
||
void init_ssl(){ | ||
CRYPTO_set_id_callback((unsigned long (*) ()) rgw_ssl_thread_id_callback); | ||
CRYPTO_set_locking_callback(rgw_ssl_locking_callback); | ||
} | ||
#else | ||
void init_ssl(){} | ||
#endif // WITH_RADOSGW_OPENSSL_LOCK_COMPAT | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters