int ActivePyModule::load(ActivePyModules *py_modules)
{
- assert(py_modules);
+ ceph_assert(py_modules);
Gil gil(py_module->pMyThreadState, true);
// We tell the module how we name it, so that it can be consistent
void ActivePyModule::notify(const std::string ¬ify_type, const std::string ¬ify_id)
{
- assert(pClassInstance != nullptr);
+ ceph_assert(pClassInstance != nullptr);
Gil gil(py_module->pMyThreadState, true);
void ActivePyModule::notify_clog(const LogEntry &log_entry)
{
- assert(pClassInstance != nullptr);
+ ceph_assert(pClassInstance != nullptr);
Gil gil(py_module->pMyThreadState, true);
PyObject *kwargs,
std::string *err)
{
- assert(err != nullptr);
+ ceph_assert(err != nullptr);
// Rather than serializing arguments, pass the CPython objects.
// Works because we happen to know that the subinterpreter
auto boundMethod = PyObject_GetAttrString(pClassInstance, method.c_str());
// Caller should have done method_exists check first!
- assert(boundMethod != nullptr);
+ ceph_assert(boundMethod != nullptr);
dout(20) << "Calling " << py_module->get_name()
<< "." << method << "..." << dendl;
std::stringstream *ds,
std::stringstream *ss)
{
- assert(ss != nullptr);
- assert(ds != nullptr);
+ ceph_assert(ss != nullptr);
+ ceph_assert(ds != nullptr);
if (pClassInstance == nullptr) {
// Not the friendliest error string, but we could only
{
Mutex::Locker l(lock);
- assert(modules.count(py_module->get_name()) == 0);
+ ceph_assert(modules.count(py_module->get_name()) == 0);
modules[py_module->get_name()].reset(new ActivePyModule(py_module, clog));
auto active_module = modules.at(py_module->get_name()).get();
std::string *err)
{
auto mod_iter = modules.find(other_module);
- assert(mod_iter != modules.end());
+ ceph_assert(mod_iter != modules.end());
return mod_iter->second->dispatch_remote(method, args, kwargs, err);
}
derr << "Failed to import python module:" << dendl;
derr << handle_pyerror() << dendl;
}
- assert(module);
+ ceph_assert(module);
PyObject *wrapper_type = PyObject_GetAttrString(
module, (const char*)clsname.c_str());
derr << "Failed to get python type:" << dendl;
derr << handle_pyerror() << dendl;
}
- assert(wrapper_type);
+ ceph_assert(wrapper_type);
// Construct a capsule containing an OSDMap.
auto wrapped_capsule = PyCapsule_New(wrapped, nullptr, nullptr);
- assert(wrapped_capsule);
+ ceph_assert(wrapped_capsule);
// Construct the python OSDMap
auto pArgs = PyTuple_Pack(1, wrapped_capsule);
derr << "Failed to construct python OSDMap:" << dendl;
derr << handle_pyerror() << dendl;
}
- assert(wrapper_instance != nullptr);
+ ceph_assert(wrapper_instance != nullptr);
Py_DECREF(pArgs);
Py_DECREF(wrapped_capsule);
: py_modules(py_modules_), python_completion(ev),
tag(tag_), pThreadState(ts_)
{
- assert(python_completion != nullptr);
+ ceph_assert(python_completion != nullptr);
Py_INCREF(python_completion);
}
void finish(int r) override
{
- assert(python_completion != nullptr);
+ ceph_assert(python_completion != nullptr);
dout(10) << "MonCommandCompletion::finish()" << dendl;
{
Gil gil(pThreadState, true);
auto set_fn = PyObject_GetAttrString(python_completion, "complete");
- assert(set_fn != nullptr);
+ ceph_assert(set_fn != nullptr);
auto pyR = PyInt_FromLong(r);
auto pyOutBl = PyString_FromString(outbl.to_str().c_str());
if (set_fn == nullptr) {
ceph_abort(); // TODO raise python exception instead
} else {
- assert(PyCallable_Check(set_fn));
+ ceph_assert(PyCallable_Check(set_fn));
}
Py_DECREF(set_fn);
return nullptr;
}
- assert(self->this_module);
+ ceph_assert(self->this_module);
self->this_module->log(level, record);
self->py_modules = static_cast<ActivePyModules*>(PyCapsule_GetPointer(
py_modules_capsule, nullptr));
- assert(self->py_modules);
+ ceph_assert(self->py_modules);
self->this_module = static_cast<ActivePyModule*>(PyCapsule_GetPointer(
this_module_capsule, nullptr));
- assert(self->this_module);
+ ceph_assert(self->this_module);
return 0;
}
self->this_module = static_cast<StandbyPyModule*>(PyCapsule_GetPointer(
this_module_capsule, nullptr));
- assert(self->this_module);
+ ceph_assert(self->this_module);
return 0;
}
return nullptr;
}
- assert(self->this_module);
+ ceph_assert(self->this_module);
self->this_module->log(level, record);
void with_monmap(Args &&... args) const
{
Mutex::Locker l(lock);
- assert(monc != nullptr);
+ ceph_assert(monc != nullptr);
monc->with_monmap(std::forward<Args>(args)...);
}
auto with_osdmap(Args &&... args) const ->
decltype(objecter->with_osdmap(std::forward<Args>(args)...))
{
- assert(objecter != nullptr);
+ ceph_assert(objecter != nullptr);
return objecter->with_osdmap(std::forward<Args>(args)...);
}
// fire after all modules have had a chance to set their health checks.
void DaemonServer::schedule_tick_locked(double delay_sec)
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
if (tick_event) {
timer.cancel_event(tick_event);
}
// Update the DaemonState
- assert(daemon != nullptr);
+ ceph_assert(daemon != nullptr);
{
Mutex::Locker l(daemon->lock);
auto &daemon_counters = daemon->perf_counters;
std::stringstream ss;
std::string prefix;
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
/**
* The working data for processing an MCommand. This lives in
for (auto& q : p.second.daemons) {
f->open_object_section(q.first.c_str());
DaemonKey key(p.first, q.first);
- assert(daemon_state.exists(key));
+ ceph_assert(daemon_state.exists(key));
auto daemon = daemon_state.get(key);
Mutex::Locker l(daemon->lock);
f->dump_stream("status_stamp") << daemon->service_status_stamp;
if (!pool_name.empty()) {
poolid = osdmap.lookup_pg_pool_name(pool_name);
if (poolid < 0) {
- assert(poolid == -ENOENT);
+ ceph_assert(poolid == -ENOENT);
ss << "unrecognized pool '" << pool_name << "'";
return -ENOENT;
}
}
break;
default:
- assert(0 == "actual_op value is not supported");
+ ceph_assert(0 == "actual_op value is not supported");
}
parsed_pgs.push_back(std::move(parsed_pg));
void DaemonServer::_send_configure(ConnectionRef c)
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
auto configure = new MMgrConfigure();
configure->stats_period = g_conf().get_val<int64_t>("mgr_stats_period");
void DaemonStateIndex::_erase(const DaemonKey& dmk)
{
- assert(lock.is_wlocked());
+ ceph_assert(lock.is_wlocked());
const auto to_erase = all.find(dmk);
- assert(to_erase != all.end());
+ ceph_assert(to_erase != all.end());
const auto dm = to_erase->second;
for (auto& i : dm->devices) {
auto d = _get_or_create_device(i.first);
- assert(d->daemons.count(dmk));
+ ceph_assert(d->daemons.count(dmk));
d->daemons.erase(dmk);
d->devnames.erase(make_pair(dm->hostname, i.second));
if (d->empty()) {
SafeThreadState::SafeThreadState(PyThreadState *ts_)
: ts(ts_)
{
- assert(ts != nullptr);
+ ceph_assert(ts != nullptr);
thread = pthread_self();
}
PyThreadState_Swap(pNewThreadState);
dout(20) << "Switched to new thread state " << pNewThreadState << dendl;
} else {
- assert(pthread_self() == pThreadState.thread);
+ ceph_assert(pthread_self() == pThreadState.thread);
}
}
void Mgr::background_init(Context *completion)
{
Mutex::Locker l(lock);
- assert(!initializing);
- assert(!initialized);
+ ceph_assert(!initializing);
+ ceph_assert(!initialized);
initializing = true;
finisher.start();
std::map<std::string, std::string> Mgr::load_store()
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
dout(10) << "listing keys" << dendl;
JSONCommand cmd;
lock.Unlock();
cmd.wait();
lock.Lock();
- assert(cmd.r == 0);
+ ceph_assert(cmd.r == 0);
std::map<std::string, std::string> loaded;
void Mgr::init()
{
Mutex::Locker l(lock);
- assert(initializing);
- assert(!initialized);
+ ceph_assert(initializing);
+ ceph_assert(!initialized);
// Start communicating with daemons to learn statistics etc
int r = server.init(monc->get_global_id(), client_messenger->get_myaddrs());
void Mgr::load_all_metadata()
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
JSONCommand mds_cmd;
mds_cmd.run(monc, "{\"prefix\": \"mds metadata\"}");
mon_cmd.wait();
lock.Lock();
- assert(mds_cmd.r == 0);
- assert(mon_cmd.r == 0);
- assert(osd_cmd.r == 0);
+ ceph_assert(mds_cmd.r == 0);
+ ceph_assert(mon_cmd.r == 0);
+ ceph_assert(osd_cmd.r == 0);
for (auto &metadata_val : mds_cmd.json_result.get_array()) {
json_spirit::mObject daemon_meta = metadata_val.get_obj();
void Mgr::handle_osd_map()
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
std::set<std::string> names_exist;
void Mgr::handle_fs_map(MFSMap* m)
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
std::set<std::string> names_exist;
: Dispatcher(cct_), cct(cct_), msgr(msgr_),
timer(cct_, lock)
{
- assert(cct != nullptr);
+ ceph_assert(cct != nullptr);
}
void MgrClient::init()
{
Mutex::Locker l(lock);
- assert(msgr != nullptr);
+ ceph_assert(msgr != nullptr);
timer.init();
}
void MgrClient::reconnect()
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
if (session) {
ldout(cct, 4) << "Terminating session with "
// resend any pending commands
for (const auto &p : command_table.get_commands()) {
MCommand *m = p.second.get_message({});
- assert(session);
- assert(session->con);
+ ceph_assert(session);
+ ceph_assert(session->con);
session->con->send_message(m);
}
}
bool MgrClient::handle_mgr_map(MMgrMap *m)
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
ldout(cct, 20) << *m << dendl;
void MgrClient::_send_report()
{
- assert(lock.is_locked_by_me());
- assert(session);
+ ceph_assert(lock.is_locked_by_me());
+ ceph_assert(session);
report_callback = nullptr;
auto report = new MMgrReport();
bool MgrClient::handle_mgr_configure(MMgrConfigure *m)
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
ldout(cct, 20) << *m << dendl;
bool MgrClient::handle_command_reply(MCommandReply *m)
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
ldout(cct, 20) << *m << dendl;
void MgrStandby::send_beacon()
{
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
dout(4) << state_str() << dendl;
std::list<PyModuleRef> modules = py_module_registry.get_modules();
void MgrStandby::handle_signal(int signum)
{
Mutex::Locker l(lock);
- assert(signum == SIGINT || signum == SIGTERM);
+ ceph_assert(signum == SIGINT || signum == SIGTERM);
derr << "*** Got signal " << sig_str(signum) << " ***" << dendl;
shutdown();
}
void MgrStandby::shutdown()
{
// Expect already to be locked as we're called from signal handler
- assert(lock.is_locked_by_me());
+ ceph_assert(lock.is_locked_by_me());
dout(4) << "Shutting down" << dendl;
/* Print CWD for the user's interest */
char buf[PATH_MAX];
char *cwd = getcwd(buf, sizeof(buf));
- assert(cwd);
+ ceph_assert(cwd);
dout(1) << " cwd " << cwd << dendl;
/* Fall back to a best-effort: just running in our CWD */
void PyFormatter::dump_unsigned(const char *name, uint64_t u)
{
PyObject *p = PyLong_FromLongLong(u);
- assert(p);
+ ceph_assert(p);
dump_pyobject(name, p);
}
void PyFormatter::dump_int(const char *name, int64_t u)
{
PyObject *p = PyLong_FromLongLong(u);
- assert(p);
+ ceph_assert(p);
dump_pyobject(name, p);
}
void open_object_section(const char *name) override;
void close_section() override
{
- assert(cursor != root);
- assert(!stack.empty());
+ ceph_assert(cursor != root);
+ ceph_assert(!stack.empty());
cursor = stack.top();
stack.pop();
}
{
PyObject *ptype, *pvalue, *ptraceback;
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
- assert(ptype);
- assert(pvalue);
+ ceph_assert(ptype);
+ ceph_assert(pvalue);
PyObject *pvalue_str = PyObject_Str(pvalue);
std::string exc_msg = PyString_AsString(pvalue_str);
Py_DECREF(pvalue_str);
// CPython doesn't auto-add site-packages dirs to sys.path for us,
// but it does provide a module that we can ask for them.
auto site_module = PyImport_ImportModule("site");
- assert(site_module);
+ ceph_assert(site_module);
auto site_packages_fn = PyObject_GetAttrString(site_module, "getsitepackages");
if (site_packages_fn != nullptr) {
auto site_packages_list = PyObject_CallObject(site_packages_fn, nullptr);
- assert(site_packages_list);
+ ceph_assert(site_packages_list);
auto n = PyList_Size(site_packages_list);
for (Py_ssize_t i = 0; i < n; ++i) {
// run inside virtualenvs :-/
auto site_packages_fn = PyObject_GetAttrString(site_module, "addsitepackages");
- assert(site_packages_fn);
+ ceph_assert(site_packages_fn);
auto known_paths = PySet_New(nullptr);
auto pArgs = PyTuple_Pack(1, known_paths);
Py_DECREF(site_packages_fn);
auto sys_module = PyImport_ImportModule("sys");
- assert(sys_module);
+ ceph_assert(sys_module);
auto sys_path = PyObject_GetAttrString(sys_module, "path");
- assert(sys_path);
+ ceph_assert(sys_path);
dout(1) << "sys.path:" << dendl;
auto n = PyList_Size(sys_path);
#else
PyObject *ceph_module = Py_InitModule("ceph_module", module_methods);
#endif
- assert(ceph_module != nullptr);
+ ceph_assert(ceph_module != nullptr);
std::map<const char*, PyTypeObject*> classes{
{{"BaseMgrModule", &BaseMgrModuleType},
{"BaseMgrStandbyModule", &BaseMgrStandbyModuleType},
for (auto [name, type] : classes) {
type->tp_new = PyType_GenericNew;
if (PyType_Ready(type) < 0) {
- assert(0);
+ ceph_assert(0);
}
Py_INCREF(type);
int PyModule::load(PyThreadState *pMainThreadState)
{
- assert(pMainThreadState != nullptr);
+ ceph_assert(pMainThreadState != nullptr);
// Configure sub-interpreter
{
const size_t list_size = PyList_Size(command_list);
for (size_t i = 0; i < list_size; ++i) {
PyObject *command = PyList_GetItem(command_list, i);
- assert(command != nullptr);
+ ceph_assert(command != nullptr);
if (!PyDict_Check(command)) {
derr << "Module " << get_name() << " has non-dict entry "
ModuleCommand command;
PyObject *pCmd = PyDict_GetItemString(pCommand, "cmd");
- assert(pCmd != nullptr);
+ ceph_assert(pCmd != nullptr);
command.cmdstring = PyString_AsString(pCmd);
dout(20) << "loaded command " << command.cmdstring << dendl;
PyObject *pDesc = PyDict_GetItemString(pCommand, "desc");
- assert(pDesc != nullptr);
+ ceph_assert(pDesc != nullptr);
command.helpstring = PyString_AsString(pDesc);
PyObject *pPerm = PyDict_GetItemString(pCommand, "perm");
- assert(pPerm != nullptr);
+ ceph_assert(pPerm != nullptr);
command.perm = PyString_AsString(pPerm);
command.polling = false;
{
int r = walk_dict_list("OPTIONS", [this](PyObject *pOption) -> int {
PyObject *pName = PyDict_GetItemString(pOption, "name");
- assert(pName != nullptr);
+ ceph_assert(pName != nullptr);
ModuleOption option;
option.name = PyString_AsString(pName);
void get_commands(std::vector<ModuleCommand> *out) const
{
Mutex::Locker l(lock);
- assert(out != nullptr);
+ ceph_assert(out != nullptr);
out->insert(out->end(), commands.begin(), commands.end());
}
// Drop the GIL and remember the main thread state (current
// thread state becomes NULL)
pMainThreadState = PyEval_SaveThread();
- assert(pMainThreadState != nullptr);
+ ceph_assert(pMainThreadState != nullptr);
std::list<std::string> failed_modules;
void PyModuleRegistry::standby_start(MonClient &mc)
{
Mutex::Locker l(lock);
- assert(active_modules == nullptr);
- assert(standby_modules == nullptr);
+ ceph_assert(active_modules == nullptr);
+ ceph_assert(standby_modules == nullptr);
// Must have seen a MgrMap by this point, in order to know
// which modules should be enabled
- assert(mgr_map.epoch > 0);
+ ceph_assert(mgr_map.epoch > 0);
dout(4) << "Starting modules in standby mode" << dendl;
dout(4) << "Starting modules in active mode" << dendl;
- assert(active_modules == nullptr);
+ ceph_assert(active_modules == nullptr);
// Must have seen a MgrMap by this point, in order to know
// which modules should be enabled
- assert(mgr_map.epoch > 0);
+ ceph_assert(mgr_map.epoch > 0);
if (standby_modules != nullptr) {
standby_modules->shutdown();
void with_active_modules(Callback&& cb, Args&&...args) const
{
Mutex::Locker l(lock);
- assert(active_modules != nullptr);
+ ceph_assert(active_modules != nullptr);
std::forward<Callback>(cb)(*active_modules, std::forward<Args>(args)...);
}
std::map<std::string, std::string> get_services() const
{
- assert(active_modules);
+ ceph_assert(active_modules);
return active_modules->get_services();
}
// <<< (end of ActivePyModules cheeky call-throughs)
int PyModuleRunner::serve()
{
- assert(pClassInstance != nullptr);
+ ceph_assert(pClassInstance != nullptr);
// This method is called from a separate OS thread (i.e. a thread not
// created by Python), so tell Gil to wrap this in a new thread state.
void PyModuleRunner::shutdown()
{
- assert(pClassInstance != nullptr);
+ ceph_assert(pClassInstance != nullptr);
Gil gil(py_module->pMyThreadState, true);
// required to be <16 chars
thread_name = py_module->get_name().substr(0, 15);
- assert(py_module != nullptr);
+ ceph_assert(py_module != nullptr);
}
~PyModuleRunner();
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O",
const_cast<char**>(kwlist),
&osdmap_capsule)) {
- assert(0);
+ ceph_assert(0);
return -1;
}
- assert(PyObject_TypeCheck(osdmap_capsule, &PyCapsule_Type));
+ ceph_assert(PyObject_TypeCheck(osdmap_capsule, &PyCapsule_Type));
self->osdmap = (OSDMap*)PyCapsule_GetPointer(
osdmap_capsule, nullptr);
- assert(self->osdmap);
+ ceph_assert(self->osdmap);
return 0;
}
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O",
const_cast<char**>(kwlist),
&inc_capsule)) {
- assert(0);
+ ceph_assert(0);
return -1;
}
- assert(PyObject_TypeCheck(inc_capsule, &PyCapsule_Type));
+ ceph_assert(PyObject_TypeCheck(inc_capsule, &PyCapsule_Type));
self->inc = (OSDMap::Incremental*)PyCapsule_GetPointer(
inc_capsule, nullptr);
- assert(self->inc);
+ ceph_assert(self->inc);
return 0;
}
}
CrushWrapper crush;
- assert(self->inc->crush.length()); // see new_incremental
+ ceph_assert(self->inc->crush.length()); // see new_incremental
auto p = self->inc->crush.cbegin();
decode(crush, p);
crush.create_choose_args(CrushWrapper::DEFAULT_CHOOSE_ARGS, 1);
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O",
const_cast<char**>(kwlist),
&crush_capsule)) {
- assert(0);
+ ceph_assert(0);
return -1;
}
- assert(PyObject_TypeCheck(crush_capsule, &PyCapsule_Type));
+ ceph_assert(PyObject_TypeCheck(crush_capsule, &PyCapsule_Type));
auto ptr_ref = (std::shared_ptr<CrushWrapper>*)(
PyCapsule_GetPointer(crush_capsule, nullptr));
// pointer construction now, and then we throw away that pointer to
// the shared pointer.
self->crush = *ptr_ref;
- assert(self->crush);
+ ceph_assert(self->crush);
return 0;
}
Mutex::Locker l(lock);
const std::string &module_name = py_module->get_name();
- assert(modules.count(module_name) == 0);
+ ceph_assert(modules.count(module_name) == 0);
modules[module_name].reset(new StandbyPyModule(
state,
// We tell the module how we name it, so that it can be consistent
// with us in logging etc.
auto pThisPtr = PyCapsule_New(this, nullptr, nullptr);
- assert(pThisPtr != nullptr);
+ ceph_assert(pThisPtr != nullptr);
auto pModuleName = PyString_FromString(get_name().c_str());
- assert(pModuleName != nullptr);
+ ceph_assert(pModuleName != nullptr);
auto pArgs = PyTuple_Pack(2, pModuleName, pThisPtr);
Py_DECREF(pThisPtr);
Py_DECREF(pModuleName);