Line data Source code
1 4 : GQuark bd_md_error_quark (void) {
2 4 : return g_quark_from_static_string ("g-bd-md-error-quark");
3 : }
4 :
5 : /**
6 : * BDMDExamineData:
7 : * @device: path of the MD device
8 : * @level: RAID level of the device
9 : * @num_devices: number of devices used by the MD device
10 : * @name: name of the MD device
11 : * @size: size of the MD device
12 : * @uuid: array UUID
13 : * @update_time: update time of the MD device
14 : * @dev_uuid: UUID of the member device
15 : * @events: number of events on the MD device
16 : * @metadata: version of the metadata used by the MD device
17 : * @chunk_size: chunk size used by the MD device
18 : */
19 : /**
20 : * bd_md_examine_data_copy: (skip)
21 : * @data: (nullable): %BDMDExamineData to copy
22 : *
23 : * Creates a new copy of @data.
24 : */
25 0 : BDMDExamineData* bd_md_examine_data_copy (BDMDExamineData *data) {
26 0 : if (data == NULL)
27 0 : return NULL;
28 :
29 0 : BDMDExamineData *new_data = g_new0 (BDMDExamineData, 1);
30 :
31 0 : new_data->device = g_strdup (data->device);
32 0 : new_data->level = g_strdup (data->level);
33 0 : new_data->num_devices = data->num_devices;
34 0 : new_data->name = g_strdup (data->name);
35 0 : new_data->size = data->size;
36 0 : new_data->uuid = g_strdup (data->uuid);
37 0 : new_data->update_time = data->update_time;
38 0 : new_data->dev_uuid = g_strdup (data->dev_uuid);
39 0 : new_data->events = data->events;
40 0 : new_data->metadata = g_strdup (data->metadata);
41 0 : new_data->chunk_size = data->chunk_size;
42 0 : return new_data;
43 : }
44 :
45 : /**
46 : * bd_md_examine_data_free: (skip)
47 : * @data: (nullable): %BDMDExamineData to free
48 : *
49 : * Frees @data.
50 : */
51 8 : void bd_md_examine_data_free (BDMDExamineData *data) {
52 8 : if (data == NULL)
53 0 : return;
54 :
55 8 : g_free (data->device);
56 8 : g_free (data->level);
57 8 : g_free (data->name);
58 8 : g_free (data->uuid);
59 8 : g_free (data->dev_uuid);
60 8 : g_free (data->metadata);
61 8 : g_free (data);
62 : }
63 :
64 25 : GType bd_md_examine_data_get_type () {
65 : static GType type = 0;
66 :
67 25 : if (G_UNLIKELY(type == 0)) {
68 1 : type = g_boxed_type_register_static("BDMDExamineData",
69 : (GBoxedCopyFunc) bd_md_examine_data_copy,
70 : (GBoxedFreeFunc) bd_md_examine_data_free);
71 : }
72 :
73 25 : return type;
74 : }
75 :
76 : /**
77 : * BDMDDetailData:
78 : * @device: path of the device
79 : * @metadata: version of the metadata used by the device
80 : * @creation_time: creation time
81 : * @level: level of the MD RAID
82 : * @name: name of the MD device
83 : * @array_size: size of the MD array
84 : * @use_dev_size: size of the used space
85 : * @raid_devices: number of devices in the MD array
86 : * @total_devices: total number of devices in the MD array
87 : * @active_devices: number of active devices in the MD array
88 : * @working_devices: number of working devices in the MD array
89 : * @failed_devices: number of failed devices in the MD array
90 : * @spare_devices: number of spare devices in the MD array
91 : * @clean: whether the MD array is clean or not
92 : * @uuid: uuid of the MD array
93 : * @container: path of the MD container this device belongs to
94 : */
95 : /**
96 : * bd_md_detail_data_copy: (skip)
97 : * @data: (nullable): %BDMDDetailData to copy
98 : *
99 : * Creates a new copy of @data.
100 : */
101 0 : BDMDDetailData* bd_md_detail_data_copy (BDMDDetailData *data) {
102 0 : if (data == NULL)
103 0 : return NULL;
104 :
105 0 : BDMDDetailData *new_data = g_new0 (BDMDDetailData, 1);
106 :
107 0 : new_data->device = g_strdup (data->device);
108 0 : new_data->name = g_strdup (data->name);
109 0 : new_data->metadata = g_strdup (data->metadata);
110 0 : new_data->creation_time = g_strdup (data->creation_time);
111 0 : new_data->level = g_strdup (data->level);
112 0 : new_data->array_size = data->array_size;
113 0 : new_data->use_dev_size = data->use_dev_size;
114 0 : new_data->raid_devices = data->raid_devices;
115 0 : new_data->active_devices = data->active_devices;
116 0 : new_data->working_devices = data->working_devices;
117 0 : new_data->failed_devices = data->failed_devices;
118 0 : new_data->spare_devices = data->spare_devices;
119 0 : new_data->clean = data->clean;
120 0 : new_data->uuid = g_strdup (data->uuid);
121 0 : new_data->container = g_strdup (data->container);
122 :
123 0 : return new_data;
124 : }
125 :
126 : /**
127 : * bd_md_detail_data_free: (skip)
128 : * @data: (nullable): %BDMDDetailData to free
129 : *
130 : * Frees @data.
131 : */
132 12 : void bd_md_detail_data_free (BDMDDetailData *data) {
133 12 : if (data == NULL)
134 0 : return;
135 :
136 12 : g_free (data->device);
137 12 : g_free (data->name);
138 12 : g_free (data->metadata);
139 12 : g_free (data->creation_time);
140 12 : g_free (data->level);
141 12 : g_free (data->uuid);
142 12 : g_free (data->container);
143 :
144 12 : g_free (data);
145 : }
146 :
147 32 : GType bd_md_detail_data_get_type () {
148 : static GType type = 0;
149 :
150 32 : if (G_UNLIKELY(type == 0)) {
151 1 : type = g_boxed_type_register_static("BDMDDetailData",
152 : (GBoxedCopyFunc) bd_md_detail_data_copy,
153 : (GBoxedFreeFunc) bd_md_detail_data_free);
154 : }
155 :
156 32 : return type;
157 : }
158 :
159 0 : static gboolean bd_md_is_tech_avail_stub (BDMDTech tech G_GNUC_UNUSED, guint64 mode G_GNUC_UNUSED, GError **error) {
160 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_is_tech_avail' called, but not implemented!");
161 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
162 : "The function 'bd_md_is_tech_avail' called, but not implemented!");
163 0 : return FALSE;
164 : }
165 :
166 : static gboolean (*_bd_md_is_tech_avail) (BDMDTech tech, guint64 mode, GError **error) = bd_md_is_tech_avail_stub;
167 :
168 : /**
169 : * bd_md_is_tech_avail:
170 : * @tech: the queried tech
171 : * @mode: a bit mask of queried modes of operation for @tech
172 : * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
173 : *
174 : * Returns: whether the @tech-@mode combination is available -- supported by the
175 : * plugin implementation and having all the runtime dependencies available
176 : */
177 6 : gboolean bd_md_is_tech_avail (BDMDTech tech, guint64 mode, GError **error) {
178 6 : return _bd_md_is_tech_avail (tech, mode, error);
179 : }
180 :
181 :
182 0 : static guint64 bd_md_get_superblock_size_stub (guint64 member_size G_GNUC_UNUSED, const gchar *version G_GNUC_UNUSED, GError **error) {
183 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_get_superblock_size' called, but not implemented!");
184 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
185 : "The function 'bd_md_get_superblock_size' called, but not implemented!");
186 0 : return 0;
187 : }
188 :
189 : static guint64 (*_bd_md_get_superblock_size) (guint64 member_size, const gchar *version, GError **error) = bd_md_get_superblock_size_stub;
190 :
191 : /**
192 : * bd_md_get_superblock_size:
193 : * @member_size: size of an array member
194 : * @version: (nullable): metadata version or %NULL to use the current default version
195 : * @error: (out) (optional): place to store error (if any)
196 : *
197 : * Returns: Calculated superblock size for an array with a given @member_size
198 : * and metadata @version or default if unsupported @version is used.
199 : *
200 : * Tech category: always available
201 : */
202 11 : guint64 bd_md_get_superblock_size (guint64 member_size, const gchar *version, GError **error) {
203 11 : return _bd_md_get_superblock_size (member_size, version, error);
204 : }
205 :
206 :
207 0 : static gboolean bd_md_create_stub (const gchar *device_name G_GNUC_UNUSED, const gchar *level G_GNUC_UNUSED, const gchar **disks G_GNUC_UNUSED, guint64 spares G_GNUC_UNUSED, const gchar *version G_GNUC_UNUSED, const gchar *bitmap G_GNUC_UNUSED, guint64 chunk_size G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
208 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_create' called, but not implemented!");
209 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
210 : "The function 'bd_md_create' called, but not implemented!");
211 0 : return FALSE;
212 : }
213 :
214 : static gboolean (*_bd_md_create) (const gchar *device_name, const gchar *level, const gchar **disks, guint64 spares, const gchar *version, const gchar *bitmap, guint64 chunk_size, const BDExtraArg **extra, GError **error) = bd_md_create_stub;
215 :
216 : /**
217 : * bd_md_create:
218 : * @device_name: name of the device to create
219 : * @level: RAID level (as understood by mdadm, see mdadm(8))
220 : * @disks: (array zero-terminated=1): disks to use for the new RAID (including spares)
221 : * @spares: number of spare devices
222 : * @version: (nullable): metadata version
223 : * @bitmap: (nullable): write-intent bitmap location ('none', 'internal') or %NULL to let mdadm decide (i.e. internal > 100GB)
224 : * @chunk_size: chunk size of the device to create
225 : * @extra: (nullable) (array zero-terminated=1): extra options for the creation (right now
226 : * passed to the 'mdadm' utility)
227 : * @error: (out) (optional): place to store error (if any)
228 : *
229 : * Returns: whether the new MD RAID device @device_name was successfully created or not
230 : *
231 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_CREATE
232 : */
233 13 : gboolean bd_md_create (const gchar *device_name, const gchar *level, const gchar **disks, guint64 spares, const gchar *version, const gchar *bitmap, guint64 chunk_size, const BDExtraArg **extra, GError **error) {
234 13 : return _bd_md_create (device_name, level, disks, spares, version, bitmap, chunk_size, extra, error);
235 : }
236 :
237 :
238 0 : static gboolean bd_md_destroy_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
239 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_destroy' called, but not implemented!");
240 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
241 : "The function 'bd_md_destroy' called, but not implemented!");
242 0 : return FALSE;
243 : }
244 :
245 : static gboolean (*_bd_md_destroy) (const gchar *device, GError **error) = bd_md_destroy_stub;
246 :
247 : /**
248 : * bd_md_destroy:
249 : * @device: device to destroy MD RAID metadata on
250 : * @error: (out) (optional): place to store error (if any)
251 : *
252 : * Returns: whether the MD RAID metadata was successfully destroyed on @device or not
253 : *
254 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_DELETE
255 : */
256 31 : gboolean bd_md_destroy (const gchar *device, GError **error) {
257 31 : return _bd_md_destroy (device, error);
258 : }
259 :
260 :
261 0 : static gboolean bd_md_deactivate_stub (const gchar *raid_spec G_GNUC_UNUSED, GError **error) {
262 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_deactivate' called, but not implemented!");
263 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
264 : "The function 'bd_md_deactivate' called, but not implemented!");
265 0 : return FALSE;
266 : }
267 :
268 : static gboolean (*_bd_md_deactivate) (const gchar *raid_spec, GError **error) = bd_md_deactivate_stub;
269 :
270 : /**
271 : * bd_md_deactivate:
272 : * @raid_spec: specification of the RAID device (name, node or path)
273 : * @error: (out) (optional): place to store error (if any)
274 : *
275 : * Returns: whether the RAID device @raid_spec was successfully deactivated or not
276 : *
277 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
278 : */
279 44 : gboolean bd_md_deactivate (const gchar *raid_spec, GError **error) {
280 44 : return _bd_md_deactivate (raid_spec, error);
281 : }
282 :
283 :
284 0 : static gboolean bd_md_activate_stub (const gchar *raid_spec G_GNUC_UNUSED, const gchar **members G_GNUC_UNUSED, const gchar *uuid G_GNUC_UNUSED, gboolean start_degraded G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
285 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_activate' called, but not implemented!");
286 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
287 : "The function 'bd_md_activate' called, but not implemented!");
288 0 : return FALSE;
289 : }
290 :
291 : static gboolean (*_bd_md_activate) (const gchar *raid_spec, const gchar **members, const gchar *uuid, gboolean start_degraded, const BDExtraArg **extra, GError **error) = bd_md_activate_stub;
292 :
293 : /**
294 : * bd_md_activate:
295 : * @raid_spec: (nullable): specification of the RAID device (name, node or path) to activate (if not given "--scan" is implied and @members is ignored)
296 : * @members: (nullable) (array zero-terminated=1): member devices to be considered for @device activation
297 : * @uuid: (nullable): UUID (in the MD RAID format!) of the MD RAID to activate
298 : * @start_degraded: whether to start the array even if it's degraded
299 : * @extra: (nullable) (array zero-terminated=1): extra options for the activation (right now
300 : * passed to the 'mdadm' utility)
301 : * @error: (out) (optional): place to store error (if any)
302 : *
303 : * Returns: whether the MD RAID @device was successfully activated or not
304 : *
305 : * Note: either @members or @uuid (or both) have to be specified.
306 : *
307 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
308 : */
309 8 : gboolean bd_md_activate (const gchar *raid_spec, const gchar **members, const gchar *uuid, gboolean start_degraded, const BDExtraArg **extra, GError **error) {
310 8 : return _bd_md_activate (raid_spec, members, uuid, start_degraded, extra, error);
311 : }
312 :
313 :
314 0 : static gboolean bd_md_run_stub (const gchar *raid_spec G_GNUC_UNUSED, GError **error) {
315 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_run' called, but not implemented!");
316 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
317 : "The function 'bd_md_run' called, but not implemented!");
318 0 : return FALSE;
319 : }
320 :
321 : static gboolean (*_bd_md_run) (const gchar *raid_spec, GError **error) = bd_md_run_stub;
322 :
323 : /**
324 : * bd_md_run:
325 : * @raid_spec: specification of the (possibly degraded) RAID device (name, node or path) to be started
326 : * @error: (out) (optional): place to store error (if any)
327 : *
328 : * Returns: whether the @raid_spec was successfully started or not
329 : *
330 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
331 : */
332 0 : gboolean bd_md_run (const gchar *raid_spec, GError **error) {
333 0 : return _bd_md_run (raid_spec, error);
334 : }
335 :
336 :
337 0 : static gboolean bd_md_nominate_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
338 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_nominate' called, but not implemented!");
339 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
340 : "The function 'bd_md_nominate' called, but not implemented!");
341 0 : return FALSE;
342 : }
343 :
344 : static gboolean (*_bd_md_nominate) (const gchar *device, GError **error) = bd_md_nominate_stub;
345 :
346 : /**
347 : * bd_md_nominate:
348 : * @device: device to nominate (add to its appropriate RAID) as a MD RAID device
349 : * @error: (out) (optional): place to store error (if any)
350 : *
351 : * Returns: whether the @device was successfully nominated (added to its
352 : * appropriate RAID) or not
353 : *
354 : * Note: may start the MD RAID if it becomes ready by adding @device.
355 : *
356 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
357 : */
358 2 : gboolean bd_md_nominate (const gchar *device, GError **error) {
359 2 : return _bd_md_nominate (device, error);
360 : }
361 :
362 :
363 0 : static gboolean bd_md_denominate_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
364 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_denominate' called, but not implemented!");
365 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
366 : "The function 'bd_md_denominate' called, but not implemented!");
367 0 : return FALSE;
368 : }
369 :
370 : static gboolean (*_bd_md_denominate) (const gchar *device, GError **error) = bd_md_denominate_stub;
371 :
372 : /**
373 : * bd_md_denominate:
374 : * @device: device to denominate (remove from its appropriate RAID) as a MD RAID device
375 : * @error: (out) (optional): place to store error (if any)
376 : *
377 : * Returns: whether the @device was successfully denominated (added to its
378 : * appropriate RAID) or not
379 : *
380 : * Note: may start the MD RAID if it becomes ready by adding @device.
381 : *
382 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
383 : */
384 2 : gboolean bd_md_denominate (const gchar *device, GError **error) {
385 2 : return _bd_md_denominate (device, error);
386 : }
387 :
388 :
389 0 : static gboolean bd_md_add_stub (const gchar *raid_spec G_GNUC_UNUSED, const gchar *device G_GNUC_UNUSED, guint64 raid_devs G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
390 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_add' called, but not implemented!");
391 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
392 : "The function 'bd_md_add' called, but not implemented!");
393 0 : return FALSE;
394 : }
395 :
396 : static gboolean (*_bd_md_add) (const gchar *raid_spec, const gchar *device, guint64 raid_devs, const BDExtraArg **extra, GError **error) = bd_md_add_stub;
397 :
398 : /**
399 : * bd_md_add:
400 : * @raid_spec: specification of the RAID device (name, node or path) to add @device into
401 : * @device: name of the device to add to the @raid_spec RAID device
402 : * @raid_devs: number of devices the @raid_spec RAID should actively use or 0
403 : * to leave unspecified (see below)
404 : * @extra: (nullable) (array zero-terminated=1): extra options for the addition (right now
405 : * passed to the 'mdadm' utility)
406 : * @error: (out) (optional): place to store error (if any)
407 : *
408 : * Returns: whether the @device was successfully added to the @raid_spec RAID or
409 : * not
410 : *
411 : * The @raid_devs parameter is used when adding devices to a raid array that has
412 : * no actual redundancy. In this case it is necessary to explicitly grow the
413 : * array all at once rather than manage it in the sense of adding spares.
414 : *
415 : * Whether the new device will be added as a spare or an active member is
416 : * decided by mdadm.
417 : *
418 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
419 : */
420 5 : gboolean bd_md_add (const gchar *raid_spec, const gchar *device, guint64 raid_devs, const BDExtraArg **extra, GError **error) {
421 5 : return _bd_md_add (raid_spec, device, raid_devs, extra, error);
422 : }
423 :
424 :
425 0 : static gboolean bd_md_remove_stub (const gchar *raid_spec G_GNUC_UNUSED, const gchar *device G_GNUC_UNUSED, gboolean fail G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
426 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_remove' called, but not implemented!");
427 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
428 : "The function 'bd_md_remove' called, but not implemented!");
429 0 : return FALSE;
430 : }
431 :
432 : static gboolean (*_bd_md_remove) (const gchar *raid_spec, const gchar *device, gboolean fail, const BDExtraArg **extra, GError **error) = bd_md_remove_stub;
433 :
434 : /**
435 : * bd_md_remove:
436 : * @raid_spec: specification of the RAID device (name, node or path) to remove @device from
437 : * @device: device to remove from the @raid_spec RAID
438 : * @fail: whether to mark the @device as failed before removing
439 : * @extra: (nullable) (array zero-terminated=1): extra options for the removal (right now
440 : * passed to the 'mdadm' utility)
441 : * @error: (out) (optional): place to store error (if any)
442 : *
443 : * Returns: whether the @device was successfully removed from the @raid_spec
444 : * RAID or not.
445 : *
446 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
447 : */
448 2 : gboolean bd_md_remove (const gchar *raid_spec, const gchar *device, gboolean fail, const BDExtraArg **extra, GError **error) {
449 2 : return _bd_md_remove (raid_spec, device, fail, extra, error);
450 : }
451 :
452 :
453 0 : static BDMDExamineData* bd_md_examine_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
454 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_examine' called, but not implemented!");
455 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
456 : "The function 'bd_md_examine' called, but not implemented!");
457 0 : return NULL;
458 : }
459 :
460 : static BDMDExamineData* (*_bd_md_examine) (const gchar *device, GError **error) = bd_md_examine_stub;
461 :
462 : /**
463 : * bd_md_examine:
464 : * @device: name of the device (a member of an MD RAID) to examine
465 : * @error: (out) (optional): place to store error (if any)
466 : *
467 : * Returns: information about the MD RAID extracted from the @device
468 : *
469 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
470 : */
471 8 : BDMDExamineData* bd_md_examine (const gchar *device, GError **error) {
472 8 : return _bd_md_examine (device, error);
473 : }
474 :
475 :
476 0 : static BDMDDetailData* bd_md_detail_stub (const gchar *raid_spec G_GNUC_UNUSED, GError **error) {
477 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_detail' called, but not implemented!");
478 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
479 : "The function 'bd_md_detail' called, but not implemented!");
480 0 : return NULL;
481 : }
482 :
483 : static BDMDDetailData* (*_bd_md_detail) (const gchar *raid_spec, GError **error) = bd_md_detail_stub;
484 :
485 : /**
486 : * bd_md_detail:
487 : * @raid_spec: specification of the RAID device (name, node or path) to examine
488 : * @error: (out) (optional): place to store error (if any)
489 : *
490 : * Returns: information about the MD RAID @raid_spec
491 : *
492 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
493 : */
494 17 : BDMDDetailData* bd_md_detail (const gchar *raid_spec, GError **error) {
495 17 : return _bd_md_detail (raid_spec, error);
496 : }
497 :
498 :
499 4 : static gchar* bd_md_canonicalize_uuid_stub (const gchar *uuid G_GNUC_UNUSED, GError **error) {
500 4 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_canonicalize_uuid' called, but not implemented!");
501 4 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
502 : "The function 'bd_md_canonicalize_uuid' called, but not implemented!");
503 4 : return NULL;
504 : }
505 :
506 : static gchar* (*_bd_md_canonicalize_uuid) (const gchar *uuid, GError **error) = bd_md_canonicalize_uuid_stub;
507 :
508 : /**
509 : * bd_md_canonicalize_uuid:
510 : * @uuid: UUID to canonicalize
511 : * @error: (out) (optional): place to store error (if any)
512 : *
513 : * Returns: (transfer full): canonicalized form of @uuid
514 : *
515 : * This function expects a UUID in the form that mdadm returns. The change is as
516 : * follows: 3386ff85:f5012621:4a435f06:1eb47236 -> 3386ff85-f501-2621-4a43-5f061eb47236
517 : *
518 : * Tech category: always available
519 : */
520 32 : gchar* bd_md_canonicalize_uuid (const gchar *uuid, GError **error) {
521 32 : return _bd_md_canonicalize_uuid (uuid, error);
522 : }
523 :
524 :
525 0 : static gchar* bd_md_get_md_uuid_stub (const gchar *uuid G_GNUC_UNUSED, GError **error) {
526 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_get_md_uuid' called, but not implemented!");
527 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
528 : "The function 'bd_md_get_md_uuid' called, but not implemented!");
529 0 : return NULL;
530 : }
531 :
532 : static gchar* (*_bd_md_get_md_uuid) (const gchar *uuid, GError **error) = bd_md_get_md_uuid_stub;
533 :
534 : /**
535 : * bd_md_get_md_uuid:
536 : * @uuid: UUID to transform into format used by MD RAID
537 : * @error: (out) (optional): place to store error (if any)
538 : *
539 : * Returns: (transfer full): transformed form of @uuid
540 : *
541 : * This function expects a UUID in the canonical (traditional format) and
542 : * returns a UUID in the format used by MD RAID and is thus reverse to
543 : * bd_md_canonicalize_uuid(). The change is as follows:
544 : * 3386ff85-f501-2621-4a43-5f061eb47236 -> 3386ff85:f5012621:4a435f06:1eb47236
545 : *
546 : * Tech category: always available
547 : */
548 3 : gchar* bd_md_get_md_uuid (const gchar *uuid, GError **error) {
549 3 : return _bd_md_get_md_uuid (uuid, error);
550 : }
551 :
552 :
553 0 : static gchar* bd_md_node_from_name_stub (const gchar *name G_GNUC_UNUSED, GError **error) {
554 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_node_from_name' called, but not implemented!");
555 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
556 : "The function 'bd_md_node_from_name' called, but not implemented!");
557 0 : return NULL;
558 : }
559 :
560 : static gchar* (*_bd_md_node_from_name) (const gchar *name, GError **error) = bd_md_node_from_name_stub;
561 :
562 : /**
563 : * bd_md_node_from_name:
564 : * @name: name of the MD RAID
565 : * @error: (out) (optional): place to store error (if any)
566 : *
567 : * Returns: device node of the @name MD RAID or %NULL in case of error
568 : *
569 : * Tech category: always available
570 : */
571 37 : gchar* bd_md_node_from_name (const gchar *name, GError **error) {
572 37 : return _bd_md_node_from_name (name, error);
573 : }
574 :
575 :
576 0 : static gchar* bd_md_name_from_node_stub (const gchar *node G_GNUC_UNUSED, GError **error) {
577 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_name_from_node' called, but not implemented!");
578 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
579 : "The function 'bd_md_name_from_node' called, but not implemented!");
580 0 : return NULL;
581 : }
582 :
583 : static gchar* (*_bd_md_name_from_node) (const gchar *node, GError **error) = bd_md_name_from_node_stub;
584 :
585 : /**
586 : * bd_md_name_from_node:
587 : * @node: path of the MD RAID's device node
588 : * @error: (out) (optional): place to store error (if any)
589 : *
590 : * Returns: @name of the MD RAID the device node belongs to or %NULL in case of error
591 : *
592 : * Tech category: always available
593 : */
594 3 : gchar* bd_md_name_from_node (const gchar *node, GError **error) {
595 3 : return _bd_md_name_from_node (node, error);
596 : }
597 :
598 :
599 0 : static gchar* bd_md_get_status_stub (const gchar *raid_spec G_GNUC_UNUSED, GError **error) {
600 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_get_status' called, but not implemented!");
601 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
602 : "The function 'bd_md_get_status' called, but not implemented!");
603 0 : return NULL;
604 : }
605 :
606 : static gchar* (*_bd_md_get_status) (const gchar *raid_spec, GError **error) = bd_md_get_status_stub;
607 :
608 : /**
609 : * bd_md_get_status
610 : * @raid_spec: specification of the RAID device (name, node or path) to get status
611 : * @error: (out) (optional): place to store error (if any)
612 : *
613 : * Returns: (transfer full): status of the @raid_spec RAID.
614 : *
615 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
616 : */
617 1 : gchar* bd_md_get_status (const gchar *raid_spec, GError **error) {
618 1 : return _bd_md_get_status (raid_spec, error);
619 : }
620 :
621 :
622 0 : static gboolean bd_md_set_bitmap_location_stub (const gchar *raid_spec G_GNUC_UNUSED, const gchar *location G_GNUC_UNUSED, GError **error) {
623 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_set_bitmap_location' called, but not implemented!");
624 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
625 : "The function 'bd_md_set_bitmap_location' called, but not implemented!");
626 0 : return FALSE;
627 : }
628 :
629 : static gboolean (*_bd_md_set_bitmap_location) (const gchar *raid_spec, const gchar *location, GError **error) = bd_md_set_bitmap_location_stub;
630 :
631 : /**
632 : * bd_md_set_bitmap_location:
633 : * @raid_spec: specification of the RAID device (name, node or path) to set the bitmap location
634 : * @location: bitmap location (none, internal or path)
635 : * @error: (out) (optional): place to store error (if any)
636 : *
637 : * Returns: whether @location was successfully set for @raid_spec
638 : *
639 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
640 : */
641 5 : gboolean bd_md_set_bitmap_location (const gchar *raid_spec, const gchar *location, GError **error) {
642 5 : return _bd_md_set_bitmap_location (raid_spec, location, error);
643 : }
644 :
645 :
646 0 : static gchar* bd_md_get_bitmap_location_stub (const gchar *raid_spec G_GNUC_UNUSED, GError **error) {
647 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_get_bitmap_location' called, but not implemented!");
648 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
649 : "The function 'bd_md_get_bitmap_location' called, but not implemented!");
650 0 : return NULL;
651 : }
652 :
653 : static gchar* (*_bd_md_get_bitmap_location) (const gchar *raid_spec, GError **error) = bd_md_get_bitmap_location_stub;
654 :
655 : /**
656 : * bd_md_get_bitmap_location:
657 : * @raid_spec: specification of the RAID device (name, node or path) to get the bitmap location
658 : * @error: (out) (optional): place to store error (if any)
659 : *
660 : * Returns: (transfer full): bitmap location for @raid_spec
661 : *
662 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
663 : */
664 7 : gchar* bd_md_get_bitmap_location (const gchar *raid_spec, GError **error) {
665 7 : return _bd_md_get_bitmap_location (raid_spec, error);
666 : }
667 :
668 :
669 0 : static gboolean bd_md_request_sync_action_stub (const gchar *raid_spec G_GNUC_UNUSED, const gchar *action G_GNUC_UNUSED, GError **error) {
670 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_md_request_sync_action' called, but not implemented!");
671 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
672 : "The function 'bd_md_request_sync_action' called, but not implemented!");
673 0 : return FALSE;
674 : }
675 :
676 : static gboolean (*_bd_md_request_sync_action) (const gchar *raid_spec, const gchar *action, GError **error) = bd_md_request_sync_action_stub;
677 :
678 : /**
679 : * bd_md_request_sync_action:
680 : * @raid_spec: specification of the RAID device (name, node or path) to request sync action on
681 : * @action: requested sync action (resync, recovery, check, repair or idle)
682 : * @error: (out) (optional): place to store error (if any)
683 : *
684 : * Returns: whether the @action was successfully requested for the @raid_spec
685 : * RAID or not.
686 : *
687 : * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
688 : */
689 1 : gboolean bd_md_request_sync_action (const gchar *raid_spec, const gchar *action, GError **error) {
690 1 : return _bd_md_request_sync_action (raid_spec, action, error);
691 : }
692 :
693 :
694 26 : static gpointer load_mdraid_from_plugin(const gchar *so_name) {
695 26 : void *handle = NULL;
696 26 : char *error = NULL;
697 26 : gboolean (*init_fn) (void) = NULL;
698 :
699 26 : handle = dlopen(so_name, RTLD_LAZY);
700 26 : if (!handle) {
701 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load module mdraid: %s", dlerror());
702 0 : return NULL;
703 : }
704 :
705 26 : dlerror();
706 26 : * (void**) (&init_fn) = dlsym(handle, "bd_md_init");
707 26 : if ((error = dlerror()) != NULL)
708 0 : bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the init() function for mdraid: %s", error);
709 : /* coverity[dead_error_condition] */
710 26 : if (init_fn && !init_fn()) {
711 0 : dlclose(handle);
712 0 : return NULL;
713 : }
714 26 : init_fn = NULL;
715 :
716 26 : dlerror();
717 26 : * (void**) (&_bd_md_is_tech_avail) = dlsym(handle, "bd_md_is_tech_avail");
718 26 : if ((error = dlerror()) != NULL)
719 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_is_tech_avail: %s", error);
720 :
721 26 : dlerror();
722 26 : * (void**) (&_bd_md_get_superblock_size) = dlsym(handle, "bd_md_get_superblock_size");
723 26 : if ((error = dlerror()) != NULL)
724 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_get_superblock_size: %s", error);
725 :
726 26 : dlerror();
727 26 : * (void**) (&_bd_md_create) = dlsym(handle, "bd_md_create");
728 26 : if ((error = dlerror()) != NULL)
729 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_create: %s", error);
730 :
731 26 : dlerror();
732 26 : * (void**) (&_bd_md_destroy) = dlsym(handle, "bd_md_destroy");
733 26 : if ((error = dlerror()) != NULL)
734 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_destroy: %s", error);
735 :
736 26 : dlerror();
737 26 : * (void**) (&_bd_md_deactivate) = dlsym(handle, "bd_md_deactivate");
738 26 : if ((error = dlerror()) != NULL)
739 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_deactivate: %s", error);
740 :
741 26 : dlerror();
742 26 : * (void**) (&_bd_md_activate) = dlsym(handle, "bd_md_activate");
743 26 : if ((error = dlerror()) != NULL)
744 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_activate: %s", error);
745 :
746 26 : dlerror();
747 26 : * (void**) (&_bd_md_run) = dlsym(handle, "bd_md_run");
748 26 : if ((error = dlerror()) != NULL)
749 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_run: %s", error);
750 :
751 26 : dlerror();
752 26 : * (void**) (&_bd_md_nominate) = dlsym(handle, "bd_md_nominate");
753 26 : if ((error = dlerror()) != NULL)
754 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_nominate: %s", error);
755 :
756 26 : dlerror();
757 26 : * (void**) (&_bd_md_denominate) = dlsym(handle, "bd_md_denominate");
758 26 : if ((error = dlerror()) != NULL)
759 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_denominate: %s", error);
760 :
761 26 : dlerror();
762 26 : * (void**) (&_bd_md_add) = dlsym(handle, "bd_md_add");
763 26 : if ((error = dlerror()) != NULL)
764 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_add: %s", error);
765 :
766 26 : dlerror();
767 26 : * (void**) (&_bd_md_remove) = dlsym(handle, "bd_md_remove");
768 26 : if ((error = dlerror()) != NULL)
769 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_remove: %s", error);
770 :
771 26 : dlerror();
772 26 : * (void**) (&_bd_md_examine) = dlsym(handle, "bd_md_examine");
773 26 : if ((error = dlerror()) != NULL)
774 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_examine: %s", error);
775 :
776 26 : dlerror();
777 26 : * (void**) (&_bd_md_detail) = dlsym(handle, "bd_md_detail");
778 26 : if ((error = dlerror()) != NULL)
779 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_detail: %s", error);
780 :
781 26 : dlerror();
782 26 : * (void**) (&_bd_md_canonicalize_uuid) = dlsym(handle, "bd_md_canonicalize_uuid");
783 26 : if ((error = dlerror()) != NULL)
784 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_canonicalize_uuid: %s", error);
785 :
786 26 : dlerror();
787 26 : * (void**) (&_bd_md_get_md_uuid) = dlsym(handle, "bd_md_get_md_uuid");
788 26 : if ((error = dlerror()) != NULL)
789 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_get_md_uuid: %s", error);
790 :
791 26 : dlerror();
792 26 : * (void**) (&_bd_md_node_from_name) = dlsym(handle, "bd_md_node_from_name");
793 26 : if ((error = dlerror()) != NULL)
794 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_node_from_name: %s", error);
795 :
796 26 : dlerror();
797 26 : * (void**) (&_bd_md_name_from_node) = dlsym(handle, "bd_md_name_from_node");
798 26 : if ((error = dlerror()) != NULL)
799 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_name_from_node: %s", error);
800 :
801 26 : dlerror();
802 26 : * (void**) (&_bd_md_get_status) = dlsym(handle, "bd_md_get_status");
803 26 : if ((error = dlerror()) != NULL)
804 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_get_status: %s", error);
805 :
806 26 : dlerror();
807 26 : * (void**) (&_bd_md_set_bitmap_location) = dlsym(handle, "bd_md_set_bitmap_location");
808 26 : if ((error = dlerror()) != NULL)
809 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_set_bitmap_location: %s", error);
810 :
811 26 : dlerror();
812 26 : * (void**) (&_bd_md_get_bitmap_location) = dlsym(handle, "bd_md_get_bitmap_location");
813 26 : if ((error = dlerror()) != NULL)
814 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_get_bitmap_location: %s", error);
815 :
816 26 : dlerror();
817 26 : * (void**) (&_bd_md_request_sync_action) = dlsym(handle, "bd_md_request_sync_action");
818 26 : if ((error = dlerror()) != NULL)
819 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_md_request_sync_action: %s", error);
820 :
821 26 : return handle;
822 : }
823 :
824 26 : static gboolean unload_mdraid (gpointer handle) {
825 26 : char *error = NULL;
826 26 : gboolean (*close_fn) (void) = NULL;
827 :
828 26 : _bd_md_is_tech_avail = bd_md_is_tech_avail_stub;
829 26 : _bd_md_get_superblock_size = bd_md_get_superblock_size_stub;
830 26 : _bd_md_create = bd_md_create_stub;
831 26 : _bd_md_destroy = bd_md_destroy_stub;
832 26 : _bd_md_deactivate = bd_md_deactivate_stub;
833 26 : _bd_md_activate = bd_md_activate_stub;
834 26 : _bd_md_run = bd_md_run_stub;
835 26 : _bd_md_nominate = bd_md_nominate_stub;
836 26 : _bd_md_denominate = bd_md_denominate_stub;
837 26 : _bd_md_add = bd_md_add_stub;
838 26 : _bd_md_remove = bd_md_remove_stub;
839 26 : _bd_md_examine = bd_md_examine_stub;
840 26 : _bd_md_detail = bd_md_detail_stub;
841 26 : _bd_md_canonicalize_uuid = bd_md_canonicalize_uuid_stub;
842 26 : _bd_md_get_md_uuid = bd_md_get_md_uuid_stub;
843 26 : _bd_md_node_from_name = bd_md_node_from_name_stub;
844 26 : _bd_md_name_from_node = bd_md_name_from_node_stub;
845 26 : _bd_md_get_status = bd_md_get_status_stub;
846 26 : _bd_md_set_bitmap_location = bd_md_set_bitmap_location_stub;
847 26 : _bd_md_get_bitmap_location = bd_md_get_bitmap_location_stub;
848 26 : _bd_md_request_sync_action = bd_md_request_sync_action_stub;
849 :
850 26 : dlerror();
851 26 : * (void**) (&close_fn) = dlsym(handle, "bd_md_close");
852 26 : if (((error = dlerror()) != NULL) || !close_fn)
853 0 : bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the close_plugin() function for mdraid: %s", error);
854 : /* coverity[dead_error_condition] */
855 26 : if (close_fn) {
856 26 : close_fn();
857 : }
858 :
859 26 : return dlclose(handle) == 0;
860 : }
861 :
|