[libvirt] [PATCH v3 2/2] virsh: introduce flage --direct for save command

Chen Hanxiao chen_han_xiao at 126.com
Thu Mar 9 04:22:23 UTC 2017


From: Chen Hanxiao <chenhanxiao at gmail.com>

Base upon patches from Roy Keene <rkeene at knightpoint.com>

This patch introduces --direct flag for save command.

We could use this flag to save vm to a PIPE.

We could saving a VM state directly to Ceph RBD images
without having an intermediate file.

How to test:
fifo="$(mktemp -u)"; mkfifo "${fifo}" && virsh save --pipe cirros  "${fifo}" &
cat "${fifo}" | rbd --id cinder import - hotsnapshot/test1234 & wait; rm -f "${fifo}"

Signed-off-by: Roy Keene <rkeene at knightpoint.com>
Signed-off-by: Chen Hanxiao <chenhanxiao at gmail.com>
---
v3:
  rebase on upstream

v2-resend:
  rebase on upstream

v2:
  rename VIR_DOMAIN_SAVE_PIPE to VIR_DOMAIN_SAVE_DIRECT

 tools/virsh-domain.c | 6 ++++++
 tools/virsh.pod      | 5 ++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 09a9f82..d96e894 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4192,6 +4192,10 @@ static const vshCmdOptDef opts_save[] = {
      .type = VSH_OT_BOOL,
      .help = N_("set domain to be paused on restore")
     },
+    {.name = "direct",
+     .type = VSH_OT_BOOL,
+     .help = N_("write the file directly, needed by PIPE/FIFO")
+    },
     {.name = "verbose",
      .type = VSH_OT_BOOL,
      .help = N_("display the progress of save")
@@ -4228,6 +4232,8 @@ doSave(void *opaque)
         flags |= VIR_DOMAIN_SAVE_RUNNING;
     if (vshCommandOptBool(cmd, "paused"))
         flags |= VIR_DOMAIN_SAVE_PAUSED;
+    if (vshCommandOptBool(cmd, "direct"))
+        flags |= VIR_DOMAIN_SAVE_DIRECT;
 
     if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
         goto out;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index ee79046..9dcb527 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1928,7 +1928,7 @@ have also reverted all storage volumes back to the same contents as when
 the state file was created.
 
 =item B<save> I<domain> I<state-file> [I<--bypass-cache>] [I<--xml> B<file>]
-[{I<--running> | I<--paused>}] [I<--verbose>]
+[{I<--running> | I<--paused>}] [I<--direct>] [I<--verbose>]
 
 Saves a running domain (RAM, but not disk state) to a state file so that
 it can be restored
@@ -1943,6 +1943,9 @@ with B<domjobabort> command (sent by another virsh instance). Another option
 is to send SIGINT (usually with C<Ctrl-C>) to the virsh process running
 B<save> command. I<--verbose> displays the progress of save.
 
+Usually B<save> command will save the domain's state as a regular file.
+If you want to save it into a PIPE/FIFO, then flag I<--direct> must be set.
+
 This is roughly equivalent to doing a hibernate on a running computer,
 with all the same limitations.  Open network connections may be
 severed upon restore, as TCP timeouts may have expired.
-- 
2.7.4





More information about the libvir-list mailing list