From 3bea2a35317db41539931a89b9f15e7a853a4398 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Sun, 31 Jul 2016 12:39:37 -0400 Subject: [PATCH] rgw: add static function to generate lock cookie Signed-off-by: Casey Bodley (cherry picked from commit 9a1b2359730df27e6688a77bfa3d5e801ad846a3) --- src/rgw/rgw_cr_rados.h | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/rgw/rgw_cr_rados.h b/src/rgw/rgw_cr_rados.h index 941949a87cfb3..bda1bcda264db 100644 --- a/src/rgw/rgw_cr_rados.h +++ b/src/rgw/rgw_cr_rados.h @@ -486,6 +486,13 @@ public: int send_request(); int request_complete(); + + static std::string gen_random_cookie(CephContext* cct) { +#define COOKIE_LEN 16 + char buf[COOKIE_LEN + 1]; + gen_rand_alphanumeric(cct, buf, sizeof(buf) - 1); + return buf; + } }; class RGWSimpleRadosUnlockCR : public RGWSimpleCoroutine { @@ -917,33 +924,30 @@ class RGWContinuousLeaseCR : public RGWCoroutine { RGWRados *store; const rgw_bucket& pool; - string oid; + const string oid; - string lock_name; - string cookie; + const string lock_name; + const string cookie; int interval; Mutex lock; atomic_t going_down; - bool locked; + bool locked{false}; RGWCoroutine *caller; - bool aborted; + bool aborted{false}; public: RGWContinuousLeaseCR(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store, const rgw_bucket& _pool, const string& _oid, - const string& _lock_name, int _interval, RGWCoroutine *_caller) : RGWCoroutine(_store->ctx()), async_rados(_async_rados), store(_store), - pool(_pool), oid(_oid), lock_name(_lock_name), interval(_interval), - lock("RGWContimuousLeaseCR"), locked(false), caller(_caller), aborted(false) { -#define COOKIE_LEN 16 - char buf[COOKIE_LEN + 1]; - - gen_rand_alphanumeric(cct, buf, sizeof(buf) - 1); - cookie = buf; - } + const string& _lock_name, int _interval, RGWCoroutine *_caller) + : RGWCoroutine(_store->ctx()), async_rados(_async_rados), store(_store), + pool(_pool), oid(_oid), lock_name(_lock_name), + cookie(RGWSimpleRadosLockCR::gen_random_cookie(cct)), + interval(_interval), lock("RGWContinuousLeaseCR"), caller(_caller) + {} int operate(); -- 2.39.5