cpr-luo requires walking through each LUO-supported fd to preserve it.
Unlike cpr-exec or cpr-transfer, which only require the fd value, cpr-luo
requires additional information, such as a token, to preserve an fd.

In addition, we may want to return more values, such as a retrieved fd
based on a session fd and token, and pass errp when an error occurs.

Therefore, rework cpr_walk_fd() by adding more arguments for
flexibility.

Remove the assertion on elem->fd, since cpr-luo does not save or load the
fd itself, only its name, ID, and token.

Signed-off-by: Dongli Zhang <[email protected]>
---
 include/migration/cpr.h |  4 ++--
 migration/cpr-exec.c    | 12 ++++++------
 migration/cpr.c         |  5 ++---
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index 4897d302f1..775f584368 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -49,8 +49,8 @@ void cpr_resave_fd(const char *name, int id, int fd);
 int cpr_open_fd(const char *path, int flags, const char *name, int id,
                 Error **errp);
 
-typedef bool (*cpr_walk_fd_cb)(int fd);
-bool cpr_walk_fd(cpr_walk_fd_cb cb);
+typedef bool (*cpr_walk_fd_cb)(CprFd *fd, Error **errp);
+bool cpr_walk_fd(cpr_walk_fd_cb cb, Error **errp);
 
 MigMode cpr_get_incoming_mode(void);
 void cpr_set_incoming_mode(MigMode mode);
diff --git a/migration/cpr-exec.c b/migration/cpr-exec.c
index b31ec3e59f..06cbced7e0 100644
--- a/migration/cpr-exec.c
+++ b/migration/cpr-exec.c
@@ -94,26 +94,26 @@ QEMUFile *cpr_exec_input(Error **errp)
     return cpr_file_new_fd_input(mfd, CPR_EXEC_STATE_NAME);
 }
 
-static bool preserve_fd(int fd)
+static bool preserve_fd(CprFd *elem, Error **errp)
 {
-    qemu_clear_cloexec(fd);
+    qemu_clear_cloexec(elem->fd);
     return true;
 }
 
-static bool unpreserve_fd(int fd)
+static bool unpreserve_fd(CprFd *elem, Error **errp)
 {
-    qemu_set_cloexec(fd);
+    qemu_set_cloexec(elem->fd);
     return true;
 }
 
 static void cpr_exec_preserve_fds(void)
 {
-    cpr_walk_fd(preserve_fd);
+    cpr_walk_fd(preserve_fd, NULL);
 }
 
 void cpr_exec_unpreserve_fds(void)
 {
-    cpr_walk_fd(unpreserve_fd);
+    cpr_walk_fd(unpreserve_fd, NULL);
 }
 
 static void cpr_exec_cb(void *opaque)
diff --git a/migration/cpr.c b/migration/cpr.c
index 2253fddb42..bc4d1e979d 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -230,15 +230,14 @@ int cpr_open_fd(const char *path, int flags, const char 
*name, int id,
     return fd;
 }
 
-bool cpr_walk_fd(cpr_walk_fd_cb cb)
+bool cpr_walk_fd(cpr_walk_fd_cb cb, Error **errp)
 {
     GHashTableIter iter;
     CprFd *elem;
 
     g_hash_table_iter_init(&iter, get_cpr_fds_hash());
     while (g_hash_table_iter_next(&iter, (gpointer *)&elem, NULL)) {
-        g_assert(elem->fd >= 0);
-        if (!cb(elem->fd)) {
+        if (!cb(elem, errp)) {
             return false;
         }
     }
-- 
2.43.5


Reply via email to