On 05/06/2014 02:53 AM, Vivek Goyal wrote:
On Tue, Apr 29, 2014 at 07:27:55PM +0530, Hari Bathini wrote:
> Take a backup of original initrd when fadump is used first time or
> when user has switched from kdump to fadump. This will allow us to
> fall back to original initrd when kdump service fails to rebuild
> the fadump ready default initrd. Also, if the user switches from
> fadump to kdump, then the original initrd will be restored when
> kdump script is run first time after the switch.
Thinking more about it. Why should kdump worry about keeping an initrd
backup and restoring that later.
I feel this should be left to user if he needs to do so.
Kdump should just build initrd separately and upon successful build
replace the original with this one.
I think it is similar to admin invoking "dracut" to rebuild initrd. dracut
does not create a backup of original initrd.
I don't think kdump should be tasked with keeping a backup of original
initrd and restore it. That does not sound right to me. That's not kdump's
job.
Thanks
Vivek
Vivek, in fadump case, as default initrd is the initrd image for fadump
as well, it becomes a bit tricky on when to rebuild the initrd image
with fadump support as the default initrd image could already be built
with fadump support in most cases. Having a backup image solves this
problem. Also, it helps in cases where default initrd is manually created
by user for specific needs as while switching back from fadump to kdump,
creating a new default initrd image instead of restoring the original
initrd image may be undesirable. Please share your opinion on this.
Thanks
Hari
> Signed-off-by: Mahesh Salgaonkar
<mahesh(a)linux.vnet.ibm.com>
> Signed-off-by: Hari Bathini <hbathini(a)linux.vnet.ibm.com>
> ---
> kdumpctl | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 85 insertions(+), 17 deletions(-)
>
> diff --git a/kdumpctl b/kdumpctl
> index efd77ce..5170487 100755
> --- a/kdumpctl
> +++ b/kdumpctl
> @@ -16,6 +16,7 @@ DUMP_MODE="kdump" # kdump shall be the default dump mode
> . /lib/kdump/kdump-lib.sh
>
> standard_kexec_args="-p"
> +declare -i image_time
>
> if [ -f /etc/sysconfig/kdump ]; then
> . /etc/sysconfig/kdump
> @@ -29,12 +30,25 @@ single_instance_lock()
>
> determine_dump_mode()
> {
> + if [ -z "$KDUMP_KERNELVER" ]; then
> + kdump_kver=`uname -r`
> + else
> + kdump_kver=$KDUMP_KERNELVER
> + fi
> +
> + default_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}.img"
> + kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img"
> + default_initrd_bak="$default_initrd.default.bak"
> +
> # Check if firmware-assisted dump is enabled
> # if yes, set the dump mode as fadump
> if is_fadump_capable; then
> echo "Using dump mode fadump"
> DUMP_MODE="fadump"
> fi
> +
> + # Handle dump mode switch from kdump to fadump OR fadump to kdump
> + handle_dump_mode_switch
> }
>
> # remove_cmdline_param <kernel cmdline> <param1> [<param2>] ...
[<paramN>]
> @@ -134,6 +148,10 @@ function save_core()
>
> function rebuild_initrd()
> {
> + if [ $DUMP_MODE == "fadump" ]; then
> + backup_default_initrd
> + fi
> +
> $MKDUMPRD $kdump_initrd $kdump_kver
> if [ $? != 0 ]; then
> echo "mkdumprd: failed to make kdump initrd" >&2
> @@ -163,6 +181,61 @@ function check_executable()
> done
> }
>
> +backup_default_initrd()
> +{
> + # Check if backup initrd is already present. If not, then
> + # this is the first time fadump is being used OR user
> + # has switched from kdump to fadump.
> + # Take a backup of the original default initrd before
> + # we rebuild default initrd for fadump support.
> + if [ ! -e $default_initrd_bak ];then
> + echo "Backing up default initrd"
> + cp $default_initrd $default_initrd_bak
> + sync
> + fi
> +}
> +
> +handle_dump_mode_switch()
> +{
> + if [ $DUMP_MODE == "fadump" ]; then
> + if [ -e $kdump_initrd ];then
> + # This means user has switched from kdump to fadump.
> + # Remove kdump initrd which is no longer needed
> + rm -f $kdump_initrd
> + fi
> + else
> + if [ -e $default_initrd_bak ];then
> + # !fadump and original initrd backup file exists.
> + # This means user has switched from fadump to kdump.
> + # Restore the original default initrd.
> + mv $default_initrd_bak $default_initrd
> + sync
> + fi
> + fi
> +}
> +
> +find_initrd_image_time()
> +{
> + image_time=0
> +
> + # Check to see if dependent files have been modified
> + # since last build of the image file
> + if [ $DUMP_MODE == "fadump" ]; then
> + # If this is the 1st time we are using fadump then let image_time be
> + # zero to force rebuild initrd. The non-existance of backup initrd
> + # means this is the 1st time fadump is being used. If it exists then
> + # return the image time of default initrd.
> + if [ -e $default_initrd_bak ]; then
> + image_time=`stat -c "%Y" $default_initrd 2>/dev/null`
> + fi
> + else
> + if [ -f $kdump_initrd ]; then
> + image_time=`stat -c "%Y" $kdump_initrd 2>/dev/null`
> + return
> + fi
> + fi
> +}
> +
> function check_config()
> {
> local nr
> @@ -234,14 +307,7 @@ function check_rebuild()
> local extra_modules modified_files=""
> local _force_rebuild force_rebuild="0"
>
> - if [ -z "$KDUMP_KERNELVER" ]; then
> - kdump_kver=`uname -r`
> - else
> - kdump_kver=$KDUMP_KERNELVER
> - fi
> -
>
kdump_kernel="${KDUMP_BOOTDIR}/${KDUMP_IMG}-${kdump_kver}${KDUMP_IMG_EXT}"
> - kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img"
>
> _force_rebuild=`grep ^force_rebuild $KDUMP_CONFIG_FILE 2>/dev/null`
> if [ $? -eq 0 ]; then
> @@ -256,13 +322,9 @@ function check_rebuild()
> extra_modules=`grep ^extra_modules $KDUMP_CONFIG_FILE`
> [ -n "$extra_modules" ] && force_rebuild="1"
>
> - #check to see if dependent files has been modified
> - #since last build of the image file
> - if [ -f $kdump_initrd ]; then
> - image_time=`stat -c "%Y" $kdump_initrd 2>/dev/null`
> - else
> - image_time=0
> - fi
> + # Find initrd image time based on whether dependent files have been
> + # modified since last build of the image file
> + find_initrd_image_time
>
> #also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled.
> modified_files=$(get_pcs_cluster_modified_files $image_time)
> @@ -285,11 +347,17 @@ function check_rebuild()
> done
>
> if [ $image_time -eq 0 ]; then
> - echo -n "No kdump initial ramdisk found."; echo
> + if [ $DUMP_MODE == "kdump" ]; then
> + echo -n "No kdump initial ramdisk found."; echo
> + fi
> elif [ "$force_rebuild" != "0" ]; then
> - echo -n "Force rebuild $kdump_initrd"; echo
> + if [ $DUMP_MODE == "kdump" ]; then
> + echo -n "Force rebuild $kdump_initrd"; echo
> + else
> + echo -n "Force rebuild $default_initrd with fadump support"; echo
> + fi
> elif [ -n "$modified_files" ]; then
> - echo "Detected change(s) the following file(s):"
> + echo "Detected change(s) in the following file(s):"
> echo -n " "; echo "$modified_files" | sed 's/\s/\n
/g'
> else
> return 0
>
> _______________________________________________
> kexec mailing list
> kexec(a)lists.fedoraproject.org
>
https://lists.fedoraproject.org/mailman/listinfo/kexec