diff mbox series

[RFC,V1,04/12] migration: cpr_find_fd_any

Message ID 1721502937-87102-5-git-send-email-steven.sistare@oracle.com
State New
Headers show
Series Live update: iommufd | expand

Commit Message

Steven Sistare July 20, 2024, 7:15 p.m. UTC
Add a function for finding a CPR fd by name, for any value of id, and
return the id.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 include/migration/cpr.h |  1 +
 migration/cpr.c         | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index bfd9864..c9e6111 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -19,6 +19,7 @@  typedef int (*cpr_walk_fd_cb)(int fd);
 void cpr_save_fd(const char *name, int id, int fd);
 void cpr_delete_fd(const char *name, int id);
 int cpr_find_fd(const char *name, int id);
+int cpr_find_fd_any(const char *name, int *id_p);
 int cpr_walk_fd(cpr_walk_fd_cb cb);
 void cpr_resave_fd(const char *name, int id, int fd);
 
diff --git a/migration/cpr.c b/migration/cpr.c
index 853d3a1..096e8d8 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -109,6 +109,21 @@  int cpr_find_fd(const char *name, int id)
     return fd;
 }
 
+int cpr_find_fd_any(const char *name, int *id_p)
+{
+    CprFd *elem;
+
+    QLIST_FOREACH(elem, &cpr_state.fds, next) {
+        if (!strcmp(elem->name, name)) {
+            trace_cpr_find_fd(name, elem->id, elem->fd);
+            *id_p = elem->id;
+            return elem->fd;
+        }
+    }
+    trace_cpr_find_fd(name, -1, -1);
+    return -1;
+}
+
 int cpr_walk_fd(cpr_walk_fd_cb cb)
 {
     CprFd *elem;