From 7aeeb1d17eb1f1cea837974ca3362db32ce9d6f2 Mon Sep 17 00:00:00 2001 From: Pratyush Anand Date: Mon, 9 May 2016 13:47:55 +0530 Subject: [PATCH] kdumpctl: force rebuild in case of file system is modified kdumpctl passes --device argument if dump target is a raw device. It passes --mount argument if dump target is either mounted as nfs or as a bulk device. When dump target device is a root device then it does not pass any of the above two arguments. After kdumpctl restart, if there is any change in file system which needs different dracut arguments, then initramfs must be rebuild. Modification in filesystem for a raw target does not affect dracut arguments. So, we do not consider to check any modification if raw target was specified in kdump.conf. We might need to change dracut arguments if there is some changes in nfs and ssh target related files. However, we do not consider them in this patch. We mainly consider changes in bulk target specified in kdump.conf. We also consider changes in bulk and nfs file system, if there was no dump target specified in kdump.conf but dump path is mounting such file systems. So the initramfs must be rebuild if, either dump target's persistent path or it's mount point or its file system type changes. If there is no dump target specified then, both dump path and root path must mount same device, otherwise rebuild should be triggered. Some of the examples when we can need a rebuild: -- "dump target" is specified as one of ext[234], xfs or btrfs. But after kdump initramfs building its UUID is changed by reformatting. -- "dump target" is specified as file system type fs1 (say ext3). But after kdump initramfs building, user change it to fs2 (say ext4), probably by a mkfs.ext4 executing on the target device. -- "dump target" is not specified, but "dump path" mounts a device which is different than device for root path and either UUID or file system type is modified after kdump initramfs build. -- "dump target" is not specified, but "dump path" mounts a nfs device and nfs host path changes after kdump initramfs build. Some testing: Initial conditions: -- No dump target specified -- dump path (/var/crash) and root(/) are on same device -- kdumpctl was already executed once after last modification in /etc/kdump.conf # kdumpctl restart No rebuild # mkfs.ext2 /dev/md0;mount /dev/md0 /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # kdumpctl restart No rebuild # umount /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # kdumpctl restart No rebuild # mount /dev/md0 /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # umount /var/crash;mkfs.ext4 /dev/md0; # mount /dev/md0 /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # umount /var/crash;mkfs.ext4 /dev/mapper/fedora-swap # mount /dev/mapper/fedora-swap /var/crash/ # kdumpctl restart Rebuilt because "Detected change in File System" # umount /var/crash;mkfs.btrfs /dev/mapper/fedora-swap -f # mount /dev/mapper/fedora-swap /var/crash/ # kdumpctl restart Rebuilt because "Detected change in File System" # kdumpctl restart No rebuild # umount /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # mount /dev/mapper/fedora-swap /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # umount /var/crash;mkfs.minix /dev/md0 # mount /dev/md0 /var/crash/; kdumpctl restart Rebuilt because "Detected change in File System" # kdumpctl restart No rebuild # umount /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # mount 192.168.1.16:/nfsroot /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # umount /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # mount 192.168.1.16:/nfsroot /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" # kdumpctl restart No rebuild # umount /var/crash;mount 192.168.1.12:/nfsroot /var/crash/ # kdumpctl restart Rebuilt because "Detected change in File System" # umount /var/crash/;kdumpctl restart Rebuilt because "Detected change in File System" Added "raw /dev/md0" in /etc/kdump.conf # kdumpctl restart Rebuilt because "Detected change in /etc/kdump.conf" # mkfs.ext4 /dev/md0 ;kdumpctl restart No rebuild Added "ext4 /dev/md0" in /etc/kdump.conf # mkfs.ext4 /dev/md0;mount /dev/md0 /mnt # mkdir /mnt/var;mkdir /mnt/var/crash; kdumpctl restart Rebuilt because "Detected change in /etc/kdump.conf" # umount /mnt;mkfs.ext4 /dev/md0;mount /dev/md0 /mnt # mkdir /mnt/var;mkdir /mnt/var/crash; kdumpctl restart Rebuilt because "Detected change in /etc/kdump.conf" Most of the credits for this patch goes to Xunlei Pang for suggesting several improvements. Signed-off-by: Pratyush Anand Acked-by: Xunlei Pang Acked-by: Baoquan He Acked-by: Dave Young --- kdumpctl | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/kdumpctl b/kdumpctl index 2ce7651..34b64f3 100755 --- a/kdumpctl +++ b/kdumpctl @@ -359,6 +359,74 @@ check_files_modified() return 0 } +check_dump_fs_modified() +{ + local _old_dev _old_mntpoint _old_fstype + local _new_dev _new_mntpoint _new_fstype + local _target _path _dracut_args + + # No need to check in case of raw target. + # Currently we do not check also if ssh/nfs target is specified + if is_ssh_dump_target || is_nfs_dump_target || is_raw_dump_target; then + return 0 + fi + + _target=$(get_user_configured_dump_disk) + + if [[ -n "$_target" ]]; then + _target=$(to_dev_name $_target) + _new_fstype=$(blkid $_target | awk -F"TYPE=" '{print $2}' | cut -d '"' -f 2) + else + _path=$(get_save_path) + set -- $(df -T $_path 2>/dev/null | tail -1 | awk '{ print $1, $2}') + _target=$(to_dev_name $1) + _new_fstype=$2 + if [[ -z "$_target" || -z "$_new_fstype" ]];then + echo "Dump path $_path does not exist" + return 2 + fi + fi + + if [[ $(expr substr $_new_fstype 1 3) = "nfs" ]];then + _new_dev=$_target + else + _new_dev=$(get_persistent_dev $_target $_new_fstype) + if ! findmnt $_target >/dev/null; then + echo "Dump target $_target is probably not mounted." + return 2 + fi + fi + + if ! findmnt $_target >/dev/null; then + echo "Dump target $_target is probably not mounted." + return 2 + fi + _new_mntpoint="/kdumproot/$(get_mntpoint_from_target $_target)" + + _dracut_args=$(lsinitrd $TARGET_INITRD | grep "^Arguments:" | head -1) + if [[ -z "$_dracut_args" ]];then + echo "Warning: No dracut arguments found in initrd" + return 0 + fi + + # if --mount argument present then match old and new target, mount + # point and file system. If any of them mismatches then rebuild + echo $_dracut_args | grep "\-\-mount" &> /dev/null + if [[ $? -eq 0 ]];then + set -- $(echo $_dracut_args | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) + _old_dev=$1 + _old_mntpoint=$2 + _old_fstype=$3 + [[ $_new_dev = $_old_dev && $_new_mntpoint = $_old_mntpoint && $_new_fstype = $_old_fstype ]] && return 0 + # otherwise rebuild if target device is not a root device + else + [[ "$_target" = "$(get_root_fs_device)" ]] && return 0 + fi + + echo "Detected change in File System" + return 1 +} + # returns 0 if system is not modified # returns 1 if system is modified # returns 2 if system modification is invalid @@ -374,6 +442,12 @@ check_system_modified() return $ret fi + check_dump_fs_modified + ret=$? + if [ $ret -ne 0 ]; then + return $ret + fi + return 0 }