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

device_id: improve validate debug messages

Make the device_ids_validate messages consistent.

Consistently use "noupdate" and "update_needed" args.
This commit is contained in:
David Teigland 2023-10-27 17:13:25 -05:00
parent ec47f0763d
commit a5628cf782
5 changed files with 46 additions and 42 deletions

View File

@ -1627,7 +1627,7 @@ int lvmcache_label_scan(struct cmd_context *cmd)
if (!dm_list_empty(&cmd->device_ids_check_serial)) { if (!dm_list_empty(&cmd->device_ids_check_serial)) {
struct dm_list scan_devs; struct dm_list scan_devs;
dm_list_init(&scan_devs); dm_list_init(&scan_devs);
device_ids_check_serial(cmd, &scan_devs, NULL, 0); device_ids_check_serial(cmd, &scan_devs, 0, NULL);
if (!dm_list_empty(&scan_devs)) if (!dm_list_empty(&scan_devs))
label_scan_devs(cmd, cmd->filter, &scan_devs); label_scan_devs(cmd, cmd->filter, &scan_devs);
} }
@ -1660,7 +1660,7 @@ int lvmcache_label_scan(struct cmd_context *cmd)
if (cmd->device_ids_invalid || cmd->device_ids_refresh_trigger) { if (cmd->device_ids_invalid || cmd->device_ids_refresh_trigger) {
struct dm_list refresh_devs; struct dm_list refresh_devs;
dm_list_init(&refresh_devs); dm_list_init(&refresh_devs);
device_ids_refresh(cmd, &refresh_devs, NULL, 0); device_ids_refresh(cmd, &refresh_devs, NULL, 0, NULL);
if (!dm_list_empty(&refresh_devs)) if (!dm_list_empty(&refresh_devs))
label_scan_devs(cmd, cmd->filter, &refresh_devs); label_scan_devs(cmd, cmd->filter, &refresh_devs);
} }

View File

