From nobody Mon Apr 29 09:11:30 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 1487844144400310.28916655397325; Thu, 23 Feb 2017 02:02:24 -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 v1N9x8NN035180; Thu, 23 Feb 2017 04:59:08 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1N9wKbV017436 for ; Thu, 23 Feb 2017 04:58:20 -0500 Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N9wKiF028712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 23 Feb 2017 04:58:20 -0500 Received: from m15-112.126.com (m15-112.126.com [220.181.15.112]) by mx1.redhat.com (Postfix) with ESMTP id B5187552CE for ; Thu, 23 Feb 2017 09:58:17 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [58.213.111.46]) by smtp2 (Coremail) with SMTP id DMmowABnEhgpsq5YuhpHDA--.11907S3; Thu, 23 Feb 2017 17:58:15 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=m9lxRHng46usGkmS4J +rhmyVcJbF8CfOCGDJ7Tf0XgI=; b=mRrbLlnfou1pKFndzeiejSxZ+09NKyX+3f coMi0MvZY6ZOD+8I11wKaimO2RmM6rRXolY/JVSywkxbk6PbP6/yqjunIe0BH8QV khwIwaueUOwKUBwgVJmf/zMKcvM1aEEmFltRDVQjFOVC9w0t79JLsSDUkCa6KRvd 2kpkm8vB0= From: Chen Hanxiao To: libvir-list@redhat.com Date: Thu, 23 Feb 2017 17:57:56 +0800 Message-Id: <1487843877-3497-2-git-send-email-chen_han_xiao@126.com> In-Reply-To: <1487843877-3497-1-git-send-email-chen_han_xiao@126.com> References: <1487843877-3497-1-git-send-email-chen_han_xiao@126.com> X-CM-TRANSID: DMmowABnEhgpsq5YuhpHDA--.11907S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxtFW7CrW7tw48Xw4kGFWkCrg_yoW7AFW5pa 1Sga47trW8Xr1Syrs7uF47ZFyUArZ5GFyrKw45WrnYvw15Wr4vq3yrt34F9FZYyrn3AF4I vF1xuFWDGFs7XFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UWWl9UUUUU= X-Originating-IP: [58.213.111.46] X-CM-SenderInfo: xfkh0spkdqs5xldrqiyswou0bp/1tbi4xeHrlUw6C1fUwAAsx X-Greylist: Delayed for 00:08:51 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Feb 2017 09:58:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Feb 2017 09:58:19 +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: 2.799 ** (BAYES_50, 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.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-loop: libvir-list@redhat.com Cc: Chen Hanxiao Subject: [libvirt] [PATCH resend v2 1/2] qemu: Allow saving QEMU libvirt 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 --- v2-resend: rebase on upstream v2: rename VIR_DOMAIN_SAVE_PIPE to VIR_DOMAIN_SAVE_DIRECT remove S_ISFIFO check for dst path include/libvirt/libvirt-domain.h | 1 + src/qemu/qemu_driver.c | 54 ++++++++++++++++++++++++++----------= ---- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index e303140..b28b9a4 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 d4422f3..e44d0c6 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 Mon Apr 29 09:11:30 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 1487844117342509.99141237185427; Thu, 23 Feb 2017 02:01:57 -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 v1N9wLb1035118; Thu, 23 Feb 2017 04:58:21 -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 v1N9wKxD017431 for ; Thu, 23 Feb 2017 04:58:20 -0500 Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N9wKME013791 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 23 Feb 2017 04:58:20 -0500 Received: from m15-112.126.com (m15-112.126.com [220.181.15.112]) by mx1.redhat.com (Postfix) with ESMTP id E6B8B3A7696 for ; Thu, 23 Feb 2017 09:58:17 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [58.213.111.46]) by smtp2 (Coremail) with SMTP id DMmowABnEhgpsq5YuhpHDA--.11907S4; Thu, 23 Feb 2017 17:58:15 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=V8LqiH5pCx9snOwYjp TI6DpD+DFUwhYi80Y08r4lXNk=; b=c05+0ZrR43B1QYS8EZVzWRvhv8JDcPSnIh u6KHZKQd/6/+FY3bbgrixP5qzP70896xPrCCBxY1hNvOj4ZAi/TAH/0tr1vj/DPm 3Y+9A0ZxQmxsPPzvdvdPh6/iotlXrCzRi2kQmSKHZkxPJsgpbdpT4PgrcK0LQkYl onEVSRGZ4= From: Chen Hanxiao To: libvir-list@redhat.com Date: Thu, 23 Feb 2017 17:57:57 +0800 Message-Id: <1487843877-3497-3-git-send-email-chen_han_xiao@126.com> In-Reply-To: <1487843877-3497-1-git-send-email-chen_han_xiao@126.com> References: <1487843877-3497-1-git-send-email-chen_han_xiao@126.com> X-CM-TRANSID: DMmowABnEhgpsq5YuhpHDA--.11907S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF1rXFW3uFWxAFyUJr1DKFg_yoW5XFWUpa yruw12ka4fXr1ktws3uF1ruFy8GrZ7Zry0qan3Ww1qvF13Gan5WF1SqFyq9Fy3Zr4FywsY vFy2gr9rJr15AFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07joa0QUUUUU= X-Originating-IP: [58.213.111.46] X-CM-SenderInfo: xfkh0spkdqs5xldrqiyswou0bp/1tbikRiHrlP7KMORxQAAs3 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Feb 2017 09:58:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Feb 2017 09:58:19 +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: 3.499 *** (BAYES_60, 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.29 X-loop: libvir-list@redhat.com Cc: Chen Hanxiao Subject: [libvirt] [PATCH resend v2 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 --- 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 93587e8..88492e0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4187,6 +4187,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") @@ -4223,6 +4227,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 0e434c0..25cfce3 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1896,7 +1896,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 @@ -1911,6 +1911,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