163
164
int dm_get_library_version(char *version, size_t size);
164
165
int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size);
165
166
int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);
166
const char *dm_task_get_name(const struct dm_task *dmt);
167
167
const char *dm_task_get_uuid(const struct dm_task *dmt);
169
169
struct dm_deps *dm_task_get_deps(struct dm_task *dmt);
170
struct dm_versions *dm_task_get_versions(struct dm_task *dmt);
173
* These functions return device-mapper names based on the value
174
* of the mangling mode set during preceding dm_task_run call:
175
* - unmangled name for DM_STRING_MANGLING_{AUTO, HEX},
176
* - name without any changes for DM_STRING_MANGLING_NONE.
178
* To get mangled or unmangled form of the name directly, use
179
* dm_task_get_name_mangled or dm_task_get_name_unmangled function.
181
const char *dm_task_get_name(const struct dm_task *dmt);
170
182
struct dm_names *dm_task_get_names(struct dm_task *dmt);
171
struct dm_versions *dm_task_get_versions(struct dm_task *dmt);
173
184
int dm_task_set_ro(struct dm_task *dmt);
174
185
int dm_task_set_newname(struct dm_task *dmt, const char *newname);
236
248
void *next, uint64_t *start, uint64_t *length,
237
249
char **target_type, char **params);
251
/* Parse params from STATUS call for thin_pool target */
254
struct dm_status_thin_pool {
255
uint64_t transaction_id;
256
uint64_t used_metadata_blocks;
257
uint64_t total_metadata_blocks;
258
uint64_t used_data_blocks;
259
uint64_t total_data_blocks;
260
uint64_t held_metadata_root;
263
int dm_get_status_thin_pool(struct dm_pool *mem, const char *params,
264
struct dm_status_thin_pool **status);
266
/* Parse params from STATUS call for thin target */
267
struct dm_status_thin {
268
uint64_t mapped_sectors;
269
uint64_t highest_mapped_sector;
272
int dm_get_status_thin(struct dm_pool *mem, const char *params,
273
struct dm_status_thin **status);
240
276
* Call this to actually run the ioctl.
248
284
void dm_task_update_nodes(void);
289
* Character whitelist: 0-9, A-Z, a-z, #+-.:=@_
290
* HEX mangling format: \xNN, NN being the hex value of the character.
291
* (whitelist and format supported by udev)
294
DM_STRING_MANGLING_NONE, /* do not mangle at all */
295
DM_STRING_MANGLING_AUTO, /* mangle only if not already mangled with hex, error when mixed */
296
DM_STRING_MANGLING_HEX /* always mangle with hex encoding, no matter what the input is */
297
} dm_string_mangling_t;
300
* Set/get mangling mode used for device-mapper names.
302
int dm_set_name_mangling_mode(dm_string_mangling_t name_mangling);
303
dm_string_mangling_t dm_get_name_mangling_mode(void);
306
* Get mangled/unmangled form of the device-mapper name
307
* irrespective of the global setting (set by dm_set_name_mangling_mode).
308
* The name returned needs to be freed after use by calling dm_free!
310
char *dm_task_get_name_mangled(const struct dm_task *dmt);
311
char *dm_task_get_name_unmangled(const struct dm_task *dmt);
251
314
* Configure the device-mapper directory
253
316
int dm_set_dev_dir(const char *dir);
254
317
const char *dm_dir(void);
320
* Configure sysfs directory, /sys by default
322
int dm_set_sysfs_dir(const char *dir);
323
const char *dm_sysfs_dir(void);
326
* Configure default UUID prefix string.
327
* Conventionally this is a short capitalised prefix indicating the subsystem
328
* that is managing the devices, e.g. "LVM-" or "MPATH-".
329
* To support stacks of devices from different subsystems, recursive functions
330
* stop recursing if they reach a device with a different prefix.
332
int dm_set_uuid_prefix(const char *uuid_prefix);
333
const char *dm_uuid_prefix(void);
257
336
* Determine whether a major number belongs to device-mapper or not.
259
338
int dm_is_dm_major(uint32_t major);
341
* Get associated device name for given major and minor number by reading
342
* the sysfs content. If this is a dm device, get associated dm name, the one
343
* that appears in /dev/mapper. DM names could be resolved this way only if
344
* kernel used >= 2.6.29, kernel name is found otherwise (e.g. dm-0).
345
* If prefer_kernel_name is set, the kernel name is always preferred over
346
* device-mapper name for dm devices no matter what the kernel version is.
347
* For non-dm devices, we always get associated kernel name, e.g sda, md0 etc.
348
* Returns 0 on error or if sysfs is not used (or configured incorrectly),
349
* otherwise returns 1 and the supplied buffer holds the device name.
351
int dm_device_get_name(uint32_t major, uint32_t minor,
352
int prefer_kernel_name,
353
char *buf, size_t buf_size);
356
* Determine whether a device has any holders (devices
357
* using this device). If sysfs is not used (or configured
358
* incorrectly), returns 0.
360
int dm_device_has_holders(uint32_t major, uint32_t minor);
363
* Determine whether a device contains mounted filesystem.
364
* If sysfs is not used (or configured incorrectly), returns 0.
366
int dm_device_has_mounted_fs(uint32_t major, uint32_t minor);
372
void dm_lib_init(void) __attribute__((constructor));
262
375
* Release library resources
264
377
void dm_lib_release(void);
509
627
uint32_t slog_region_size);
510
628
/* End of Replicator API */
631
* FIXME: Defines bellow are based on kernel's dm-thin.c defines
632
* DATA_DEV_BLOCK_SIZE_MIN_SECTORS (64 * 1024 >> SECTOR_SHIFT)
633
* DATA_DEV_BLOCK_SIZE_MAX_SECTORS (1024 * 1024 * 1024 >> SECTOR_SHIFT)
635
#define DM_THIN_MIN_DATA_BLOCK_SIZE (UINT32_C(128))
636
#define DM_THIN_MAX_DATA_BLOCK_SIZE (UINT32_C(2097152))
638
int dm_tree_node_add_thin_pool_target(struct dm_tree_node *node,
640
uint64_t transaction_id,
641
const char *metadata_uuid,
642
const char *pool_uuid,
643
uint32_t data_block_size,
644
uint64_t low_water_mark,
645
unsigned skip_block_zeroing);
647
/* Supported messages for thin provision target */
649
DM_THIN_MESSAGE_CREATE_SNAP, /* device_id, origin_id */
650
DM_THIN_MESSAGE_CREATE_THIN, /* device_id */
651
DM_THIN_MESSAGE_DELETE, /* device_id */
652
DM_THIN_MESSAGE_SET_TRANSACTION_ID, /* current_id, new_id */
655
int dm_tree_node_add_thin_pool_message(struct dm_tree_node *node,
656
dm_thin_message_t type,
657
uint64_t id1, uint64_t id2);
660
* FIXME: Defines bellow are based on kernel's dm-thin.c defines
661
* MAX_DEV_ID ((1 << 24) - 1)
663
#define DM_THIN_MAX_DEVICE_ID (UINT32_C((1 << 24) - 1))
664
int dm_tree_node_add_thin_target(struct dm_tree_node *node,
666
const char *pool_uuid,
669
void dm_tree_node_set_udev_flags(struct dm_tree_node *node, uint16_t udev_flags);
512
671
void dm_tree_node_set_presuspend_node(struct dm_tree_node *node,
513
672
struct dm_tree_node *presuspend_node);
529
688
uint32_t read_ahead,
530
689
uint32_t read_ahead_flags);
692
* Set node callback hook before de/activation.
693
* Callback is called before 'activation' of node for activation tree,
694
* or 'deactivation' of node for deactivation tree.
697
DM_NODE_CALLBACK_PRELOADED, /* Node has preload deps */
698
DM_NODE_CALLBACK_DEACTIVATED, /* Node is deactivated */
699
} dm_node_callback_t;
700
typedef int (*dm_node_callback_fn) (struct dm_tree_node *node,
701
dm_node_callback_t type, void *cb_data);
702
void dm_tree_node_set_callback(struct dm_tree_node *node,
703
dm_node_callback_fn cb, void *cb_data);
532
705
void dm_tree_set_cookie(struct dm_tree_node *node, uint32_t cookie);
533
706
uint32_t dm_tree_get_cookie(struct dm_tree_node *node);
1015
1188
const char *dm_basename(const char *path);
1191
* Returns number of occurrences of 'c' in 'str' of length 'size'.
1193
unsigned dm_count_chars(const char *str, size_t len, const int c);
1196
* Length of string after escaping double quotes and backslashes.
1198
size_t dm_escaped_len(const char *str);
1201
* <vg>-<lv>-<layer> or if !layer just <vg>-<lv>.
1203
char *dm_build_dm_name(struct dm_pool *mem, const char *vgname,
1204
const char *lvname, const char *layer);
1205
char *dm_build_dm_uuid(struct dm_pool *mem, const char *prefix, const char *lvid, const char *layer);
1208
* Copies a string, quoting double quotes with backslashes.
1210
char *dm_escape_double_quotes(char *out, const char *src);
1213
* Undo quoting in situ.
1215
void dm_unescape_double_quotes(char *src);
1218
* Unescape colons and "at" signs in situ and save the substrings
1219
* starting at the position of the first unescaped colon and the
1220
* first unescaped "at" sign. This is normally used to unescape
1221
* device names used as PVs.
1223
void dm_unescape_colons_and_at_signs(char *src,
1224
char **substr_first_unquoted_colon,
1225
char **substr_first_unquoted_at_sign);
1228
* Replacement for strncpy() function.
1230
* Copies no more than n bytes from string pointed by src to the buffer
1231
* pointed by dest and ensure string is finished with '\0'.
1232
* Returns 0 if the whole string does not fit.
1234
int dm_strncpy(char *dest, const char *src, size_t n);
1017
1236
/**************************
1018
1237
* file/stream manipulation
1019
1238
**************************/
1181
1402
void dm_report_field_set_value(struct dm_report_field *field, const void *value,
1182
1403
const void *sortvalue);
1405
/*************************
1406
* config file parse/print
1407
*************************/
1413
} dm_config_value_type_t;
1415
struct dm_config_value {
1416
dm_config_value_type_t type;
1421
double d; /* Unused. */
1425
struct dm_config_value *next; /* For arrays */
1428
struct dm_config_node {
1430
struct dm_config_node *parent, *sib, *child;
1431
struct dm_config_value *v;
1434
struct dm_config_tree {
1435
struct dm_config_node *root;
1436
struct dm_config_tree *cascade;
1437
struct dm_pool *mem;
1441
struct dm_config_tree *dm_config_create(void);
1442
struct dm_config_tree *dm_config_from_string(const char *config_settings);
1443
int dm_config_parse(struct dm_config_tree *cft, const char *start, const char *end);
1445
void *dm_config_get_custom(struct dm_config_tree *cft);
1446
void dm_config_set_custom(struct dm_config_tree *cft, void *custom);
1449
* When searching, first_cft is checked before second_cft.
1451
struct dm_config_tree *dm_config_insert_cascaded_tree(struct dm_config_tree *first_cft, struct dm_config_tree *second_cft);
1454
* If there's a cascaded dm_config_tree, remove the top layer
1455
* and return the layer below. Otherwise return NULL.
1457
struct dm_config_tree *dm_config_remove_cascaded_tree(struct dm_config_tree *cft);
1459
void dm_config_destroy(struct dm_config_tree *cft);
1461
typedef int (*dm_putline_fn)(const char *line, void *baton);
1462
int dm_config_write_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton);
1464
struct dm_config_node *dm_config_find_node(const struct dm_config_node *cn, const char *path);
1465
int dm_config_has_node(const struct dm_config_node *cn, const char *path);
1466
const char *dm_config_find_str(const struct dm_config_node *cn, const char *path, const char *fail);
1467
const char *dm_config_find_str_allow_empty(const struct dm_config_node *cn, const char *path, const char *fail);
1468
int dm_config_find_int(const struct dm_config_node *cn, const char *path, int fail);
1469
int64_t dm_config_find_int64(const struct dm_config_node *cn, const char *path, int64_t fail);
1470
float dm_config_find_float(const struct dm_config_node *cn, const char *path, float fail);
1472
const struct dm_config_node *dm_config_tree_find_node(const struct dm_config_tree *cft, const char *path);
1473
const char *dm_config_tree_find_str(const struct dm_config_tree *cft, const char *path, const char *fail);
1474
const char *dm_config_tree_find_str_allow_empty(const struct dm_config_tree *cft, const char *path, const char *fail);
1475
int dm_config_tree_find_int(const struct dm_config_tree *cft, const char *path, int fail);
1476
int64_t dm_config_tree_find_int64(const struct dm_config_tree *cft, const char *path, int64_t fail);
1477
float dm_config_tree_find_float(const struct dm_config_tree *cft, const char *path, float fail);
1478
int dm_config_tree_find_bool(const struct dm_config_tree *cft, const char *path, int fail);
1481
* Understands (0, ~0), (y, n), (yes, no), (on,
1482
* off), (true, false).
1484
int dm_config_find_bool(const struct dm_config_node *cn, const char *path, int fail);
1486
int dm_config_get_uint32(const struct dm_config_node *cn, const char *path, uint32_t *result);
1487
int dm_config_get_uint64(const struct dm_config_node *cn, const char *path, uint64_t *result);
1488
int dm_config_get_str(const struct dm_config_node *cn, const char *path, const char **result);
1489
int dm_config_get_list(const struct dm_config_node *cn, const char *path, const struct dm_config_value **result);
1490
int dm_config_get_section(const struct dm_config_node *cn, const char *path, const struct dm_config_node **result);
1492
unsigned dm_config_maybe_section(const char *str, unsigned len);
1494
const char *dm_config_parent_name(const struct dm_config_node *n);
1496
struct dm_config_node *dm_config_clone_node_with_mem(struct dm_pool *mem, const struct dm_config_node *node, int siblings);
1497
struct dm_config_node *dm_config_create_node(struct dm_config_tree *cft, const char *key);
1498
struct dm_config_value *dm_config_create_value(struct dm_config_tree *cft);
1499
struct dm_config_node *dm_config_clone_node(struct dm_config_tree *cft, const struct dm_config_node *cn, int siblings);
1501
struct dm_pool *dm_config_memory(struct dm_config_tree *cft);
1184
1503
/* Cookie prefixes.
1185
1505
* The cookie value consists of a prefix (16 bits) and a base (16 bits).
1186
1506
* We can use the prefix to store the flags. These flags are sent to
1187
1507
* kernel within given dm task. When returned back to userspace in