mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
device_manager: add device_get_uuid
Function that is working with DM target is located within lib/activate directory. This function is able to use cached dm_device_list when possible to quickly resolve checks for device's UUID. Function can fully replace get_dm_uuid_from_sysfs() and instead of syscalls for open/read/close get the UUID with single ioctl. When there is cached dm devs list, we can get many UUID from a single syscall.
This commit is contained in:
parent
5da282fa23
commit
dac2bfe6a4
@ -109,6 +109,8 @@ int target_version(const char *target_name, uint32_t *maj,
|
|||||||
|
|
||||||
int get_device_list(const struct volume_group *vg, struct dm_list **devs,
|
int get_device_list(const struct volume_group *vg, struct dm_list **devs,
|
||||||
unsigned *devs_features);
|
unsigned *devs_features);
|
||||||
|
int device_get_uuid(struct cmd_context *cmd, int major, int minor,
|
||||||
|
char *uuid_buf, size_t uuid_buf_size);
|
||||||
|
|
||||||
int raid4_is_supported(struct cmd_context *cmd, const struct segment_type *segtype);
|
int raid4_is_supported(struct cmd_context *cmd, const struct segment_type *segtype);
|
||||||
int lvm_dm_prefix_check(int major, int minor, const char *prefix);
|
int lvm_dm_prefix_check(int major, int minor, const char *prefix);
|
||||||
|
@ -880,6 +880,36 @@ int device_is_usable(struct cmd_context *cmd, struct device *dev, struct dev_usa
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read UUID from a given DM device into buf_uuid */
|
||||||
|
int device_get_uuid(struct cmd_context *cmd, int major, int minor,
|
||||||
|
char *uuid_buf, size_t uuid_buf_size)
|
||||||
|
{
|
||||||
|
struct dm_task *dmt;
|
||||||
|
struct dm_info info;
|
||||||
|
const char *uuid;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
|
if (cmd->cache_dm_devs) {
|
||||||
|
if (dm_device_list_find_by_dev(cmd->cache_dm_devs, major, minor, NULL, &uuid)) {
|
||||||
|
dm_strncpy(uuid_buf, uuid, uuid_buf_size);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
uuid_buf[0] = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(dmt = _setup_task_run(DM_DEVICE_INFO, &info, NULL, NULL, NULL,
|
||||||
|
major, minor, 0, 0, 0)))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
if (info.exists && (uuid = dm_task_get_uuid(dmt)))
|
||||||
|
r = dm_strncpy(uuid_buf, uuid, uuid_buf_size);
|
||||||
|
|
||||||
|
dm_task_destroy(dmt);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If active LVs were activated by a version of LVM2 before 2.02.00 we must
|
* If active LVs were activated by a version of LVM2 before 2.02.00 we must
|
||||||
* perform additional checks to find them because they do not have the LVM-
|
* perform additional checks to find them because they do not have the LVM-
|
||||||
|
Loading…
Reference in New Issue
Block a user