[PATCH 10/15] qemu: Assume QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD

Michal Privoznik mprivozn at redhat.com
Thu Nov 3 16:22:08 UTC 2022


Introduced in QEMU's commit of v2.11.0-rc0~95^2~9 the .discard
attribute of memory-backend-file is always available for all QEMU
versions we support (4.2.0, currently). Therefore, we can assume
the capability is always set and thus doesn't need to be checked
for.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/qemu/qemu_command.c                           | 15 ++++-----------
 .../pages-dimm-discard.x86_64-latest.args         |  2 +-
 .../pages-discard-hugepages.x86_64-latest.args    |  2 +-
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index bcd30ef4f3..395b2e0a8f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3351,17 +3351,10 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps,
             return -1;
 
         if (!mem->nvdimmPath &&
-            discard == VIR_TRISTATE_BOOL_YES) {
-            if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("this QEMU doesn't support memory discard"));
-                return -1;
-            }
-
-            if (virJSONValueObjectAdd(&props,
-                                      "B:discard-data", true,
-                                      NULL) < 0)
-                return -1;
+            virJSONValueObjectAdd(&props,
+                                  "T:discard-data", discard,
+                                  NULL) < 0) {
+            return -1;
         }
 
         if (qemuBuildMemoryBackendPropsShare(props, memAccess) < 0)
diff --git a/tests/qemuxml2argvdata/pages-dimm-discard.x86_64-latest.args b/tests/qemuxml2argvdata/pages-dimm-discard.x86_64-latest.args
index 6324443e93..19ed3928de 100644
--- a/tests/qemuxml2argvdata/pages-dimm-discard.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/pages-dimm-discard.x86_64-latest.args
@@ -29,7 +29,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-fedora/.config \
 -no-acpi \
 -boot strict=on \
 -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
--object '{"qom-type":"memory-backend-file","id":"memdimm0","mem-path":"/dev/hugepages1G/libvirt/qemu/-1-fedora","prealloc":true,"size":1073741824,"host-nodes":[1,2,3],"policy":"bind"}' \
+-object '{"qom-type":"memory-backend-file","id":"memdimm0","mem-path":"/dev/hugepages1G/libvirt/qemu/-1-fedora","discard-data":false,"prealloc":true,"size":1073741824,"host-nodes":[1,2,3],"policy":"bind"}' \
 -device '{"driver":"pc-dimm","node":0,"memdev":"memdimm0","id":"dimm0","slot":0}' \
 -object '{"qom-type":"memory-backend-file","id":"memdimm1","mem-path":"/var/lib/libvirt/qemu/ram/-1-fedora/dimm1","discard-data":true,"share":false,"size":536870912}' \
 -device '{"driver":"pc-dimm","node":0,"memdev":"memdimm1","id":"dimm1","slot":1}' \
diff --git a/tests/qemuxml2argvdata/pages-discard-hugepages.x86_64-latest.args b/tests/qemuxml2argvdata/pages-discard-hugepages.x86_64-latest.args
index 880e0de192..3b03f940f9 100644
--- a/tests/qemuxml2argvdata/pages-discard-hugepages.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/pages-discard-hugepages.x86_64-latest.args
@@ -16,7 +16,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-SomeDummyHugepagesGu/.config \
 -m 1024 \
 -overcommit mem-lock=off \
 -smp 2,sockets=2,cores=1,threads=1 \
--object '{"qom-type":"memory-backend-file","id":"ram-node0","mem-path":"/dev/hugepages2M/libvirt/qemu/-1-SomeDummyHugepagesGu","prealloc":true,"size":268435456}' \
+-object '{"qom-type":"memory-backend-file","id":"ram-node0","mem-path":"/dev/hugepages2M/libvirt/qemu/-1-SomeDummyHugepagesGu","discard-data":false,"prealloc":true,"size":268435456}' \
 -numa node,nodeid=0,cpus=0,memdev=ram-node0 \
 -object '{"qom-type":"memory-backend-file","id":"ram-node1","mem-path":"/dev/hugepages2M/libvirt/qemu/-1-SomeDummyHugepagesGu","discard-data":true,"prealloc":true,"size":805306368}' \
 -numa node,nodeid=1,cpus=1,memdev=ram-node1 \
-- 
2.37.4



More information about the libvir-list mailing list