From 62e2bca8d8c20ff880ecb1e216da14f735fb4944 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 30 Sep 2014 11:56:30 -0700 Subject: [PATCH] osd: swap state spinlock for atomic_t We are hitting a strange issue with valgrind and pthread spinlocks. Avoid the issue by using an atomic_t here (which is simpler anyway). Avoids: #8822 Backport: firefly Signed-off-by: Sage Weil --- src/osd/OSD.cc | 2 +- src/osd/OSD.h | 24 ++++++++---------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 4e735b085f8d..a53dfca4859c 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1642,7 +1642,7 @@ OSD::OSD(CephContext *cct_, ObjectStore *store_, dispatch_running(false), asok_hook(NULL), osd_compat(get_osd_compat_set()), - state_lock(), state(STATE_INITIALIZING), + state(STATE_INITIALIZING), osd_tp(cct, "OSD::osd_tp", cct->_conf->osd_op_threads, "osd_op_threads"), osd_op_tp(cct, "OSD::osd_op_tp", cct->_conf->osd_op_num_threads_per_shard * cct->_conf->osd_op_num_shards), diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 8ad18e3b0963..426a2b1fab70 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1050,37 +1050,29 @@ public: } private: - Spinlock state_lock; // protects access to state - int state; + atomic_t state; public: int get_state() { - Spinlock::Locker l(state_lock); - return state; + return state.read(); } void set_state(int s) { - Spinlock::Locker l(state_lock); - state = s; + state.set(s); } bool is_initializing() { - Spinlock::Locker l(state_lock); - return state == STATE_INITIALIZING; + return get_state() == STATE_INITIALIZING; } bool is_booting() { - Spinlock::Locker l(state_lock); - return state == STATE_BOOTING; + return get_state() == STATE_BOOTING; } bool is_active() { - Spinlock::Locker l(state_lock); - return state == STATE_ACTIVE; + return get_state() == STATE_ACTIVE; } bool is_stopping() { - Spinlock::Locker l(state_lock); - return state == STATE_STOPPING; + return get_state() == STATE_STOPPING; } bool is_waiting_for_healthy() { - Spinlock::Locker l(state_lock); - return state == STATE_WAITING_FOR_HEALTHY; + return get_state() == STATE_WAITING_FOR_HEALTHY; } private: -- 2.47.3