qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
	"Steve Sistare" <steven.sistare@oracle.com>,
	"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 10/27] migration: cpr helpers
Date: Wed, 11 Jun 2025 17:06:02 +0200	[thread overview]
Message-ID: <20250611150620.701903-11-clg@redhat.com> (raw)
In-Reply-To: <20250611150620.701903-1-clg@redhat.com>

From: Steve Sistare <steven.sistare@oracle.com>

Add the cpr_incoming_needed, cpr_open_fd, and cpr_resave_fd helpers,
for use when adding cpr support for vfio and iommufd.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/1749569991-25171-2-git-send-email-steven.sistare@oracle.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/migration/cpr.h |  5 +++++
 migration/cpr.c         | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index 7561fc75adc5e25f11726c199a22de831082d802..07858e93fa2fbd9ca0c31af218216025c14369a6 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -18,6 +18,9 @@
 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);
+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);
 
 MigMode cpr_get_incoming_mode(void);
 void cpr_set_incoming_mode(MigMode mode);
@@ -28,6 +31,8 @@ int cpr_state_load(MigrationChannel *channel, Error **errp);
 void cpr_state_close(void);
 struct QIOChannel *cpr_state_ioc(void);
 
+bool cpr_incoming_needed(void *opaque);
+
 QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp);
 QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp);
 
diff --git a/migration/cpr.c b/migration/cpr.c
index 42c46563e522d43e68c49b2de7b4d45bb56bf662..a50a57edca754b50e68fa9c294b3c89791e62ba8 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -95,6 +95,36 @@ int cpr_find_fd(const char *name, int id)
     trace_cpr_find_fd(name, id, fd);
     return fd;
 }
+
+void cpr_resave_fd(const char *name, int id, int fd)
+{
+    CprFd *elem = find_fd(&cpr_state.fds, name, id);
+    int old_fd = elem ? elem->fd : -1;
+
+    if (old_fd < 0) {
+        cpr_save_fd(name, id, fd);
+    } else if (old_fd != fd) {
+        error_setg(&error_fatal,
+                   "internal error: cpr fd '%s' id %d value %d "
+                   "already saved with a different value %d",
+                   name, id, fd, old_fd);
+    }
+}
+
+int cpr_open_fd(const char *path, int flags, const char *name, int id,
+                Error **errp)
+{
+    int fd = cpr_find_fd(name, id);
+
+    if (fd < 0) {
+        fd = qemu_open(path, flags, errp);
+        if (fd >= 0) {
+            cpr_save_fd(name, id, fd);
+        }
+    }
+    return fd;
+}
+
 /*************************************************************************/
 #define CPR_STATE "CprState"
 
@@ -228,3 +258,9 @@ void cpr_state_close(void)
         cpr_state_file = NULL;
     }
 }
+
+bool cpr_incoming_needed(void *opaque)
+{
+    MigMode mode = migrate_mode();
+    return mode == MIG_MODE_CPR_TRANSFER;
+}
-- 
2.49.0



  parent reply	other threads:[~2025-06-11 15:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11 15:05 [PULL 00/27] vfio queue Cédric Le Goater
2025-06-11 15:05 ` [PULL 01/27] vfio/container: Fix vfio_listener_commit() Cédric Le Goater
2025-06-11 15:05 ` [PULL 02/27] vfio/pci: Fix instance_size of VFIO_PCI_BASE Cédric Le Goater
2025-06-11 15:05 ` [PULL 03/27] hw/vfio/ap: notification handler for AP config changed event Cédric Le Goater
2025-06-11 15:05 ` [PULL 04/27] hw/vfio/ap: store object indicating AP config changed in a queue Cédric Le Goater
2025-06-11 15:05 ` [PULL 05/27] hw/vfio/ap: Storing event information for an AP configuration change event Cédric Le Goater
2025-06-11 15:05 ` [PULL 06/27] s390: implementing CHSC SEI for AP config change Cédric Le Goater
2025-06-11 15:05 ` [PULL 07/27] vfio: export PCI helpers needed for vfio-user Cédric Le Goater
2025-06-11 15:06 ` [PULL 08/27] vfio: add per-region fd support Cédric Le Goater
2025-06-11 15:06 ` [PULL 09/27] vfio: mark posted writes in region write callbacks Cédric Le Goater
2025-06-11 15:06 ` Cédric Le Goater [this message]
2025-06-11 15:06 ` [PULL 11/27] migration: lower handler priority Cédric Le Goater
2025-06-11 15:06 ` [PULL 12/27] vfio/container: register container for cpr Cédric Le Goater
2025-06-11 15:06 ` [PULL 13/27] vfio/container: preserve descriptors Cédric Le Goater
2025-06-11 15:06 ` [PULL 14/27] vfio/container: discard old DMA vaddr Cédric Le Goater
2025-06-11 15:06 ` [PULL 15/27] vfio/container: restore " Cédric Le Goater
2025-06-11 15:06 ` [PULL 16/27] vfio/container: mdev cpr blocker Cédric Le Goater
2025-06-11 15:06 ` [PULL 17/27] vfio/container: recover from unmap-all-vaddr failure Cédric Le Goater
2025-06-11 15:06 ` [PULL 18/27] pci: export msix_is_pending Cédric Le Goater
2025-06-11 15:06 ` [PULL 19/27] pci: skip reset during cpr Cédric Le Goater
2025-06-11 15:06 ` [PULL 20/27] vfio-pci: " Cédric Le Goater
2025-06-11 15:06 ` [PULL 21/27] vfio/pci: vfio_pci_vector_init Cédric Le Goater
2025-06-11 15:06 ` [PULL 22/27] vfio/pci: vfio_notifier_init Cédric Le Goater
2025-06-11 15:06 ` [PULL 23/27] vfio/pci: pass vector to virq functions Cédric Le Goater
2025-06-11 15:06 ` [PULL 24/27] vfio/pci: vfio_notifier_init cpr parameters Cédric Le Goater
2025-06-11 15:06 ` [PULL 25/27] vfio/pci: vfio_notifier_cleanup Cédric Le Goater
2025-06-11 15:06 ` [PULL 26/27] vfio/pci: export MSI functions Cédric Le Goater
2025-06-11 15:06 ` [PULL 27/27] vfio: improve VFIODeviceIOOps docs Cédric Le Goater
2025-06-11 18:22 ` [PULL 00/27] vfio queue Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250611150620.701903-11-clg@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=steven.sistare@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).