[libvirt] [PATCH 14/8] save: add --direct flag to virsh restore operations

Eric Blake eblake at redhat.com
Sat Jul 16 02:42:44 UTC 2011

* tools/virsh.c (cmdStart, cmdRestore): Add new flag.
* tools/virsh.pod (start, restore): Document flags.

Counterpart to 4/8

 tools/virsh.c   |    9 ++++++++-
 tools/virsh.pod |   10 ++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 3cf0618..00ea533 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1481,6 +1481,7 @@ static const vshCmdOptDef opts_start[] = {
     {"paused", VSH_OT_BOOL, 0, N_("leave the guest paused after creation")},
     {"autodestroy", VSH_OT_BOOL, 0, N_("automatically destroy the guest when virsh disconnects")},
+    {"direct", VSH_OT_BOOL, 0, N_("use O_DIRECT when loading")},
     {NULL, 0, 0, NULL}

@@ -1511,6 +1512,8 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_START_PAUSED;
     if (vshCommandOptBool(cmd, "autodestroy"))
+    if (vshCommandOptBool(cmd, "direct"))
+        flags |= VIR_DOMAIN_START_DIRECT;

     /* Prefer older API unless we have to pass a flag.  */
     if ((flags ? virDomainCreateWithFlags(dom, flags)
@@ -1940,6 +1943,7 @@ static const vshCmdInfo info_restore[] = {

 static const vshCmdOptDef opts_restore[] = {
     {"file", VSH_OT_DATA, VSH_OFLAG_REQ, N_("the state to restore")},
+    {"direct", VSH_OT_BOOL, 0, N_("use O_DIRECT when restoring")},
     {NULL, 0, 0, NULL}

@@ -1948,6 +1952,7 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
     const char *from = NULL;
     bool ret = true;
+    bool direct = vshCommandOptBool(cmd, "direct");

     if (!vshConnectionUsability(ctl, ctl->conn))
         return false;
@@ -1955,7 +1960,9 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptString(cmd, "file", &from) <= 0)
         return false;

-    if (virDomainRestore(ctl->conn, from) == 0) {
+    if ((direct ? virDomainRestoreFlags(ctl->conn, from, NULL,
+                                        VIR_DOMAIN_SAVE_DIRECT)
+         : virDomainRestore(ctl->conn, from)) == 0) {
         vshPrint(ctl, _("Domain restored from %s\n"), from);
     } else {
         vshError(ctl, _("Failed to restore domain from %s"), from);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 1e04464..8e8e9bc 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -592,10 +592,13 @@ domain actually reboots.
 The exact behavior of a domain when it reboots is set by the
 I<on_reboot> parameter in the domain's XML definition.

-=item B<restore> I<state-file>
+=item B<restore> I<state-file> [I<--direct>]

 Restores a domain from a B<virsh save> state file. See I<save> for more info.

+If I<--direct> is specified, the restore uses O_DIRECT, which reduces
+file system cache pressure but may slow down the operation.
 B<Note>: To avoid corrupting file system contents within the domain, you
 should not reuse the saved state file for a second B<restore> unless you
 have also reverted all storage volumes back to the same contents as when
@@ -794,6 +797,7 @@ The exact behavior of a domain when it shuts down is set by the
 I<on_shutdown> parameter in the domain's XML definition.

 =item B<start> I<domain-name> [I<--console>] [I<--paused>] [I<--autodestroy>]

 Start a (previously defined) inactive domain, either from the last
 B<managedsave> state, or via a fresh boot if no managedsave state is
@@ -802,7 +806,9 @@ used and supported by the driver; otherwise it will be running.
 If I<--console> is requested, attach to the console after creation.
 If I<--autodestroy> is requested, then the guest will be automatically
 destroyed when virsh closes its connection to libvirt, or otherwise
+exits.  If I<--direct> is specified, and managedsave state exists,
+the restore uses O_DIRECT, which reduces file system cache pressure
+but may slow down the operation.

 =item B<suspend> I<domain-id>


More information about the libvir-list mailing list