From c82a453c67efd394cd6871a5e438d13362a630c0 Mon Sep 17 00:00:00 2001 From: Minfei Huang Date: Fri, 17 Apr 2015 16:26:26 +0800 Subject: [PATCH] Get the mount point correctly, if the device has several mount point Any block device can be mounted multiply on the different mount point. Once a mount point is mounted in bind mode, the general mount point can be unmounted. Thus kdump would not find the general mount point[1] to handle the path. The mount point, which is as general mount point, will be got by "fintmnt" previously. But the mntpoint may be incorrect, if the mntpoint is bind mount. In order to fix it to support bind mounted in atomic, we will add a judgement to comfirm the mntpoint is bind mounted, or not. For general mount, returning path is like following, if we use "findmnt". The returning is same as "findmnt -v". -bash-4.2# findmnt /var | tail -n 1 | awk '{print $2}' /dev/mapper/atomicos-root But for bind mount, returning path is like following, if we use "fintmnt". -bash-4.2# findmnt /var | tail -n 1 | awk '{print $2}' /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var] Use "findmnt -v" is like this: -bash-4.2# findmnt -v /var | tail -n 1 | awk '{print $2}' /dev/mapper/atomicos-root So we can determine the bind mount, if the returning is different between "findmnt" and "findmnt -v". [1] general mount point is a directory without being in bind mounted mode, just a normal directory. Signed-off-by: Minfei Huang Acked-by: Dave Young Acked-by: Baoquan He --- kdump-lib.sh | 26 +++++++++++++++++++++++++- mkdumprd | 8 ++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 8b0516f..5333fe4 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -133,9 +133,33 @@ get_fs_type_from_target() echo $(findmnt -k -f -n -r -o FSTYPE $1) } +# input: device path +# output: the general mount point +# find the general mount point, not the bind mounted point in atomic +# As general system, Use the previous code +# +# ERROR and EXIT: +# the device can be umounted the general mount point, if one of the mount point is bind mounted +# For example: +# mount /dev/sda /mnt/ +# mount -o bind /mnt/var /var +# umount /mnt get_mntpoint_from_target() { - echo $(findmnt -k -f -n -r -o TARGET $1) + if is_atomic; then + for _mnt in $(findmnt -k -n -r -o TARGET $1) + do + if ! is_bind_mount $_mnt; then + echo $_mnt + return + fi + done + + echo "Mount $1 firstly, without the bind mode" >&2 + exit 1 + else + echo $(findmnt -k -f -n -r -o TARGET $1) + fi } # get_option_value diff --git a/mkdumprd b/mkdumprd index 7c572a7..14ec70f 100644 --- a/mkdumprd +++ b/mkdumprd @@ -103,7 +103,7 @@ to_mount() { local _dev=$1 _source _target _fstype _options _mntopts _pdev _source=$(findmnt -k -f -n -r -o SOURCE $_dev) - _target=$(findmnt -k -f -n -r -o TARGET $_dev) + _target=$(get_mntpoint_from_target $_dev) # mount under /sysroot if dump to root disk or mount under #/kdumproot/$_target in other cases in 2nd kernel. systemd #will be in charge to umount it. @@ -147,10 +147,6 @@ to_mount() { echo "$_pdev $_mntopts" } -to_mount_point() { - echo $(findmnt -k -f -n -r -o TARGET $1) -} - is_readonly_mount() { local _mnt _mnt=$(findmnt -k -f -n -r -o OPTIONS $1) @@ -204,7 +200,7 @@ mkdir_save_path_ssh() #Function: get_fs_size #$1=dump target get_fs_size() { - local _mnt=$(to_mount_point $1) + local _mnt=$(get_mntpoint_from_target $1) echo -n $(df -P "${_mnt}/$SAVE_PATH"|tail -1|awk '{print $4}') }