diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 311cbb4a6..0c7a49a2c 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -672,13 +672,13 @@ 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) +int get_dm_active_devices(const struct volume_group *vg, struct dm_list **devs, + unsigned *devs_features) { if (!activation()) return 0; - return dev_manager_get_device_list(NULL, devs, devs_features); + return dev_manager_get_dm_active_devices(NULL, devs, devs_features); } /* diff --git a/lib/activate/activate.h b/lib/activate/activate.h index ca8b6e695..b9798ed48 100644 --- a/lib/activate/activate.h +++ b/lib/activate/activate.h @@ -107,10 +107,12 @@ 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, +int get_dm_active_devices(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); +int devno_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); diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index 35e720c84..745fa262d 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -888,8 +888,8 @@ int device_is_usable(struct cmd_context *cmd, struct device *dev, struct dev_usa } /* 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) +int devno_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; @@ -918,6 +918,13 @@ int device_get_uuid(struct cmd_context *cmd, int major, int minor, return r; } +int dev_dm_uuid(struct cmd_context *cmd, struct device *dev, + char *uuid_buf, size_t uuid_buf_size) +{ + return devno_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- @@ -1036,7 +1043,12 @@ int dev_manager_check_prefix_dm_major_minor(uint32_t major, uint32_t minor, cons return r; } -int dev_manager_get_device_list(const char *prefix, struct dm_list **devs, unsigned *devs_features) +/* + * Get a list of active dm devices from the kernel. + * The 'devs' list contains a struct dm_active_device. + */ + +int dev_manager_get_dm_active_devices(const char *prefix, struct dm_list **devs, unsigned *devs_features) { struct dm_task *dmt; int r = 1; diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h index 59f45b6f1..353c3c7d2 100644 --- a/lib/activate/dev_manager.h +++ b/lib/activate/dev_manager.h @@ -108,7 +108,7 @@ int dev_manager_device_uses_vg(struct device *dev, int dev_manager_remove_dm_major_minor(uint32_t major, uint32_t minor); int dev_manager_check_prefix_dm_major_minor(uint32_t major, uint32_t minor, const char *prefix); -int dev_manager_get_device_list(const char *prefix, struct dm_list **devs, - unsigned *devs_features); +int dev_manager_get_dm_active_devices(const char *prefix, struct dm_list **devs, + unsigned *devs_features); #endif diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 7e6d59191..217a45e71 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -593,7 +593,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); @@ -1343,7 +1343,7 @@ int dev_cache_update_dm_devs(struct cmd_context *cmd) _cache.dm_uuids = NULL; } - if (!get_device_list(NULL, &cmd->cache_dm_devs, &devs_features)) + if (!get_dm_active_devices(NULL, &cmd->cache_dm_devs, &devs_features)) return 1; if (!(devs_features & DM_DEVICE_LIST_HAS_UUID)) { diff --git a/lib/device/dev-mpath.c b/lib/device/dev-mpath.c index 01fc4c89f..e13c0bf21 100644 --- a/lib/device/dev-mpath.c +++ b/lib/device/dev-mpath.c @@ -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 (devno_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); diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c index 748d1d75a..c7c2a838d 100644 --- a/lib/device/dev-type.c +++ b/lib/device/dev-type.c @@ -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 (!devno_dm_uuid(cmd, dm_dev_major, dm_dev_minor, dm_uuid, sizeof(dm_uuid))) continue; if (!strncmp(dm_uuid, UUID_PREFIX, lvm_prefix_len)) diff --git a/lib/device/device_id.c b/lib/device/device_id.c index ea15fa303..b3330f2ba 100644 --- a/lib/device/device_id.c +++ b/lib/device/device_id.c @@ -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-")) diff --git a/lib/label/label.c b/lib/label/label.c index 20ac1bdc8..d1e175cad 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -1257,8 +1257,12 @@ int label_scan(struct cmd_context *cmd) if (!label_scan_setup_bcache()) return_0; - /* Initialize dm device cache early so - * 'Hints' file processing can also use it */ + /* + * Initialize cache of dm device uuids, which uses a special dm kernel + * feature for efficiently querying many dm devs together. (It's done + * here, before processing the hints file, so that the dm uuid checks + * in hint processing can benefit from the dm uuid cache.) + */ if (!dev_cache_update_dm_devs(cmd)) return_0; diff --git a/tools/toollib.c b/tools/toollib.c index 0e684e8de..62cc5cf65 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -6066,7 +6066,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 (!devno_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);