Skip to content

Commit

Permalink
Merge PR ceph#60037 into main
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
batrick committed Oct 9, 2024
2 parents 5074c40 + a48080a commit 3c9dd67
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 42 deletions.
5 changes: 0 additions & 5 deletions src/common/ceph_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ namespace ceph {
return {};
}

static constexpr bool mutex_debugging = false;
#define ceph_mutex_is_locked(m) true
#define ceph_mutex_is_locked_by_me(m) true
}
Expand Down Expand Up @@ -131,8 +130,6 @@ namespace ceph {
return {std::forward<Args>(args)...};
}

static constexpr bool mutex_debugging = true;

// debug methods
#define ceph_mutex_is_locked(m) ((m).is_locked())
#define ceph_mutex_is_not_locked(m) (!(m).is_locked())
Expand Down Expand Up @@ -186,8 +183,6 @@ namespace ceph {
return {};
}

static constexpr bool mutex_debugging = false;

// debug methods. Note that these can blindly return true
// because any code that does anything other than assert these
// are true is broken.
Expand Down
1 change: 0 additions & 1 deletion src/common/config_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ConfigProxy {
using rev_obs_map_t = ObsMgr::rev_obs_map;

void _call_observers(rev_obs_map_t& rev_obs) {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
for (auto& [obs, keys] : rev_obs) {
(*obs)->handle_conf_change(*this, keys);
}
Expand Down
22 changes: 14 additions & 8 deletions src/common/mutex_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,16 @@ class mutex_debug_impl : public mutex_debugging_base
}

bool try_lock(bool no_lockdep = false) {
bool locked = try_lock_impl();
if (locked) {
if (enable_lockdep(no_lockdep))
_locked();
_post_lock();
}
return locked;
ceph_assert(recursive || !is_locked_by_me());
return _try_lock(no_lockdep);
}

void lock(bool no_lockdep = false) {
ceph_assert(recursive || !is_locked_by_me());
if (enable_lockdep(no_lockdep))
_will_lock(recursive);

if (try_lock(no_lockdep))
if (_try_lock(no_lockdep))
return;

lock_impl();
Expand All @@ -198,6 +194,16 @@ class mutex_debug_impl : public mutex_debugging_base
unlock_impl();
}

private:
bool _try_lock(bool no_lockdep) {
bool locked = try_lock_impl();
if (locked) {
if (enable_lockdep(no_lockdep))
_locked();
_post_lock();
}
return locked;
}
};


Expand Down
14 changes: 0 additions & 14 deletions src/osdc/Journaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,76 +529,62 @@ class Journaler {
// ===================

Header get_last_committed() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return last_committed;
}
Header get_last_written() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return last_written;
}

uint64_t get_layout_period() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return layout.get_period();
}
file_layout_t get_layout() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return layout;
}
bool is_active() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return state == STATE_ACTIVE;
}
bool is_stopping() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return state == STATE_STOPPING;
}
int get_error() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return error;
}
bool is_readonly() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return readonly;
}
bool is_readable();
bool _is_readable();
bool try_read_entry(bufferlist& bl);
uint64_t get_write_pos() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return write_pos;
}
uint64_t get_write_safe_pos() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return safe_pos;
}
uint64_t get_read_pos() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return read_pos;
}
uint64_t get_expire_pos() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return expire_pos;
}
uint64_t get_trimmed_pos() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return trimmed_pos;
}
size_t get_journal_envelope_size() const {
ceph_assert(!ceph::mutex_debugging || !ceph_mutex_is_locked_by_me(lock));
lock_guard l(lock);
return journal_stream.get_envelope_size();
}
Expand Down
20 changes: 6 additions & 14 deletions src/test/common/test_mutex_debug.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 &smarttab
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
Expand Down Expand Up @@ -57,21 +57,13 @@ TEST(MutexDebug, Lock) {
test_lock<ceph::mutex_debug>();
}

TEST(MutexDebug, NotRecursive) {
TEST(MutexDebugDeathTest, NotRecursive) {
ceph::mutex_debug m("foo");
auto ttl = &test_try_lock<mutex_debug>;

ASSERT_NO_THROW(m.lock());
ASSERT_TRUE(m.is_locked());
ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get());

ASSERT_THROW(m.lock(), std::system_error);
// avoid assert during test cleanup where the mutex is locked and cannot be
// pthread_mutex_destroy'd
std::unique_lock locker{m};
ASSERT_TRUE(m.is_locked());
ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get());

ASSERT_NO_THROW(m.unlock());
ASSERT_FALSE(m.is_locked());
ASSERT_TRUE(std::async(std::launch::async, ttl, &m).get());
ASSERT_DEATH(m.lock(), "FAILED ceph_assert(recursive || !is_locked_by_me())");
}

TEST(MutexRecursiveDebug, Lock) {
Expand Down

0 comments on commit 3c9dd67

Please sign in to comment.