From nobody Sat Nov 23 18:13:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1723160637; cv=none; d=zohomail.com; s=zohoarc; b=mtJCC9GLB6BXv77a0jVDIoRROFvnJpz5LKaBn1ebty4+sBZGcdWj85JPGTH0GcwcusU7cFbgRlkBkTYHc4iBpvc4BFMaLdeclhrn0fYJmAMowR7q8KfaTJdmCmJkGmGFcjYmVzIOIzY2awgX7eDUKw5TSWhPjNz0w4NWRoJd0OM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723160637; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=iMPB8GhNQ/oOqEr8v2DxQseFL9nakaKGcP+L2n5eH2Q=; b=PLrfOHu5o1DsV6IxaEZntpEIr6lS1urOH/Png1UChX84dr51CczbRyNPITsR+FNkr6BiZ5VhnPOIX1Xsek0k/XDIF5F4oaa+7eg65DfRotfKPHqMUi8Q/nDac9295tTcnU65XwFK65ZCq406k3kJnC+7XvwYzJTXap4EpRxWoE0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723160637660177.28050107983097; Thu, 8 Aug 2024 16:43:57 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 953581496; Thu, 8 Aug 2024 19:43:56 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 516FD151A; Thu, 8 Aug 2024 19:39:05 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1102012CA; Thu, 8 Aug 2024 19:38:59 -0400 (EDT) Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 333E112CA for ; Thu, 8 Aug 2024 19:38:38 -0400 (EDT) Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-369c609d0c7so1153029f8f.3 for ; Thu, 08 Aug 2024 16:38:38 -0700 (PDT) Received: from localhost ([69.51.98.127]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ca46deacfbsm1623771173.46.2024.08.08.16.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 16:38:36 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1723160317; x=1723765117; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ai8nXKrq+L8+8zpltGno9LGSLpBI1G7vvr0MGN7RcgY=; b=GFHdkM9bnSc1yaEXGNAcBCMJC0fgCNQ99DAF2sz59PWvEoUco9qlQl3wBeXjM/JySW SAdvOYMbeDRn/H9QI6X8az8SdRaiCV01k/CwoH3hb5YDvQWz3aPBnODDFRVW2OBfiCcZ +N9tQ816V6f6/3OWqnbz2YqoEYiL02Lg32gpmC2xXZ1cE0bB2FN/i2Pq5StPYCaUkyXo B0OYRcBVvlTYwfZeYbRIYJCjg3NcPy3QOeIHGVhs7oIOk076+QdClv/MW1VGSGY03KP9 ed3LUVzT31QxBzRP5BofVXC3P62mjYdop0waIOrZeOb/Rx1pTTb6NuUjlQ3piypyg+mF IgFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723160317; x=1723765117; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ai8nXKrq+L8+8zpltGno9LGSLpBI1G7vvr0MGN7RcgY=; b=fEBGJ/j3iJK4hvK9hjDh2vFtX7185chlzsDMpQLD+PnSCrwYalY3GbIAePqyUHllBp LvWKgGYDQ5F45NDO7e/WbsTL509hHXEY62EFYQuuEDOkDxvV+4hnPWk2R52a8zCKIGmr CJza/B/ABPwDncr80Q7nkwUR2fUinM+tN336FWgwy6itg11Z44RdIMGphLS2Qq0afqpn eZpdxBqD+xE/l4FLmm02HYBKQJAoHlKl5+HGXJW69JX/WWw4G0jP6IWzGyNvXrlgq/ml Aqs8YC2q4Jic0wtsfCb2+Y4bEnUSuwk126lU59KU1qISlkS0+w22yxF/WnwZ7RecESr8 jvoA== X-Gm-Message-State: AOJu0Yz8spgE49U+xrfkzuy5efa+EKCBgehxIoq5bZZP0PP4zW/Nlzbm 6+oTYHSd2oUU3qmwEBFDNFek9dIGnoWPDlbMgel/xrsztRi4jau1amnPFv4vuSCkaEWUf98Glxt K X-Google-Smtp-Source: AGHT+IFD+JN6okvTLEZYFAcePODNSK1rc7AsRT3pijRPjLPwVKF3TsygKZtdBXTbk8mxI70/cBXOrg== X-Received: by 2002:adf:fe8b:0:b0:368:7f8f:ca68 with SMTP id ffacd0b85a97d-36d2751ba90mr2808227f8f.30.1723160316826; Thu, 08 Aug 2024 16:38:36 -0700 (PDT) To: devel@lists.libvirt.org Subject: [PATCH 10/20] qemu: Add support for mapped-ram on save Date: Thu, 8 Aug 2024 17:38:03 -0600 Message-Id: <20240808233813.22905-11-jfehlig@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240808233813.22905-1-jfehlig@suse.com> References: <20240808233813.22905-1-jfehlig@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: APACYLQXGGQHASJMODIBA7SSRXAULMVL X-Message-ID-Hash: APACYLQXGGQHASJMODIBA7SSRXAULMVL X-MailFrom: jfehlig@suse.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: farosas@suse.de X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Jim Fehlig via Devel Reply-To: Jim Fehlig X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723160639521116600 Content-Type: text/plain; charset="utf-8" Introduce support for QEMU's new mapped-ram stream format [1]. mapped-ram is enabled by default if the underlying QEMU advertises the mapped-ram migration capability. It can be disabled by changing the 'save_image_version' setting in qemu.conf to version '2'. To use mapped-ram with QEMU: - The 'mapped-ram' migration capability must be set to true - The 'multifd' migration capability must be set to true and the 'multifd-channels' migration parameter must set to 1 - QEMU must be provided an fdset containing the migration fd - The 'migrate' qmp command is invoked with a URI referencing the fdset and an offset where to start writing the data stream, e.g. {"execute":"migrate", "arguments":{"detach":true,"resume":false, "uri":"file:/dev/fdset/0,offset=3D0x11921"}} The mapped-ram stream, in conjunction with direct IO and multifd support provided by subsequent patches, can significantly improve the time required to save VM memory state. The following tables compare mapped-ram with the existing, sequential save stream. In all cases, the save and restore operations are to/from a block device comprised of two NVMe disks in RAID0 configuration with xfs (~8600MiB/s). The values in the 'save time' and 'restore time' columns were scraped from the 'real' time reported by time(1). The 'Size' and 'Blocks' columns were provided by the corresponding outputs of stat(1). VM: 32G RAM, 1 vcpu, idle (shortly after boot) | save | restore | | time | time | Size | Blocks -----------------------+---------+---------+--------------+-------- legacy | 6.193s | 4.399s | 985744812 | 1925288 -----------------------+---------+---------+--------------+-------- mapped-ram | 5.109s | 1.176s | 34368554354 | 1774472 -----------------------+---------+---------+--------------+-------- legacy + direct IO | 5.725s | 4.512s | 985765251 | 1925328 -----------------------+---------+---------+--------------+-------- mapped-ram + direct IO | 4.627s | 1.490s | 34368554354 | 1774304 -----------------------+---------+---------+--------------+-------- mapped-ram + direct IO | | | | + multifd-channels=3D8 | 4.421s | 0.845s | 34368554318 | 1774312 ------------------------------------------------------------------- VM: 32G RAM, 30G dirty, 1 vcpu in tight loop dirtying memory | save | restore | | time | time | Size | Blocks -----------------------+---------+---------+--------------+--------- legacy | 25.800s | 14.332s | 33154309983 | 64754512 -----------------------+---------+---------+--------------+--------- mapped-ram | 18.742s | 15.027s | 34368559228 | 64617160 -----------------------+---------+---------+--------------+--------- legacy + direct IO | 13.115s | 18.050s | 33154310496 | 64754520 -----------------------+---------+---------+--------------+--------- mapped-ram + direct IO | 13.623s | 15.959s | 34368557392 | 64662040 -----------------------+-------- +---------+--------------+--------- mapped-ram + direct IO | | | | + multifd-channels=3D8 | 6.994s | 6.470s | 34368554980 | 64665776 -------------------------------------------------------------------- As can be seen from the tables, one caveat of mapped-ram is the logical file size of a saved image is basically equivalent to the VM memory size. Note however that mapped-ram typically uses fewer blocks on disk. Another caveat of mapped-ram is the requirement for a seekable file descriptor, which currently makes it incompatible with libvirt's support for save image compression. Also note the mapped-ram stream is incompatible with the existing stream format, hence mapped-ram cannot be used to restore an image saved with the existing format and vice versa. [1] https://gitlab.com/qemu-project/qemu/-/blob/master/docs/devel/migration= /mapped-ram.rst?ref_type=3Dheads Signed-off-by: Jim Fehlig --- src/qemu/qemu_driver.c | 20 ++++-- src/qemu/qemu_migration.c | 139 ++++++++++++++++++++++++++------------ src/qemu/qemu_migration.h | 4 +- src/qemu/qemu_monitor.c | 36 ++++++++++ src/qemu/qemu_monitor.h | 4 ++ src/qemu/qemu_saveimage.c | 43 +++++++++--- src/qemu/qemu_saveimage.h | 2 + src/qemu/qemu_snapshot.c | 9 ++- 8 files changed, 195 insertions(+), 62 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6c0d3e097c..977763e5d8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2617,6 +2617,8 @@ qemuDomainSaveInternal(virQEMUDriver *driver, qemuDomainObjPrivate *priv =3D vm->privateData; virQEMUSaveData *data =3D NULL; g_autoptr(qemuDomainSaveCookie) cookie =3D NULL; + g_autoptr(qemuMigrationParams) saveParams =3D NULL; + bool mappedRam =3D false; =20 if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_SAVE, VIR_DOMAIN_JOB_OPERATION_SAVE, flags) < = 0) @@ -2683,12 +2685,17 @@ qemuDomainSaveInternal(virQEMUDriver *driver, if (!(cookie =3D qemuDomainSaveCookieNew(vm))) goto endjob; =20 - if (!(data =3D virQEMUSaveDataNew(driver, xml, cookie, was_running, co= mpressed))) + + if (!(data =3D virQEMUSaveDataNew(driver, vm, xml, cookie, was_running= , compressed))) goto endjob; xml =3D NULL; =20 + mappedRam =3D data->header.features & QEMU_SAVE_FEATURE_MAPPED_RAM; + if (!(saveParams =3D qemuMigrationParamsForSave(mappedRam))) + goto endjob; + ret =3D qemuSaveImageCreate(driver, vm, path, data, compressor, - flags, VIR_ASYNC_JOB_SAVE); + saveParams, flags, VIR_ASYNC_JOB_SAVE); if (ret < 0) goto endjob; =20 @@ -3122,6 +3129,8 @@ doCoreDump(virQEMUDriver *driver, memory_dump_format) < 0) goto cleanup; } else { + g_autoptr(qemuMigrationParams) dump_params =3D NULL; + if (dumpformat !=3D VIR_DOMAIN_CORE_DUMP_FORMAT_RAW) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("kdump-compressed format is only supported wi= th memory-only dump")); @@ -3131,8 +3140,11 @@ doCoreDump(virQEMUDriver *driver, if (!qemuMigrationSrcIsAllowed(vm, false, VIR_ASYNC_JOB_DUMP, 0)) goto cleanup; =20 - if (qemuMigrationSrcToFile(driver, vm, fd, compressor, - VIR_ASYNC_JOB_DUMP) < 0) + if (!(dump_params =3D qemuMigrationParamsNew())) + goto cleanup; + + if (qemuMigrationSrcToFile(driver, vm, &fd, compressor, + dump_params, dump_flags, VIR_ASYNC_JOB_= DUMP) < 0) goto cleanup; } =20 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index c1bdaa273b..3ab5e2fa30 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -6944,46 +6944,17 @@ qemuMigrationProcessUnattended(virQEMUDriver *drive= r, } =20 =20 -/* Helper function called while vm is active. */ -int -qemuMigrationSrcToFile(virQEMUDriver *driver, virDomainObj *vm, - int fd, - virCommand *compressor, - virDomainAsyncJob asyncJob) +static int +qemuMigrationSrcToLegacyFile(virQEMUDriver *driver, + virDomainObj *vm, + int fd, + virCommand *compressor, + virDomainAsyncJob asyncJob) { qemuDomainObjPrivate *priv =3D vm->privateData; - int rc; int ret =3D -1; int pipeFD[2] =3D { -1, -1 }; - unsigned long saveMigBandwidth =3D priv->migMaxBandwidth; char *errbuf =3D NULL; - virErrorPtr orig_err =3D NULL; - g_autoptr(qemuMigrationParams) migParams =3D NULL; - - if (qemuMigrationSetDBusVMState(driver, vm) < 0) - return -1; - - /* Increase migration bandwidth to unlimited since target is a file. - * Failure to change migration speed is not fatal. */ - if (!(migParams =3D qemuMigrationParamsForSave(false))) - return -1; - - if (qemuMigrationParamsSetULL(migParams, - QEMU_MIGRATION_PARAM_MAX_BANDWIDTH, - QEMU_DOMAIN_MIG_BANDWIDTH_MAX * 1024 * 1= 024) < 0) - return -1; - - if (qemuMigrationParamsApply(vm, asyncJob, migParams, 0) < 0) - return -1; - - priv->migMaxBandwidth =3D QEMU_DOMAIN_MIG_BANDWIDTH_MAX; - - if (!virDomainObjIsActive(vm)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("guest unexpectedly quit")); - /* nothing to tear down */ - return -1; - } =20 if (compressor && virPipe(pipeFD) < 0) return -1; @@ -7000,7 +6971,7 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDoma= inObj *vm, goto cleanup; =20 if (!compressor) { - rc =3D qemuMonitorMigrateToFd(priv->mon, 0, fd); + ret =3D qemuMonitorMigrateToFd(priv->mon, 0, fd); } else { virCommandSetInputFD(compressor, pipeFD[0]); virCommandSetOutputFD(compressor, &fd); @@ -7016,12 +6987,99 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDo= mainObj *vm, qemuDomainObjExitMonitor(vm); goto cleanup; } - rc =3D qemuMonitorMigrateToFd(priv->mon, 0, pipeFD[1]); + ret =3D qemuMonitorMigrateToFd(priv->mon, 0, pipeFD[1]); if (VIR_CLOSE(pipeFD[0]) < 0 || VIR_CLOSE(pipeFD[1]) < 0) VIR_WARN("failed to close intermediate pipe"); } qemuDomainObjExitMonitor(vm); + + cleanup: + VIR_FORCE_CLOSE(pipeFD[0]); + VIR_FORCE_CLOSE(pipeFD[1]); + + if (errbuf) { + VIR_DEBUG("Compression binary stderr: %s", NULLSTR(errbuf)); + VIR_FREE(errbuf); + } + + return ret; +} + + +static int +qemuMigrationSrcToMappedFile(virQEMUDriver *driver, + virDomainObj *vm, + int *fd, + unsigned int flags, + virDomainAsyncJob asyncJob) +{ + int ret; + + /* mapped-ram does not support directIO */ + if ((flags & VIR_DOMAIN_SAVE_BYPASS_CACHE)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("bypass cache unsupported by this system")); + return -1; + } + + if (qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, *fd)= < 0) + return -1; + + if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) + return -1; + + ret =3D qemuMonitorMigrateToFdSet(vm, 0, fd); + qemuDomainObjExitMonitor(vm); + return ret; +} + + +/* Helper function called while vm is active. */ +int +qemuMigrationSrcToFile(virQEMUDriver *driver, virDomainObj *vm, + int *fd, + virCommand *compressor, + qemuMigrationParams *migParams, + unsigned int flags, + virDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + int rc; + int ret =3D -1; + unsigned long saveMigBandwidth =3D priv->migMaxBandwidth; + virErrorPtr orig_err =3D NULL; + + if (qemuMigrationSetDBusVMState(driver, vm) < 0) + return -1; + + /* Increase migration bandwidth to unlimited since target is a file. + * Failure to change migration speed is not fatal. */ + if (migParams && + qemuMigrationParamsSetULL(migParams, + QEMU_MIGRATION_PARAM_MAX_BANDWIDTH, + QEMU_DOMAIN_MIG_BANDWIDTH_MAX * 1024 * 1= 024) < 0) + return -1; + + if (qemuMigrationParamsApply(vm, asyncJob, migParams, 0) < 0) + return -1; + + priv->migMaxBandwidth =3D QEMU_DOMAIN_MIG_BANDWIDTH_MAX; + + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("guest unexpectedly quit")); + /* nothing to tear down */ + return -1; + } + + if (migParams && + qemuMigrationParamsCapEnabled(migParams, QEMU_MIGRATION_CAP_MAPPED= _RAM)) { + rc =3D qemuMigrationSrcToMappedFile(driver, vm, fd, flags, asyncJo= b); + } else { + rc =3D qemuMigrationSrcToLegacyFile(driver, vm, *fd, compressor, a= syncJob); + } + if (rc < 0) goto cleanup; =20 @@ -7057,13 +7115,6 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDom= ainObj *vm, priv->migMaxBandwidth =3D saveMigBandwidth; } =20 - VIR_FORCE_CLOSE(pipeFD[0]); - VIR_FORCE_CLOSE(pipeFD[1]); - if (errbuf) { - VIR_DEBUG("Compression binary stderr: %s", NULLSTR(errbuf)); - VIR_FREE(errbuf); - } - virErrorRestore(&orig_err); =20 return ret; diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index ed62fd4a91..039a926e69 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -236,8 +236,10 @@ qemuMigrationSrcIsAllowed(virDomainObj *vm, int qemuMigrationSrcToFile(virQEMUDriver *driver, virDomainObj *vm, - int fd, + int *fd, virCommand *compressor, + qemuMigrationParams *migParams, + unsigned int flags, virDomainAsyncJob asyncJob) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index b1c0c6a064..9a454a1d08 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2237,6 +2237,42 @@ qemuMonitorMigrateToFd(qemuMonitor *mon, } =20 =20 +int +qemuMonitorMigrateToFdSet(virDomainObj *vm, + unsigned int flags, + int *fd) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + qemuMonitor *mon =3D priv->mon; + off_t offset; + g_autoptr(qemuFDPass) fdPassMigrate =3D NULL; + unsigned int setId; + g_autofree char *uri =3D NULL; + int ret; + + VIR_DEBUG("fd=3D%d flags=3D0x%x", *fd, flags); + + QEMU_CHECK_MONITOR(mon); + + if ((offset =3D lseek(*fd, 0, SEEK_CUR)) =3D=3D -1) { + virReportSystemError(errno, + "%s", _("failed to seek on file descriptor")); + return -1; + } + + fdPassMigrate =3D qemuFDPassNew("migrate", priv); + qemuFDPassAddFD(fdPassMigrate, fd, "-buffered-fd"); + if (qemuFDPassTransferMonitor(fdPassMigrate, mon) < 0) + return -1; + + qemuFDPassGetId(fdPassMigrate, &setId); + uri =3D g_strdup_printf("file:/dev/fdset/%u,offset=3D%#lx", setId, off= set); + ret =3D qemuMonitorJSONMigrate(mon, flags, uri); + + return ret; +} + + int qemuMonitorMigrateToHost(qemuMonitor *mon, unsigned int flags, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 76c859a888..ebacdf110e 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -844,6 +844,10 @@ int qemuMonitorMigrateToFd(qemuMonitor *mon, unsigned int flags, int fd); =20 +int qemuMonitorMigrateToFdSet(virDomainObj *vm, + unsigned int flags, + int *fd); + int qemuMonitorMigrateToHost(qemuMonitor *mon, unsigned int flags, const char *protocol, diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c index 6f2ce40124..98a1ad638d 100644 --- a/src/qemu/qemu_saveimage.c +++ b/src/qemu/qemu_saveimage.c @@ -96,6 +96,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUSaveData, virQEMUSav= eDataFree); */ virQEMUSaveData * virQEMUSaveDataNew(virQEMUDriver *driver, + virDomainObj *vm, char *domXML, qemuDomainSaveCookie *cookieObj, bool running, @@ -115,6 +116,19 @@ virQEMUSaveDataNew(virQEMUDriver *driver, header =3D &data->header; memcpy(header->magic, QEMU_SAVE_PARTIAL, sizeof(header->magic)); header->version =3D cfg->saveImageVersion; + + /* Enable mapped-ram feature if available and save version >=3D 3 */ + if (header->version >=3D QEMU_SAVE_VERSION && + qemuMigrationCapsGet(vm, QEMU_MIGRATION_CAP_MAPPED_RAM)) { + if (compressed !=3D QEMU_SAVE_FORMAT_RAW) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("compression is not supported with save image= version %1$u"), + header->version); + goto error; + } + header->features |=3D QEMU_SAVE_FEATURE_MAPPED_RAM; + } + header->was_running =3D running ? 1 : 0; header->compressed =3D compressed; =20 @@ -366,6 +380,7 @@ qemuSaveImageCreateFd(virQEMUDriver *driver, virDomainObj *vm, const char *path, virFileWrapperFd *wrapperFd, + bool mappedRam, bool *needUnlink, unsigned int flags) { @@ -375,7 +390,7 @@ qemuSaveImageCreateFd(virQEMUDriver *driver, int directFlag =3D 0; unsigned int wrapperFlags =3D VIR_FILE_WRAPPER_NON_BLOCKING; =20 - if (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) { + if (!mappedRam && flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) { wrapperFlags |=3D VIR_FILE_WRAPPER_BYPASS_CACHE; directFlag =3D virFileDirectFdFlag(); if (directFlag < 0) { @@ -395,7 +410,7 @@ qemuSaveImageCreateFd(virQEMUDriver *driver, if (qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, fd) = < 0) return -1; =20 - if (!(wrapperFd =3D virFileWrapperFdNew(&fd, path, wrapperFlags))) + if (!mappedRam && !(wrapperFd =3D virFileWrapperFdNew(&fd, path, wrapp= erFlags))) return -1; =20 ret =3D fd; @@ -414,6 +429,7 @@ qemuSaveImageCreate(virQEMUDriver *driver, const char *path, virQEMUSaveData *data, virCommand *compressor, + qemuMigrationParams *saveParams, unsigned int flags, virDomainAsyncJob asyncJob) { @@ -422,9 +438,10 @@ qemuSaveImageCreate(virQEMUDriver *driver, int ret =3D -1; int fd =3D -1; virFileWrapperFd *wrapperFd =3D NULL; + bool mappedRam =3D data->header.features & QEMU_SAVE_FEATURE_MAPPED_RA= M; =20 /* Obtain the file handle. */ - fd =3D qemuSaveImageCreateFd(driver, vm, path, wrapperFd, &needUnlink,= flags); + fd =3D qemuSaveImageCreateFd(driver, vm, path, wrapperFd, mappedRam, &= needUnlink, flags); =20 if (fd < 0) goto cleanup; @@ -433,7 +450,7 @@ qemuSaveImageCreate(virQEMUDriver *driver, goto cleanup; =20 /* Perform the migration */ - if (qemuMigrationSrcToFile(driver, vm, fd, compressor, asyncJob) < 0) + if (qemuMigrationSrcToFile(driver, vm, &fd, compressor, saveParams, fl= ags, asyncJob) < 0) goto cleanup; =20 /* Touch up file header to mark image complete. */ @@ -441,14 +458,18 @@ qemuSaveImageCreate(virQEMUDriver *driver, /* 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 %1$s"), path); - goto cleanup; - } + * that's acceptable. + * If using mapped-ram, the fd was passed to qemu, so no need + * to close it. */ + if (!mappedRam) { + if (VIR_CLOSE(fd) < 0) { + virReportSystemError(errno, _("unable to close %1$s"), path); + goto cleanup; + } =20 - if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0) - goto cleanup; + if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0) + goto cleanup; + } =20 if ((fd =3D qemuDomainOpenFile(cfg, vm->def, path, O_WRONLY, NULL)) < = 0 || virQEMUSaveDataFinish(data, &fd, path) < 0) diff --git a/src/qemu/qemu_saveimage.h b/src/qemu/qemu_saveimage.h index 3cee846f14..eb2835f11b 100644 --- a/src/qemu/qemu_saveimage.h +++ b/src/qemu/qemu_saveimage.h @@ -114,6 +114,7 @@ qemuSaveImageCreate(virQEMUDriver *driver, const char *path, virQEMUSaveData *data, virCommand *compressor, + qemuMigrationParams *saveParams, unsigned int flags, virDomainAsyncJob asyncJob); =20 @@ -124,6 +125,7 @@ virQEMUSaveDataWrite(virQEMUSaveData *data, =20 virQEMUSaveData * virQEMUSaveDataNew(virQEMUDriver *driver, + virDomainObj *vm, char *domXML, qemuDomainSaveCookie *cookieObj, bool running, diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 1d75208814..9833fb6206 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1367,6 +1367,8 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *drive= r, =20 /* do the memory snapshot if necessary */ if (memory) { + g_autoptr(qemuMigrationParams) snap_params =3D NULL; + /* check if migration is possible */ if (!qemuMigrationSrcIsAllowed(vm, false, VIR_ASYNC_JOB_SNAPSHOT, = 0)) goto cleanup; @@ -1390,7 +1392,7 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *drive= r, !(snapdef->cookie =3D (virObject *) qemuDomainSaveCookieNew(vm= ))) goto cleanup; =20 - if (!(data =3D virQEMUSaveDataNew(driver, xml, + if (!(data =3D virQEMUSaveDataNew(driver, vm, xml, (qemuDomainSaveCookie *) snapdef->= cookie, resume, compressed))) goto cleanup; @@ -1398,8 +1400,11 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driv= er, =20 memory_existing =3D virFileExists(snapdef->memorysnapshotfile); =20 + if (!(snap_params =3D qemuMigrationParamsNew())) + goto cleanup; + if ((ret =3D qemuSaveImageCreate(driver, vm, snapdef->memorysnapsh= otfile, - data, compressor, 0, + data, compressor, snap_params, 0, VIR_ASYNC_JOB_SNAPSHOT)) < 0) goto cleanup; =20 --=20 2.35.3