diff mbox series

[RFC,V1,4/6] migration: cpr_get_fd_param helper

Message ID 1725018997-363706-5-git-send-email-steven.sistare@oracle.com (mailing list archive)
State New, archived
Headers show
Series Live Update: tap and vhost | expand

Commit Message

Steven Sistare Aug. 30, 2024, 11:56 a.m. UTC
Add the helper function cpr_get_fd_param, for use by tap and vdpa.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 include/migration/cpr.h |  2 ++
 migration/cpr.c         | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

Comments

Fabiano Rosas Sept. 3, 2024, 3:38 p.m. UTC | #1
Steve Sistare <steven.sistare@oracle.com> writes:

> Add the helper function cpr_get_fd_param, for use by tap and vdpa.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>

Reviewed-by: Fabiano Rosas <farosas@suse.de>
diff mbox series

Patch

diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index 9a76365..b5fa264 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -27,6 +27,8 @@  void cpr_set_cpr_uri(const char *uri);
 int cpr_state_save(Error **errp);
 int cpr_state_load(Error **errp);
 bool cpr_needed_for_reuse(void *opaque);
+int cpr_get_fd_param(const char *name, const char *fdname,
+                     int index, Error **errp);
 
 QEMUFile *cpr_exec_output(Error **errp);
 QEMUFile *cpr_exec_input(Error **errp);
diff --git a/migration/cpr.c b/migration/cpr.c
index 096d684..0940ee2 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -13,6 +13,7 @@ 
 #include "migration/qemu-file.h"
 #include "migration/savevm.h"
 #include "migration/vmstate.h"
+#include "monitor/monitor.h"
 #include "sysemu/runstate.h"
 #include "trace.h"
 
@@ -268,3 +269,28 @@  bool cpr_needed_for_reuse(void *opaque)
     MigMode mode = migrate_mode();
     return mode == MIG_MODE_CPR_EXEC || mode == MIG_MODE_CPR_TRANSFER;
 }
+
+int cpr_get_fd_param(const char *name, const char *fdname, int index,
+                     Error **errp)
+{
+    int fd;
+
+    /*
+     * fd's are passed by name to the monitor when a NIC is hot plugged, but
+     * the name is not known to qemu after cpr.  The manager can pass -1 for
+     * the fd "name" in the new qemu args to indicate that qemu should search
+     * for a saved name.
+     */
+    if (!strcmp(fdname, "-1")) {
+        fd = cpr_find_fd(name, index);
+        if (fd < 0) {
+            error_setg(errp, "cannot find saved value for fd %s", fdname);
+        }
+    } else {
+        fd = monitor_fd_param(monitor_cur(), fdname, errp);
+    }
+    if (fd >= 0) {
+        cpr_resave_fd(name, index, fd);
+    }
+    return fd;
+}