Skip to content

Commit

Permalink
mgr: s/Mutex/ceph::mutex/
Browse files Browse the repository at this point in the history
Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Aug 3, 2019
1 parent ed75406 commit c93dc88
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 87 deletions.
1 change: 0 additions & 1 deletion src/mgr/ActivePyModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "common/cmdparse.h"
#include "common/LogEntry.h"
#include "common/Mutex.h"
#include "common/Thread.h"
#include "mon/health_check.h"
#include "mgr/Gil.h"
Expand Down
20 changes: 10 additions & 10 deletions src/mgr/ActivePyModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ActivePyModules::ActivePyModules(PyModuleConfig &module_config_,
monc(mc), clog(clog_), audit_clog(audit_clog_), objecter(objecter_),
client(client_), finisher(f),
cmd_finisher(g_ceph_context, "cmd_finisher", "cmdfin"),
server(server), py_module_registry(pmr), lock("ActivePyModules")
server(server), py_module_registry(pmr)
{
store_cache = std::move(store_data);
cmd_finisher.start();
Expand Down Expand Up @@ -434,21 +434,21 @@ void ActivePyModules::shutdown()
auto module = i.second.get();
const auto& name = i.first;

lock.Unlock();
lock.unlock();
dout(10) << "calling module " << name << " shutdown()" << dendl;
module->shutdown();
dout(10) << "module " << name << " shutdown() returned" << dendl;
lock.Lock();
lock.lock();
}

// For modules implementing serve(), finish the threads where we
// were running that.
for (auto &i : modules) {
lock.Unlock();
lock.unlock();
dout(10) << "joining module " << i.first << dendl;
i.second->thread.join();
dout(10) << "joined module " << i.first << dendl;
lock.Lock();
lock.lock();
}

cmd_finisher.wait_for_empty();
Expand Down Expand Up @@ -895,12 +895,12 @@ void ActivePyModules::set_health_checks(const std::string& module_name,
{
bool changed = false;

lock.Lock();
lock.lock();
auto p = modules.find(module_name);
if (p != modules.end()) {
changed = p->second->set_health_checks(std::move(checks));
}
lock.Unlock();
lock.unlock();

// immediately schedule a report to be sent to the monitors with the new
// health checks that have changed. This is done asynchronusly to avoid
Expand All @@ -925,15 +925,15 @@ int ActivePyModules::handle_command(
std::stringstream *ds,
std::stringstream *ss)
{
lock.Lock();
lock.lock();
auto mod_iter = modules.find(module_name);
if (mod_iter == modules.end()) {
*ss << "Module '" << module_name << "' is not available";
lock.Unlock();
lock.unlock();
return -ENOENT;
}

lock.Unlock();
lock.unlock();
return mod_iter->second->handle_command(cmdmap, inbuf, ds, ss);
}

Expand Down
4 changes: 2 additions & 2 deletions src/mgr/ActivePyModules.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "ActivePyModule.h"

#include "common/Finisher.h"
#include "common/Mutex.h"
#include "common/ceph_mutex.h"

#include "PyFormatter.h"

Expand Down Expand Up @@ -55,7 +55,7 @@ class ActivePyModules

map<std::string,ProgressEvent> progress_events;

mutable Mutex lock{"ActivePyModules::lock"};
mutable ceph::mutex lock = ceph::make_mutex("ActivePyModules::lock");

public:
ActivePyModules(PyModuleConfig &module_config,
Expand Down
1 change: 0 additions & 1 deletion src/mgr/ClusterState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ClusterState::ClusterState(
const MgrMap& mgrmap)
: monc(monc_),
objecter(objecter_),
lock("ClusterState"),
mgr_map(mgrmap)
{}

Expand Down
4 changes: 2 additions & 2 deletions src/mgr/ClusterState.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "mds/FSMap.h"
#include "mon/MgrMap.h"
#include "common/Mutex.h"
#include "common/ceph_mutex.h"

#include "osdc/Objecter.h"
#include "mon/MonClient.h"
Expand All @@ -39,7 +39,7 @@ class ClusterState
Objecter *objecter;
FSMap fsmap;
ServiceMap servicemap;
mutable Mutex lock;
mutable ceph::mutex lock = ceph::make_mutex("ClusterState");

MgrMap mgr_map;

Expand Down
5 changes: 2 additions & 3 deletions src/mgr/DaemonServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ DaemonServer::DaemonServer(MonClient *monc_,
py_modules(py_modules_),
clog(clog_),
audit_clog(audit_clog_),
lock("DaemonServer"),
pgmap_ready(false),
timer(g_ceph_context, lock),
shutting_down(false),
Expand Down Expand Up @@ -308,7 +307,7 @@ void DaemonServer::tick()
// fire after all modules have had a chance to set their health checks.
void DaemonServer::schedule_tick_locked(double delay_sec)
{
ceph_assert(lock.is_locked_by_me());
ceph_assert(ceph_mutex_is_locked_by_me(lock));

if (tick_event) {
timer.cancel_event(tick_event);
Expand Down Expand Up @@ -2755,7 +2754,7 @@ void DaemonServer::handle_conf_change(const ConfigProxy& conf,

void DaemonServer::_send_configure(ConnectionRef c)
{
ceph_assert(lock.is_locked_by_me());
ceph_assert(ceph_mutex_is_locked_by_me(lock));

auto configure = make_message<MMgrConfigure>();
configure->stats_period = g_conf().get_val<int64_t>("mgr_stats_period");
Expand Down
4 changes: 2 additions & 2 deletions src/mgr/DaemonServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <set>
#include <string>

#include "common/Mutex.h"
#include "common/ceph_mutex.h"
#include "common/LogClient.h"
#include "common/Timer.h"

Expand Down Expand Up @@ -76,7 +76,7 @@ class DaemonServer : public Dispatcher, public md_config_obs_t

epoch_t pending_service_map_dirty = 0;

Mutex lock;
ceph::mutex lock = ceph::make_mutex("DaemonServer");

static void _generate_command_map(cmdmap_t& cmdmap,
map<string,string> &param_str_map);
Expand Down
2 changes: 1 addition & 1 deletion src/mgr/DaemonState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void DaemonStateIndex::_insert(DaemonStatePtr dm)

void DaemonStateIndex::_erase(const DaemonKey& dmk)
{
ceph_assert(lock.is_wlocked());
ceph_assert(ceph_mutex_is_wlocked(lock));

const auto to_erase = all.find(dmk);
ceph_assert(to_erase != all.end());
Expand Down
45 changes: 20 additions & 25 deletions src/mgr/Mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Mgr::Mgr(MonClient *monc_, const MgrMap& mgrmap,
objecter(objecter_),
client(client_),
client_messenger(clientm_),
lock("Mgr::lock"),
finisher(g_ceph_context, "Mgr", "mgr-fin"),
digest_received(false),
py_module_registry(py_module_registry_),
Expand Down Expand Up @@ -167,14 +166,14 @@ void Mgr::background_init(Context *completion)

std::map<std::string, std::string> Mgr::load_store()
{
ceph_assert(lock.is_locked_by_me());
ceph_assert(ceph_mutex_is_locked_by_me(lock));

dout(10) << "listing keys" << dendl;
JSONCommand cmd;
cmd.run(monc, "{\"prefix\": \"config-key ls\"}");
lock.Unlock();
lock.unlock();
cmd.wait();
lock.Lock();
lock.lock();
ceph_assert(cmd.r == 0);

std::map<std::string, std::string> loaded;
Expand All @@ -194,9 +193,9 @@ std::map<std::string, std::string> Mgr::load_store()
std::ostringstream cmd_json;
cmd_json << "{\"prefix\": \"config-key get\", \"key\": \"" << key << "\"}";
get_cmd.run(monc, cmd_json.str());
lock.Unlock();
lock.unlock();
get_cmd.wait();
lock.Lock();
lock.lock();
if (get_cmd.r == 0) { // tolerate racing config-key change
if (key.substr(0, device_prefix.size()) == device_prefix) {
// device/
Expand Down Expand Up @@ -227,7 +226,7 @@ std::map<std::string, std::string> Mgr::load_store()

void Mgr::init()
{
std::lock_guard l(lock);
std::unique_lock l(lock);
ceph_assert(initializing);
ceph_assert(!initialized);

Expand Down Expand Up @@ -263,9 +262,9 @@ void Mgr::init()
monc->reopen_session();

// Start Objecter and wait for OSD map
lock.Unlock(); // Drop lock because OSDMap dispatch calls into my ms_dispatch
lock.unlock(); // Drop lock because OSDMap dispatch calls into my ms_dispatch
objecter->wait_for_osd_map();
lock.Lock();
lock.lock();

// Populate PGs in ClusterState
cluster_state.with_osdmap_and_pgmap([this](const OSDMap &osd_map,
Expand All @@ -275,26 +274,22 @@ void Mgr::init()

// Wait for FSMap
dout(4) << "waiting for FSMap..." << dendl;
while (!cluster_state.have_fsmap()) {
fs_map_cond.Wait(lock);
}
fs_map_cond.wait(l, [this] { return cluster_state.have_fsmap();});

dout(4) << "waiting for config-keys..." << dendl;

// Wait for MgrDigest...
dout(4) << "waiting for MgrDigest..." << dendl;
while (!digest_received) {
digest_cond.Wait(lock);
}
digest_cond.wait(l, [this] { return digest_received; });

// Load module KV store
auto kv_store = load_store();

// Migrate config from KV store on luminous->mimic
// drop lock because we do blocking config sets to mon
lock.Unlock();
lock.unlock();
py_module_registry->upgrade_config(monc, kv_store);
lock.Lock();
lock.lock();

// assume finisher already initialized in background_init
dout(4) << "starting python modules..." << dendl;
Expand All @@ -309,7 +304,7 @@ void Mgr::init()

void Mgr::load_all_metadata()
{
ceph_assert(lock.is_locked_by_me());
ceph_assert(ceph_mutex_is_locked_by_me(lock));

JSONCommand mds_cmd;
mds_cmd.run(monc, "{\"prefix\": \"mds metadata\"}");
Expand All @@ -318,11 +313,11 @@ void Mgr::load_all_metadata()
JSONCommand mon_cmd;
mon_cmd.run(monc, "{\"prefix\": \"mon metadata\"}");

lock.Unlock();
lock.unlock();
mds_cmd.wait();
osd_cmd.wait();
mon_cmd.wait();
lock.Lock();
lock.lock();

ceph_assert(mds_cmd.r == 0);
ceph_assert(mon_cmd.r == 0);
Expand Down Expand Up @@ -422,7 +417,7 @@ void Mgr::shutdown()

void Mgr::handle_osd_map()
{
ceph_assert(lock.is_locked_by_me());
ceph_assert(ceph_mutex_is_locked_by_me(lock));

std::set<std::string> names_exist;

Expand Down Expand Up @@ -508,7 +503,7 @@ void Mgr::handle_service_map(ref_t<MServiceMap> m)
void Mgr::handle_mon_map()
{
dout(20) << __func__ << dendl;
assert(lock.is_locked_by_me());
assert(ceph_mutex_is_locked_by_me(lock));
std::set<std::string> names_exist;
cluster_state.with_monmap([&] (auto &monmap) {
for (unsigned int i = 0; i < monmap.size(); i++) {
Expand Down Expand Up @@ -562,13 +557,13 @@ bool Mgr::ms_dispatch2(const ref_t<Message>& m)

void Mgr::handle_fs_map(ref_t<MFSMap> m)
{
ceph_assert(lock.is_locked_by_me());
ceph_assert(ceph_mutex_is_locked_by_me(lock));

std::set<std::string> names_exist;

const FSMap &new_fsmap = m->get_fsmap();

fs_map_cond.Signal();
fs_map_cond.notify_all();

// TODO: callers (e.g. from python land) are potentially going to see
// the new fsmap before we've bothered populating all the resulting
Expand Down Expand Up @@ -668,7 +663,7 @@ void Mgr::handle_mgr_digest(ref_t<MMgrDigest> m)

if (!digest_received) {
digest_received = true;
digest_cond.Signal();
digest_cond.notify_all();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/mgr/Mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class Mgr {
Client *client;
Messenger *client_messenger;

mutable Mutex lock;
mutable ceph::mutex lock = ceph::make_mutex("Mgr::lock");
Finisher finisher;

// Track receipt of initial data during startup
Cond fs_map_cond;
ceph::condition_variable fs_map_cond;
bool digest_received;
Cond digest_cond;
ceph::condition_variable digest_cond;

PyModuleRegistry *py_module_registry;
DaemonStateIndex daemon_state;
Expand Down
Loading

0 comments on commit c93dc88

Please sign in to comment.