iterate across plugins and determine each capability's reqirement merge requirements into merge_caps set
| 45 | // iterate across plugins and determine each capability's reqirement |
| 46 | // merge requirements into merge_caps set |
| 47 | int get_required_caps(CephContext *cct, cap_t &merge_caps) |
| 48 | { |
| 49 | cap_t plugin_caps = nullptr; |
| 50 | auto close_caps_on_return = make_scope_guard([&] { |
| 51 | if (plugin_caps != nullptr) { |
| 52 | cap_free(plugin_caps); |
| 53 | } |
| 54 | }); |
| 55 | |
| 56 | // plugin-private cap set to populate by a plugin |
| 57 | plugin_caps = cap_init(); |
| 58 | if (plugin_caps == nullptr) { |
| 59 | return -errno; |
| 60 | } |
| 61 | auto registry = cct->get_plugin_registry(); |
| 62 | std::lock_guard l(registry->lock); |
| 63 | // did we preload any extblkdev type plugins? |
| 64 | auto ptype = registry->plugins.find("extblkdev"); |
| 65 | if (ptype != registry->plugins.end()) { |
| 66 | // iterate over all extblkdev plugins |
| 67 | for (auto& it : ptype->second) { |
| 68 | // clear cap set before passing to plugin |
| 69 | if (cap_clear(plugin_caps) < 0) { |
| 70 | return -errno; |
| 71 | } |
| 72 | // let plugin populate set with required caps |
| 73 | auto ebdplugin = dynamic_cast<ExtBlkDevPlugin*>(it.second); |
| 74 | if (ebdplugin == nullptr) { |
| 75 | derr << __func__ << " Is not an extblkdev plugin: " << it.first << dendl; |
| 76 | return -ENOENT; |
| 77 | } |
| 78 | int rc = ebdplugin->get_required_cap_set(plugin_caps); |
| 79 | if (rc != 0) |
| 80 | return rc; |
| 81 | // iterate over capabilities and check for active bits |
| 82 | for (int i = 0; i <= CAP_LAST_CAP; ++i) { |
| 83 | cap_flag_value_t val; |
| 84 | if (cap_get_flag(plugin_caps, i, CAP_PERMITTED, &val) < 0) { |
| 85 | return -errno; |
| 86 | } |
| 87 | if (val != CAP_CLEAR) { |
| 88 | cap_value_t arr[1]; |
| 89 | arr[0] = i; |
| 90 | // set capability in merged set |
| 91 | if (cap_set_flag(merge_caps, CAP_PERMITTED, 1, arr, CAP_SET) < 0) { |
| 92 | return -errno; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | // trim away all capabilities of this process that are not explicitly set in merge_set |
| 102 | int trim_caps(CephContext *cct, cap_t &merge_caps) |
no test coverage detected