From c0b4a3f95dd80256cc6d7084436235e69b4933fb Mon Sep 17 00:00:00 2001 From: David Vrabel Date: Wed, 6 Nov 2013 14:55:22 +0000 Subject: kexec/xen: directly load images images into Xen Xen 4.4 has an improvided kexec hypercall ABI that allows images to be loaded and executed without any kernel involvement. Use the API provided by libxc to load images when running in a Xen guest. Support for loading images via the kexec_load syscall in non-upstream ("classic") Xen kernels is no longer supported. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Signed-off-by: Simon Horman --- kexec/kexec.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'kexec/kexec.c') diff --git a/kexec/kexec.c b/kexec/kexec.c index 2ce570f..9dc3fa4 100644 --- a/kexec/kexec.c +++ b/kexec/kexec.c @@ -764,8 +764,12 @@ static int my_load(const char *type, int fileind, int argc, char **argv, if (kexec_debug) print_segments(stderr, &info); - result = kexec_load( - info.entry, info.nr_segments, info.segment, info.kexec_flags); + if (xen_present()) + result = xen_kexec_load(&info); + else + result = kexec_load(info.entry, + info.nr_segments, info.segment, + info.kexec_flags); if (result != 0) { /* The load failed, print some debugging information */ fprintf(stderr, "kexec_load failed: %s\n", @@ -789,10 +793,13 @@ static int k_unload (unsigned long kexec_flags) } kexec_flags |= native_arch; - result = kexec_load(NULL, 0, NULL, kexec_flags); + if (xen_present()) + result = xen_kexec_unload(kexec_flags); + else + result = kexec_load(NULL, 0, NULL, kexec_flags); if (result != 0) { /* The unload failed, print some debugging information */ - fprintf(stderr, "kexec_load (0 segments) failed: %s\n", + fprintf(stderr, "kexec unload failed: %s\n", strerror(errno)); } return result; @@ -823,7 +830,10 @@ static int my_shutdown(void) */ static int my_exec(void) { - reboot(LINUX_REBOOT_CMD_KEXEC); + if (xen_present()) + xen_kexec_exec(); + else + reboot(LINUX_REBOOT_CMD_KEXEC); /* I have failed if I make it here */ fprintf(stderr, "kexec failed: %s\n", strerror(errno)); @@ -928,6 +938,10 @@ static int kexec_loaded(void) 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("/sys/kernel/kexec_loaded", "r"); if (fp == NULL) return -1; -- cgit