| 134 | } |
| 135 | |
| 136 | int 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); |
no test coverage detected