提交 31190ed7 编写于 作者: M Marc-André Lureau 提交者: Michael S. Tsirkin

vhost: add migration block if memfd failed

Signed-off-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
Tested-by: NThibaut Collet <thibaut.collet@6wind.com>
上级 de1372d4
......@@ -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");
}
}
......
......@@ -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 */
......@@ -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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册