diff mbox series

[V9,28/46] hostmem-epc: cpr support

Message ID 1658851843-236870-29-git-send-email-steven.sistare@oracle.com (mailing list archive)
State New, archived
Headers show
Series Live Update | expand

Commit Message

Steven Sistare July 26, 2022, 4:10 p.m. UTC
Preserve memory-backend-epc memory objects during cpr.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 backends/hostmem-epc.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c
index 037292d..c6b1fe4 100644
--- a/backends/hostmem-epc.c
+++ b/backends/hostmem-epc.c
@@ -16,32 +16,34 @@ 
 #include "qapi/error.h"
 #include "sysemu/hostmem.h"
 #include "hw/i386/hostmem-epc.h"
+#include "migration/cpr-state.h"
 
 static void
 sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
 {
     uint32_t ram_flags;
-    char *name;
-    int fd;
+    g_autofree char *name = object_get_canonical_path(OBJECT(backend));
+    int fd = cpr_find_fd(name, 0);
 
     if (!backend->size) {
         error_setg(errp, "can't create backend with size 0");
         return;
     }
 
-    fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
     if (fd < 0) {
-        error_setg_errno(errp, errno,
-                         "failed to open /dev/sgx_vepc to alloc SGX EPC");
-        return;
+        fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
+        if (fd < 0) {
+            error_setg_errno(errp, errno,
+                            "failed to open /dev/sgx_vepc to alloc SGX EPC");
+            return;
+        }
+        cpr_save_fd(name, 0, fd);
     }
 
-    name = object_get_canonical_path(OBJECT(backend));
     ram_flags = (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED;
     memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend),
                                    name, backend->size, ram_flags,
                                    fd, 0, errp);
-    g_free(name);
 }
 
 static void sgx_epc_backend_instance_init(Object *obj)