Received: from eggs.gnu.org ([2001:4830:134:3::10]:38726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhhbP-0008My-9M for qemu-devel@nongnu.org; Thu, 01 Oct 2015 13:25:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhhbO-0000pE-Cr for qemu-devel@nongnu.org; Thu, 01 Oct 2015 13:25:07 -0400 Received: from mail-qg0-x234.google.com ([2607:f8b0:400d:c04::234]:34601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhhbO-0000oT-8s for qemu-devel@nongnu.org; Thu, 01 Oct 2015 13:25:06 -0400 Received: by qgez77 with SMTP id z77so73354583qge.1 for ; Thu, 01 Oct 2015 10:25:06 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Thu, 1 Oct 2015 19:24:02 +0200 Message-Id: <1443720248-15482-19-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1443720248-15482-1-git-send-email-marcandre.lureau@redhat.com> References: <1443720248-15482-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v7 18/24] vhost: add migration block if memfd failed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: haifeng.lin@huawei.com, mst@redhat.com, thibaut.collet@6wind.com, jasowang@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau Signed-off-by: Marc-André Lureau --- hw/virtio/vhost.c | 3 +++ include/qemu/memfd.h | 2 ++ util/memfd.c | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 1e8ee76..eaf8117 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -994,6 +994,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL feature."); + } else if (!qemu_memfd_check()) { + error_setg(&hdev->migration_blocker, + "Migration disabled: failed to allocate shared memory"); } } diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h index 950fb88..53858ed 100644 --- a/include/qemu/memfd.h +++ b/include/qemu/memfd.h @@ -2,6 +2,7 @@ #define QEMU_MEMFD_H #include "config-host.h" +#include #ifndef F_LINUX_SPECIFIC_BASE #define F_LINUX_SPECIFIC_BASE 1024 @@ -20,5 +21,6 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, int *fd); void qemu_memfd_free(void *ptr, size_t size, int fd); +bool qemu_memfd_check(void); #endif /* QEMU_MEMFD_H */ diff --git a/util/memfd.c b/util/memfd.c index ff577b5..2632436 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -141,3 +141,25 @@ void qemu_memfd_free(void *ptr, size_t size, int fd) close(fd); } } + +enum { + MEMFD_KO, + MEMFD_OK, + MEMFD_TODO +}; + +bool qemu_memfd_check(void) +{ + static int memfd_check = MEMFD_TODO; + + if (memfd_check == MEMFD_TODO) { + int fd; + void *ptr; + + ptr = qemu_memfd_alloc("test", 4096, 0, &fd); + memfd_check = ptr ? MEMFD_OK : MEMFD_KO; + qemu_memfd_free(ptr, 4096, fd); + } + + return memfd_check == MEMFD_OK; +} -- 2.4.3