@@ -15,6 +15,7 @@
#include "sysemu/sysemu.h"
#include "qom/object_interfaces.h"
#include "qemu/memfd.h"
+#include "qemu/env.h"
#include "qemu/module.h"
#include "qapi/error.h"
#include "qom/object.h"
@@ -36,23 +37,25 @@ static void
memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
{
HostMemoryBackendMemfd *m = MEMORY_BACKEND_MEMFD(backend);
- char *name;
- int fd;
+ char *name = host_memory_backend_get_name(backend);
+ int fd = getenv_fd(name);
if (!backend->size) {
error_setg(errp, "can't create backend with size 0");
return;
}
- fd = qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size,
- m->hugetlb, m->hugetlbsize, m->seal ?
- F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL : 0,
- errp);
- if (fd == -1) {
- return;
+ if (fd < 0) {
+ fd = qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size,
+ m->hugetlb, m->hugetlbsize, m->seal ?
+ F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL : 0,
+ errp);
+ if (fd == -1) {
+ return;
+ }
+ setenv_fd(name, fd);
}
- name = host_memory_backend_get_name(backend);
memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend),
name, backend->size,
backend->share, fd, 0, errp);
Preserve memory-backend-memfd memory objects during cpr. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> --- backends/hostmem-memfd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)