[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 05/24] util: add fallback for qemu_memfd_alloc()
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH v7 05/24] util: add fallback for qemu_memfd_alloc() |
Date: |
Thu, 1 Oct 2015 19:23:49 +0200 |
From: Marc-André Lureau <address@hidden>
Add an open/unlink/mmap fallback for system that do not support
memfd (only available since 3.17, ~1y ago).
This patch may require additional SELinux policies to work for enforced
systems, but should fail gracefully in this case.
Signed-off-by: Marc-André Lureau <address@hidden>
---
util/memfd.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/util/memfd.c b/util/memfd.c
index dd47552..ff577b5 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -100,8 +100,24 @@ void *qemu_memfd_alloc(const char *name, size_t size,
unsigned int seals,
return NULL;
}
} else {
- perror("memfd");
- return NULL;
+ const char *tmpdir = g_get_tmp_dir();
+ gchar *fname;
+
+ fname = g_strdup_printf("%s/memfd-XXXXXX", tmpdir);
+ mfd = mkstemp(fname);
+ unlink(fname);
+ g_free(fname);
+
+ if (mfd == -1) {
+ perror("mkstemp");
+ return NULL;
+ }
+
+ if (ftruncate(mfd, size) == -1) {
+ perror("ftruncate");
+ close(mfd);
+ return NULL;
+ }
}
ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0);
--
2.4.3
[Qemu-devel] [PATCH v7 02/24] linux-headers: add unistd.h, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 21/24] vhost-user-test: wrap server in TestServer struct, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 22/24] vhost-user-test: learn to tweak various qemu arguments, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 19/24] vhost-user-test: move wait_for_fds() out, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 09/24] vhost: alloc shareable log, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 14/24] net: add trace_vhost_user_event, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 23/24] vhost-user-test: add live-migration test, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 05/24] util: add fallback for qemu_memfd_alloc(),
marcandre . lureau <=
[Qemu-devel] [PATCH v7 06/24] vhost: document log resizing, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 08/24] vhost-user: add vhost_user_requires_shm_log(), marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 11/24] vhost-user: add a migration blocker, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 10/24] vhost-user: send log shm fd along with log_base, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 13/24] vhost-user: document migration log, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v7 12/24] vhost: use a function for each call, marcandre . lureau, 2015/10/08