Hi Xunlei,
On 05/05/2016:11:20:51 AM, Xunlei Pang wrote:
On 2016/04/29 at 14: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 | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 85 insertions(+)
>
> diff --git a/kdumpctl b/kdumpctl
> index 1cba00b9dc0f..c7abaafdda27 100755
> --- a/kdumpctl
> +++ b/kdumpctl
> @@ -359,6 +359,85 @@ is_files_modified()
> return 0
> }
>
> +is_dump_fs_modified()
> +{
> + local _dracut_args _mount _uuid _fstype _target _id _dev _tdev
> +
> + # No need to ckeck if raw target is specified
> + is_raw_dump_target && return 0
> +
> + _target=$(get_user_configured_dump_disk)
> +
> + if [[ -n "$_target" ]]; then
> + _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=$1
> + _fstype=$2
For NFS target, if it got umounted, then "kdumpctl restart" will hit this and
got
empty _target and _fstype, so I think we should have a judgement here, otherwise
it is problematic when executing following scripts.
But, when NFS target is unmounted then "dump path" will be pointing to a
directory (say /var/crash) into a local filesystem. So the _target and _fstype
would be of local FS.
See following:
[root@localhost panand]# mount 192.168.1.16:/nfsroot /var/crash/
[root@localhost panand]# kdumpctl restart
kexec: unloaded kdump kernel
Stopping kdump: [OK]
Detected change in NFS host
Rebuilding /boot/initramfs-4.5.0-302.fc24.x86_64+debugkdump.img
kexec: loaded kdump kernel
Starting kdump: [OK]
[root@localhost panand]# lsinitrd
/boot/initramfs-4.5.0-302.fc24.x86_64+debugkdump.img | grep "Arguments"
Arguments: --hostonly -o 'plymouth dash resume ifcfg' -a 'watchdog' --add
'nfs'
--mount '192.168.1.16:/nfsroot /kdumproot//var/crash nfs4
rw,relatime,vers=4.1,rsize=65536,wsize=65536,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.12,local_lock=none,addr=192.168.1.16,x-initrd.mount'
-f
[root@localhost panand]# umount /var/crash
[root@localhost panand]# kdumpctl restart
kexec: unloaded kdump kernel
Stopping kdump: [OK]
Detected change in File System
Rebuilding /boot/initramfs-4.5.0-302.fc24.x86_64+debugkdump.img
kexec: loaded kdump kernel
Starting kdump: [OK]
[root@localhost panand]# lsinitrd
/boot/initramfs-4.5.0-302.fc24.x86_64+debugkdump.img | grep "Arguments"
Arguments: --hostonly -o 'plymouth dash resume ifcfg' -a 'watchdog' -f
> + fi
> + _target=$(to_dev_name $_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 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
I guess things are more complicated than we thought before, for example,
what if the fs mounting option changes? NFS that users mounted beforehand,
or fs that users mounted directly onto the PATH. Is it worthy for us to handle
with not-so-small code complexity introduced?
Probably, I could not get this correctly. When you say "NFS that users mounted
beforehand,", do you mean that NFS mounting option specified through
/etc/kdump.conf? and when you say that "nfs that users mounted directly onto the
PATH", means when a NFS path is mounted to "dump path"?
I think, for such cases it will work. When we change anything into
/etc/kdump.conf then this function will not be called. is_files_modified() will
take care of that. If there was no modification in /etc.kdump.conf then only we
come here to check for modifications.
~Pratyush
> > + [[ $? -eq 0 ]] && return 0
> > + echo "Detected change in NFS host"
> > + return 1
> > + fi
> > +
> > + # if dracut argument has "by-uuid", and darcut 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 darcut 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
> > + [[ $? -eq 0 ]] && return 0
> > + echo "Detected change in File System"
> > + return 1
> > + fi
> > + # if dracut argument has "by-id", and darcut 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 $_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 +453,12 @@ is_system_modified()
> > return $ret
> > fi
> >
> > + is_dump_fs_modified
> > + ret=$?
> > + if [ $ret -ne 0 ]; then
> > + return $ret
> > + fi
> > +
> > return 0
> > }
> >