From ef94190ce50de1f58bf191f290c3586e8ba91eeb Mon Sep 17 00:00:00 2001 From: Minfei Huang Date: Fri, 17 Apr 2015 16:26:24 +0800 Subject: [PATCH] kdump-lib: Add the new function to enhance bind mounted judgement findmnt uses the option "-v, --nofsroot" to exclude the [/dir] in the SOURCE column for bind-mounts, then if $_mntpoint equals to $_mntpoint_nofsroot, the mountpoint is not bind mounted directory. the value of $_mntpoint may be like /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the directory is bind mounted. The former part represents the device path, the rest part is the bind mounted directory which quotes by bracket "[]". Signed-off-by: Minfei Huang Acked-by: Dave Young Acked-by: Baoquan He --- kdump-lib.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index f24f08d..ca7563a 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -86,6 +86,38 @@ get_root_fs_device() return } +# findmnt uses the option "-v, --nofsroot" to exclusive the [/dir] +# in the SOURCE column for bind-mounts, then if $_mntpoint equals to +# $_mntpoint_nofsroot, the mountpoint is not bind mounted directory. +is_bind_mount() +{ + local _mntpoint=$(findmnt $1 | tail -n 1 | awk '{print $2}') + local _mntpoint_nofsroot=$(findmnt -v $1 | tail -n 1 | awk '{print $2}') + + if [[ $_mntpoint = $_mntpoint_nofsroot ]]; then + return 1 + else + return 0 + fi +} + +# Below is just an example for mount info +# /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the +# directory is bind mounted. The former part represents the device path, rest +# part is the bind mounted directory which quotes by bracket "[]". +get_bind_mount_directory() +{ + local _mntpoint=$(findmnt $1 | tail -n 1 | awk '{print $2}') + local _mntpoint_nofsroot=$(findmnt -v $1 | tail -n 1 | awk '{print $2}') + + _mntpoint=${_mntpoint#*$_mntpoint_nofsroot} + + _mntpoint=${_mntpoint#[} + _mntpoint=${_mntpoint%]} + + echo $_mntpoint +} + get_mntpoint_from_path() { echo $(df $1 | tail -1 | awk '{print $NF}')