MCPcopy Create free account
hub / github.com/ceph/ceph / load

Method load

src/mgr/PyModule.cc:339–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339int PyModule::load(PyThreadState *pMainThreadState)
340{
341 ceph_assert(pMainThreadState != nullptr);
342
343 const auto subinterpreter_modules_opt = g_conf().get_val<std::string>(
344 "mgr_subinterpreter_modules"
345 );
346 auto subinterpreter_modules = ceph::split(subinterpreter_modules_opt);
347 use_main_interpreter = std::count(
348 subinterpreter_modules.begin(), subinterpreter_modules.end(), "*"
349 ) == 0 && std::count(
350 subinterpreter_modules.begin(), subinterpreter_modules.end(), module_name
351 ) == 0;
352
353 if (use_main_interpreter) {
354 // Use main interpreter
355 derr << "Loading module " << module_name << " in main interpreter" << dendl;
356 pMyThreadState.set(pMainThreadState);
357 } else {
358 // Configure sub-interpreter
359 derr << "Loading module " << module_name << " in sub-interpreter" << dendl;
360 SafeThreadState sts(pMainThreadState);
361 Gil gil(sts);
362
363 auto thread_state = Py_NewInterpreter();
364 if (thread_state == nullptr) {
365 derr << "Failed to create python sub-interpreter for '" << module_name << '"' << dendl;
366 return -EINVAL;
367 } else {
368 pMyThreadState.set(thread_state);
369 }
370 }
371
372 // Environment is all good, import the external module
373 {
374 Gil gil(pMyThreadState);
375
376 int r;
377
378 pPickleModule = PyImport_ImportModule("pickle");
379 if (!pPickleModule) {
380 derr << "Unable to load pickle" << dendl;
381 return -EINVAL;
382 }
383
384 r = load_subclass_of("MgrModule", &pClass);
385 if (r) {
386 derr << "Class not found in module '" << module_name << "'" << dendl;
387 return r;
388 }
389
390 r = load_commands();
391 if (r != 0) {
392 derr << "Missing or invalid COMMANDS attribute in module '"
393 << module_name << "'" << dendl;
394 error_string = "Missing or invalid COMMANDS attribute";
395 return r;
396 }

Callers 10

initMethod · 0.45
dump_pg_readyMethod · 0.45
maybe_readyMethod · 0.45
get_tidMethod · 0.45
start_oneMethod · 0.45
EntryMethod · 0.45
is_enabledMethod · 0.45
get_hitsMethod · 0.45
get_missesMethod · 0.45
insertMethod · 0.45

Calls 6

handle_pyerrorFunction · 0.85
splitClass · 0.50
get_nameFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected