From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhDIn-0001fb-Jk for qemu-devel@nongnu.org; Wed, 30 Sep 2015 05:03:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhDIi-0005gU-JU for qemu-devel@nongnu.org; Wed, 30 Sep 2015 05:03:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45722) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhDIi-0005gJ-EU for qemu-devel@nongnu.org; Wed, 30 Sep 2015 05:03:48 -0400 Date: Wed, 30 Sep 2015 12:03:42 +0300 From: "Michael S. Tsirkin" Message-ID: <20150930120224-mutt-send-email-mst@redhat.com> References: <1443544494-28737-1-git-send-email-marcandre.lureau@redhat.com> <1443544494-28737-7-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1443544494-28737-7-git-send-email-marcandre.lureau@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v6 06/24] memfd: add fallback for memfd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com Cc: haifeng.lin@huawei.com, thibaut.collet@6wind.com, jasowang@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com On Tue, Sep 29, 2015 at 06:34:36PM +0200, marcandre.lureau@redhat.com wro= te: > From: Marc-Andr=E9 Lureau >=20 > 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. >=20 > Signed-off-by: Marc-Andr=E9 Lureau I'd rather just fail migration. > --- > util/memfd.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) >=20 > 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 =3D getenv("TMPDIR"); > + gchar *fname; > + > + tmpdir =3D tmpdir ? tmpdir : "/tmp"; > + > + 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 > 2.4.3