Skip to content

Commit

Permalink
vdev_id: Fix partition regular expression
Browse files Browse the repository at this point in the history
Given a DM device name, the old vdev_id script would extract any text
after a 'p' as the partition number.  It then appends "-part" + the
partition number to the name, giving a by-vdev name like "L0-part5".

This works fine if the DM name is like 'dm-2p5', but doesn't work if
the DM name is a multipath name like "mpatha".  In those cases it
incorrectly matches the 'p' in "mpatha", giving by-vdev names like
"L0-partatha".

This patch fixes the issue by making the partition regex match stricter.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes openzfs#11637
  • Loading branch information
tonyhutter authored and jsai20 committed Mar 30, 2021
1 parent 85ec12a commit f860f7c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/vdev_id/vdev_id
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ sas_handler() {
# we have to append the -part suffix directly in the
# helper.
if [ "$DEVTYPE" != "partition" ] ; then
PART=$(echo "$DM_NAME" | awk -Fp '/p/{print "-part"$2}')
# Match p[number], remove the 'p' and prepend "-part"
PART=$(echo "$DM_NAME" |
awk 'match($0,/p[0-9]+$/) {print "-part"substr($0,RSTART+1,RLENGTH-1)}')
fi

# Strip off partition information.
Expand Down Expand Up @@ -499,7 +501,9 @@ scsi_handler() {
# we have to append the -part suffix directly in the
# helper.
if [ "$DEVTYPE" != "partition" ] ; then
PART=$(echo "$DM_NAME" | awk -Fp '/p/{print "-part"$2}')
# Match p[number], remove the 'p' and prepend "-part"
PART=$(echo "$DM_NAME" |
awk 'match($0,/p[0-9]+$/) {print "-part"substr($0,RSTART+1,RLENGTH-1)}')
fi

# Strip off partition information.
Expand Down Expand Up @@ -648,7 +652,9 @@ alias_handler () {
DM_PART=
if echo "$DM_NAME" | grep -q -E 'p[0-9][0-9]*$' ; then
if [ "$DEVTYPE" != "partition" ] ; then
DM_PART=$(echo "$DM_NAME" | awk -Fp '/p/{print "-part"$2}')
# Match p[number], remove the 'p' and prepend "-part"
DM_PART=$(echo "$DM_NAME" |
awk 'match($0,/p[0-9]+$/) {print "-part"substr($0,RSTART+1,RLENGTH-1)}')
fi
fi

Expand Down

0 comments on commit f860f7c

Please sign in to comment.