Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Kiper <daniel.kiper@oracle.com>
To: Eric DeVolder <eric.devolder@oracle.com>
Cc: andrew.cooper3@citrix.com, horms@verge.net.au,
	kexec@lists.infradead.org, konrad.wilk@oracle.com,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v4] kexec: implemented XEN KEXEC STATUS to determine if an image is loaded
Date: Thu, 26 Jan 2017 00:02:48 +0100	[thread overview]
Message-ID: <20170125230248.GM16671@olila.local.net-space.pl> (raw)
In-Reply-To: <1485358275-11304-1-git-send-email-eric.devolder@oracle.com>

On Wed, Jan 25, 2017 at 09:31:15AM -0600, Eric DeVolder wrote:

[...]

> diff --git a/kexec/kexec.c b/kexec/kexec.c
> index 500e5a9..ec16247 100644
> --- a/kexec/kexec.c
> +++ b/kexec/kexec.c
> @@ -51,6 +51,9 @@
>  #include "kexec-lzma.h"
>  #include <arch/options.h>
>
> +#define KEXEC_LOADED_PATH "/sys/kernel/kexec_loaded"
> +#define KEXEC_CRASH_LOADED_PATH "/sys/kernel/kexec_crash_loaded"
> +
>  unsigned long long mem_min = 0;
>  unsigned long long mem_max = ULONG_MAX;
>  static unsigned long kexec_flags = 0;
> @@ -890,8 +893,6 @@ static int my_exec(void)
>  	return -1;
>  }
>
> -static int kexec_loaded(void);
> -
>  static int load_jump_back_helper_image(unsigned long kexec_flags, void *entry)
>  {
>  	int result;
> @@ -902,6 +903,40 @@ static int load_jump_back_helper_image(unsigned long kexec_flags, void *entry)
>  	return result;
>  }
>
> +static int kexec_loaded(const char *file)
> +{
> +	long ret = -1;
> +	FILE *fp;
> +	char *p;
> +	char line[3];
> +
> +	/* No way to tell if an image is loaded under Xen, assume it is. */
> +	if (xen_present())
> +		return 1;
> +
> +	fp = fopen(file, "r");
> +	if (fp == NULL)
> +		return -1;
> +
> +	p = fgets(line, sizeof(line), fp);
> +	fclose(fp);
> +
> +	if (p == NULL)
> +		return -1;
> +
> +	ret = strtol(line, &p, 10);
> +
> +	/* Too long */
> +	if (ret > INT_MAX)
> +		return -1;
> +
> +	/* No digits were found */
> +	if (p == line)
> +		return -1;
> +
> +	return (int)ret;
> +}
> +
>  /*
>   *	Jump back to the original kernel
>   */
> @@ -909,7 +944,7 @@ static int my_load_jump_back_helper(unsigned long kexec_flags, void *entry)
>  {
>  	int result;
>
> -	if (kexec_loaded()) {
> +	if (kexec_loaded(KEXEC_LOADED_PATH)) {
>  		fprintf(stderr, "There is kexec kernel loaded, make sure "
>  			"you are in kexeced kernel.\n");
>  		return -1;
> @@ -970,6 +1005,7 @@ void usage(void)
>  	       "                      to original kernel.\n"
>  	       " -s, --kexec-file-syscall Use file based syscall for kexec operation\n"
>  	       " -d, --debug           Enable debugging to help spot a failure.\n"
> +	       " -S, --status         Return 0 if the type (by default crash) is loaded.\n"
>  	       "\n"
>  	       "Supported kernel file types and options: \n");
>  	for (i = 0; i < file_types; i++) {
> @@ -981,40 +1017,30 @@ void usage(void)
>  	printf("\n");
>  }
>
> -static int kexec_loaded(void)
> +static int k_status(unsigned long kexec_flags)
>  {
> -	long ret = -1;
> -	FILE *fp;
> -	char *p;
> -	char line[3];
> +	int result;
> +	long native_arch;
> +
> +	/* set the arch */
> +	native_arch = physical_arch();
> +	if (native_arch < 0) {
> +		return -1;
> +	}
> +	kexec_flags |= native_arch;
>
> -	/* No way to tell if an image is loaded under Xen, assume it is. */
>  	if (xen_present())
> -		return 1;
> -
> -	fp = fopen("/sys/kernel/kexec_loaded", "r");
> -	if (fp == NULL)
> -		return -1;
> -
> -	p = fgets(line, sizeof(line), fp);
> -	fclose(fp);
> -
> -	if (p == NULL)
> -		return -1;
> -
> -	ret = strtol(line, &p, 10);
> -
> -	/* Too long */
> -	if (ret > INT_MAX)
> -		return -1;
> -
> -	/* No digits were found */
> -	if (p == line)
> -		return -1;
> -
> -	return (int)ret;
> +		result = xen_kexec_status(kexec_flags);
> +	else {
> +		if (kexec_flags & KEXEC_ON_CRASH)
> +			result = kexec_loaded(KEXEC_CRASH_LOADED_PATH);
> +		else
> +			result = kexec_loaded(KEXEC_LOADED_PATH);
> +	}
> +	return result;
>  }

Ohhh... This is awful. Have you tried --patience option for "git format-patch"?
Does it help? If yes please repost. If it does not let's wait for maintainers
opinion about that. Maybe we should leave forward declaration in first patch
as is and then move kexec_loaded() in second (as a cleanup).

Though otherwise LGTM.

Daniel

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2017-01-25 23:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25 15:31 [PATCH v4] kexec: implemented XEN KEXEC STATUS to determine if an image is loaded Eric DeVolder
2017-01-25 23:02 ` Daniel Kiper [this message]
2017-01-26 10:22   ` Simon Horman
2017-01-26 12:28     ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170125230248.GM16671@olila.local.net-space.pl \
    --to=daniel.kiper@oracle.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=eric.devolder@oracle.com \
    --cc=horms@verge.net.au \
    --cc=kexec@lists.infradead.org \
    --cc=konrad.wilk@oracle.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox