On Wed, Sep 30, 2015 at 05:06:55AM -0400, Marc-André Lureau wrote:
> Hi
>
> ----- Original Message -----
> > On Tue, Sep 29, 2015 at 06:34:36PM +0200, [email protected] wrote:
> > > From: Marc-André Lureau <[email protected]>
> > >
> > > 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 <[email protected]>
> >
> > I'd rather just fail migration.
>
> So we don't provide this compatibility code and migration should fail.
>
> Would it be enough to check if memfd works at early runtime and add a
> migration blocker for vhost-user? Or is it possible to recover if migration
> fails when memfd fails to allocate? I would thing the former is better.
Fine with me.
> >
> > > ---
> > > 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
> >