Skip to contentSkip to conversation

ismounted fix

PATCH In review Dave Young 3 participants 3 messages Sep 17, 2012 – Sep 19, 2012 2 messages not in the archive

lore
Share & tools
lore

Dave Young

author
#0 lore raw

PATCH v2 1/2 ismounted fix

ismounted handles both find-by-dev and find-by-mnt, but there's two issues:
1. for find-by-dev, it use readlink to get the canonical dev name, but lvm is different with other devices, the canonical name for lvm devices are symlinks like /dev/mapper/vg-lv00
2. for nfs mounting, just use [ -b $dev ] is not enough, it need being handled seperately.

Per Karel Zak's suggestion, findmnt util is suitable for this purpose, it handles these cases well, so just use findmnt instead of implement all the logic by ourselves. Thanks, Karel.

---
 modules.d/99base/dracut-lib.sh   |   19 +------------------
 modules.d/99base/module-setup.sh |    2 +-
 2 files changed, 2 insertions(+), 19 deletions(-)
modules.d/99base/dracut-lib.sh +1 -18
@@ -452,27 +452,10 @@ udevproperty() {
     fi
 }
 
-find_mount() {
-    local dev mnt etc wanted_dev
-    wanted_dev="$(readlink -e -q $1)"
-    while read dev mnt etc; do
-        [ "$dev" = "$wanted_dev" ] && echo "$dev" && return 0
-    done < /proc/mounts
-    return 1
-}
-
 # usage: ismounted <mountpoint>
 # usage: ismounted /dev/<device>
 ismounted() {
-    if [ -b "$1" ]; then
-        find_mount "$1" > /dev/null && return 0
-        return 1
-    fi
-
-    while read a m a; do
-        [ "$m" = "$1" ] && return 0
-    done < /proc/mounts
-    return 1
+    findmnt "$1" > /dev/null
 }
 
 wait_for_if_up() {
modules.d/99base/module-setup.sh +1 -1
@@ -13,7 +13,7 @@ depends() {
 
 install() {
     local _d
-    dracut_install mount mknod mkdir pidof sleep chroot \
+    dracut_install mount mknod mkdir pidof sleep chroot findmnt\
         sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid
     inst $(command -v modprobe) /sbin/modprobe
 

A message that is not in the archive (sent off-list or not yet received): 20120917100103.GA18640-4/[email protected]

#2 lore raw
Quoted 11 lines · Dave Young

ismounted handles both find-by-dev and find-by-mnt, but there's two issues:
1. for find-by-dev, it use readlink to get the canonical dev name, but lvm is different with other devices, the canonical name for lvm devices are symlinks like /dev/mapper/vg-lv00
2. for nfs mounting, just use [ -b $dev ] is not enough, it need being handled seperately.

Per Karel Zak's suggestion, findmnt util is suitable for this purpose, it handles these cases well, so just use findmnt instead of implement all the logic by ourselves. Thanks, Karel.

This patch looks reasonable to me. Harald, are you fine with it?

Vivek

Quoted 49 lines
---
 modules.d/99base/dracut-lib.sh   |   19 +------------------
 modules.d/99base/module-setup.sh |    2 +-
 2 files changed, 2 insertions(+), 19 deletions(-)
modules.d/99base/dracut-lib.sh +1 -18
@@ -452,27 +452,10 @@ udevproperty() {
     fi
 }
 
-find_mount() {
-    local dev mnt etc wanted_dev
-    wanted_dev="$(readlink -e -q $1)"
-    while read dev mnt etc; do
-        [ "$dev" = "$wanted_dev" ] && echo "$dev" && return 0
-    done < /proc/mounts
-    return 1
-}
-
 # usage: ismounted <mountpoint>
 # usage: ismounted /dev/<device>
 ismounted() {
-    if [ -b "$1" ]; then
-        find_mount "$1" > /dev/null && return 0
-        return 1
-    fi
-
-    while read a m a; do
-        [ "$m" = "$1" ] && return 0
-    done < /proc/mounts
-    return 1
+    findmnt "$1" > /dev/null
 }
 
 wait_for_if_up() {
modules.d/99base/module-setup.sh +1 -1
@@ -13,7 +13,7 @@ depends() {
 
 install() {
     local _d
-    dracut_install mount mknod mkdir pidof sleep chroot \
+    dracut_install mount mknod mkdir pidof sleep chroot findmnt\
         sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid
     inst $(command -v modprobe) /sbin/modprobe
 

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Am 19.09.2012 15:59, schrieb Vivek Goyal:

Quoted 9 lines · Dave Young
Quoted 8 lines

ismounted handles both find-by-dev and find-by-mnt, but there's two issues:
1. for find-by-dev, it use readlink to get the canonical dev name, but lvm is different with other devices, the canonical name for lvm devices are symlinks like /dev/mapper/vg-lv00
2. for nfs mounting, just use [ -b $dev ] is not enough, it need being handled seperately.

Quoted 7 lines
Quoted 3 lines

Per Karel Zak's suggestion, findmnt util is suitable for this purpose, it handles these cases well, so just use findmnt instead of implement all the logic by ourselves. Thanks, Karel.

This patch looks reasonable to me. Harald, are you fine with it?

Vivek

Yes. Looks good!