Add helpers to preserve and retrieve LUO fds by calling
LIVEUPDATE_SESSION_PRESERVE_FD or LIVEUPDATE_SESSION_RETRIEVE_FD.

The LUO API is available only on Linux. Provide error stubs on other OSes.

Signed-off-by: Dongli Zhang <[email protected]>
---
 include/migration/cpr.h  |  3 +++
 migration/cpr-luo-stub.c | 11 +++++++++++
 migration/cpr-luo.c      | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index f8b161b3d6..5f30df7ec8 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -77,4 +77,7 @@ void cpr_exec_unpreserve_fds(void);
 
 int cpr_luo_create_session(const char *name, Error **errp);
 int cpr_luo_retrieve_session(const char *name, Error **errp);
+int cpr_luo_preserve_fd(int session_fd, int fd, uint64_t token,
+                        Error **errp);
+int cpr_luo_retrieve_fd(int session_fd, uint64_t token, Error **errp);
 #endif
diff --git a/migration/cpr-luo-stub.c b/migration/cpr-luo-stub.c
index ca060ae8c8..ab64e1f99b 100644
--- a/migration/cpr-luo-stub.c
+++ b/migration/cpr-luo-stub.c
@@ -24,3 +24,14 @@ int cpr_luo_retrieve_session(const char *name, Error **errp)
 {
     return cpr_luo_unsupported(errp);
 }
+
+int cpr_luo_preserve_fd(int session_fd, int fd, uint64_t token,
+                        Error **errp)
+{
+    return cpr_luo_unsupported(errp);
+}
+
+int cpr_luo_retrieve_fd(int session_fd, uint64_t token, Error **errp)
+{
+    return cpr_luo_unsupported(errp);
+}
diff --git a/migration/cpr-luo.c b/migration/cpr-luo.c
index 48288ed5f9..f6e0e23657 100644
--- a/migration/cpr-luo.c
+++ b/migration/cpr-luo.c
@@ -72,3 +72,36 @@ int cpr_luo_retrieve_session(const char *name, Error **errp)
     close(fd);
     return retrieve.fd;
 }
+
+int cpr_luo_preserve_fd(int session_fd, int fd, uint64_t token,
+                        Error **errp)
+{
+    struct liveupdate_session_preserve_fd preserve = {
+        .size = sizeof(preserve),
+        .fd = fd,
+        .token = token,
+    };
+
+    if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &preserve) < 0) {
+        error_setg_errno(errp, errno, "failed to preserve fd %d with LUO",
+                         fd);
+        return -1;
+    }
+
+    return 0;
+}
+
+int cpr_luo_retrieve_fd(int session_fd, uint64_t token, Error **errp)
+{
+    struct liveupdate_session_retrieve_fd retrieve = {
+        .size = sizeof(retrieve),
+        .token = token,
+    };
+
+    if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &retrieve) < 0) {
+        error_setg_errno(errp, errno, "failed to retrieve LUO fd");
+        return -1;
+    }
+
+    return retrieve.fd;
+}
-- 
2.43.5


Reply via email to