@ -2428,7 +2428,7 @@ static void _get_devs_with_serial_numbers(struct cmd_context *cmd, struct dm_lis
* use_devices entries from the devices file. * use_devices entries from the devices file.
*/ */
void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs, int noupdate, int using_hints) void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs, int using_hints, int noupdate, int *update_needed)
{ {
struct dm_list wrong_devs; struct dm_list wrong_devs;
struct device *dev = NULL; struct device *dev = NULL;
@ -2495,9 +2495,8 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
* probably wants to do something about it. * probably wants to do something about it.
*/ */
if (!cmd->filter->passes_filter(cmd, cmd->filter, dev, "persistent")) { if (!cmd->filter->passes_filter(cmd, cmd->filter, dev, "persistent")) {
log_debug("Validate %s %s PVID %s on %s: filtered", log_debug("Validate %s %s PVID %s on %s: filtered (%s)",
idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: ".", dev_name(dev)); idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: ".",
log_warn("Devices file %s is excluded: %s.",
dev_name(dev), dev_filtered_reason(dev)); dev_name(dev), dev_filtered_reason(dev));
continue; continue;
} }
@ -2612,10 +2611,11 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
cmd->device_ids_invalid = 1; cmd->device_ids_invalid = 1;
} }
/* Fix the DEVNAME field if it's outdated, not generally expected */ /* Fix the DEVNAME field if it's outdated. */
if (!du->devname || strcmp(devname, du->devname)) { if (!du->devname || strcmp(devname, du->devname)) {
log_debug("Updating outdated DEVNAME from %s to %s for PVID %s", log_debug("Validate %s %s PVID %s on %s: outdated DEVNAME %s",
du->devname ?: ".", devname, du->pvid); idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: ".", devname,
du->devname ?: ".");
if (!(tmpdup = strdup(devname))) if (!(tmpdup = strdup(devname)))
continue; continue;
free(du->devname); free(du->devname);
@ -2668,7 +2668,8 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
devname = dev_name(dev); devname = dev_name(dev);
log_debug("New match for devices file PVID %s now on %s.", du->pvid, devname); log_debug("Validate %s %s PVID %s: found on %s",
idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: ".", devname);
dup_devname1 = strdup(devname); dup_devname1 = strdup(devname);
dup_devname2 = strdup(devname); dup_devname2 = strdup(devname);
@ -2719,7 +2720,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
continue; continue;
if (du->dev) if (du->dev)
continue; continue;
log_debug("Validate %s %s PVID %s: no device match", log_debug("Validate %s %s PVID %s: no device found",
idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: "."); idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: ".");
} }
@ -2750,10 +2751,11 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
/* /*
* du2 is correctly matched to a dev using this pvid, * du2 is correctly matched to a dev using this pvid,
* so drop the pvid from du. * so drop the pvid from du.
* TOOD: it would make sense to clear IDNAME, but * TODO: it would make sense to clear IDNAME, but
* can we handle entries with no IDNAME? * can we handle entries with no IDNAME?
*/ */
log_debug("Device %s no longer has PVID %s.", dev_name(du->dev), du->pvid); log_debug("Validate %s %s PVID %s: no device found, remove incorrect PVID",
idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: ".");
free(du->pvid); free(du->pvid);
free(du->devname); free(du->devname);
du->pvid = NULL; du->pvid = NULL;
@ -2800,10 +2802,9 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
if (strcmp(du->idname, du2->idname)) if (strcmp(du->idname, du2->idname))
continue; continue;
log_debug("Repeated idname %s pvids %s %s",
du->idname, du->pvid ?: ".", du2->pvid ?: ".");
if (!du2->pvid) { if (!du2->pvid) {
log_debug("Validate %s %s PVID none: remove entry with repeated devname",
idtype_to_str(du2->idtype), du2->idname ?: ".");
dm_list_del(&du2->list); dm_list_del(&du2->list);
free_du(du2); free_du(du2);
update_file = 1; update_file = 1;
@ -2847,6 +2848,9 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
if (update_file || cmd->device_ids_invalid) if (update_file || cmd->device_ids_invalid)
unlink_searched_devnames(cmd); unlink_searched_devnames(cmd);
if (update_file && update_needed)
*update_needed = 1;
/* FIXME: for wrong devname cases, wait to write new until device_ids_refresh? */ /* FIXME: for wrong devname cases, wait to write new until device_ids_refresh? */
/* /*
@ -2895,7 +2899,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
* (This could also be done for duplicate wwids if needed.) * (This could also be done for duplicate wwids if needed.)
*/ */
void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs, void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs,
int *update_needed, int noupdate) int noupdate, int *update_needed)
{ {
struct dm_list dus_check; /* dev_use_list */ struct dm_list dus_check; /* dev_use_list */
struct dm_list devs_check; /* device_list */ struct dm_list devs_check; /* device_list */
@ -3176,8 +3180,8 @@ void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs,
* is using a non-system devices file? * is using a non-system devices file?
*/ */
void device_ids_refresh(struct cmd_context *cmd, struct dm_list *dev_list, void device_ids_refresh(struct cmd_context *cmd, struct dm_list *refresh_devs,
int *search_count, int noupdate) int *search_count, int noupdate, int *update_needed)
{ {
struct device *dev; struct device *dev;
struct dev_use *du; struct dev_use *du;
@ -3528,6 +3532,9 @@ void device_ids_refresh(struct cmd_context *cmd, struct dm_list *dev_list,
log_debug("Search for PVIDs found no updates"); log_debug("Search for PVIDs found no updates");
} }
if (update_file && update_needed)
*update_needed = 1;
/* /*
* The entries in search_list_pvids with a dev set are the new devs found * The entries in search_list_pvids with a dev set are the new devs found
* for the PVIDs that we want to return to the caller in a device_list * for the PVIDs that we want to return to the caller in a device_list
@ -3541,7 +3548,7 @@ void device_ids_refresh(struct cmd_context *cmd, struct dm_list *dev_list,
if (!(devl = dm_pool_zalloc(cmd->mem, sizeof(*devl)))) if (!(devl = dm_pool_zalloc(cmd->mem, sizeof(*devl))))
continue; continue;
devl->dev = dev; devl->dev = dev;
dm_list_add(dev_list, &devl->list); dm_list_add(refresh_devs, &devl->list);
} }
/* /*

View File

@ -33,12 +33,15 @@ void device_id_pvremove(struct cmd_context *cmd, struct device *dev);
void device_ids_match(struct cmd_context *cmd); void device_ids_match(struct cmd_context *cmd);
int device_ids_match_dev(struct cmd_context *cmd, struct device *dev); int device_ids_match_dev(struct cmd_context *cmd, struct device *dev);
void device_ids_match_device_list(struct cmd_context *cmd); void device_ids_match_device_list(struct cmd_context *cmd);
void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs, int noupdate, int using_hints); void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs, int using_hints,
int device_ids_version_unchanged(struct cmd_context *cmd); int noupdate, int *update_needed);
void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs, int *update_needed, int noupdate); void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs,
void device_ids_refresh(struct cmd_context *cmd, struct dm_list *dev_list, int *search_count, int noupdate); int noupdate, int *update_needed);
void device_ids_refresh(struct cmd_context *cmd, struct dm_list *dev_list, int *search_count,
int noupdate, int *update_needed);
const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, uint16_t idtype); const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, uint16_t idtype);
void device_id_update_vg_uuid(struct cmd_context *cmd, struct volume_group *vg, struct id *old_vg_id); void device_id_update_vg_uuid(struct cmd_context *cmd, struct volume_group *vg, struct id *old_vg_id);
int device_ids_version_unchanged(struct cmd_context *cmd);
struct dev_use *get_du_for_devno(struct cmd_context *cmd, dev_t devno); struct dev_use *get_du_for_devno(struct cmd_context *cmd, dev_t devno);
struct dev_use *get_du_for_dev(struct cmd_context *cmd, struct device *dev); struct dev_use *get_du_for_dev(struct cmd_context *cmd, struct device *dev);

View File

@ -1457,7 +1457,7 @@ int label_scan(struct cmd_context *cmd)
* Check if the devices_file content is up to date and * Check if the devices_file content is up to date and
* if not update it. * if not update it.
*/ */
device_ids_validate(cmd, &scan_devs, 0, using_hints); device_ids_validate(cmd, &scan_devs, using_hints, 0, NULL);
dm_list_iterate_items_safe(devl, devl2, &all_devs) { dm_list_iterate_items_safe(devl, devl2, &all_devs) {
dm_list_del(&devl->list); dm_list_del(&devl->list);

View File

@ -188,7 +188,6 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
int update_set = arg_is_set(cmd, update_ARG); int update_set = arg_is_set(cmd, update_ARG);
int search_count = 0; int search_count = 0;
int update_needed = 0; int update_needed = 0;
int serial_update_needed = 0;
unlink_searched_devnames(cmd); unlink_searched_devnames(cmd);
@ -226,13 +225,9 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
/* /*
* Check that the pvid read from the lvm label matches the pvid * Check that the pvid read from the lvm label matches the pvid
* for this devices file entry. Also print a warning if a dev * for this devices file entry.
* from use_devices does not pass the filters that have been
* run just above.
*/ */
device_ids_validate(cmd, NULL, 1, 0); device_ids_validate(cmd, NULL, 0, 1, &update_needed);
if (cmd->device_ids_invalid)
update_needed = 1;
/* /*
* Remove multipath components. * Remove multipath components.
@ -275,17 +270,16 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
} }
} }
if (!dm_list_empty(&cmd->device_ids_check_serial)) if (!dm_list_empty(&cmd->device_ids_check_serial)) {
device_ids_check_serial(cmd, &scan_devs, &serial_update_needed, 1); device_ids_check_serial(cmd, &scan_devs, 1, &update_needed);
/* device_ids_check_serial has done label_read_pvid on the scan_devs. */
}
/* /*
* Find and fix any devname entries that have moved to a * Find and fix any devname entries that have moved to a
* renamed device. * renamed device.
*/ */
device_ids_refresh(cmd, &found_devs, &search_count, 1); device_ids_refresh(cmd, &found_devs, &search_count, 1, &update_needed);
if (search_count && !strcmp(cmd->search_for_devnames, "none"))
log_print("Not searching for missing devnames, search_for_devnames=\"none\".");
dm_list_iterate_items(du, &cmd->use_devices) { dm_list_iterate_items(du, &cmd->use_devices) {
if (du->dev) if (du->dev)
@ -305,7 +299,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
} }
if (arg_is_set(cmd, update_ARG)) { if (arg_is_set(cmd, update_ARG)) {
if (update_needed || serial_update_needed || !dm_list_empty(&found_devs)) { if (update_needed || !dm_list_empty(&found_devs)) {
if (!device_ids_write(cmd)) if (!device_ids_write(cmd))
goto_bad; goto_bad;
log_print("Updated devices file to version %s", devices_file_version()); log_print("Updated devices file to version %s", devices_file_version());
@ -318,7 +312,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
* needs updates, i.e. running --update would make * needs updates, i.e. running --update would make
* changes. * changes.
*/ */
if (update_needed || serial_update_needed) { if (update_needed) {
log_error("Updates needed for devices file."); log_error("Updates needed for devices file.");
goto bad; goto bad;
} }