HVM save restore: frame work
PATCH 1/8 HVM save restore: frame work
[PATCH 1/8] HVM save restore: frame work
Signed-off-by Zhai Edwin <[email protected]>
frame work for HVM save restore in Control Panel
tools/libxc/Makefile +1 -1
@@ -27,7 +27,7 @@ GUEST_SRCS-$(CONFIG_X86) += xc_linux_bui GUEST_SRCS-$(CONFIG_X86) += xc_linux_build.c GUEST_SRCS-$(CONFIG_IA64) += xc_linux_build.c GUEST_SRCS-$(CONFIG_MIGRATE) += xc_linux_restore.c xc_linux_save.c -GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c +GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c xc_hvm_restore.c xc_hvm_save.c -include $(XEN_TARGET_ARCH)/Makefile
tools/libxc/xenguest.h +20 -0
@@ -11,6 +11,7 @@#define XCFLAGS_LIVE 1#define XCFLAGS_DEBUG 2 +#define XCFLAGS_HVM 4/**
@@ -25,6 +26,13 @@ int xc_linux_save(int xc_handle, int io_ uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */, int (*suspend)(int domid)); +/** +* This function will save a hvm domain running unmodified guest. +* @return 0 on success, -1 on failure +*/ +int xc_hvm_save (int xc_handle,int io_fd,uint32_t dom,uint32_t max_iters, +uint32_t max_factor,uint32_t flags/* XCFLAGS_xxx */ , +int (*suspend)(int domid));/** * This function will restore a saved domain running Linux.
@@ -41,6 +49,18 @@ int xc_linux_restore(int xc_handle, int unsigned long nr_pfns, unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, unsigned long *console_mfn); + +/** +* This function will restore a saved hvm domain running unmodified guest. +* +* @parm store_mfn pass mem size & returned with the mfn of the store page +* @return 0 on success, -1 on failure +*/ +int xc_hvm_restore (int xc_handle,int io_fd,uint32_t dom, +unsigned long nr_pfns,unsigned int store_evtchn, +unsigned long *store_mfn,unsigned int console_evtchn, +unsigned long *console_mfn, +unsigned int pae,unsigned int apic);/** * This function will create a domain for a paravirtualized Linux
tools/python/xen/lowlevel/xc/xc.c +22 -0
@@ -158,6 +158,20 @@ static PyObject *pyxc_domain_destroy(XcOstatic PyObject *pyxc_domain_destroy (XcObject *self,PyObject *args) {return dom_op (self, args, xc_domain_destroy); +} + +static PyObject *pyxc_domain_shutdown (XcObject *self,PyObject *args) +{ +uint32_t dom, reason; + +if (!PyArg_ParseTuple (args,"ii" , &dom, &reason)) +return NULL ; + +if (xc_domain_shutdown (self->xc_handle, dom, reason) !=0 ) +return pyxc_error_to_exception (); + +Py_INCREF (zero); +return zero; }
@@ -1027,6 +1041,14 @@ static PyMethodDef pyxc_methods[] = {METH_VARARGS ,"\n" "Destroy a domain.\n" " dom [int]: Identifier of domain to be destroyed.\n\n" + "Returns: [int] 0 on success; -1 on error.\n" }, + + { "domain_shutdown", + (PyCFunction )pyxc_domain_shutdown, +METH_VARARGS ,"\n" +"Shutdown a domain.\n" +" dom [int, 0]: Domain identifier to use.\n" +" reason [int, 0]: Reason for shutdown.\n" "Returns: [int] 0 on success; -1 on error.\n" }, { "vcpu_setaffinity",
tools/python/xen/xend/XendCheckpoint.py +75 -7
139 lines not on this page · raw message
tools/python/xen/xend/XendDomainInfo.py +25 -1
@@ -451,6 +451,16 @@ class XendDomainInfo: self._removeVm('xend/previous_restart_time') self.storeDom("control/shutdown", reason) + ## shutdown hypercall for hvm domain desides xenstore write + image_cfg = self.info.get('image', {}) + hvm = image_cfg.has_key('hvm') + if hvm: + for code in DOMAIN_SHUTDOWN_REASONS.keys(): + if DOMAIN_SHUTDOWN_REASONS[code] == reason: + break + xc.domain_shutdown(self.domid, code) + + def pause(self): """Pause domain
@@ -1223,8 +1233,11 @@ class XendDomainInfo: if self.image: self.image.createDeviceModel() - def _releaseDevices(self): + def _releaseDevices(self, suspend = False): """Release all domain's devices. Nothrow guarantee.""" + if suspend and self.image: + self.image.destroy(suspend) + return while True: t = xstransact("%s/device" % self.dompath)
@@ -1390,6 +1403,7 @@ class XendDomainInfo: self.info['shadow_memory'] * 1024, self.info['memory_static_max'] * 1024) + log.debug("_initDomain:shadow_memory=0x%x, memory_static_max=0x%x, memory_static_min=0x%x.", self.info['shadow_memory'], self.info['memory_static_max'], self.info['memory_static_min'],) # Round shadow up to a multiple of a MiB, as shadow_mem_control # takes MiB and we must not round down and end up under-providing. shadow = ((shadow + 1023) / 1024) * 1024
@@ -1489,6 +1503,16 @@ class XendDomainInfo: self.console_mfn = console_mfn self._introduceDomain() + image_cfg = self.info.get('image', {}) + hvm = image_cfg.has_key('hvm') + if hvm: + self.image = image.create(self, + self.info, + self.info['image'], + self.info['devices']) + if self.image: + self.image.createDeviceModel(True) + self.image.register_shutdown_watch() self._storeDomDetails() self._registerWatches() self.refreshShutdown()
tools/python/xen/xend/image.py +10 -4
@@ -173,7 +173,7 @@ class ImageHandler: """Build the domain. Define in subclass.""" raise NotImplementedError() - def createDeviceModel(self): + def createDeviceModel(self, restore = False): """Create device model for the domain (define in subclass if needed).""" pass
@@ -478,7 +478,7 @@ class HVMImageHandler(ImageHandler): return ret - def createDeviceModel(self): + def createDeviceModel(self, restore = False): if self.pid: return # Execute device model.
@@ -487,6 +487,8 @@ class HVMImageHandler(ImageHandler): args = args + ([ "-d", "%d" % self.vm.getDomid(), "-m", "%s" % (self.getRequiredInitialReservation() / 1024)]) args = args + self.dmargs + if restore: + args = args + ([ "-loadvm", "/tmp/xen.qemu-dm.%d" % self.vm.getDomid() ]) env = dict(os.environ) if self.display: env['DISPLAY'] = self.display
@@ -505,12 +507,16 @@ class HVMImageHandler(ImageHandler): self.register_reboot_feature_watch() self.pid = self.vm.gatherDom(('image/device-model-pid', int)) - def destroy(self): + def destroy(self, suspend = False): self.unregister_shutdown_watch() self.unregister_reboot_feature_watch(); if self.pid: try: - os.kill(self.pid, signal.SIGKILL) + sig = signal.SIGKILL + if suspend: + log.info("use sigusr1 to signal qemu %d", self.pid) + sig = signal.SIGUSR1 + os.kill(self.pid, sig) except OSError, exn: log.exception(exn) try:
tools/xcutils/xc_restore.c +15 -4
@@ -19,12 +19,13 @@ main(int argc, char **argv) main(int argc, char **argv) {unsigned int xc_fd, io_fd, domid, nr_pfns, store_evtchn, console_evtchn; +unsigned int hvm, pae, apic;int ret;unsigned long store_mfn, console_mfn; -if (argc !=6 ) +if (argc !=9 )errx (1 , -"usage: %s iofd domid nr_pfns store_evtchn console_evtchn" , +"usage: %s iofd domid nr_pfns store_evtchn console_evtchn hvm pae apic" , argv[0 ]); xc_fd =xc_interface_open ();
@@ -36,9 +37,19 @@ main(int argc, char **argv) nr_pfns =atoi (argv[3 ]); store_evtchn =atoi (argv[4 ]); console_evtchn =atoi (argv[5 ]); + hvm =atoi (argv[6 ]); + pae =atoi (argv[7 ]); + apic =atoi (argv[8 ]); - ret =xc_linux_restore (xc_fd, io_fd, domid, nr_pfns, store_evtchn, - &store_mfn, console_evtchn, &console_mfn); +if (hvm) { +/* pass the memsize to xc_hvm_restore to find the store_mfn */ + store_mfn = hvm; + ret =xc_hvm_restore (xc_fd, io_fd, domid, nr_pfns, store_evtchn, + &store_mfn, console_evtchn, &console_mfn, pae, apic); + }else + ret =xc_linux_restore (xc_fd, io_fd, domid, nr_pfns, store_evtchn, + &store_mfn, console_evtchn, &console_mfn); +if (ret ==0 ) {printf ("store-mfn %li\n" , store_mfn);printf ("console-mfn %li\n" , console_mfn);
tools/xcutils/xc_save.c +4 -1
@@ -51,7 +51,10 @@ main(int argc, char **argv) max_f =atoi (argv[4 ]); flags =atoi (argv[5 ]); - ret =xc_linux_save (xc_fd, io_fd, domid, maxit, max_f, flags, &suspend); +if (flags &XCFLAGS_HVM ) + ret =xc_hvm_save (xc_fd, io_fd, domid, maxit, max_f, flags, &suspend); +else + ret =xc_linux_save (xc_fd, io_fd, domid, maxit, max_f, flags, &suspend);xc_interface_close (xc_fd);
tools/libxc/xc_hvm_restore.c new file +42 -0
42 lines not on this page · raw message
tools/libxc/xc_hvm_save.c new file +40 -0
@@ -0,0 +1,40 @@ +/****************************************************************************** +* xc_hvm_save.c +* +* Save the state of a running HVM guest. +* +* Copyright (c) 2003, K A Fraser. +* Copyright (c) 2006 Intel Corperation +* rewriten for hvm guest by Zhai Edwin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; if not, write to the Free Software Foundation, Inc., 59 Temple +* Place - Suite 330, Boston, MA 02111-1307 USA. +* +*/ + +#include <inttypes.h> +#include <time.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/time.h> + +#include "xc_private.h" +#include "xg_private.h" +#include "xg_save_restore.h" + +int xc_hvm_save (int xc_handle,int io_fd,uint32_t dom,uint32_t max_iters, +uint32_t max_factor,uint32_t flags,int (*suspend)(int )) +{ + +return 0 ; +}