Skip to content

Commit

Permalink
Merge pull request #113 from eric-ch/s9-oxt-1654
Browse files Browse the repository at this point in the history
S9: OXT-1654: Handle NVMe symlinks in /dev.
  • Loading branch information
jean-edouard authored Jul 25, 2019
2 parents 6c56607 + fb009ec commit 0886434
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
20 changes: 18 additions & 2 deletions common/stages/Functions/library
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,27 @@ reread_partition_table()
udevadm settle >&2
}

#-----------------------------------------------------------
# Usage: sanitize_devnode /dev/device
# Should /dev/device be a symlink alias, follow the link and print the block
# device path on stdout.
sanitize_devnode() {
local dev="$1"

if [ -h "${dev}" ]; then
# NVMe may have entries in /dev that are symblink aliases to their
# block device (e.g, /dev/512GB_68PS115OT8JQ-part1 -> nvme0n1p1)
readlink -f "${dev}"
else
echo "${dev}"
fi
}

#-----------------------------------------------------------
# Usage: get_devnode_disk /dev/(sd[a-z]\+[0-9]\+|/dev/nvme[0-9]\+n[0-9]\+p[0-9]\+)
# Prints the disk component of the argument devnode on stdout.
get_devnode_disk() {
local devnode="$1"
local devnode=$(sanitize_devnode "$1")
local disk

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

case "${devnode}" in
Expand Down
13 changes: 1 addition & 12 deletions part2/stages/Remove-partitions
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,13 @@

# Remove every VG assigned to that disk.
vgs=$(vgs --noheading -o vg_name)
if [ -L ${TARGET_DISK} ]; then
dev="/dev/$(readlink ${TARGET_DISK})"
else
dev="${TARGET_DISK}"
fi
for vg in ${vgs}; do
# List all PV backing current VG.
pvs="$(vgs --noheading -o pv_name ${vg})"
pvs_on_target=""
pvs_others=""
for p in ${pvs}; do
if [ -L "${p}" ]; then
# NVMe will sometimes appear as symlinks to the actual device in
# the devfs (e.g: /dev/512GB_ -> nvme0n1p1).
dev="/dev/$(readlink ${p})"
else
dev="${p##/dev}"
fi
dev=$(sanitize_devnode "${p}")
if [ "${dev##${TARGET_DISK}}" != "${dev}" ]; then
pvs_on_target="${pvs_of_vg} ${dev}"
else
Expand Down

0 comments on commit 0886434

Please sign in to comment.