1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Unamngle dm device name list automatically on ioctl return.

If dm_task_get_name or dm_task_get_names gets called, these will return
unmangled form of the names so the name mangling stays totally transparent
to any libdevmapper user (unless DM_STRING_MANGLING_NONE is used in which
case the name is not touched and it is is returned as it is in kernel).

For example:

dmsetup create "a b" - will create a\x20b device in kernel and so udev will
create /dev/mapper/a\x20b

dm_task_get_name/names will still return "a b"

In AUTO mode, the libdevmapper user can still query the device by using
the mangled ("a\x20b") or unmangled form of the name when calling dm_task_set_name.
If mangled name is provided, it's detected and the name is kept as it is.
If unmangled name is provided, it will be mangled. IOW in AUTO mode it's
totally transparent and it should not require any changes in the code
using libdevmapper.

However, any libdevmapper user must be aware of the fact that the mangled form
of the name appears in /dev/mapper (udev just can't deal with those blacklisted
characters).
This commit is contained in:
Peter Rajnoha 2012-02-15 12:01:28 +00:00
parent 69a82801ef
commit 573e57f83f
2 changed files with 46 additions and 2 deletions

View File

@ -1523,6 +1523,39 @@ static const char *_sanitise_message(char *message)
return sanitised_message;
}
static void _do_dm_ioctl_unmangle_name(char *name)
{
char buf[DM_NAME_LEN];
int r;
if ((r = unmangle_name(name, DM_NAME_LEN, buf, sizeof(buf),
dm_get_name_mangling_mode())) < 0)
log_debug("_do_dm_ioctl_unmangle_name: failed to "
"unmangle \"%s\"", name);
else if (r)
memcpy(name, buf, strlen(buf) + 1);
}
static void _dm_ioctl_unmangle_names(int type, struct dm_ioctl *dmi)
{
struct dm_names *names;
unsigned next = 0;
char *name;
if ((name = dmi->name))
_do_dm_ioctl_unmangle_name(name);
if (type == DM_DEVICE_LIST &&
((names = ((struct dm_names *) ((char *)dmi + dmi->data_start)))) &&
names->dev) {
do {
names = (struct dm_names *)((char *) names + next);
_do_dm_ioctl_unmangle_name(names->name);
next = names->next;
} while (next);
}
}
static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
unsigned buffer_repeat_count,
unsigned retry_repeat_count,
@ -1651,6 +1684,8 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
_udev_complete(dmt);
}
(void) _dm_ioctl_unmangle_names(dmt->type, dmi);
#else /* Userspace alternative for testing */
#endif
return dmi;

View File

@ -164,13 +164,22 @@ struct dm_versions {
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_info(struct dm_task *dmt, struct dm_info *dmi);
const char *dm_task_get_name(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_names *dm_task_get_names(struct dm_task *dmt);
struct dm_versions *dm_task_get_versions(struct dm_task *dmt);
/*
* These functions return device-mapper names 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_name_mangled or dm_task_get_name_unmangled function.
*/
const char *dm_task_get_name(const struct dm_task *dmt);
struct dm_names *dm_task_get_names(struct dm_task *dmt);
int dm_task_set_ro(struct dm_task *dmt);
int dm_task_set_newname(struct dm_task *dmt, const char *newname);