Fedora 33 now have btrfs by default, and kdump is failing.
Currently the get_bind_mount_source function won't work with btrfs, and in fails sone corner cases. This series fixes the issues.
Kairui Song (2): Make get_mount_info work with bind mount kdump-lib: Fix get_bind_mount_source to support btrfs and fstab
kdump-lib-initramfs.sh | 2 +- kdump-lib.sh | 46 +++++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 17 deletions(-)
Remove the --real when calling findmnt.
The option is only useful in capture kernel, to avoid `findmnt` returning the pseudo 'rootfs' for non mounted path.
example, when /kdumproot/mnt/ is not mounted: kdump:/# findmnt --target /kdumproot/mnt TARGET SOURCE FSTYPE OPTIONS / rootfs rootfs rw,size=61368k,nr_inodes=15342
kdump:/# findmnt --target /kdumproot/mnt <return 1 and empty output>
But this function will make findmnt also return empty value for bind mount. So remove it and add an extra if statement for second kernel. --- kdump-lib-initramfs.sh | 2 +- kdump-lib.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index d8d4893..9275c83 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -123,7 +123,7 @@ dump_fs() ddebug "_mp=$_mp _dev=$_dev _op=$_op"
# If dump path have a corresponding device entry but not mounted, mount it. - if [ -n "$_dev" ]; then + if [ -n "$_dev" ] && [ "$_dev" != "rootfs" ]; then if ! is_mounted "$_mp"; then dinfo "dump target $_dev is not mounted, trying to mount..." mkdir -p $_mp diff --git a/kdump-lib.sh b/kdump-lib.sh index 98ff27c..f04095a 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -256,9 +256,9 @@ is_mounted() get_mount_info() { local _info_type=$1 _src_type=$2 _src=$3; shift 3 - local _info=$(findmnt --real -k -n -r -o $_info_type --$_src_type $_src $@) + local _info=$(findmnt -k -n -r -o $_info_type --$_src_type $_src $@)
- [ -z "$_info" ] && [ -e "/etc/fstab" ] && _info=$(findmnt --real -s -n -r -o $_info_type --$_src_type $_src $@) + [ -z "$_info" ] && [ -e "/etc/fstab" ] && _info=$(findmnt -s -n -r -o $_info_type --$_src_type $_src $@)
echo $_info }
Currently get_bind_mount_source will not work on btrfs, that's because this function relies on findmnt to detect bind mount.
For a bind mount, findmnt will return different value with "-v" option.
For example, we have /dev/sdc mounted on /mnt/source, and then bind mount /mnt/source/sub/path to /mnt/bind:
$ findmnt /mnt/bind TARGET SOURCE FSTYPE OPTIONS /mnt/bind /dev/sdc[/sub/path] ext4 rw,relatime,seclabel
$ findmnt -v /mnt/bind TARGET SOURCE FSTYPE OPTIONS /mnt/bind /dev/sdc ext4 rw,relatime,seclabel
But findmnt also return similiar result for btrfs, on a fresh installed Fedora 33:
$ findmnt / TARGET SOURCE FSTYPE OPTIONS / /dev/sdb7[/root] btrfs rw,relatime,seclabel,ssd,space_cache,subvolid=256,subvol=/root
$ findmnt -v / TARGET SOURCE FSTYPE OPTIONS / /dev/sdb7 btrfs rw,relatime,seclabel,ssd,space_cache,subvolid=256,subvol=/root
The [...] indicator will contain the subvol of btrfs as well. And if it's bind mounted under btrfs, it will contain a mixup of btrfs subvol and the actuall fsroot.
And also, if the bind mount source device is not mounted on /, get_bind_mount_source will also not work.
So rewrite the get_bind_mount_source function, make it work in every cases.
Tested with: - Silverblue's bind mount - Bind mount with source device mounted not under / - Btrfs - Bind mount and source device is Btrfs
Signed-off-by: Kairui Song kasong@redhat.com --- kdump-lib.sh | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh index f04095a..0e38580 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -211,8 +211,8 @@ get_kdump_targets() # /mnt/bind -> /path/to/src, /mnt/bind/dump -> /path/to/src/dump # # 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. +# in the SOURCE column for bind-mounts, then if $_src equals to +# $_src_nofsroot, the mountpoint is not bind mounted directory. # # Below is just an example for mount info # /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the @@ -220,22 +220,36 @@ get_kdump_targets() # part is the bind mounted directory which quotes by bracket "[]". get_bind_mount_source() { - local _path=$1 - # In case it's a sub path in a mount point, get the mount point first - local _mnt_top=$(df $_path | tail -1 | awk '{print $NF}') - local _mntpoint=$(findmnt $_mnt_top | tail -n 1 | awk '{print $2}') - local _mntpoint_nofsroot=$(findmnt -v $_mnt_top | tail -n 1 | awk '{print $2}') + local _mnt=$(df $1 | tail -1 | awk '{print $NF}') + local _path=${1#$_mnt}
- if [[ "$_mntpoint" = $_mntpoint_nofsroot ]]; then - echo $_path && return + local _src=$(get_mount_info SOURCE target $_mnt -f) + local _opt=$(get_mount_info OPTIONS target $_mnt -f) + local _fstype=$(get_mount_info FSTYPE target $_mnt -f) + + # bind mount in fstab + if [[ -d "$_src" ]] && [[ "$_fstype" = none ]] && (echo "$_opt" | grep -q "\bbind\b"); then + echo $_src$_path && return + fi + + # direct mount + local _src_nofsroot=$(get_mount_info SOURCE target $_mnt -v -f) + if [[ $_src_nofsroot = $_src ]]; then + echo $_mnt$_path && return fi
- _mntpoint=${_mntpoint#*$_mntpoint_nofsroot} - _mntpoint=${_mntpoint#[} - _mntpoint=${_mntpoint%]} - _path=${_path#$_mnt_top} + local _fsroot=${_src#$_src_nofsroot[} + _fsroot=${_fsroot%]} + _mnt=$(get_mount_info TARGET source $_src_nofsroot -f)
- echo $_mntpoint$_path + # for btrfs, _fsroot will also contain the subvol value as well, strip it + if [[ "$_fstype" = btrfs ]]; then + local _subvol + _subvol=${_opt#*subvol=} + _subvol=${_subvol%,*} + _fsroot=${_fsroot#$_subvol} + fi + echo $_mnt$_fsroot$_path }
# Return the current underlaying device of a path, ignore bind mounts
On 11/25/2020 06:36 PM, Kairui Song wrote:
Fedora 33 now have btrfs by default, and kdump is failing.
Currently the get_bind_mount_source function won't work with btrfs, and in fails sone corner cases. This series fixes the issues.
Kairui Song (2): Make get_mount_info work with bind mount kdump-lib: Fix get_bind_mount_source to support btrfs and fstab
kdump-lib-initramfs.sh | 2 +- kdump-lib.sh | 46 +++++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 17 deletions(-)
For the series, Acked-by: Pingfan Liu piliu@redhat.com