mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
libdm: add dm_task_get_uuid_mangled/unmangled
Just like we already have existing mangling support for device-mapper names, we need exactly the same for device-mapper UUIDs as their character whitelist is wider than what udev supports. In case udev is used to create entries in /dev based on UUIDs and these UUIDs contain characters not supported by udev, we'll end up with incorrect /dev content for such devices. So we need to mangle them to a form that is supported by udev. The mangling used for UUIDs follows the mangling used for names (that is already supported and used throughout). That means, setting the name mangling mode via dm_set_name_mangling_mode affects mangling used for UUIDs in exactly the same manner. It would be useless to add a new and separate dm_set_uuid_mangling_mode fn, we'll reuse existing interface.
This commit is contained in:
parent
b0f48b9533
commit
12f5c3f726
@ -681,11 +681,6 @@ uint32_t dm_task_get_read_ahead(const struct dm_task *dmt, uint32_t *read_ahead)
|
|||||||
MINOR(dmt->dmi.v4->dev), read_ahead);
|
MINOR(dmt->dmi.v4->dev), read_ahead);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *dm_task_get_uuid(const struct dm_task *dmt)
|
|
||||||
{
|
|
||||||
return (dmt->dmi.v4->uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
|
struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
|
||||||
{
|
{
|
||||||
return (struct dm_deps *) (((char *) dmt->dmi.v4) +
|
return (struct dm_deps *) (((char *) dmt->dmi.v4) +
|
||||||
|
@ -164,6 +164,16 @@ struct dm_versions {
|
|||||||
int dm_get_library_version(char *version, size_t size);
|
int dm_get_library_version(char *version, size_t size);
|
||||||
int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size);
|
int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size);
|
||||||
int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);
|
int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function returns dm device's UUID based on the value
|
||||||
|
* of the mangling mode set during preceding dm_task_run call:
|
||||||
|
* - unmangled name for DM_STRING_MANGLING_{AUTO, HEX},
|
||||||
|
* - name without any changes for DM_STRING_MANGLING_NONE.
|
||||||
|
*
|
||||||
|
* To get mangled or unmangled form of the name directly, use
|
||||||
|
* dm_task_get_uuid_mangled or dm_task_get_uuid_unmangled function.
|
||||||
|
*/
|
||||||
const char *dm_task_get_uuid(const struct dm_task *dmt);
|
const char *dm_task_get_uuid(const struct dm_task *dmt);
|
||||||
|
|
||||||
struct dm_deps *dm_task_get_deps(struct dm_task *dmt);
|
struct dm_deps *dm_task_get_deps(struct dm_task *dmt);
|
||||||
@ -297,18 +307,20 @@ typedef enum {
|
|||||||
} dm_string_mangling_t;
|
} dm_string_mangling_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set/get mangling mode used for device-mapper names.
|
* Set/get mangling mode used for device-mapper names and uuids.
|
||||||
*/
|
*/
|
||||||
int dm_set_name_mangling_mode(dm_string_mangling_t name_mangling);
|
int dm_set_name_mangling_mode(dm_string_mangling_t name_mangling);
|
||||||
dm_string_mangling_t dm_get_name_mangling_mode(void);
|
dm_string_mangling_t dm_get_name_mangling_mode(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get mangled/unmangled form of the device-mapper name
|
* Get mangled/unmangled form of the device-mapper name or uuid
|
||||||
* irrespective of the global setting (set by dm_set_name_mangling_mode).
|
* irrespective of the global setting (set by dm_set_name_mangling_mode).
|
||||||
* The name returned needs to be freed after use by calling dm_free!
|
* The name or uuid returned needs to be freed after use by calling dm_free!
|
||||||
*/
|
*/
|
||||||
char *dm_task_get_name_mangled(const struct dm_task *dmt);
|
char *dm_task_get_name_mangled(const struct dm_task *dmt);
|
||||||
char *dm_task_get_name_unmangled(const struct dm_task *dmt);
|
char *dm_task_get_name_unmangled(const struct dm_task *dmt);
|
||||||
|
char *dm_task_get_uuid_mangled(const struct dm_task *dmt);
|
||||||
|
char *dm_task_get_uuid_unmangled(const struct dm_task *dmt);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configure the device-mapper directory
|
* Configure the device-mapper directory
|
||||||
|
@ -582,18 +582,51 @@ const char *dm_task_get_name(const struct dm_task *dmt)
|
|||||||
return (dmt->dmi.v4->name);
|
return (dmt->dmi.v4->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *_task_get_string_mangled(const char *str, const char *str_name,
|
||||||
|
char *buf, size_t buf_size,
|
||||||
|
dm_string_mangling_t mode)
|
||||||
|
{
|
||||||
|
char *rs;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
if ((r = mangle_string(str, str_name, strlen(str), buf, buf_size, mode)) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!(rs = r ? dm_strdup(buf) : dm_strdup(str)))
|
||||||
|
log_error("_task_get_string_mangled: dm_strdup failed");
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *_task_get_string_unmangled(const char *str, const char *str_name,
|
||||||
|
char *buf, size_t buf_size,
|
||||||
|
dm_string_mangling_t mode)
|
||||||
|
{
|
||||||
|
char *rs;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unless the mode used is 'none', the string
|
||||||
|
* is *already* unmangled on ioctl return!
|
||||||
|
*/
|
||||||
|
if (mode == DM_STRING_MANGLING_NONE &&
|
||||||
|
(r = unmangle_string(str, str_name, strlen(str), buf, buf_size, mode)) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!(rs = r ? dm_strdup(buf) : dm_strdup(str)))
|
||||||
|
log_error("_task_get_string_unmangled: dm_strdup failed");
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
char *dm_task_get_name_mangled(const struct dm_task *dmt)
|
char *dm_task_get_name_mangled(const struct dm_task *dmt)
|
||||||
{
|
{
|
||||||
const char *s = dm_task_get_name(dmt);
|
const char *s = dm_task_get_name(dmt);
|
||||||
char buf[DM_NAME_LEN];
|
char buf[DM_NAME_LEN];
|
||||||
char *rs = NULL;
|
char *rs;
|
||||||
int r;
|
|
||||||
|
|
||||||
if ((r = mangle_string(s, "name", strlen(s), buf, sizeof(buf),
|
if (!(rs = _task_get_string_mangled(s, "name", buf, sizeof(buf), dm_get_name_mangling_mode())))
|
||||||
dm_get_name_mangling_mode())) < 0)
|
|
||||||
log_error("Failed to mangle device name \"%s\".", s);
|
log_error("Failed to mangle device name \"%s\".", s);
|
||||||
else if (!(rs = r ? dm_strdup(buf) : dm_strdup(s)))
|
|
||||||
log_error("dm_task_get_name_mangled: dm_strdup failed");
|
|
||||||
|
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
@ -602,19 +635,39 @@ char *dm_task_get_name_unmangled(const struct dm_task *dmt)
|
|||||||
{
|
{
|
||||||
const char *s = dm_task_get_name(dmt);
|
const char *s = dm_task_get_name(dmt);
|
||||||
char buf[DM_NAME_LEN];
|
char buf[DM_NAME_LEN];
|
||||||
char *rs = NULL;
|
char *rs;
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
/*
|
if (!(rs = _task_get_string_unmangled(s, "name", buf, sizeof(buf), dm_get_name_mangling_mode())))
|
||||||
* Unless the mode used is 'none', the name
|
|
||||||
* is *already* unmangled on ioctl return!
|
|
||||||
*/
|
|
||||||
if (dm_get_name_mangling_mode() == DM_STRING_MANGLING_NONE &&
|
|
||||||
(r = unmangle_string(s, "name", strlen(s), buf, sizeof(buf),
|
|
||||||
dm_get_name_mangling_mode())) < 0)
|
|
||||||
log_error("Failed to unmangle device name \"%s\".", s);
|
log_error("Failed to unmangle device name \"%s\".", s);
|
||||||
else if (!(rs = r ? dm_strdup(buf) : dm_strdup(s)))
|
|
||||||
log_error("dm_task_get_name_unmangled: dm_strdup failed");
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *dm_task_get_uuid(const struct dm_task *dmt)
|
||||||
|
{
|
||||||
|
return (dmt->dmi.v4->uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *dm_task_get_uuid_mangled(const struct dm_task *dmt)
|
||||||
|
{
|
||||||
|
const char *s = dm_task_get_uuid(dmt);
|
||||||
|
char buf[DM_UUID_LEN];
|
||||||
|
char *rs;
|
||||||
|
|
||||||
|
if (!(rs = _task_get_string_mangled(s, "UUID", buf, sizeof(buf), dm_get_name_mangling_mode())))
|
||||||
|
log_error("Failed to mangle device uuid \"%s\".", s);
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *dm_task_get_uuid_unmangled(const struct dm_task *dmt)
|
||||||
|
{
|
||||||
|
const char *s = dm_task_get_uuid(dmt);
|
||||||
|
char buf[DM_UUID_LEN];
|
||||||
|
char *rs;
|
||||||
|
|
||||||
|
if (!(rs = _task_get_string_unmangled(s, "UUID", buf, sizeof(buf), dm_get_name_mangling_mode())))
|
||||||
|
log_error("Failed to unmangle device uuid \"%s\".", s);
|
||||||
|
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user