[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 27/38] vhost: add migration block if memfd failed
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 27/38] vhost: add migration block if memfd failed |
Date: |
Wed, 21 Oct 2015 13:28:04 +0300 |
From: Marc-André Lureau <address@hidden>
Signed-off-by: Marc-André Lureau <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Tested-by: Thibaut Collet <address@hidden>
---
include/qemu/memfd.h | 2 ++
hw/virtio/vhost.c | 3 +++
util/memfd.c | 22 ++++++++++++++++++++++
3 files changed, 27 insertions(+)
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 <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 */
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 2e78e4b..feeaaa4 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -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");
}
}
diff --git a/util/memfd.c b/util/memfd.c
index 4b23765..7c40691 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -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;
+}
--
MST
- [Qemu-devel] [PULL 17/38] vhost-user: add vhost_user_requires_shm_log(), (continued)
- [Qemu-devel] [PULL 17/38] vhost-user: add vhost_user_requires_shm_log(), Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 18/38] vhost: alloc shareable log, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 19/38] vhost-user: send log shm fd along with log_base, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 20/38] vhost-user: add a migration blocker, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 22/38] vhost-user: document migration log, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 21/38] vhost: use a function for each call, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 23/38] net: add trace_vhost_user_event, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 24/38] vhost user: add support of live migration, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 25/38] vhost user: add rarp sending after live migration for legacy guest, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 26/38] vhost-user: use an enum helper for features mask, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 27/38] vhost: add migration block if memfd failed,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 28/38] vhost-user-test: move wait_for_fds() out, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 29/38] vhost-user-test: remove useless static check, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 30/38] vhost-user-test: wrap server in TestServer struct, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 31/38] vhost-user-test: learn to tweak various qemu arguments, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 32/38] vhost-user-test: add live-migration test, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 33/38] vhost-user-test: check ownership during migration, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 34/38] seccomp: add memfd_create to whitelist, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 35/38] piix: fix resource leak reported by Coverity, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 36/38] vhost: set the correct queue index in case of migration with multiqueue, Michael S. Tsirkin, 2015/10/21
- [Qemu-devel] [PULL 38/38] hw/isa/lpc_ich9: inject the SMI on the VCPU that is writing to APM_CNT, Michael S. Tsirkin, 2015/10/21