From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkIYY-0005xo-BY for qemu-devel@nongnu.org; Thu, 08 Oct 2015 17:16:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkIYX-00077y-EB for qemu-devel@nongnu.org; Thu, 08 Oct 2015 17:16:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkIYX-00077p-9m for qemu-devel@nongnu.org; Thu, 08 Oct 2015 17:16:53 -0400 Date: Fri, 9 Oct 2015 00:16:49 +0300 From: "Michael S. Tsirkin" Message-ID: <1444338957-15293-6-git-send-email-mst@redhat.com> References: <1444338957-15293-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1444338957-15293-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 05/25] util: add fallback for qemu_memfd_alloc() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?us-ascii?B?PT9VVEYtOD9xP01hcmMtQW5kcj1DMz1BOT0yMEx1cmVhdT89?= From: Marc-Andr=E9 Lureau 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=E9 Lureau Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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 =3D g_get_tmp_dir(); + gchar *fname; + + fname =3D g_strdup_printf("%s/memfd-XXXXXX", tmpdir); + mfd =3D mkstemp(fname); + unlink(fname); + g_free(fname); + + if (mfd =3D=3D -1) { + perror("mkstemp"); + return NULL; + } + + if (ftruncate(mfd, size) =3D=3D -1) { + perror("ftruncate"); + close(mfd); + return NULL; + } } =20 ptr =3D mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); --=20 MST