summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMarc-André Lureau2018-09-06 18:14:15 +0200
committerPaolo Bonzini2018-10-02 18:47:55 +0200
commit3829640049cf516d229620e5919b0ab66fd6ac86 (patch)
treeef5eb722c0fe8fd4ece5bf28bf0065374f98cdde /util
parentdump: fix Windows dump memory run mapping (diff)
downloadqemu-3829640049cf516d229620e5919b0ab66fd6ac86.tar.gz
qemu-3829640049cf516d229620e5919b0ab66fd6ac86.tar.xz
qemu-3829640049cf516d229620e5919b0ab66fd6ac86.zip
hostmem-memfd: add checks before adding hostmem-memfd & properties
Run some memfd-related checks before registering hostmem-memfd & various properties. This will help libvirt to figure out what the host is supposed to be capable of. qemu_memfd_check() is changed to a less optimized version, since it is used with various flags, it no longer caches the result. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20180906161415.8543-1-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/memfd.c35
1 files changed, 6 insertions, 29 deletions
diff --git a/util/memfd.c b/util/memfd.c
index 6287946b61..8debd0d037 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -45,22 +45,6 @@ static int memfd_create(const char *name, unsigned int flags)
}
#endif
-#ifndef MFD_CLOEXEC
-#define MFD_CLOEXEC 0x0001U
-#endif
-
-#ifndef MFD_ALLOW_SEALING
-#define MFD_ALLOW_SEALING 0x0002U
-#endif
-
-#ifndef MFD_HUGETLB
-#define MFD_HUGETLB 0x0004U
-#endif
-
-#ifndef MFD_HUGE_SHIFT
-#define MFD_HUGE_SHIFT 26
-#endif
-
int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
uint64_t hugetlbsize, unsigned int seals, Error **errp)
{
@@ -201,23 +185,16 @@ bool qemu_memfd_alloc_check(void)
*
* Check if host supports memfd.
*/
-bool qemu_memfd_check(void)
+bool qemu_memfd_check(unsigned int flags)
{
#ifdef CONFIG_LINUX
- static int memfd_check = MEMFD_TODO;
+ int mfd = memfd_create("test", flags);
- if (memfd_check == MEMFD_TODO) {
- int mfd = memfd_create("test", 0);
- if (mfd >= 0) {
- memfd_check = MEMFD_OK;
- close(mfd);
- } else {
- memfd_check = MEMFD_KO;
- }
+ if (mfd >= 0) {
+ close(mfd);
+ return true;
}
+#endif
- return memfd_check == MEMFD_OK;
-#else
return false;
-#endif
}