From nobody Sat Apr 20 14:17:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1489033622763293.01979287472307; Wed, 8 Mar 2017 20:27:02 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v294NhQS012703; Wed, 8 Mar 2017 23:23:43 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v294N8lJ008694 for ; Wed, 8 Mar 2017 23:23:08 -0500 Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v294N8oD027258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 8 Mar 2017 23:23:08 -0500 Received: from m15-112.126.com (m15-112.126.com [220.181.15.112]) by mx1.redhat.com (Postfix) with ESMTP id D858761BAE for ; Thu, 9 Mar 2017 04:23:04 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [58.213.111.46]) by smtp2 (Coremail) with SMTP id DMmowAAHvaWg2MBYhIiADg--.22235S3; Thu, 09 Mar 2017 12:23:02 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=GcI42lccIUxhSDCfvQ 56cLQs39iJnuhWU3QmS9X3BQ0=; b=e1fumF69bUr8RDzuJ68m7nld6VRFT9Q+ON HpfcOA88aM3nlvuqBHftaRUh9yOJZP2HhjDmyNWW6bJ+0FmzzZ0Gz4ZE9xsml65E D4M5jTw3/HSUYAl98uJ0AiiYoQ3d4Z33m/pvmmk7LlUNGUCAIAQXlftlPqOB4WB7 0LKXjQtsM= From: Chen Hanxiao To: libvir-list@redhat.com Date: Thu, 9 Mar 2017 12:22:22 +0800 Message-Id: <1489033343-15084-2-git-send-email-chen_han_xiao@126.com> In-Reply-To: <1489033343-15084-1-git-send-email-chen_han_xiao@126.com> References: <1489033343-15084-1-git-send-email-chen_han_xiao@126.com> X-CM-TRANSID: DMmowAAHvaWg2MBYhIiADg--.22235S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxtFW7CrW7tw48Xr13tFyDAwb_yoW7KF1Upa 1Ig347trW8Xr1Syrs7Wa17ZFy5ArZ5GFyrGw4YgrnYvw1UGr4vq3yrt34FvFWYyrn3AF4I vFyIkayDCFs7JFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jjLvtUUUUU= X-Originating-IP: [58.213.111.46] X-CM-SenderInfo: xfkh0spkdqs5xldrqiyswou0bp/1tbiFgaVrlhgj7dwFAAAsP X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 09 Mar 2017 04:23:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 09 Mar 2017 04:23:05 +0000 (UTC) for IP:'220.181.15.112' DOMAIN:'m15-112.126.com' HELO:'m15-112.126.com' FROM:'chen_han_xiao@126.com' RCPT:'' X-RedHat-Spam-Score: 1.999 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_PSBL, RP_MATCHES_RCVD, SPF_PASS) 220.181.15.112 m15-112.126.com 220.181.15.112 m15-112.126.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-loop: libvir-list@redhat.com Cc: Chen Hanxiao Subject: [libvirt] [PATCH v3 1/2] qemu: Allow qemuDomainSaveMemory saving VM state to a pipe X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Chen Hanxiao Base upon patches from Roy Keene Currently qemuDomainSaveMemory can save vm's config and memory to fd. It write a magic QEMU_SAVE_PARTIAL firstly, then re-open it to change QEMU_SAVE_PARTIAL as QEMU_SAVE_MAGIC. For pipes this is not possible, attempting to re-open the pipe will not connect you to the same consumer. Seeking is also not possible on a pipe. This patch introduce VIR_DOMAIN_SAVE_DIRECT If set, write QEMU_SAVE_MAGIC directly. This is useful to me for saving a VM state directly to Ceph RBD images without having an intermediate file. Signed-off-by: Roy Keene Signed-off-by: Chen Hanxiao --- v3: add news.xml v2-resend: rebase on upstream v2: rename VIR_DOMAIN_SAVE_PIPE to VIR_DOMAIN_SAVE_DIRECT remove S_ISFIFO check for dst path docs/news.xml | 9 +++++++ include/libvirt/libvirt-domain.h | 1 + src/qemu/qemu_driver.c | 54 ++++++++++++++++++++++++++----------= ---- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/docs/news.xml b/docs/news.xml index 9515395..57088db 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -37,6 +37,15 @@ applications running on the platform. + + + qemu: Allow qemuDomainSaveMemory saving VM state to a pipe + + + Introduce flag VIR_DOMAIN_SAVE_DIRECT to enable command 'save' + to write to PIPE, for PIPE can't be reopened. + +
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index c490d71..f58fe2c 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1169,6 +1169,7 @@ typedef enum { VIR_DOMAIN_SAVE_BYPASS_CACHE =3D 1 << 0, /* Avoid file system cache po= llution */ VIR_DOMAIN_SAVE_RUNNING =3D 1 << 1, /* Favor running over paused = */ VIR_DOMAIN_SAVE_PAUSED =3D 1 << 2, /* Favor paused over running = */ + VIR_DOMAIN_SAVE_DIRECT =3D 1 << 3, /* Write QEMU_SAVE_MAGIC dire= ctly */ } virDomainSaveRestoreFlags; =20 int virDomainSave (virDomainPtr domain, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2032fac..29b7677 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3059,6 +3059,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, virQEMUSaveHeader header; bool bypassSecurityDriver =3D false; bool needUnlink =3D false; + bool canReopen =3D true; int ret =3D -1; int fd =3D -1; int directFlag =3D 0; @@ -3066,7 +3067,6 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, unsigned int wrapperFlags =3D VIR_FILE_WRAPPER_NON_BLOCKING; =20 memset(&header, 0, sizeof(header)); - memcpy(header.magic, QEMU_SAVE_PARTIAL, sizeof(header.magic)); header.version =3D QEMU_SAVE_VERSION; header.was_running =3D was_running ? 1 : 0; header.compressed =3D compressed; @@ -3082,6 +3082,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, goto cleanup; } } + fd =3D qemuOpenFile(driver, vm, path, O_WRONLY | O_TRUNC | O_CREAT | directFlag, &needUnlink, &bypassSecurityDriver); @@ -3094,6 +3095,20 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, if (!(wrapperFd =3D virFileWrapperFdNew(&fd, path, wrapperFlags))) goto cleanup; =20 + /* Set the header magic. + * Setting flags VIR_DOMAIN_SAVE_DIRECT will write + * magic QEMU_SAVE_MAGIC directly. + * For PIPE, we should do this because it can't be reopen. + * Otherwise we'll update the magic after + * the saving completes successfully. + */ + if (flags & VIR_DOMAIN_SAVE_DIRECT) { + canReopen =3D false; + memcpy(header.magic, QEMU_SAVE_MAGIC, sizeof(header.magic)); + } else { + memcpy(header.magic, QEMU_SAVE_PARTIAL, sizeof(header.magic)); + } + /* Write header to file, followed by XML */ if (qemuDomainSaveHeader(fd, path, domXML, &header) < 0) goto cleanup; @@ -3102,28 +3117,30 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, if (qemuMigrationToFile(driver, vm, fd, compressedpath, asyncJob) < 0) goto cleanup; =20 - /* Touch up file header to mark image complete. */ + if (canReopen) { + /* Touch up file header to mark image complete. */ =20 - /* Reopen the file to touch up the header, since we aren't set - * up to seek backwards on wrapperFd. The reopened fd will - * trigger a single page of file system cache pollution, but - * that's acceptable. */ - if (VIR_CLOSE(fd) < 0) { - virReportSystemError(errno, _("unable to close %s"), path); - goto cleanup; - } + /* Reopen the file to touch up the header, since we aren't set + * up to seek backwards on wrapperFd. The reopened fd will + * trigger a single page of file system cache pollution, but + * that's acceptable. */ + if (VIR_CLOSE(fd) < 0) { + virReportSystemError(errno, _("unable to close %s"), path); + goto cleanup; + } =20 - if (virFileWrapperFdClose(wrapperFd) < 0) - goto cleanup; + if (virFileWrapperFdClose(wrapperFd) < 0) + goto cleanup; =20 - if ((fd =3D qemuOpenFile(driver, vm, path, O_WRONLY, NULL, NULL)) < 0) - goto cleanup; + if ((fd =3D qemuOpenFile(driver, vm, path, O_WRONLY, NULL, NULL)) = < 0) + goto cleanup; =20 - memcpy(header.magic, QEMU_SAVE_MAGIC, sizeof(header.magic)); + memcpy(header.magic, QEMU_SAVE_MAGIC, sizeof(header.magic)); =20 - if (safewrite(fd, &header, sizeof(header)) !=3D sizeof(header)) { - virReportSystemError(errno, _("unable to write %s"), path); - goto cleanup; + if (safewrite(fd, &header, sizeof(header)) !=3D sizeof(header)) { + virReportSystemError(errno, _("unable to write %s"), path); + goto cleanup; + } } =20 if (VIR_CLOSE(fd) < 0) { @@ -3353,6 +3370,7 @@ qemuDomainSaveFlags(virDomainPtr dom, const char *pat= h, const char *dxml, =20 virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | VIR_DOMAIN_SAVE_RUNNING | + VIR_DOMAIN_SAVE_DIRECT | VIR_DOMAIN_SAVE_PAUSED, -1); =20 cfg =3D virQEMUDriverGetConfig(driver); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 14:17:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1489033618292532.0743646351866; Wed, 8 Mar 2017 20:26:58 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v294N7Hd019974; Wed, 8 Mar 2017 23:23:08 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v294N6OP008679 for ; Wed, 8 Mar 2017 23:23:06 -0500 Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v294N6B5002924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 8 Mar 2017 23:23:06 -0500 Received: from m15-112.126.com (m15-112.126.com [220.181.15.112]) by mx1.redhat.com (Postfix) with ESMTP id 0588C8124B for ; Thu, 9 Mar 2017 04:23:05 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [58.213.111.46]) by smtp2 (Coremail) with SMTP id DMmowAAHvaWg2MBYhIiADg--.22235S4; Thu, 09 Mar 2017 12:23:03 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=ec+ZmE+BGasyJfzeYf jQ2qFouaPSY7v8bPpWy5egHy8=; b=m5jN6f3OfZfk2qbJ91+y2OC/omaLyLuoRA /Zz//H1xEDOD3JlA9janYShSC8dnOxMc7kpy5zW9fDanOOZRMscNMz1s+tcFfQff 7c/5ZlYFrbnVPznqdv6Vq2J/XkHlWuFNjqXPe5p0nVnItw1Y6zkNHOJY1UP/cH8e PP4Hd5mJs= From: Chen Hanxiao To: libvir-list@redhat.com Date: Thu, 9 Mar 2017 12:22:23 +0800 Message-Id: <1489033343-15084-3-git-send-email-chen_han_xiao@126.com> In-Reply-To: <1489033343-15084-1-git-send-email-chen_han_xiao@126.com> References: <1489033343-15084-1-git-send-email-chen_han_xiao@126.com> X-CM-TRANSID: DMmowAAHvaWg2MBYhIiADg--.22235S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF1rXFW3uFWxAF4ktF1UJrb_yoW5Xw1kpa 95ur1Ika4fXr1ktws3uF15uFy8G397Zry0qan3Ww1qvFnxGan5Wr1SqFyq9Fy3Zr40yanY vFy2gr9rJr1rJFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j4FAJUUUUU= X-Originating-IP: [58.213.111.46] X-CM-SenderInfo: xfkh0spkdqs5xldrqiyswou0bp/1tbiaQeVrlag2dbbQwAAs0 X-Greylist: Delayed for 64:41:50 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 09 Mar 2017 04:23:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 09 Mar 2017 04:23:05 +0000 (UTC) for IP:'220.181.15.112' DOMAIN:'m15-112.126.com' HELO:'m15-112.126.com' FROM:'chen_han_xiao@126.com' RCPT:'' X-RedHat-Spam-Score: 1.999 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_PSBL, RP_MATCHES_RCVD, SPF_PASS) 220.181.15.112 m15-112.126.com 220.181.15.112 m15-112.126.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-loop: libvir-list@redhat.com Cc: Chen Hanxiao Subject: [libvirt] [PATCH v3 2/2] virsh: introduce flage --direct for save command X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Chen Hanxiao Base upon patches from Roy Keene 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=3D"$(mktemp -u)"; mkfifo "${fifo}" && virsh save --pipe cirros "${fif= o}" & cat "${fifo}" | rbd --id cinder import - hotsnapshot/test1234 & wait; rm -f= "${fifo}" Signed-off-by: Roy Keene Signed-off-by: Chen Hanxiao --- 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[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("set domain to be paused on restore") }, + {.name =3D "direct", + .type =3D VSH_OT_BOOL, + .help =3D N_("write the file directly, needed by PIPE/FIFO") + }, {.name =3D "verbose", .type =3D VSH_OT_BOOL, .help =3D N_("display the progress of save") @@ -4228,6 +4232,8 @@ doSave(void *opaque) flags |=3D VIR_DOMAIN_SAVE_RUNNING; if (vshCommandOptBool(cmd, "paused")) flags |=3D VIR_DOMAIN_SAVE_PAUSED; + if (vshCommandOptBool(cmd, "direct")) + flags |=3D VIR_DOMAIN_SAVE_DIRECT; =20 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 sa= me contents as when the state file was created. =20 =3Ditem B I I [I<--bypass-cache>] [I<--xml> B] -[{I<--running> | I<--paused>}] [I<--verbose>] +[{I<--running> | I<--paused>}] [I<--direct>] [I<--verbose>] =20 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 command (sent by another virsh in= stance). Another option is to send SIGINT (usually with C) to the virsh process running B command. I<--verbose> displays the progress of save. =20 +Usually B 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. --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list