From d068f9609c663ef9c4d52d7c2f942f10fc9dcb04 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 1 Apr 2010 18:05:38 +0200 Subject: [PATCH] Add a managedsave command to virsh This command implements the managed save operation * tools/virsh.c: new command * tools/virsh.pod: documentation --- tools/virsh.c | 40 ++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 6 ++++++ 2 files changed, 46 insertions(+) diff --git a/tools/virsh.c b/tools/virsh.c index 5c56fa6008..ca1a003702 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1332,6 +1332,44 @@ cmdSave(vshControl *ctl, const vshCmd *cmd) return ret; } +/* + * "managedsave" command + */ +static const vshCmdInfo info_managedsave[] = { + {"help", N_("managed save of a domain state")}, + {"desc", N_("Save and stop a running domain, so libvirt can restart it from the same state")}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_managedsave[] = { + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, + {NULL, 0, 0, NULL} +}; + +static int +cmdManagedSave(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom; + char *name; + int ret = TRUE; + + if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) + return FALSE; + + if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) + return FALSE; + + if (virDomainManagedSave(dom, 0) == 0) { + vshPrint(ctl, _("Domain %s state saved by libvirt\n"), name); + } else { + vshError(ctl, _("Failed to save domain %s state"), name); + ret = FALSE; + } + + virDomainFree(dom); + return ret; +} + /* * "schedinfo" command */ @@ -8208,6 +8246,8 @@ static const vshCmdDef commands[] = { {"iface-start", cmdInterfaceStart, opts_interface_start, info_interface_start}, {"iface-destroy", cmdInterfaceDestroy, opts_interface_destroy, info_interface_destroy}, + {"managedsave", cmdManagedSave, opts_managedsave, info_managedsave}, + {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo}, {"nodedev-list", cmdNodeListDevices, opts_node_list_devices, info_node_list_devices}, diff --git a/tools/virsh.pod b/tools/virsh.pod index fc4a70c4c2..62395d7f12 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -335,6 +335,12 @@ except that it does some error checking. The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment variables, and defaults to C. +=item B I + +Ask libvirt to save a running domain state in a place managed by libvirt. +If libvirt is asked to restart the domain later on it will resume it from +the saved domain state (and the state is discarded). + =item B optional I<--live> I<--suspend> I I I Migrate domain to another host. Add --live for live migration; --suspend