diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2015-10-09 17:17:21 +0200 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2015-10-22 14:34:49 +0300 |
commit | 35f9b6ef3acc9d0546c395a566b04e63ca84e302 (patch) | |
tree | 60c61e946a41bca2bca032ee1481c2933aad364c /util/memfd.c | |
parent | d3592199ba3db504c6585115b9531b4cf7c50a0d (diff) |
util: add fallback for qemu_memfd_alloc()
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 <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Thibaut Collet <thibaut.collet@6wind.com>
Diffstat (limited to 'util/memfd.c')
-rw-r--r-- | util/memfd.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/util/memfd.c b/util/memfd.c index c1194832be..4b23765b4a 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -97,8 +97,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); |