qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: haifeng.lin@huawei.com, mst@redhat.com, thibaut.collet@6wind.com,
	jasowang@redhat.com, pbonzini@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v6 06/24] memfd: add fallback for memfd
Date: Tue, 29 Sep 2015 18:34:36 +0200	[thread overview]
Message-ID: <1443544494-28737-7-git-send-email-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <1443544494-28737-1-git-send-email-marcandre.lureau@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Add an open/unlink/mmap fallback for system that do not support memfd.
This patch may require additional SELinux policies to work for enforced
systems, but should gracefully fail nonetheless.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 util/memfd.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/util/memfd.c b/util/memfd.c
index 3168902..970b5b0 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -84,8 +84,26 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals,
             return NULL;
         }
     } else {
-        perror("memfd");
-        return NULL;
+        const char *tmpdir = getenv("TMPDIR");
+        gchar *fname;
+
+        tmpdir = tmpdir ? tmpdir : "/tmp";
+
+        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

  parent reply	other threads:[~2015-09-29 16:35 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29 16:34 [Qemu-devel] [PATCH v6 00/24] vhost-user: add migration support marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 01/24] vhost-user: unit test for new messages marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 02/24] configure: probe for memfd marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 03/24] linux-headers: add unistd.h marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 04/24] util: add linux-only memfd fallback marcandre.lureau
2015-09-30  8:42   ` Michael S. Tsirkin
2015-10-01 17:20     ` Marc-André Lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 05/24] util: add memfd helpers marcandre.lureau
2015-09-30  9:06   ` Michael S. Tsirkin
2015-09-30 14:13     ` Marc-André Lureau
2015-09-29 16:34 ` marcandre.lureau [this message]
2015-09-30  9:03   ` [Qemu-devel] [PATCH v6 06/24] memfd: add fallback for memfd Michael S. Tsirkin
2015-09-30  9:06     ` Marc-André Lureau
2015-09-30  9:08       ` Michael S. Tsirkin
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 07/24] vhost: document log resizing marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 08/24] vhost: add vhost_set_log_base op marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 09/24] vhost-user: add vhost_user_requires_shm_log() marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 10/24] vhost: alloc shareable log marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 11/24] vhost-user: send log shm fd along with log_base marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 12/24] vhost-user: add a migration blocker marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 13/24] vhost: use a function for each call marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 14/24] vhost-user: document migration log marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 15/24] net: add trace_vhost_user_event marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 16/24] vhost user: add support of live migration marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 17/24] vhost user: add rarp sending after live migration for legacy guest marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 18/24] vhost-user-test: move wait_for_fds() out marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 19/24] vhost-user-test: remove useless static check marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 20/24] vhost-user-test: wrap server in TestServer struct marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 21/24] vhost-user-test: learn to tweak various qemu arguments marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 22/24] vhost-user-test: add live-migration test marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 23/24] vhost-user-test: check ownership during migration marcandre.lureau
2015-09-29 16:34 ` [Qemu-devel] [PATCH v6 24/24] vhost-user: use an enum helper for features mask marcandre.lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443544494-28737-7-git-send-email-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=haifeng.lin@huawei.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thibaut.collet@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).