mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
dm uuid cache: clarify interface for new dm uuid cache
The previous function names used the word "device", which in lvm typically means "struct device". Use names that make it clear that these are about lists of dm uuids: get_device_list() -> create_dm_uuid_cache() device_get_uuid() -> dev_dm_uuid() / devn_dm_uuid() Also simplify the args for these functions.
This commit is contained in:
parent
6e6d4c62b3
commit
389cc338ff
@ -672,13 +672,23 @@ int target_present(struct cmd_context *cmd, const char *target_name,
|
||||
&maj, &min, &patchlevel);
|
||||
}
|
||||
|
||||
int get_device_list(const struct volume_group *vg, struct dm_list **devs,
|
||||
unsigned *devs_features)
|
||||
void create_dm_uuid_cache(struct dm_list **devs)
|
||||
{
|
||||
if (!activation())
|
||||
return 0;
|
||||
unsigned devs_features = 0;
|
||||
|
||||
return dev_manager_get_device_list(NULL, devs, devs_features);
|
||||
if (!activation())
|
||||
return;
|
||||
|
||||
dm_device_list_destroy(devs);
|
||||
|
||||
if (!dev_manager_get_device_list(NULL, devs, &devs_features))
|
||||
return;
|
||||
|
||||
if (!(devs_features & DM_DEVICE_LIST_HAS_UUID)) {
|
||||
/* Using older kernels without UUIDs in LIST,
|
||||
* -> cannot use cache */
|
||||
dm_device_list_destroy(devs);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -107,10 +107,11 @@ int target_present(struct cmd_context *cmd, const char *target_name,
|
||||
int target_version(const char *target_name, uint32_t *maj,
|
||||
uint32_t *min, uint32_t *patchlevel);
|
||||
|
||||
int get_device_list(const struct volume_group *vg, struct dm_list **devs,
|
||||
unsigned *devs_features);
|
||||
int device_get_uuid(struct cmd_context *cmd, int major, int minor,
|
||||
char *uuid_buf, size_t uuid_buf_size);
|
||||
void create_dm_uuid_cache(struct dm_list **devs);
|
||||
int devn_dm_uuid(struct cmd_context *cmd, int major, int minor,
|
||||
char *uuid_buf, size_t uuid_buf_size);
|
||||
int dev_dm_uuid(struct cmd_context *cmd, struct device *dev,
|
||||
char *uuid_buf, size_t uuid_buf_size);
|
||||
|
||||
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);
|
||||
|
@ -880,13 +880,15 @@ int device_is_usable(struct cmd_context *cmd, struct device *dev, struct dev_usa
|
||||
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)
|
||||
/* Read UUID from a given DM device into uuid_buf. */
|
||||
|
||||
int devn_dm_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) {
|
||||
@ -894,8 +896,12 @@ int device_get_uuid(struct cmd_context *cmd, int major, int minor,
|
||||
dm_strncpy(uuid_buf, uuid, uuid_buf_size);
|
||||
return 1;
|
||||
}
|
||||
uuid_buf[0] = 0;
|
||||
return 0;
|
||||
|
||||
if (major != cmd->dev_types->device_mapper_major) {
|
||||
/* This function is not expected to be used for non-dm devs. */
|
||||
uuid_buf[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(dmt = _setup_task_run(DM_DEVICE_INFO, &info, NULL, NULL, NULL,
|
||||
@ -907,9 +913,20 @@ int device_get_uuid(struct cmd_context *cmd, int major, int minor,
|
||||
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
if (r && cmd->cache_dm_devs)
|
||||
log_debug("WARNING: dm uuid cache failed for %d:%d %s",
|
||||
major, minor, uuid_buf);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int dev_dm_uuid(struct cmd_context *cmd, struct device *dev,
|
||||
char *uuid_buf, size_t uuid_buf_size)
|
||||
{
|
||||
return devn_dm_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev),
|
||||
uuid_buf, uuid_buf_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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-
|
||||
|
@ -563,7 +563,7 @@ static int _get_vgid_and_lvid_for_dev(struct cmd_context *cmd, struct device *de
|
||||
char uuid[DM_UUID_LEN];
|
||||
size_t uuid_len;
|
||||
|
||||
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
|
||||
if (!dev_dm_uuid(cmd, dev, uuid, sizeof(uuid)))
|
||||
return_0;
|
||||
|
||||
uuid_len = strlen(uuid);
|
||||
|
@ -535,7 +535,7 @@ static int _dev_is_mpath_component_sysfs(struct cmd_context *cmd, struct device
|
||||
|
||||
/* Check whether holder's UUID uses MPATH prefix */
|
||||
/* TODO: reuse/merge with dev_has_mpath_uuid() as this function also recognizes kpartx partition */
|
||||
if (device_get_uuid(cmd, dm_dev_major, dm_dev_minor, uuid, sizeof(uuid)) &&
|
||||
if (devn_dm_uuid(cmd, dm_dev_major, dm_dev_minor, uuid, sizeof(uuid)) &&
|
||||
!strncmp(uuid, MPATH_PREFIX, sizeof(MPATH_PREFIX) - 1)) {
|
||||
log_debug_devs("dev_is_mpath_component %s holder %s %u:%u ignore mpath component",
|
||||
dev_name(dev), holder_name, dm_dev_major, dm_dev_minor);
|
||||
|
@ -55,8 +55,7 @@ int dev_is_lv(struct cmd_context *cmd, struct device *dev)
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
if (device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev),
|
||||
buffer, sizeof(buffer)) &&
|
||||
if (dev_dm_uuid(cmd, dev, buffer, sizeof(buffer)) &&
|
||||
!strncmp(buffer, UUID_PREFIX, sizeof(UUID_PREFIX) - 1))
|
||||
return 1;
|
||||
|
||||
@ -128,7 +127,7 @@ int dev_is_used_by_active_lv(struct cmd_context *cmd, struct device *dev, int *u
|
||||
* by reading DM status and seeing if the uuid begins
|
||||
* with UUID_PREFIX ("LVM-")
|
||||
*/
|
||||
if (!device_get_uuid(cmd, dm_dev_major, dm_dev_minor, dm_uuid, sizeof(dm_uuid)))
|
||||
if (!devn_dm_uuid(cmd, dm_dev_major, dm_dev_minor, dm_uuid, sizeof(dm_uuid)))
|
||||
continue;
|
||||
|
||||
if (!strncmp(dm_uuid, UUID_PREFIX, lvm_prefix_len))
|
||||
|
@ -512,7 +512,7 @@ int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, char **idnam
|
||||
char uuid[DM_UUID_LEN];
|
||||
char *idname;
|
||||
|
||||
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
|
||||
if (!dev_dm_uuid(cmd, dev, uuid, sizeof(uuid)))
|
||||
return_0;
|
||||
|
||||
if (!_dm_uuid_has_prefix(uuid, "mpath-"))
|
||||
@ -531,7 +531,7 @@ static int _dev_has_crypt_uuid(struct cmd_context *cmd, struct device *dev, char
|
||||
char uuid[DM_UUID_LEN];
|
||||
char *idname;
|
||||
|
||||
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
|
||||
if (!dev_dm_uuid(cmd, dev, uuid, sizeof(uuid)))
|
||||
return_0;
|
||||
|
||||
if (!_dm_uuid_has_prefix(uuid, "CRYPT-"))
|
||||
@ -550,7 +550,7 @@ static int _dev_has_lvmlv_uuid(struct cmd_context *cmd, struct device *dev, char
|
||||
char uuid[DM_UUID_LEN];
|
||||
char *idname;
|
||||
|
||||
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
|
||||
if (!dev_dm_uuid(cmd, dev, uuid, sizeof(uuid)))
|
||||
return_0;
|
||||
|
||||
if (!_dm_uuid_has_prefix(uuid, UUID_PREFIX))
|
||||
@ -786,7 +786,7 @@ char *device_id_system_read(struct cmd_context *cmd, struct device *dev, uint16_
|
||||
case DEV_ID_TYPE_MPATH_UUID:
|
||||
case DEV_ID_TYPE_CRYPT_UUID:
|
||||
case DEV_ID_TYPE_LVMLV_UUID:
|
||||
(void)device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), sysbuf, sizeof(sysbuf));
|
||||
(void)dev_dm_uuid(cmd, dev, sysbuf, sizeof(sysbuf));
|
||||
break;
|
||||
case DEV_ID_TYPE_MD_UUID:
|
||||
read_sys_block(cmd, dev, "md/uuid", sysbuf, sizeof(sysbuf));
|
||||
@ -1005,7 +1005,7 @@ static int _dev_has_stable_id(struct cmd_context *cmd, struct device *dev)
|
||||
}
|
||||
|
||||
if ((MAJOR(dev->dev) == cmd->dev_types->device_mapper_major)) {
|
||||
if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), sysbuf, sizeof(sysbuf)))
|
||||
if (!dev_dm_uuid(cmd, dev, sysbuf, sizeof(sysbuf)))
|
||||
goto_out;
|
||||
|
||||
if (_dm_uuid_has_prefix(sysbuf, "mpath-"))
|
||||
|
@ -1259,7 +1259,6 @@ int label_scan(struct cmd_context *cmd)
|
||||
uint64_t max_metadata_size_bytes;
|
||||
int using_hints;
|
||||
int create_hints = 0; /* NEWHINTS_NONE */
|
||||
unsigned devs_features = 0;
|
||||
|
||||
log_debug_devs("Finding devices to scan");
|
||||
|
||||
@ -1271,14 +1270,22 @@ int label_scan(struct cmd_context *cmd)
|
||||
if (!label_scan_setup_bcache())
|
||||
return_0;
|
||||
|
||||
/* Initialize device_list cache early so
|
||||
* 'Hints' file processing can also use it */
|
||||
dm_device_list_destroy(&cmd->cache_dm_devs);
|
||||
if (get_device_list(NULL, &cmd->cache_dm_devs, &devs_features))
|
||||
if (!(devs_features & DM_DEVICE_LIST_HAS_UUID))
|
||||
/* Using older kernels without UUIDs in LIST,
|
||||
* -> cannot use cache */
|
||||
dm_device_list_destroy(&cmd->cache_dm_devs);
|
||||
/*
|
||||
* Initialize cache of dm device uuids here so that hints file
|
||||
* processing can use it. It's ok if the cache cannot be
|
||||
* created, a dm uuid will simply be read directly if/when it's
|
||||
* needed when the cache doesn't exist.
|
||||
*
|
||||
* This cache mechanism is not simple, and is implemented in
|
||||
* libdm, not in lvm itself. This introduces a lot of complexity
|
||||
* for little benefit; in fact for the large majority of cases,
|
||||
* this extra code/complexity will have a negative effect.
|
||||
*
|
||||
* create_dm_uuid_cache() ->
|
||||
* dev_manager_get_device_list() ->
|
||||
* dm_task_get_device_list() which is a very complex function.
|
||||
*/
|
||||
create_dm_uuid_cache(&cmd->cache_dm_devs);
|
||||
|
||||
/*
|
||||
* Creates a list of available devices, does not open or read any,
|
||||
|
@ -6035,7 +6035,7 @@ int get_rootvg_dev_uuid(struct cmd_context *cmd, char **dm_uuid_out)
|
||||
if (stat(me->mnt_dir, &info) < 0)
|
||||
return_0;
|
||||
|
||||
if (!device_get_uuid(cmd, MAJOR(info.st_dev), MINOR(info.st_dev), dm_uuid, sizeof(dm_uuid)))
|
||||
if (!devn_dm_uuid(cmd, MAJOR(info.st_dev), MINOR(info.st_dev), dm_uuid, sizeof(dm_uuid)))
|
||||
return_0;
|
||||
|
||||
log_debug("Found root dm_uuid %s", dm_uuid);
|
||||
|
Loading…
Reference in New Issue
Block a user