1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-25 21:57:45 +03:00

device_id: fix handling of non-PV with duplicate serial number

Fix in the code that matches devices to system.devices entries when
the devices have the same serial number.  A non-PV device in
system.devices has no pvid value, and the code was segfaulting
when checking the null pvid value.
This commit is contained in:
David Teigland 2023-06-08 12:24:05 -05:00
parent 8e53b3bc14
commit 74feebdab7
2 changed files with 40 additions and 0 deletions

View File

@ -2625,6 +2625,8 @@ void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs,
* Match du to a dev based on PVID.
*/
dm_list_iterate_items(dul, &dus_check) {
if (!dul->du->pvid)
continue;
log_debug("Matching suspect serial device id %s PVID %s prev %s",
dul->du->idname, dul->du->pvid, dul->du->devname);
found = 0;

View File

@ -853,6 +853,44 @@ grep $PVID4 out4
vgcreate $vg2 $dev2 $dev3
vgs | grep $vg2
# 3 devs with duplicate serial, 2 pvs with stale devnames, 1 non-pv device
aux wipefs_a $dev1
aux wipefs_a $dev2
aux wipefs_a $dev3
echo $SERIAL1 > $SYS_DIR/dev/block/$MAJOR1:$MINOR1/device/serial
echo $SERIAL1 > $SYS_DIR/dev/block/$MAJOR2:$MINOR2/device/serial
echo $SERIAL1 > $SYS_DIR/dev/block/$MAJOR3:$MINOR3/device/serial
rm $DF
touch $DF
vgcreate $vg1 $dev1 $dev2
lvmdevices --adddev $dev3
cat $DF
cp $DF $ORIG
PVID1=`pvs "$dev1" --noheading -o uuid | tr -d - | awk '{print $1}'`
PVID2=`pvs "$dev2" --noheading -o uuid | tr -d - | awk '{print $1}'`
OPVID1=`pvs "$dev1" --noheading -o uuid | awk '{print $1}'`
OPVID2=`pvs "$dev2" --noheading -o uuid | awk '{print $1}'`
pvs -o+uuid,deviceid
sed -e "s|DEVNAME=$dev1|DEVNAME=tmp|" $ORIG > tmp1
sed -e "s|DEVNAME=$dev2|DEVNAME=$dev1|" tmp1 > tmp2
sed -e "s|DEVNAME=tmp|DEVNAME=$dev2|" tmp2 > $DF
cat $DF
# pvs should report the correct info and fix the DF
pvs -o+uuid,deviceid |tee out
grep $dev1 out |tee out1
grep $dev2 out |tee out2
grep $OPVID1 out1
grep $OPVID2 out2
grep $SERIAL1 out1
grep $SERIAL1 out2
remove_base
rmmod brd