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

Method load

src/common/PluginRegistry.cc:136–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136int PluginRegistry::load(const std::string &type,
137 const std::string &name)
138{
139 ceph_assert(ceph_mutex_is_locked(lock));
140 ldout(cct, 1) << __func__ << " " << type << " " << name << dendl;
141
142 std::string fname = cct->_conf.get_val<std::string>("plugin_dir") + "/" + type + "/" + PLUGIN_PREFIX
143 + name + PLUGIN_SUFFIX;
144 void *library = dlopen(fname.c_str(), RTLD_NOW);
145 if (!library) {
146 string err1(dlerror());
147 // fall back to plugin_dir
148 fname = cct->_conf.get_val<std::string>("plugin_dir") + "/" + PLUGIN_PREFIX +
149 name + PLUGIN_SUFFIX;
150 library = dlopen(fname.c_str(), RTLD_NOW);
151 if (!library) {
152 lderr(cct) << __func__
153 << " failed dlopen(): \"" << err1.c_str()
154 << "\" or \"" << dlerror() << "\""
155 << dendl;
156 return -EIO;
157 }
158 }
159
160 const char * (*code_version)() =
161 (const char *(*)())dlsym(library, PLUGIN_VERSION_FUNCTION);
162 if (code_version == NULL) {
163 lderr(cct) << __func__ << " code_version == NULL" << dlerror() << dendl;
164 return -EXDEV;
165 }
166 if (code_version() != string(CEPH_GIT_NICE_VER)) {
167 lderr(cct) << __func__ << " plugin " << fname << " version "
168 << code_version() << " != expected "
169 << CEPH_GIT_NICE_VER << dendl;
170 dlclose(library);
171 return -EXDEV;
172 }
173
174 int (*code_init)(CephContext *,
175 const std::string& type,
176 const std::string& name) =
177 (int (*)(CephContext *,
178 const std::string& type,
179 const std::string& name))dlsym(library, PLUGIN_INIT_FUNCTION);
180 if (code_init) {
181 int r = code_init(cct, type, name);
182 if (r != 0) {
183 lderr(cct) << __func__ << " " << fname << " "
184 << PLUGIN_INIT_FUNCTION << "(" << cct
185 << "," << type << "," << name << "): " << cpp_strerror(r)
186 << dendl;
187 dlclose(library);
188 return r;
189 }
190 } else {
191 lderr(cct) << __func__ << " " << fname << " dlsym(" << PLUGIN_INIT_FUNCTION
192 << "): " << dlerror() << dendl;
193 dlclose(library);

Callers 15

inc_with_maxMethod · 0.45
tinc_with_maxMethod · 0.45
HW_profileMethod · 0.45
~HW_profileMethod · 0.45
cputrace_startFunction · 0.45
cputrace_stopFunction · 0.45
cputrace_dumpFunction · 0.45
unrefMethod · 0.45
get_mon_addrsMethod · 0.45
getMethod · 0.45
get_or_failMethod · 0.45

Calls 7

dlopenFunction · 0.85
dlerrorFunction · 0.85
dlsymFunction · 0.85
dlcloseFunction · 0.85
cpp_strerrorFunction · 0.85
getFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected