Debian Codegraph @

src/lib/plugin_apis/mdraid.api

raw
1 #include <glib.h>
2 #include <glib-object.h>
3 #include <blockdev/utils.h>
4
5 #ifndef BD_MD_API
6 #define BD_MD_API
7
8 /* these defaults were determined empirically (taken from blivet) */
9 #define BD_MD_SUPERBLOCK_SIZE G_GUINT64_CONSTANT (2097152ULL) /* 2 MiB */
10 #define BD_MD_CHUNK_SIZE G_GUINT64_CONSTANT (524288ULL) /* 512 KiB */
11
12 GQuark bd_md_error_quark (void) {
13 return g_quark_from_static_string ("g-bd-md-error-quark");
14 }
15
16 #define BD_MD_ERROR bd_md_error_quark ()
17 typedef enum {
18 BD_MD_ERROR_TECH_UNAVAIL,
19 BD_MD_ERROR_FAIL,
20 BD_MD_ERROR_PARSE,
21 BD_MD_ERROR_BAD_FORMAT,
22 BD_MD_ERROR_NO_MATCH,
23 BD_MD_ERROR_INVAL,
24 } BDMDError;
25
26 #define BD_MD_TYPE_EXAMINEDATA (bd_md_examine_data_get_type ())
27 GType bd_md_examine_data_get_type();
28
29 /**
30 * BDMDExamineData:
31 * @device: path of the MD device
32 * @level: RAID level of the device
33 * @num_devices: number of devices used by the MD device
34 * @name: name of the MD device
35 * @size: size of the MD device
36 * @uuid: array UUID
37 * @update_time: update time of the MD device
38 * @dev_uuid: UUID of the member device
39 * @events: number of events on the MD device
40 * @metadata: version of the metadata used by the MD device
41 * @chunk_size: chunk size used by the MD device
42 */
43 typedef struct BDMDExamineData {
44 gchar *device;
45 gchar *level;
46 guint64 num_devices;
47 gchar *name;
48 guint64 size;
49 gchar *uuid;
50 guint64 update_time;
51 gchar *dev_uuid;
52 guint64 events;
53 gchar *metadata;
54 guint64 chunk_size;
55 } BDMDExamineData;
56
57 /**
58 * bd_md_examine_data_copy: (skip)
59 * @data: (nullable): %BDMDExamineData to copy
60 *
61 * Creates a new copy of @data.
62 */
63 BDMDExamineData* bd_md_examine_data_copy (BDMDExamineData *data) {
64 if (data == NULL)
65 return NULL;
66
67 BDMDExamineData *new_data = g_new0 (BDMDExamineData, 1);
68
69 new_data->device = g_strdup (data->device);
70 new_data->level = g_strdup (data->level);
71 new_data->num_devices = data->num_devices;
72 new_data->name = g_strdup (data->name);
73 new_data->size = data->size;
74 new_data->uuid = g_strdup (data->uuid);
75 new_data->update_time = data->update_time;
76 new_data->dev_uuid = g_strdup (data->dev_uuid);
77 new_data->events = data->events;
78 new_data->metadata = g_strdup (data->metadata);
79 new_data->chunk_size = data->chunk_size;
80 return new_data;
81 }
82
83 /**
84 * bd_md_examine_data_free: (skip)
85 * @data: (nullable): %BDMDExamineData to free
86 *
87 * Frees @data.
88 */
89 void bd_md_examine_data_free (BDMDExamineData *data) {
90 if (data == NULL)
91 return;
92
93 g_free (data->device);
94 g_free (data->level);
95 g_free (data->name);
96 g_free (data->uuid);
97 g_free (data->dev_uuid);
98 g_free (data->metadata);
99 g_free (data);
100 }
101
102 GType bd_md_examine_data_get_type () {
103 static GType type = 0;
104
105 if (G_UNLIKELY(type == 0)) {
106 type = g_boxed_type_register_static("BDMDExamineData",
107 (GBoxedCopyFunc) bd_md_examine_data_copy,
108 (GBoxedFreeFunc) bd_md_examine_data_free);
109 }
110
111 return type;
112 }
113
114 #define BD_MD_TYPE_DETAILDATA (bd_md_detail_data_get_type ())
115 GType bd_md_detail_data_get_type();
116
117 /**
118 * BDMDDetailData:
119 * @device: path of the device
120 * @metadata: version of the metadata used by the device
121 * @creation_time: creation time
122 * @level: level of the MD RAID
123 * @name: name of the MD device
124 * @array_size: size of the MD array
125 * @use_dev_size: size of the used space
126 * @raid_devices: number of devices in the MD array
127 * @total_devices: total number of devices in the MD array
128 * @active_devices: number of active devices in the MD array
129 * @working_devices: number of working devices in the MD array
130 * @failed_devices: number of failed devices in the MD array
131 * @spare_devices: number of spare devices in the MD array
132 * @clean: whether the MD array is clean or not
133 * @uuid: uuid of the MD array
134 * @container: path of the MD container this device belongs to
135 */
136 typedef struct BDMDDetailData {
137 gchar *device;
138 gchar *metadata;
139 gchar *creation_time;
140 gchar *level;
141 gchar *name;
142 guint64 array_size;
143 guint64 use_dev_size;
144 guint64 raid_devices;
145 guint64 total_devices;
146 guint64 active_devices;
147 guint64 working_devices;
148 guint64 failed_devices;
149 guint64 spare_devices;
150 gboolean clean;
151 gchar *uuid;
152 gchar *container;
153 } BDMDDetailData;
154
155 /**
156 * bd_md_detail_data_copy: (skip)
157 * @data: (nullable): %BDMDDetailData to copy
158 *
159 * Creates a new copy of @data.
160 */
161 BDMDDetailData* bd_md_detail_data_copy (BDMDDetailData *data) {
162 if (data == NULL)
163 return NULL;
164
165 BDMDDetailData *new_data = g_new0 (BDMDDetailData, 1);
166
167 new_data->device = g_strdup (data->device);
168 new_data->name = g_strdup (data->name);
169 new_data->metadata = g_strdup (data->metadata);
170 new_data->creation_time = g_strdup (data->creation_time);
171 new_data->level = g_strdup (data->level);
172 new_data->array_size = data->array_size;
173 new_data->use_dev_size = data->use_dev_size;
174 new_data->raid_devices = data->raid_devices;
175 new_data->total_devices = data->total_devices;
176 new_data->active_devices = data->active_devices;
177 new_data->working_devices = data->working_devices;
178 new_data->failed_devices = data->failed_devices;
179 new_data->spare_devices = data->spare_devices;
180 new_data->clean = data->clean;
181 new_data->uuid = g_strdup (data->uuid);
182 new_data->container = g_strdup (data->container);
183
184 return new_data;
185 }
186
187 /**
188 * bd_md_detail_data_free: (skip)
189 * @data: (nullable): %BDMDDetailData to free
190 *
191 * Frees @data.
192 */
193 void bd_md_detail_data_free (BDMDDetailData *data) {
194 if (data == NULL)
195 return;
196
197 g_free (data->device);
198 g_free (data->name);
199 g_free (data->metadata);
200 g_free (data->creation_time);
201 g_free (data->level);
202 g_free (data->uuid);
203 g_free (data->container);
204
205 g_free (data);
206 }
207
208 GType bd_md_detail_data_get_type () {
209 static GType type = 0;
210
211 if (G_UNLIKELY(type == 0)) {
212 type = g_boxed_type_register_static("BDMDDetailData",
213 (GBoxedCopyFunc) bd_md_detail_data_copy,
214 (GBoxedFreeFunc) bd_md_detail_data_free);
215 }
216
217 return type;
218 }
219
220 typedef enum {
221 BD_MD_TECH_MDRAID = 0,
222 } BDMDTech;
223
224 typedef enum {
225 BD_MD_TECH_MODE_CREATE = 1 << 0,
226 BD_MD_TECH_MODE_DELETE = 1 << 1,
227 BD_MD_TECH_MODE_MODIFY = 1 << 2,
228 BD_MD_TECH_MODE_QUERY = 1 << 3,
229 } BDMDTechMode;
230
231 /**
232 * bd_md_is_tech_avail:
233 * @tech: the queried tech
234 * @mode: a bit mask of queried modes of operation for @tech
235 * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
236 *
237 * Returns: whether the @tech-@mode combination is available -- supported by the
238 * plugin implementation and having all the runtime dependencies available
239 */
240 gboolean bd_md_is_tech_avail (BDMDTech tech, guint64 mode, GError **error);
241
242 /**
243 * bd_md_get_superblock_size:
244 * @member_size: size of an array member
245 * @version: (nullable): metadata version or %NULL to use the current default version
246 * @error: (out) (optional): place to store error (if any)
247 *
248 * Returns: Calculated superblock size for an array with a given @member_size
249 * and metadata @version or default if unsupported @version is used.
250 *
251 * Tech category: always available
252 */
253 guint64 bd_md_get_superblock_size (guint64 member_size, const gchar *version, GError **error);
254
255 /**
256 * bd_md_create:
257 * @device_name: name of the device to create
258 * @level: RAID level (as understood by mdadm, see mdadm(8))
259 * @disks: (array zero-terminated=1): disks to use for the new RAID (including spares)
260 * @spares: number of spare devices
261 * @version: (nullable): metadata version
262 * @bitmap: (nullable): write-intent bitmap location ('none', 'internal') or %NULL to let mdadm decide (i.e. internal > 100GB)
263 * @chunk_size: chunk size of the device to create
264 * @extra: (nullable) (array zero-terminated=1): extra options for the creation (right now
265 * passed to the 'mdadm' utility)
266 * @error: (out) (optional): place to store error (if any)
267 *
268 * Returns: whether the new MD RAID device @device_name was successfully created or not
269 *
270 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_CREATE
271 */
272 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);
273
274 /**
275 * bd_md_destroy:
276 * @device: device to destroy MD RAID metadata on
277 * @error: (out) (optional): place to store error (if any)
278 *
279 * Returns: whether the MD RAID metadata was successfully destroyed on @device or not
280 *
281 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_DELETE
282 */
283 gboolean bd_md_destroy (const gchar *device, GError **error);
284
285 /**
286 * bd_md_deactivate:
287 * @raid_spec: specification of the RAID device (name, node or path)
288 * @error: (out) (optional): place to store error (if any)
289 *
290 * Returns: whether the RAID device @raid_spec was successfully deactivated or not
291 *
292 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
293 */
294 gboolean bd_md_deactivate (const gchar *raid_spec, GError **error);
295
296 /**
297 * bd_md_activate:
298 * @raid_spec: (nullable): specification of the RAID device (name, node or path) to activate (if not given "--scan" is implied and @members is ignored)
299 * @members: (nullable) (array zero-terminated=1): member devices to be considered for @device activation
300 * @uuid: (nullable): UUID (in the MD RAID format!) of the MD RAID to activate
301 * @start_degraded: whether to start the array even if it's degraded
302 * @extra: (nullable) (array zero-terminated=1): extra options for the activation (right now
303 * passed to the 'mdadm' utility)
304 * @error: (out) (optional): place to store error (if any)
305 *
306 * Returns: whether the MD RAID @device was successfully activated or not
307 *
308 * Note: either @members or @uuid (or both) have to be specified.
309 *
310 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
311 */
312 gboolean bd_md_activate (const gchar *raid_spec, const gchar **members, const gchar *uuid, gboolean start_degraded, const BDExtraArg **extra, GError **error);
313
314 /**
315 * bd_md_run:
316 * @raid_spec: specification of the (possibly degraded) RAID device (name, node or path) to be started
317 * @error: (out) (optional): place to store error (if any)
318 *
319 * Returns: whether the @raid_spec was successfully started or not
320 *
321 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
322 */
323 gboolean bd_md_run (const gchar *raid_spec, GError **error);
324
325 /**
326 * bd_md_nominate:
327 * @device: device to nominate (add to its appropriate RAID) as a MD RAID device
328 * @error: (out) (optional): place to store error (if any)
329 *
330 * Returns: whether the @device was successfully nominated (added to its
331 * appropriate RAID) or not
332 *
333 * Note: may start the MD RAID if it becomes ready by adding @device.
334 *
335 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
336 */
337 gboolean bd_md_nominate (const gchar *device, GError **error);
338
339 /**
340 * bd_md_denominate:
341 * @device: device to denominate (remove from its appropriate RAID) as a MD RAID device
342 * @error: (out) (optional): place to store error (if any)
343 *
344 * Returns: whether the @device was successfully denominated (added to its
345 * appropriate RAID) or not
346 *
347 * Note: may start the MD RAID if it becomes ready by adding @device.
348 *
349 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
350 */
351 gboolean bd_md_denominate (const gchar *device, GError **error);
352
353 /**
354 * bd_md_add:
355 * @raid_spec: specification of the RAID device (name, node or path) to add @device into
356 * @device: name of the device to add to the @raid_spec RAID device
357 * @raid_devs: number of devices the @raid_spec RAID should actively use or 0
358 * to leave unspecified (see below)
359 * @extra: (nullable) (array zero-terminated=1): extra options for the addition (right now
360 * passed to the 'mdadm' utility)
361 * @error: (out) (optional): place to store error (if any)
362 *
363 * Returns: whether the @device was successfully added to the @raid_spec RAID or
364 * not
365 *
366 * The @raid_devs parameter is used when adding devices to a raid array that has
367 * no actual redundancy. In this case it is necessary to explicitly grow the
368 * array all at once rather than manage it in the sense of adding spares.
369 *
370 * Whether the new device will be added as a spare or an active member is
371 * decided by mdadm.
372 *
373 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
374 */
375 gboolean bd_md_add (const gchar *raid_spec, const gchar *device, guint64 raid_devs, const BDExtraArg **extra, GError **error);
376
377 /**
378 * bd_md_remove:
379 * @raid_spec: specification of the RAID device (name, node or path) to remove @device from
380 * @device: device to remove from the @raid_spec RAID
381 * @fail: whether to mark the @device as failed before removing
382 * @extra: (nullable) (array zero-terminated=1): extra options for the removal (right now
383 * passed to the 'mdadm' utility)
384 * @error: (out) (optional): place to store error (if any)
385 *
386 * Returns: whether the @device was successfully removed from the @raid_spec
387 * RAID or not.
388 *
389 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
390 */
391 gboolean bd_md_remove (const gchar *raid_spec, const gchar *device, gboolean fail, const BDExtraArg **extra, GError **error);
392
393 /**
394 * bd_md_examine:
395 * @device: name of the device (a member of an MD RAID) to examine
396 * @error: (out) (optional): place to store error (if any)
397 *
398 * Returns: information about the MD RAID extracted from the @device
399 *
400 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
401 */
402 BDMDExamineData* bd_md_examine (const gchar *device, GError **error);
403
404 /**
405 * bd_md_detail:
406 * @raid_spec: specification of the RAID device (name, node or path) to examine
407 * @error: (out) (optional): place to store error (if any)
408 *
409 * Returns: information about the MD RAID @raid_spec
410 *
411 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
412 */
413 BDMDDetailData* bd_md_detail (const gchar *raid_spec, GError **error);
414
415 /**
416 * bd_md_canonicalize_uuid:
417 * @uuid: UUID to canonicalize
418 * @error: (out) (optional): place to store error (if any)
419 *
420 * Returns: (transfer full): canonicalized form of @uuid or %NULL in case of error
421 *
422 * This function expects a UUID in the form that mdadm returns. The change is as
423 * follows: 3386ff85:f5012621:4a435f06:1eb47236 -> 3386ff85-f501-2621-4a43-5f061eb47236
424 *
425 * Tech category: always available
426 */
427 gchar* bd_md_canonicalize_uuid (const gchar *uuid, GError **error);
428
429 /**
430 * bd_md_get_md_uuid:
431 * @uuid: UUID to transform into format used by MD RAID
432 * @error: (out) (optional): place to store error (if any)
433 *
434 * Returns: (transfer full): transformed form of @uuid or %NULL in case of error
435 *
436 * This function expects a UUID in the canonical (traditional format) and
437 * returns a UUID in the format used by MD RAID and is thus reverse to
438 * bd_md_canonicalize_uuid(). The change is as follows:
439 * 3386ff85-f501-2621-4a43-5f061eb47236 -> 3386ff85:f5012621:4a435f06:1eb47236
440 *
441 * Tech category: always available
442 */
443 gchar* bd_md_get_md_uuid (const gchar *uuid, GError **error);
444
445 /**
446 * bd_md_node_from_name:
447 * @name: name of the MD RAID
448 * @error: (out) (optional): place to store error (if any)
449 *
450 * Returns: device node of the @name MD RAID or %NULL in case of error
451 *
452 * Tech category: always available
453 */
454 gchar* bd_md_node_from_name (const gchar *name, GError **error);
455
456 /**
457 * bd_md_name_from_node:
458 * @node: path of the MD RAID's device node
459 * @error: (out) (optional): place to store error (if any)
460 *
461 * Returns: @name of the MD RAID the device node belongs to or %NULL in case of error
462 *
463 * Tech category: always available
464 */
465 gchar* bd_md_name_from_node (const gchar *node, GError **error);
466
467 /**
468 * bd_md_get_status
469 * @raid_spec: specification of the RAID device (name, node or path) to get status
470 * @error: (out) (optional): place to store error (if any)
471 *
472 * Returns: (transfer full): status of the @raid_spec RAID.
473 *
474 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
475 */
476 gchar* bd_md_get_status (const gchar *raid_spec, GError **error);
477
478 /**
479 * bd_md_set_bitmap_location:
480 * @raid_spec: specification of the RAID device (name, node or path) to set the bitmap location
481 * @location: bitmap location (none, internal or path)
482 * @error: (out) (optional): place to store error (if any)
483 *
484 * Returns: whether @location was successfully set for @raid_spec
485 *
486 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
487 */
488 gboolean bd_md_set_bitmap_location (const gchar *raid_spec, const gchar *location, GError **error);
489
490 /**
491 * bd_md_get_bitmap_location:
492 * @raid_spec: specification of the RAID device (name, node or path) to get the bitmap location
493 * @error: (out) (optional): place to store error (if any)
494 *
495 * Returns: (transfer full): bitmap location for @raid_spec
496 *
497 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
498 */
499 gchar* bd_md_get_bitmap_location (const gchar *raid_spec, GError **error);
500
501 /**
502 * bd_md_request_sync_action:
503 * @raid_spec: specification of the RAID device (name, node or path) to request sync action on
504 * @action: requested sync action (resync, recovery, check, repair or idle)
505 * @error: (out) (optional): place to store error (if any)
506 *
507 * Returns: whether the @action was successfully requested for the @raid_spec
508 * RAID or not.
509 *
510 * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_MODIFY
511 */
512 gboolean bd_md_request_sync_action (const gchar *raid_spec, const gchar *action, GError **error);
513
514 #endif /* BD_MD_API */