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

Eric Blake eblake at redhat.com
Thu Jul 14 14:24:31 UTC 2011


Wire up the new flag to virsh.  Also, the 'dump' command had
undocumented flags.

* tools/virsh.c (cmdSave, cmdManagedSave, cmdDump): Add new flag.
* tools/virsh.pod (save, managedsave, dump): Document flags.
---
 tools/virsh.c   |   12 ++++++++++--
 tools/virsh.pod |   17 ++++++++++++++---
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index bd6fea7..01c5b39 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1530,6 +1530,7 @@ static const vshCmdInfo info_save[] = {
 };

 static const vshCmdOptDef opts_save[] = {
+    {"direct", VSH_OT_BOOL, 0, N_("use O_DIRECT when saving")},
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
     {"file", VSH_OT_DATA, VSH_OFLAG_REQ, N_("where to save the data")},
     {NULL, 0, 0, NULL}
@@ -1542,6 +1543,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
     const char *name = NULL;
     const char *to = NULL;
     bool ret = true;
+    bool direct = vshCommandOptBool(cmd, "direct");

     if (!vshConnectionUsability(ctl, ctl->conn))
         return false;
@@ -1552,7 +1554,8 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
         return false;

-    if (virDomainSave(dom, to) == 0) {
+    if ((direct ? virDomainSaveFlags(dom, to, NULL, VIR_DOMAIN_SAVE_DIRECT)
+         : virDomainSave(dom, to)) == 0) {
         vshPrint(ctl, _("Domain %s saved to %s\n"), name, to);
     } else {
         vshError(ctl, _("Failed to save domain %s to %s"), name, to);
@@ -1576,6 +1579,7 @@ static const vshCmdInfo info_managedsave[] = {
 };

 static const vshCmdOptDef opts_managedsave[] = {
+    {"direct", VSH_OT_BOOL, 0, N_("use O_DIRECT when saving")},
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
     {NULL, 0, 0, NULL}
 };
@@ -1586,6 +1590,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom;
     const char *name;
     bool ret = true;
+    bool direct = vshCommandOptBool(cmd, "direct");

     if (!vshConnectionUsability(ctl, ctl->conn))
         return false;
@@ -1593,7 +1598,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
         return false;

-    if (virDomainManagedSave(dom, 0) == 0) {
+    if (virDomainManagedSave(dom, direct ? VIR_DOMAIN_SAVE_DIRECT : 0) == 0) {
         vshPrint(ctl, _("Domain %s state saved by libvirt\n"), name);
     } else {
         vshError(ctl, _("Failed to save domain %s state"), name);
@@ -1962,6 +1967,7 @@ static const vshCmdInfo info_dump[] = {
 static const vshCmdOptDef opts_dump[] = {
     {"live", VSH_OT_BOOL, 0, N_("perform a live core dump if supported")},
     {"crash", VSH_OT_BOOL, 0, N_("crash the domain after core dump")},
+    {"direct", VSH_OT_BOOL, 0, N_("use O_DIRECT when saving")},
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
     {"file", VSH_OT_DATA, VSH_OFLAG_REQ, N_("where to dump the core")},
     {NULL, 0, 0, NULL}
@@ -1989,6 +1995,8 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DUMP_LIVE;
     if (vshCommandOptBool (cmd, "crash"))
         flags |= VIR_DUMP_CRASH;
+    if (vshCommandOptBool(cmd, "direct"))
+        flags |= VIR_DUMP_DIRECT;

     if (virDomainCoreDump(dom, to, flags) == 0) {
         vshPrint(ctl, _("Domain %s dumped to %s\n"), name, to);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 1a98ec1..97e7f10 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -471,9 +471,16 @@ named by I<format> to a domain XML format.
 Convert the file I<xml> in domain XML format to the native guest
 configuration format named by I<format>.

-=item B<dump> I<domain-id> I<corefilepath>
+=item B<dump> I<domain-id> I<corefilepath> [I<--live>] [I<--crash>]
+[I<--direct>]

 Dumps the core of a domain to a file for analysis.
+If I<--live> is specified, the domain continues to run until the core
+dump is complete, rather than pausing up front.
+If I<--crash> is specified, the domain is halted with a crashed status,
+rather than merely left in a paused state.
+If I<--direct> is specified, the save uses O_DIRECT, which reduces
+file system cache pressure but may slow down the operation.

 =item B<dumpxml> I<domain-id> optional I<--inactive> I<--security-info> I<--update-cpu>

@@ -507,11 +514,13 @@ 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<vi>.

-=item B<managedsave> I<domain-id>
+=item B<managedsave> I<domain-id> [I<--direct>]

 Save and destroy (stop) a running domain, so it can be restarted from the same
 state at a later time.  When the virsh B<start> command is next run for
 the domain, it will automatically be started from this saved state.
+If I<--direct> is specified, the save uses O_DIRECT, which reduces
+file system cache pressure but may slow down the operation.

 =item B<managedsave-remove> I<domain-id>

@@ -590,13 +599,15 @@ 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
 the state file was created.

-=item B<save> I<domain-id> I<state-file>
+=item B<save> I<domain-id> I<state-file> [I<--direct>]

 Saves a running domain (RAM, but not disk state) to a state file so that
 it can be restored
 later.  Once saved, the domain will no longer be running on the
 system, thus the memory allocated for the domain will be free for
 other domains to use.  B<virsh restore> restores from this state file.
+If I<--direct> is specified, the save uses O_DIRECT, which reduces
+file system cache pressure but may slow down the operation.

 This is roughly equivalent to doing a hibernate on a running computer,
 with all the same limitations.  Open network connections may be
-- 
1.7.4.4




More information about the libvir-list mailing list