1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-04 09:18:36 +03:00

vdo: better message for missing device

Show readable message when passed device cannot be accessed.
And use STAT shell var wrapper to call 'stat' command.
This commit is contained in:
Zdenek Kabelac 2021-09-01 15:46:04 +02:00
parent 8d5b7de54f
commit 3287d37f44

View File

@ -19,7 +19,7 @@
# Needed utilities: # Needed utilities:
# lvm, dmsetup, # lvm, dmsetup,
# vdo, # vdo,
# grep, awk, sed, blockdev, readlink, mkdir # grep, awk, sed, blockdev, readlink, stat, mkdir
# #
# Conversion is using 'vdo convert' support from VDO manager to move # Conversion is using 'vdo convert' support from VDO manager to move
# existing VDO header by 2M which makes space to place in PV header # existing VDO header by 2M which makes space to place in PV header
@ -40,6 +40,7 @@ VDOCONF=${VDOCONF:-}
BLOCKDEV="blockdev" BLOCKDEV="blockdev"
READLINK="readlink" READLINK="readlink"
READLINK_E="-e" READLINK_E="-e"
STAT="stat"
MKDIR="mkdir" MKDIR="mkdir"
DMSETUP="dmsetup" DMSETUP="dmsetup"
@ -156,8 +157,8 @@ detect_lv_() {
local MAJORMINOR local MAJORMINOR
DEVICE=${1/#"${DM_DEV_DIR}/"/} DEVICE=${1/#"${DM_DEV_DIR}/"/}
DEVICE=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$DEVICE") DEVICE=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$DEVICE" || true)
test -n "$DEVICE" || error "Cannot get readlink \"$1\"." test -n "$DEVICE" || error "Readlink cannot access device \"$1\"."
RDEVICE=$DEVICE RDEVICE=$DEVICE
case "$RDEVICE" in case "$RDEVICE" in
# hardcoded /dev since udev does not create these entries elsewhere # hardcoded /dev since udev does not create these entries elsewhere
@ -168,9 +169,9 @@ detect_lv_() {
DEVMINOR=${MAJORMINOR##*:} DEVMINOR=${MAJORMINOR##*:}
;; ;;
*) *)
STAT=$(stat --format "DEVMAJOR=\$((0x%t)) DEVMINOR=\$((0x%T))" "$RDEVICE") RSTAT=$("$STAT" --format "DEVMAJOR=\$((0x%t)) DEVMINOR=\$((0x%T))" "$RDEVICE" || true)
test -n "$STAT" || error "Cannot get major:minor for \"$DEVICE\"." test -n "$RSTAT" || error "Cannot get major:minor for \"$DEVICE\"."
eval "$STAT" eval "$RSTAT"
;; ;;
esac esac
@ -269,8 +270,8 @@ convert2lvm_() {
for i in $(awk '/.*device:/ {print $2}' "$TEMPDIR/vdoconf.yml") ; do for i in $(awk '/.*device:/ {print $2}' "$TEMPDIR/vdoconf.yml") ; do
local DEV local DEV
DEV=$("$READLINK" $READLINK_E "$i") || continue DEV=$("$READLINK" $READLINK_E "$i") || continue
STAT=$(stat --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" "$DEV" 2>/dev/null) || continue RSTAT=$("$STAT" --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" "$DEV" 2>/dev/null) || continue
eval "$STAT" eval "$RSTAT"
test "$MAJOR" = "$DEVMAJOR" && test "$MINOR" = "$DEVMINOR" && { test "$MAJOR" = "$DEVMAJOR" && test "$MINOR" = "$DEVMINOR" && {
test -z "$FOUND" || error "VDO configuration contains duplicate entries $FOUND and $i" test -z "$FOUND" || error "VDO configuration contains duplicate entries $FOUND and $i"
FOUND=$i FOUND=$i