summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2016-03-18 13:42:06 +0100
committerPeter Rajnoha <prajnoha@redhat.com>2016-03-18 13:42:06 +0100
commit2879eff86edb944874c7a1bf580b851286c4da46 (patch)
tree42fe05eba855560993bc2d27af7db36cf566f4d1
parent464ebe04db33ac105f5278dbbb244a9f84d582f8 (diff)
downloadlvm2-2879eff86edb944874c7a1bf580b851286c4da46.tar.gz
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.
-rw-r--r--WHATS_NEW1
-rwxr-xr-xscripts/fsadm.sh29
2 files changed, 26 insertions, 4 deletions
diff --git a/WHATS_NEW b/WHATS_NEW
index d49e935d0..96023c823 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
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 test for lvremove failure in lvconvert --uncache (2.02.146).
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index fc85988be..4dee15c2e 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -76,6 +76,7 @@ MOUNTPOINT=
MOUNTED=
REMOUNT=
PROCMOUNTS="/proc/mounts"
+PROCSELFMOUNTINFO="/proc/self/mountinfo"
NULL="$DM_DEV_DIR/null"
IFS_OLD=$IFS
@@ -188,6 +189,7 @@ detect_fs() {
# hardcoded /dev since udev does not create these entries elsewhere
/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/}/dev MAJORMINOR 2>&1 || error "Cannot get major:minor for \"$VOLUME\""
;;
esac
# use null device as cache file to be sure about the result
@@ -198,11 +200,18 @@ detect_fs() {
verbose "\"$FSTYPE\" filesystem found on \"$VOLUME\""
}
-# check if the given device is already mounted and where
-# FIXME: resolve swap usage and device stacking
-detect_mounted() {
- test -e "$PROCMOUNTS" || error "Cannot detect mounted device \"$VOLUME\""
+detect_mounted_with_proc_self_mountinfo() {
+ MOUNTED=$("$GREP" "^[0-9]* [0-9]* $MAJORMINOR " "$PROCSELFMOUNTINFO")
+
+ # 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")
# for empty string try again with real volume name
@@ -224,6 +233,18 @@ detect_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
detect_device_size() {
# check if blockdev supports getsize64