On 2016/05/06 at 15:58, Pratyush Anand wrote:
Hi Xunlei,
On 06/05/2016:02:50:44 PM, 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.
I think we should return 2 with proper echo message in that case so that
starting kdump is failed. Probably, we should throw message something like:
Dump path $path does not exit
Starting kdump: [FAILED]
check_save_path_fs() in mkdumprd afterwards can catch it, so I guess we can simply return
1.
But what you said is fine as well.
>> + 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.
Not sure if that would reduce the complexity. We will have to write mapping from
uuid to target, id to taget..etc..
IMHO, complexity will be just shifted to another function.
What about the one in my following reply, calls get_persistent_dev() to do a conversion on
$_target?
Regards,
Xunlei
~Pratyush
> 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
>> }
>>