On 2016/05/06 at 14:50, Xunlei Pang wrote:
On 2016/05/05 at 19:50, Pratyush Anand wrote:
> Initramfs must be rebuild if:
>
> -- "dump target" is specified as ext[234], xfs or btrfs and its UUID is
> changed by reformatting.
> -- "dump target" is specified as file system type fs1 (say ext3) but
actual
> file system for the target device is of type fs2(ext4), however dracut
> "--mount" argument has file system type fs1 (say ext3)
> -- "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
> changes for a bulk device.
> -- "dump target" is nots specified, but "dump path" mounts a nfs
device,
> but nfs host path changes
>
> When "dump target" is specified as "raw" or "nfs" then
it will rebuild only
> on the basis of kdump.conf modification time.
>
> 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 NFS host"
> # 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 NFS host"
> # kdumpctl restart
> No rebuild
> # umount /var/crash;mount 192.168.1.12:/nfsroot /var/crash/
> # kdumpctl restart
> Rebuilt because "Detected change in NFS host"
> # 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"
>
> Signed-off-by: Pratyush Anand <panand(a)redhat.com>
> ---
> kdumpctl | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 87 insertions(+)
>
> diff --git a/kdumpctl b/kdumpctl
> index 793774d79a61..c37c11ef9973 100755
> --- a/kdumpctl
> +++ b/kdumpctl
> @@ -359,6 +359,87 @@ is_files_modified()
> return 0
> }
>
> +is_dump_fs_modified()
> +{
> + local _dracut_args _mount _uuid _fstype _target _id _dev _tdev
> +
> + # No need to check if ssh/nfs/raw 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)
> + _fstype=$(blkid $_target | awk -F"TYPE=" '{print $2}' | cut -d
'"' -f 2)
> + else
> + set -- $(df -T $(get_save_path) 2>/dev/null | tail -1 | awk '{ print $1,
$2}')
> + _target=$(to_dev_name $1)
> + _fstype=$2
I think we better have a non-empty check here for _target and _fstype:
supposing the PATH is not existent(for example, got deleted), we can
probaly let it rebuild and capture such error.
> + fi
> +
> + _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 is not present and, dump path and root path
> + # mounts same device then no need to check for FS modification
> + echo $_dracut_args | grep "\-\-mount" &> /dev/null
> + _mount=$?
> + [[ _mount -ne 0 ]] && [[ "$_target" =
"$(get_root_fs_device)" ]] && return 0
> +
> + # for NFS FS check if dump path still mounts same host
> + if [[ $(expr substr $_fstype 1 3) = "nfs" ]];then
> + echo $_dracut_args | grep $_target &> /dev/null
> + [[ $? -eq 0 ]] && return 0
> + echo "Detected change in NFS host"
> + return 1
> + fi
> +
> + # if dracut argument has "by-uuid", and dracut argument also contains
same uuid
> + # and fs type as that of _target then also do not rebuild
> + echo $_dracut_args | grep "by-uuid" &> /dev/null
> + if [[ $? -eq 0 ]];then
> + _uuid=$(blkid $_target | awk -F"UUID=" '{print $2}' | cut -d
'"' -f 2)
> + if [[ -n "$_uuid" ]]; then
> + echo $_dracut_args | grep $_uuid | grep $_fstype &> /dev/null
> + [[ $? -eq 0 ]] && return 0
> + fi
> + echo "Detected change in File System"
> + return 1
> + fi
> + # if dracut argument has "mapper", and dracut argument also contains same
name
> + # and fs type as that of _target then also do not rebuild
> + echo $_dracut_args | grep "mapper" &> /dev/null
> + if [[ $? -eq 0 ]];then
> + echo $_dracut_args | grep $_target | grep $_fstype &> /dev/null
I wonder whether such greps would be accurate, for example, I specify a PATH name
contains "_fstype" or "mapper" string, or the argument has a word
contains it,
actually we can easily introduce a helper to parse "--mount" argument, then
get
exactly what we want.
Besides, I was thinking if we can simply the code a little, for example:
_target_new=$(get_persistent_dev $_target)
_fstype_new=_fstype
Then with the "--mount" parsing helper, we get _target_old, _fstype_old,
we can simply do a comparing:
if [[ $_fstype_new = $_fstype_old && $_target_new = $_target_old ]]; then
return 0
fi
echo "Detected change in File System"
return 1;
Then we don't need to handle "by-uuid" or "by-id" or
"mapper" separately.
What do you think?
Regards,
Xunlei
Regards,
Xunlei
> + [[ $? -eq 0 ]] && return 0
> + echo "Detected change in File System"
> + return 1
> + fi
> + # if dracut argument has "by-id", and dracut argument also contains same
id
> + # and fs type as that of _target then also do not rebuild
> + echo $_dracut_args | grep "by-id" &> /dev/null
> + if [[ $? -eq 0 ]];then
> + _tdev=$(udevadm info --query=name --name="$_target" 2>/dev/null)
> + for _id in /dev/disk/by-id/*; do
> + _dev=$(udevadm info --query=name --name="$_id" 2>/dev/null)
> + if [[ "$_tdev" = "$_dev" ]]; then
> + echo $_dracut_args | grep $_id | grep $_fstype &> /dev/null
> + [[ $? -eq 0 ]] && return 0
> + fi
> + done
> + echo "Detected change in File System"
> + return 1
> + 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 +455,12 @@ is_system_modified()
> return $ret
> fi
>
> + is_dump_fs_modified
> + ret=$?
> + if [ $ret -ne 0 ]; then
> + return $ret
> + fi
> +
> return 0
> }
>