aboutsummaryrefslogtreecommitdiff
path: root/util/memfd.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-09-06 20:14:15 +0400
committerPaolo Bonzini <pbonzini@redhat.com>2018-10-02 18:47:55 +0200
commit3829640049cf516d229620e5919b0ab66fd6ac86 (patch)
treeef5eb722c0fe8fd4ece5bf28bf0065374f98cdde /util/memfd.c
parent7184de64a1cf23a72191484b9a6995c3bfc9fb0b (diff)
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/memfd.c')
-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
}