On 2016/05/09 at 16:23, Pratyush Anand wrote:
Hi Xunlei,
On 05/05/2016:04:49:38 PM, Xunlei Pang wrote:
> There are some complaints about nfs kdump that users must mount
> nfs beforehand, which can also cause some overhead to NFS server.
>
> To solve it, we added a new "nfs_mntopts" in "/etc/kdump.conf"
to
> allow users to specify the nfs options instead of mounting it. The
> general rule about "nfs_mntopts" is:
> 1) "nfs_mntopts" has the highest priority, if it is specified, we
> always use it as the final mount option even if it is invalid
> (kdump will fail to start).
> 2) When no nfs mounted beforehand:
> a) If "nfs_mntopts" is specifed, do a temporary mount using it
> as the mount options.
> b) If "nfs_mntopts" is not specifed, do a temporary mount using
> no options(default option).
> If the temporary mount fails, kdump restart fails.
> 3) When nfs was mounted beforehand, parsing mounted nfs as before,
> but with the following extra logic:
> a) If "nfs_mntopts" is specified, validate it by doing a temporary
> mount: If it is valid, make it as the options passed to dracut
> instead of the mounted nfs(overridding it); If it is invalid,
> kdump restart fails.
> b) If "nfs_mntopts" is not specified, parsing mounted nfs as before.
> 4) After kdump is finished(started or failed), umount the temporary nfs
> mount immediately if any.
>
> The patch introduced three new functions to do the implementation:
> nfs_mount_prepare(), nfs_mount_finish(), and nfs_mount_cleanup().
>
> Signed-off-by: Xunlei Pang <xlpang(a)redhat.com>
> ---
> kdump.conf | 4 ++++
> kdumpctl | 4 ++--
> mkdumprd | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
> 3 files changed, 81 insertions(+), 7 deletions(-)
>
> diff --git a/kdump.conf b/kdump.conf
> index 54b581d..f56556b 100644
> --- a/kdump.conf
> +++ b/kdump.conf
> @@ -18,6 +18,9 @@
> # nfs <nfs mount> - Will mount fs and copy /proc/vmcore to
> # <mnt>/var/crash/%HOST-%DATE/, supports DNS.
> #
> +# nfs_mntopts <mount options> - Will mount nfs using this options
> +# even if there's a mounted nfs with different options.
> +#
> # ssh <user@server> - Will scp /proc/vmcore to
> # <user@server>:/var/crash/%HOST-%DATE/, supports DNS
> # NOTE: make sure user has necessary write
> @@ -147,6 +150,7 @@
> #ext4 LABEL=/boot
> #ext4 UUID=03138356-5e61-4ab3-b58e-27507ac41937
> #nfs my.server.com:/export/tmp
> +#nfs_mntopts rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,timeo=500
> #ssh user(a)my.server.com
> #sshkey /root/.ssh/kdump_id_rsa
> path /var/crash
> diff --git a/kdumpctl b/kdumpctl
> index ef18a2d..8be82c7 100755
> --- a/kdumpctl
> +++ b/kdumpctl
> @@ -235,7 +235,7 @@ check_config()
> {
> local nr
>
> - nr=$(awk 'BEGIN{cnt=0}
/^raw|^ssh[[:blank:]]|^nfs|^ext[234]|^xfs|^btrfs|^minix/{cnt++} END{print cnt}'
$KDUMP_CONFIG_FILE)
> + nr=$(awk 'BEGIN{cnt=0}
/^raw|^ssh[[:blank:]]|^nfs[[:blank:]]|^ext[234]|^xfs|^btrfs|^minix/{cnt++} END{print
cnt}' $KDUMP_CONFIG_FILE)
> [ $nr -gt 1 ] && {
> echo "More than one dump targets specified."
> return 1
> @@ -247,7 +247,7 @@ check_config()
> case "$config_opt" in
> \#* | "")
> ;;
>
- raw|ext2|ext3|ext4|minix|btrfs|xfs|nfs|ssh|sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|default|force_rebuild|dracut_args|fence_kdump_args|fence_kdump_nodes)
>
+ raw|ext2|ext3|ext4|minix|btrfs|xfs|nfs|nfs_mntopts|ssh|sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|default|force_rebuild|dracut_args|fence_kdump_args|fence_kdump_nodes)
> [ -z "$config_val" ] && {
> echo "Invalid kdump config value for option $config_opt."
> return 1;
> diff --git a/mkdumprd b/mkdumprd
> index 6e3d975..aca8573 100644
> --- a/mkdumprd
> +++ b/mkdumprd
> @@ -13,6 +13,8 @@ conf_file="/etc/kdump.conf"
> SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
> SAVE_PATH=$(grep ^path $conf_file| cut -d' ' -f2)
> [ -z "$SAVE_PATH" ] && SAVE_PATH=$DEFAULT_PATH
> +NFS_MNTOPTS=$(grep ^nfs_mntopts $conf_file| cut -d' ' -f2 | head -1)
> +mntopts_override=""
> # strip the duplicated "/"
> SAVE_PATH=$(echo $SAVE_PATH | tr -s /)
>
> @@ -21,6 +23,7 @@ dracut_args=("--hostonly" "-o" "plymouth
dash resume ifcfg")
> OVERRIDE_RESETTABLE=0
>
> perror_exit() {
> + nfs_mount_cleanup
This will have conflict for my next version of "force rebuild" patch set.
perror_exit() is used by get_persistent_dev(). So, both of these functions have
been moved to kdump-lib.sh.
indeed
> echo $@ >&2
> exit 1
> }
> @@ -135,7 +138,15 @@ to_mount() {
> if ! is_nfs_dump_target; then
> _options="$_options,x-initrd.mount"
> fi
> - _mntopts="$_target $_fstype $_options"
> +
> + # use $mntopts_override instead, if non-empty
> + if [ -n "$mntopts_override" ]; then
As per abs guide test expression between [[ ]] is more flexible than the
single-bracket [ ] test.
Thanks for the tip, will do.
> + mntopts_override=${mntopts_override/#ro/rw} #mount fs target as rw in 2nd
kernel
> + _mntopts="$_target $_fstype $mntopts_override"
> + else
> + _mntopts="$_target $_fstype $_options"
> + fi
> +
> #for non-nfs _dev converting to use udev persistent name
> if [ -b "$_source" ]; then
> _pdev="$(get_persistent_dev $_source)"
> @@ -352,6 +363,61 @@ get_block_dump_target()
> [ -b "$_target" ] && echo $(to_dev_name $_target)
> }
>
> +# handle "nfs_mntopts"
> +# 1) if no nfs mounted: temporarily mount it using "nfs_mntopts" if
specifed, else do a default mount.
> +# 2) if nfs is mounted: if "nfs_mntopts" is specified and valid, use it as
the options passed to dracut.
> +nfs_mount_prepare()
> +{
> + local config_val=$1
> +
> + NFS_MNTPOINT=$(mktemp -d /tmp/nfs_MPXXXXXX)
> + if ! findmnt $config_val >/dev/null; then
> + # nfs needn't to be mounted beforehand, mount it temporarily
> + if [ -z "$NFS_MNTOPTS" ]; then
I am OK with the logic, however just to make it as per commit log (which says
NFS_MNTOPTS has the highest priority) probably, keeping check for NFS_MNTOPTS
as the top if condition will make it a bit simple.
Agree.
Under the if/else loop we can have only updates for NFS_MNTOPTS and then at the
end we have single if for `mount $config_val $NFS_MNTOPTS $NFS_MNTPOINT` and
mntopts_override update at the end.
One reason I'm doing this way is to do umount accordingly and print a different error
message.
But we may want a functional change about this patch, another concern of the users is
that
they don't like the temporary mount, which they think will impose a lot of burden onto
the common
NFS server, because many clients will start kdump and request a NFS mounting at the first
build.
Regards,
Xunlei
I am fine with current logic as well.
> + # Empty implies to use default mount option
> + echo "default nfs mount option used."
> + else
> + echo "nfs_mntopts mount option used."
> + NFS_MNTOPTS="-o $NFS_MNTOPTS"
> + fi
> +
> + if ! mount $config_val $NFS_MNTOPTS $NFS_MNTPOINT; then
> + perror_exit "Mount nfs $config_val failed. Please specify proper
nfs_mntopts in /etc/kdump.conf"
> + fi
> + elif [ -n "$NFS_MNTOPTS" ]; then
> + echo "nfs_mntopts mount option used."
> + # Validate $NFS_MNTOPTS
> + if ! mount $config_val -o $NFS_MNTOPTS $NFS_MNTPOINT; then
> + perror_exit "Validate nfs $config_val failed. Please check
nfs_mntopts in /etc/kdump.conf"
> + fi
> + # if nfs_mntopts is specified and valid, also there is a mounted nfs by
users with
> + # different options, nfs_mntopts has the priority to be used by dracut.
> + mntopts_override=$(findmnt -f -n -r -o OPTIONS $NFS_MNTPOINT)
> +
> + # after validation, umount it so as not to conflict with the previously
mounted one.
> + umount $NFS_MNTPOINT
> + else
> + echo "Mounted nfs mount option used."
> + fi
> +
> + add_dracut_module "nfs"
> +}
> +
> +# umount temporary nfs mount if there is
> +nfs_mount_finish()
> +{
> + if [ -d "$NFS_MNTPOINT" ]; then
> + umount $NFS_MNTPOINT 2>/dev/null
> + rmdir $NFS_MNTPOINT
> + fi
> +}
> +
> +# if error happens, we check to clean up temporary nfs mount.
> +nfs_mount_cleanup()
> +{
> + nfs_mount_finish
> +}
> +
> #handle the case user does not specify the dump target explicitly
> handle_default_dump_target()
> {
> @@ -540,12 +606,12 @@ do
> extra_modules="$extra_modules $config_val"
> ;;
> ext[234]|xfs|btrfs|minix|nfs)
> - if ! findmnt $config_val >/dev/null; then
> - perror_exit "Dump target $config_val is probably not
mounted."
> + if [ "$config_opt" = "nfs" ]; then
> + nfs_mount_prepare $config_val
> fi
>
> - if [ "$config_opt" = "nfs" ]; then
> - add_dracut_module "nfs"
> + if ! findmnt $config_val >/dev/null; then
> + perror_exit "Dump target $config_val is probably not
mounted."
> fi
>
> _absolute_save_path=$(make_absolute_save_path $config_val)
> @@ -559,6 +625,10 @@ do
> add_mount "$config_val"
> check_save_path_fs $_absolute_save_path
> check_size fs $config_val
> +
> + if [ "$config_opt" = "nfs" ]; then
> + nfs_mount_finish
> + fi
> ;;
> raw)
> #checking raw disk writable
~Pratyush