diff --git a/lib/device/device_id.c b/lib/device/device_id.c index 17f0c9bc6..d4f5b676f 100644 --- a/lib/device/device_id.c +++ b/lib/device/device_id.c @@ -2721,6 +2721,31 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs, } } + /* + * Set invalid if an entry using IDNAME=devname has not + * been matched to a device. It's possible that the device + * with the PVID has a new name, different from the IDNAME + * value. device_ids_refresh needs to search system devs + * for the PVID. The same applies when the IDNAME field + * has no value. + */ + dm_list_iterate_items(du, &cmd->use_devices) { + if (cmd->device_ids_invalid) + break; + + if (!du->idname || (du->idname[0] == '.')) { + log_debug("Validate %s %s PVID %s: no idname is invalid.", + idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: "."); + cmd->device_ids_invalid = 1; + } + + if ((du->idtype == DEV_ID_TYPE_DEVNAME) && !du->dev && du->pvid) { + log_debug("Validate %s %s PVID %s: no device for idtype devname is invalid.", + idtype_to_str(du->idtype), du->idname ?: ".", du->pvid ?: "."); + cmd->device_ids_invalid = 1; + } + } + /* * When a new devname/pvid mismatch is discovered, a new search for the * pvid should be permitted (searched_devnames may exist to suppress diff --git a/test/shell/devicesfile-vpd-ids.sh b/test/shell/devicesfile-vpd-ids.sh index 2e2c2f3ee..74dbebb18 100644 --- a/test/shell/devicesfile-vpd-ids.sh +++ b/test/shell/devicesfile-vpd-ids.sh @@ -435,7 +435,69 @@ vgremove $vg rm "$SYS_DIR/dev/block/$MAJOR1:$MINOR1/device/wwid" cleanup_sysfs +# +# Simply rename a device using IDNAME=devname +# use a new device name where a device exists +# on the system with that name so that there +# will be an initial, incorrect match of the +# devices file entry with IDNAME=/dev/sdb to +# the /dev/sdb that exists on the system. +# +# FIXME: this assumes that /dev/sdb exists on the system +# and is not the same as DEV1. To do this correctly +# we need to find the name of some device on the +# system other than DEV1. +# +rm "$DF" +aux wipefs_a "$DEV1" +touch "$DF" +pvcreate "$DEV1" +vgcreate $vg1 "$DEV1" +cat "$DF" +grep "IDTYPE=devname" "$DF" | tee out +grep "IDNAME=$DEV1" out +mkdir -p "$SYS_DIR/dev/block/$MAJOR1:$MINOR1/device" +pvs -o+uuid,deviceidtype,deviceid "$DEV1" +# Rename device, simulating reboot +sed -e "s|IDNAME=$DEV1|IDNAME=/dev/sdb|" "$DF" > tmpdf +sed -e "s|DEVNAME=$DEV1|DEVNAME=/dev/sdb|" tmpdf > "$DF" +cat "$DF" +# pvs will find PV on DEV1 and fix IDNAME +pvs -o+uuid,deviceidtype,deviceid | tee out +grep "$DEV1" out +grep "IDTYPE=devname" "$DF" | tee out +grep "IDNAME=$DEV1" out +cleanup_sysfs + +# +# Simply rename a device using IDNAME=devname +# use a new device name where a device does not +# exist on the system with that name +# +# This assumes that /dev/sdxx does not exist on the system. +# + +rm "$DF" +aux wipefs_a "$DEV1" +touch "$DF" +pvcreate "$DEV1" +vgcreate $vg1 "$DEV1" +cat "$DF" +grep "IDTYPE=devname" "$DF" | tee out +grep "IDNAME=$DEV1" out +mkdir -p "$SYS_DIR/dev/block/$MAJOR1:$MINOR1/device" +pvs -o+uuid,deviceidtype,deviceid "$DEV1" +# Rename device, simulating reboot +sed -e "s|IDNAME=$DEV1|IDNAME=/dev/sdxx|" "$DF" > tmpdf +sed -e "s|DEVNAME=$DEV1|DEVNAME=/dev/sdxx|" tmpdf > "$DF" +cat "$DF" +# pvs will find PV on DEV1 and fix IDNAME +pvs -o+uuid,deviceidtype,deviceid | tee out +grep "$DEV1" out +grep "IDTYPE=devname" "$DF" | tee out +grep "IDNAME=$DEV1" out +cleanup_sysfs # TODO: lvmdevices --adddev --deviceidtype --deviceid