[Xen-devel] [PATCH 3/4] kexec/xen: use libxc to get location of crash notes

Don Slutz Don at CloudSwitch.com
Tue Feb 26 08:53:52 EST 2013


On 02/21/13 12:57, David Vrabel wrote:
> From: David Vrabel <david.vrabel at citrix.com>
>
> Use xc_kexec_get_range(KEXEC_RANGE_MA_CPU) instead of parsing
> /proc/iomem (which is only populated by non-upstream ("classic") Xen
> kernels).
>
> Signed-off-by: David Vrabel <david.vrabel at citrix.com>
> ---
>   kexec/crashdump-xen.c |   61 ++++++++++++++++++++++++++++---------------------
>   1 files changed, 35 insertions(+), 26 deletions(-)
>
> diff --git a/kexec/crashdump-xen.c b/kexec/crashdump-xen.c
> index ff4706c..13335a5 100644
> --- a/kexec/crashdump-xen.c
> +++ b/kexec/crashdump-xen.c
> @@ -163,42 +163,51 @@ unsigned long xen_architecture(struct crash_elf_info *elf_info)
>   	return machine;
>   }
>   
> -static int xen_crash_note_callback(void *UNUSED(data), int nr,
> -				   char *UNUSED(str),
> -				   unsigned long base,
> -				   unsigned long length)
> -{
> -	struct crash_note_info *note = xen_phys_notes + nr;
> -
> -	note->base = base;
> -	note->length = length;
> -
> -	return 0;
> -}
> -
> +#ifdef HAVE_LIBXENCTRL
>   int xen_get_nr_phys_cpus(void)
>   {
> -	char *match = "Crash note\n";
> -	int cpus, n;
> +	xc_interface *xc;
> +	int cpu;
>   
>   	if (xen_phys_cpus)
>   		return xen_phys_cpus;
>   
> -	if ((cpus = kexec_iomem_for_each_line(match, NULL, NULL))) {
> -		n = sizeof(struct crash_note_info) * cpus;
> -		xen_phys_notes = malloc(n);
> -		if (!xen_phys_notes) {
> -			fprintf(stderr, "failed to allocate xen_phys_notes.\n");
> +	xc = xc_interface_open(NULL, NULL, 0);
> +	if ( !xc ) {
> +		fprintf(stderr, "failed to open xen control interface.\n");
> +		return -1;
> +	}
> +
> +	for (cpu = 0;; cpu++) {
This code does work.  Not sure why you did not use xc_physinfo() to get 
the number of cpus that there is data for and remove the need for 
calling realloc.
> +		uint64_t size, start;
> +		int ret;
> +
> +		ret = xc_kexec_get_range(xc, KEXEC_RANGE_MA_CPU, cpu, &size, &start);
> +		if (ret < 0)
> +			break;
> +
> +		xen_phys_notes = realloc(xen_phys_notes,
> +					 sizeof(*xen_phys_notes) * (cpu + 1));
> +		if (xen_phys_notes == NULL)
>   			return -1;
> -		}
> -		memset(xen_phys_notes, 0, n);
> -		kexec_iomem_for_each_line(match,
> -					  xen_crash_note_callback, NULL);
> -		xen_phys_cpus = cpus;
> +
> +		xen_phys_notes[cpu].base = start;
> +		xen_phys_notes[cpu].length = size;
>   	}
>   
> -	return cpus;
> +	xc_interface_close(xc);
> +
> +	xen_phys_cpus = cpu;
> +
> +	return cpu;
>   }
> +#else
> +int xen_get_nr_phys_cpus(void)
> +{
> +	return -1;
> +}
> +#endif
> +
>   
>   int xen_get_note(int cpu, uint64_t *addr, uint64_t *len)
>   {
    -Don Slutz



More information about the kexec mailing list