LUO tokens are required as keys to preserve and retrieve LUO fds.

Instead of assigning LUO tokens during fd creation, assign monotonically
increasing LUO tokens to each CprFd only when serializing the CprFd.

We reserve token 1 for the CPR LUO state for later use. Therefore, regular
LUO fd tokens start at 2.

Signed-off-by: Dongli Zhang <[email protected]>
---
 include/migration/cpr.h | 2 ++
 migration/cpr.c         | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index 3bfe91f10f..77e753a278 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -18,6 +18,7 @@
 #define QEMU_CPR_FILE_VERSION   0x00000001
 #define CPR_STATE "CprState"
 #define CPR_LUO_STATE "CprLuoState"
+#define CPR_LUO_STATE_TOKEN 1
 
 typedef struct CprFd {
     char *name;
@@ -25,6 +26,7 @@ typedef struct CprFd {
     int id;
     int fd;
     bool luo;
+    uint64_t luo_token;
     QLIST_ENTRY(CprFd) next;
 } CprFd;
 
diff --git a/migration/cpr.c b/migration/cpr.c
index eaaca6d47d..700e833003 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -49,6 +49,7 @@ static const VMStateDescription vmstate_cpr_luo_fd = {
         VMSTATE_UINT32(namelen, CprFd),
         VMSTATE_VBUFFER_ALLOC_UINT32(name, CprFd, 0, NULL, namelen),
         VMSTATE_INT32(id, CprFd),
+        VMSTATE_UINT64(luo_token, CprFd),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -98,6 +99,7 @@ static int cpr_fd_pre_save(void *opaque)
     GHashTableIter iter;
     CprFd *elem;
     MigMode mode = migrate_mode();
+    uint64_t luo_token = CPR_LUO_STATE_TOKEN + 1;
 
     QLIST_INIT(&state->fds);
 
@@ -107,6 +109,10 @@ static int cpr_fd_pre_save(void *opaque)
             continue;
         }
 
+        if (mode == MIG_MODE_CPR_LUO) {
+            elem->luo_token = luo_token++;
+        }
+
         QLIST_INSERT_HEAD(&state->fds, elem, next);
     }
 
@@ -149,6 +155,7 @@ void cpr_save_fd(const char *name, int id, int fd)
     elem->namelen = strlen(name) + 1;
     elem->id = id;
     elem->fd = fd;
+    elem->luo_token = 0;
     cpr_fd_hash_insert(elem);
 }
 
-- 
2.43.5


Reply via email to