]> git.proxmox.com Git - mirror_qemu.git/commitdiff
vhost: add migration block if memfd failed
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Fri, 9 Oct 2015 15:17:34 +0000 (17:17 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 22 Oct 2015 11:34:49 +0000 (14:34 +0300)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Thibaut Collet <thibaut.collet@6wind.com>
hw/virtio/vhost.c
include/qemu/memfd.h
util/memfd.c

index 2e78e4b706c9bc0d42dee238dfef66d94a520983..feeaaa418686c47a01c3f19ef3073730c8ddaada 100644 (file)
@@ -1019,6 +1019,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");
         }
     }
 
index 950fb882a62e4a0210ee51e7cc7409c88b28a76e..53858ed43cfe39a81d4703b098b0ae1417a4d6eb 100644 (file)
@@ -2,6 +2,7 @@
 #define QEMU_MEMFD_H
 
 #include "config-host.h"
+#include <stdbool.h>
 
 #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 */
index 4b23765b4a75bd0f79c5c2ce4357fec136cf9b83..7c406914c592a422a026a363c00ce2977a7154ad 100644 (file)
@@ -138,3 +138,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;
+}