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

fsadm: if available, use /proc/self/mountinfo to detect mounted volume

The /proc/self/mountinfo is not bound to device names like /proc/mounts
and it uses major:minor pairs instead.

This fixes a situation in which a volume is mounted and then renamed
later on - that makes /proc/mounts unreliable when detecting mounted
volumes.

See also https://bugzilla.redhat.com/show_bug.cgi?id=1196910.
This commit is contained in:
Peter Rajnoha 2016-03-18 13:42:06 +01:00
parent 464ebe04db
commit 2879eff86e
2 changed files with 26 additions and 4 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.147 - Version 2.02.147 -
================================== ==================================
If available, use /proc/self/mountinfo to detect mounted volume in fsadm.
Fix resize of stacked raid thin data volume (2.02.141). Fix resize of stacked raid thin data volume (2.02.141).
Fix test for lvremove failure in lvconvert --uncache (2.02.146). Fix test for lvremove failure in lvconvert --uncache (2.02.146).

View File

@ -76,6 +76,7 @@ MOUNTPOINT=
MOUNTED= MOUNTED=
REMOUNT= REMOUNT=
PROCMOUNTS="/proc/mounts" PROCMOUNTS="/proc/mounts"
PROCSELFMOUNTINFO="/proc/self/mountinfo"
NULL="$DM_DEV_DIR/null" NULL="$DM_DEV_DIR/null"
IFS_OLD=$IFS IFS_OLD=$IFS
@ -188,6 +189,7 @@ detect_fs() {
# hardcoded /dev since udev does not create these entries elsewhere # hardcoded /dev since udev does not create these entries elsewhere
/dev/dm-[0-9]*) /dev/dm-[0-9]*)
read </sys/block/${RVOLUME#/dev/}/dm/name SYSVOLUME 2>&1 && VOLUME="$DM_DEV_DIR/mapper/$SYSVOLUME" read </sys/block/${RVOLUME#/dev/}/dm/name SYSVOLUME 2>&1 && VOLUME="$DM_DEV_DIR/mapper/$SYSVOLUME"
read </sys/block/${RVOLUME#/dev/}/dev MAJORMINOR 2>&1 || error "Cannot get major:minor for \"$VOLUME\""
;; ;;
esac esac
# use null device as cache file to be sure about the result # use null device as cache file to be sure about the result
@ -198,11 +200,18 @@ detect_fs() {
verbose "\"$FSTYPE\" filesystem found on \"$VOLUME\"" verbose "\"$FSTYPE\" filesystem found on \"$VOLUME\""
} }
# check if the given device is already mounted and where detect_mounted_with_proc_self_mountinfo() {
# FIXME: resolve swap usage and device stacking MOUNTED=$("$GREP" "^[0-9]* [0-9]* $MAJORMINOR " "$PROCSELFMOUNTINFO")
detect_mounted() {
test -e "$PROCMOUNTS" || error "Cannot detect mounted device \"$VOLUME\""
# extract 5th field which is mount point
# echo -e translates \040 to spaces
MOUNTED=$(echo ${MOUNTED} | cut -d " " -f 5)
MOUNTED=$(echo -n -e ${MOUNTED})
test -n "$MOUNTED"
}
detect_mounted_with_proc_mounts() {
MOUNTED=$("$GREP" "^$VOLUME[ \t]" "$PROCMOUNTS") MOUNTED=$("$GREP" "^$VOLUME[ \t]" "$PROCMOUNTS")
# for empty string try again with real volume name # for empty string try again with real volume name
@ -224,6 +233,18 @@ detect_mounted() {
test -n "$MOUNTED" test -n "$MOUNTED"
} }
# check if the given device is already mounted and where
# FIXME: resolve swap usage and device stacking
detect_mounted() {
if test -e "$PROCSELFMOUNTINFO"; then
detect_mounted_with_proc_self_mountinfo
elif test -e "$PROCMOUNTS"; then
detect_mounted_with_proc_mounts
else
error "Cannot detect mounted device \"$VOLUME\""
fi
}
# get the full size of device in bytes # get the full size of device in bytes
detect_device_size() { detect_device_size() {
# check if blockdev supports getsize64 # check if blockdev supports getsize64