Skip to content

Commit 3c9dd67

Browse files
committed
Merge PR ceph#60037 into main
* refs/pull/60037/head: test/common: add death test for double !recursive lock common/test: do not test exception raised from recursive lock test/common: fix invalid vim mode common,osdc: remove obsolete ceph::mutex_debugging common: assert debug mutex lock is not held if !recursive Reviewed-by: Radoslaw Zarzynski <[email protected]> Reviewed-by: Casey Bodley <[email protected]> Reviewed-by: Ilya Dryomov <[email protected]>
2 parents 5074c40 + a48080a commit 3c9dd67

File tree

5 files changed

+20
-42
lines changed

5 files changed

+20
-42
lines changed

src/common/ceph_mutex.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ namespace ceph {
8383
return {};
8484
}
8585

86-
static constexpr bool mutex_debugging = false;
8786
#define ceph_mutex_is_locked(m) true
8887
#define ceph_mutex_is_locked_by_me(m) true
8988
}
@@ -131,8 +130,6 @@ namespace ceph {
131130
return {std::forward<Args>(args)...};
132131
}
133132

134-
static constexpr bool mutex_debugging = true;
135-
136133
// debug methods
137134
#define ceph_mutex_is_locked(m) ((m).is_locked())
138135
#define ceph_mutex_is_not_locked(m) (!(m).is_locked())
@@ -186,8 +183,6 @@ namespace ceph {
186183
return {};
187184
}
188185

189-
static constexpr bool mutex_debugging = false;
190-
191186
// debug methods. Note that these can blindly return true
192187
// because any code that does anything other than assert these
193188
// are true is broken.

src/common/config_proxy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class ConfigProxy {
3131
using rev_obs_map_t = ObsMgr::rev_obs_map;
3232

3333
void _call_observers(rev_obs_map_t& rev_obs) {
34-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
3534
for (auto& [obs, keys] : rev_obs) {
3635
(*obs)->handle_conf_change(*this, keys);
3736
}

src/common/mutex_debug.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,16 @@ class mutex_debug_impl : public mutex_debugging_base
169169
}
170170

171171
bool try_lock(bool no_lockdep = false) {
172-
bool locked = try_lock_impl();
173-
if (locked) {
174-
if (enable_lockdep(no_lockdep))
175-
_locked();
176-
_post_lock();
177-
}
178-
return locked;
172+
ceph_assert(recursive || !is_locked_by_me());
173+
return _try_lock(no_lockdep);
179174
}
180175

181176
void lock(bool no_lockdep = false) {
177+
ceph_assert(recursive || !is_locked_by_me());
182178
if (enable_lockdep(no_lockdep))
183179
_will_lock(recursive);
184180

185-
if (try_lock(no_lockdep))
181+
if (_try_lock(no_lockdep))
186182
return;
187183

188184
lock_impl();
@@ -198,6 +194,16 @@ class mutex_debug_impl : public mutex_debugging_base
198194
unlock_impl();
199195
}
200196

197+
private:
198+
bool _try_lock(bool no_lockdep) {
199+
bool locked = try_lock_impl();
200+
if (locked) {
201+
if (enable_lockdep(no_lockdep))
202+
_locked();
203+
_post_lock();
204+
}
205+
return locked;
206+
}
201207
};
202208

203209

src/osdc/Journaler.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -529,76 +529,62 @@ class Journaler {
529529
// ===================
530530

531531
Header get_last_committed() const {
532-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
533532
lock_guard l(lock);
534533
return last_committed;
535534
}
536535
Header get_last_written() const {
537-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
538536
lock_guard l(lock);
539537
return last_written;
540538
}
541539

542540
uint64_t get_layout_period() const {
543-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
544541
lock_guard l(lock);
545542
return layout.get_period();
546543
}
547544
file_layout_t get_layout() const {
548-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
549545
lock_guard l(lock);
550546
return layout;
551547
}
552548
bool is_active() const {
553-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
554549
lock_guard l(lock);
555550
return state == STATE_ACTIVE;
556551
}
557552
bool is_stopping() const {
558-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
559553
lock_guard l(lock);
560554
return state == STATE_STOPPING;
561555
}
562556
int get_error() const {
563-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
564557
lock_guard l(lock);
565558
return error;
566559
}
567560
bool is_readonly() const {
568-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
569561
lock_guard l(lock);
570562
return readonly;
571563
}
572564
bool is_readable();
573565
bool _is_readable();
574566
bool try_read_entry(bufferlist& bl);
575567
uint64_t get_write_pos() const {
576-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
577568
lock_guard l(lock);
578569
return write_pos;
579570
}
580571
uint64_t get_write_safe_pos() const {
581-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
582572
lock_guard l(lock);
583573
return safe_pos;
584574
}
585575
uint64_t get_read_pos() const {
586-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
587576
lock_guard l(lock);
588577
return read_pos;
589578
}
590579
uint64_t get_expire_pos() const {
591-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
592580
lock_guard l(lock);
593581
return expire_pos;
594582
}
595583
uint64_t get_trimmed_pos() const {
596-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
597584
lock_guard l(lock);
598585
return trimmed_pos;
599586
}
600587
size_t get_journal_envelope_size() const {
601-
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
602588
lock_guard l(lock);
603589
return journal_stream.get_envelope_size();
604590
}

src/test/common/test_mutex_debug.cc

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2-
// vim: ts=8 sw=2 &smarttab
2+
// vim: ts=8 sw=2 smarttab
33
/*
44
* Ceph - scalable distributed file system
55
*
@@ -57,21 +57,13 @@ TEST(MutexDebug, Lock) {
5757
test_lock<ceph::mutex_debug>();
5858
}
5959

60-
TEST(MutexDebug, NotRecursive) {
60+
TEST(MutexDebugDeathTest, NotRecursive) {
6161
ceph::mutex_debug m("foo");
62-
auto ttl = &test_try_lock<mutex_debug>;
63-
64-
ASSERT_NO_THROW(m.lock());
65-
ASSERT_TRUE(m.is_locked());
66-
ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get());
67-
68-
ASSERT_THROW(m.lock(), std::system_error);
62+
// avoid assert during test cleanup where the mutex is locked and cannot be
63+
// pthread_mutex_destroy'd
64+
std::unique_lock locker{m};
6965
ASSERT_TRUE(m.is_locked());
70-
ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get());
71-
72-
ASSERT_NO_THROW(m.unlock());
73-
ASSERT_FALSE(m.is_locked());
74-
ASSERT_TRUE(std::async(std::launch::async, ttl, &m).get());
66+
ASSERT_DEATH(m.lock(), "FAILED ceph_assert(recursive || !is_locked_by_me())");
7567
}
7668

7769
TEST(MutexRecursiveDebug, Lock) {

0 commit comments

Comments
 (0)