From a02ae950b75010ff731de573c1225be0b5d2161a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 17 Sep 2018 11:40:17 -0500 Subject: [PATCH] common/lockdep: add recursive flag for _will_lock Signed-off-by: Sage Weil --- src/common/Mutex.h | 2 +- src/common/lockdep.cc | 25 ++++++++++++++----------- src/common/lockdep.h | 3 ++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/common/Mutex.h b/src/common/Mutex.h index e8d528848d0..792ba3239c0 100644 --- a/src/common/Mutex.h +++ b/src/common/Mutex.h @@ -44,7 +44,7 @@ private: id = lockdep_register(name.c_str()); } void _will_lock() { // about to lock - id = lockdep_will_lock(name.c_str(), id, backtrace); + id = lockdep_will_lock(name.c_str(), id, backtrace, recursive); } void _locked() { // just locked id = lockdep_locked(name.c_str(), id, backtrace); diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index 91504bb9b48..c37e38f53db 100644 --- a/src/common/lockdep.cc +++ b/src/common/lockdep.cc @@ -269,7 +269,8 @@ static bool does_follow(int a, int b) return false; } -int lockdep_will_lock(const char *name, int id, bool force_backtrace) +int lockdep_will_lock(const char *name, int id, bool force_backtrace, + bool recursive) { pthread_t p = pthread_self(); @@ -290,17 +291,19 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace) p != m.end(); ++p) { if (p->first == id) { - lockdep_dout(0) << "\n"; - *_dout << "recursive lock of " << name << " (" << id << ")\n"; - BackTrace *bt = new BackTrace(BACKTRACE_SKIP); - bt->print(*_dout); - if (p->second) { - *_dout << "\npreviously locked at\n"; - p->second->print(*_dout); + if (!recursive) { + lockdep_dout(0) << "\n"; + *_dout << "recursive lock of " << name << " (" << id << ")\n"; + BackTrace *bt = new BackTrace(BACKTRACE_SKIP); + bt->print(*_dout); + if (p->second) { + *_dout << "\npreviously locked at\n"; + p->second->print(*_dout); + } + delete bt; + *_dout << dendl; + ceph_abort(); } - delete bt; - *_dout << dendl; - ceph_abort(); } else if (!(follows[p->first][id/8] & (1 << (id % 8)))) { // new dependency diff --git a/src/common/lockdep.h b/src/common/lockdep.h index ffafc300c3a..1c854a9eaec 100644 --- a/src/common/lockdep.h +++ b/src/common/lockdep.h @@ -23,7 +23,8 @@ extern void lockdep_register_ceph_context(CephContext *cct); extern void lockdep_unregister_ceph_context(CephContext *cct); extern int lockdep_register(const char *n); extern void lockdep_unregister(int id); -extern int lockdep_will_lock(const char *n, int id, bool force_backtrace=false); +extern int lockdep_will_lock(const char *n, int id, bool force_backtrace=false, + bool recursive=false); extern int lockdep_locked(const char *n, int id, bool force_backtrace=false); extern int lockdep_will_unlock(const char *n, int id); extern int lockdep_dump_locks(); -- 2.39.5