Skip to content

Commit 0886434

Browse files
authored
Merge pull request #113 from eric-ch/s9-oxt-1654
S9: OXT-1654: Handle NVMe symlinks in /dev.
2 parents 6c56607 + fb009ec commit 0886434

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

common/stages/Functions/library

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,27 @@ reread_partition_table()
396396
udevadm settle >&2
397397
}
398398

399+
#-----------------------------------------------------------
400+
# Usage: sanitize_devnode /dev/device
401+
# Should /dev/device be a symlink alias, follow the link and print the block
402+
# device path on stdout.
403+
sanitize_devnode() {
404+
local dev="$1"
405+
406+
if [ -h "${dev}" ]; then
407+
# NVMe may have entries in /dev that are symblink aliases to their
408+
# block device (e.g, /dev/512GB_68PS115OT8JQ-part1 -> nvme0n1p1)
409+
readlink -f "${dev}"
410+
else
411+
echo "${dev}"
412+
fi
413+
}
414+
399415
#-----------------------------------------------------------
400416
# Usage: get_devnode_disk /dev/(sd[a-z]\+[0-9]\+|/dev/nvme[0-9]\+n[0-9]\+p[0-9]\+)
401417
# Prints the disk component of the argument devnode on stdout.
402418
get_devnode_disk() {
403-
local devnode="$1"
419+
local devnode=$(sanitize_devnode "$1")
404420
local disk
405421

406422
case "${devnode}" in
@@ -414,7 +430,7 @@ get_devnode_disk() {
414430
# Usage: get_devnode_partition /dev/(sd[a-z]\+[0-9]\+|/dev/nvme[0-9]\+n[0-9]\+p[0-9]\+)
415431
# Prints the partition component of the argument devnode on stdout.
416432
get_devnode_partition() {
417-
local devnode="$1"
433+
local devnode=$(sanitize_devnode "$1")
418434
local part
419435

420436
case "${devnode}" in

part2/stages/Remove-partitions

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,13 @@
2424

2525
# Remove every VG assigned to that disk.
2626
vgs=$(vgs --noheading -o vg_name)
27-
if [ -L ${TARGET_DISK} ]; then
28-
dev="/dev/$(readlink ${TARGET_DISK})"
29-
else
30-
dev="${TARGET_DISK}"
31-
fi
3227
for vg in ${vgs}; do
3328
# List all PV backing current VG.
3429
pvs="$(vgs --noheading -o pv_name ${vg})"
3530
pvs_on_target=""
3631
pvs_others=""
3732
for p in ${pvs}; do
38-
if [ -L "${p}" ]; then
39-
# NVMe will sometimes appear as symlinks to the actual device in
40-
# the devfs (e.g: /dev/512GB_ -> nvme0n1p1).
41-
dev="/dev/$(readlink ${p})"
42-
else
43-
dev="${p##/dev}"
44-
fi
33+
dev=$(sanitize_devnode "${p}")
4534
if [ "${dev##${TARGET_DISK}}" != "${dev}" ]; then
4635
pvs_on_target="${pvs_of_vg} ${dev}"
4736
else

0 commit comments

Comments
 (0)