From nobody Sat May 4 02:28:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1486112299472685.1696204592993; Fri, 3 Feb 2017 00:58:19 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v138smqH014766; Fri, 3 Feb 2017 03:54:48 -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 v138slxa031760 for ; Fri, 3 Feb 2017 03:54:47 -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 v138slw3027677 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 3 Feb 2017 03:54:47 -0500 Received: from m15-111.126.com (m15-111.126.com [220.181.15.111]) by mx1.redhat.com (Postfix) with ESMTP id 1AC8013A60 for ; Fri, 3 Feb 2017 08:54:45 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [58.213.111.46]) by smtp1 (Coremail) with SMTP id C8mowAA3bi0aPpRYmpIoCQ--.61886S3; Fri, 03 Feb 2017 16:24:11 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=F4WWPVZDhQFwaLQGh0 07C1ogFrQiqmQKaK396S3wcGQ=; b=BENfsEgOY5P6oF3lbl05+4+QNAsiO/xT6L j3WpW5d7mbF49YUylDoP6w7s8as368d25snweWRRknv2/6pcyJCZndGZ967XD/2U jm3zbEl3M2oz0SD6yGjBTkne+0StsT6TDRcs2md/oe1oDoz2168om9ZgTq+hb+8c HNwhMhUPg= From: Chen Hanxiao To: libvir-list@redhat.com Date: Fri, 3 Feb 2017 16:23:53 +0800 Message-Id: <1486110234-8899-2-git-send-email-chen_han_xiao@126.com> In-Reply-To: <1486110234-8899-1-git-send-email-chen_han_xiao@126.com> References: <1486110234-8899-1-git-send-email-chen_han_xiao@126.com> X-CM-TRANSID: C8mowAA3bi0aPpRYmpIoCQ--.61886S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxtFW7CrW7tw48Xw4kGFWkCrg_yoW7AFW5pa 1Sga47trW8Xr1Syrs7uF47ZFyUArZ5GFyrKw45WrnYvw15Wr4vq3yrt34F9FZYyrn3AF4I vF1xuFWDGFs7XFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jjLvtUUUUU= X-Originating-IP: [58.213.111.46] X-CM-SenderInfo: xfkh0spkdqs5xldrqiyswou0bp/1tbiEwtzrlhgjsJwaAAAsp X-Greylist: Delayed for 00:30:31 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 03 Feb 2017 08:54:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 03 Feb 2017 08:54:46 +0000 (UTC) for IP:'220.181.15.111' DOMAIN:'m15-111.126.com' HELO:'m15-111.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.111 m15-111.126.com 220.181.15.111 m15-111.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 Sat May 4 02:28:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 148611230000285.19464904917663; Fri, 3 Feb 2017 00:58:20 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v138stVf014779; Fri, 3 Feb 2017 03:54:55 -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 v138sqVU031793 for ; Fri, 3 Feb 2017 03:54:52 -0500 Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v138sqB8027698 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 3 Feb 2017 03:54:52 -0500 Received: from m15-111.126.com (m15-111.126.com [220.181.15.111]) by mx1.redhat.com (Postfix) with ESMTP id 2322DC057FAC for ; Fri, 3 Feb 2017 08:54:48 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [58.213.111.46]) by smtp1 (Coremail) with SMTP id C8mowAA3bi0aPpRYmpIoCQ--.61886S4; Fri, 03 Feb 2017 16:24:11 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=n0nCsN//HCEsm0eDno TkKdZzvOZJgMu5GzI8VAIaj6Q=; b=pZ3FiFbSXkCMwSTSrifUOE72wEOsdPZrFb qDUmh/en17QNelhus12yP5hutjZYx5Qdw9cyy1kuj/HDbtf9H91bufi060MVIuv9 nqrGxcOQLpzzclQzykyC+OHO6hbjyxI8IdJOwljabSJOyeqlTeiRTzjFA2rUIALR Y6TzKja4s= From: Chen Hanxiao To: libvir-list@redhat.com Date: Fri, 3 Feb 2017 16:23:54 +0800 Message-Id: <1486110234-8899-3-git-send-email-chen_han_xiao@126.com> In-Reply-To: <1486110234-8899-1-git-send-email-chen_han_xiao@126.com> References: <1486110234-8899-1-git-send-email-chen_han_xiao@126.com> X-CM-TRANSID: C8mowAA3bi0aPpRYmpIoCQ--.61886S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF1rXFW3uFWxAFyUJr1DKFg_yoW5XFWUpa yruw12ka4fXr1ktws3uF1ruFy8GrZ7Zry0qan3Ww1qvF13Gan5WF1SqFyq9Fy3Zr4FywsY vFy2gr9rJr15AFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j4FAJUUUUU= X-Originating-IP: [58.213.111.46] X-CM-SenderInfo: xfkh0spkdqs5xldrqiyswou0bp/1tbitQtzrlYY7kZIgAAAsN X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 03 Feb 2017 08:54:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 03 Feb 2017 08:54:51 +0000 (UTC) for IP:'220.181.15.111' DOMAIN:'m15-111.126.com' HELO:'m15-111.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.111 m15-111.126.com 220.181.15.111 m15-111.126.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 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