|
19 | 19 |
|
20 | 20 | #include "config_service_v1.hpp" |
21 | 21 | #include "service_helpers.hpp" |
| 22 | +#include "v26/wsrep_api.h" |
22 | 23 | #include "v26/wsrep_config_service.h" |
23 | 24 | #include "wsrep/logger.hpp" |
24 | 25 | #include "wsrep/provider_options.hpp" |
@@ -150,7 +151,7 @@ static void config_service_v1_deinit(void* dlh) |
150 | 151 | int wsrep::config_service_v1_fetch(wsrep::provider& provider, |
151 | 152 | wsrep::provider_options* options) |
152 | 153 | { |
153 | | - struct wsrep_st* wsrep = (struct wsrep_st*)provider.native(); |
| 154 | + struct wsrep_st* wsrep = static_cast<struct wsrep_st*>(provider.native()); |
154 | 155 | if (wsrep == nullptr) |
155 | 156 | { |
156 | 157 | // Not a provider which was loaded via wsrep-API |
@@ -179,3 +180,70 @@ int wsrep::config_service_v1_fetch(wsrep::provider& provider, |
179 | 180 |
|
180 | 181 | return 0; |
181 | 182 | } |
| 183 | + |
| 184 | +namespace wsrep_config_service_v2 |
| 185 | +{ |
| 186 | + wsrep_config_service_v2_t service{ 0 }; |
| 187 | + |
| 188 | + wsrep_status_t service_callback(const wsrep_parameter* p, void* context) |
| 189 | + { |
| 190 | + return wsrep_config_service_v1::service_callback(p, context); |
| 191 | + } |
| 192 | +} // namespace wsrep_config_service_v2 |
| 193 | + |
| 194 | +static int config_service_v2_probe(void* dlh) |
| 195 | +{ |
| 196 | + typedef int (*init_fn)(wsrep_config_service_v2_t*); |
| 197 | + typedef void (*deinit_fn)(); |
| 198 | + return wsrep_impl::service_probe<init_fn>( |
| 199 | + dlh, WSREP_CONFIG_SERVICE_INIT_FUNC_V2, "config service v2") |
| 200 | + || wsrep_impl::service_probe<deinit_fn>( |
| 201 | + dlh, WSREP_CONFIG_SERVICE_DEINIT_FUNC_V2, "config service v2"); |
| 202 | +} |
| 203 | + |
| 204 | +static int config_service_v2_init(void* dlh) |
| 205 | +{ |
| 206 | + typedef int (*init_fn)(wsrep_config_service_v2_t*); |
| 207 | + return wsrep_impl::service_init<init_fn>( |
| 208 | + dlh, WSREP_CONFIG_SERVICE_INIT_FUNC_V2, |
| 209 | + &wsrep_config_service_v2::service, "config service v2"); |
| 210 | +} |
| 211 | + |
| 212 | +static void config_service_v2_deinit(void* dlh) |
| 213 | +{ |
| 214 | + typedef int (*deinit_fn)(); |
| 215 | + wsrep_impl::service_deinit<deinit_fn>( |
| 216 | + dlh, WSREP_CONFIG_SERVICE_DEINIT_FUNC_V2, "config service v2"); |
| 217 | +} |
| 218 | + |
| 219 | +int wsrep::config_service_v2_fetch(struct wsrep_st* wsrep, |
| 220 | + wsrep::provider_options* options) |
| 221 | +{ |
| 222 | + if (wsrep == nullptr) |
| 223 | + { |
| 224 | + // Not a provider which was loaded via wsrep-API |
| 225 | + return 0; |
| 226 | + } |
| 227 | + if (config_service_v2_probe(wsrep->dlh)) |
| 228 | + { |
| 229 | + wsrep::log_info() << "Provider does not support config service v2"; |
| 230 | + return 1; |
| 231 | + } |
| 232 | + if (config_service_v2_init(wsrep->dlh)) |
| 233 | + { |
| 234 | + wsrep::log_warning() << "Failed to initialize config service v2"; |
| 235 | + return 1; |
| 236 | + } |
| 237 | + |
| 238 | + wsrep_status_t ret = wsrep_config_service_v2::service.get_parameters( |
| 239 | + wsrep, &wsrep_config_service_v2::service_callback, options); |
| 240 | + |
| 241 | + config_service_v2_deinit(wsrep->dlh); |
| 242 | + |
| 243 | + if (ret != WSREP_OK) |
| 244 | + { |
| 245 | + return 1; |
| 246 | + } |
| 247 | + |
| 248 | + return 0; |
| 249 | +} |
0 commit comments