From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 2/5] migrate: vu_migrate_{source,target}() aren't actually vu speciic
Date: Thu, 30 Jan 2025 19:33:27 +1100 [thread overview]
Message-ID: <20250130083330.917030-3-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20250130083330.917030-1-david@gibson.dropbear.id.au>
vu_migrate_source() and vu_migrate_target() don't directly rely on anything
vhost-user specific - it's just that they'll only be called for vhost-user
so far. They are suitable as general top-level dispatchers for
migration. Move them to migrate.c, rename to migrate_{source,target}() and
make the lower-level functions they call local to migrate.c.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
migrate.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++------
migrate.h | 10 ++-----
vu_common.c | 66 ++-----------------------------------------
3 files changed, 75 insertions(+), 81 deletions(-)
diff --git a/migrate.c b/migrate.c
index 6707c029..148cd660 100644
--- a/migrate.c
+++ b/migrate.c
@@ -92,7 +92,7 @@ struct migrate_target_handlers target_handlers[] = {
*
* Return: 0 on success, error code on failure
*/
-int migrate_source_pre(struct ctx *c, struct migrate_meta *m)
+static int migrate_source_pre(struct ctx *c, struct migrate_meta *m)
{
struct migrate_handler *h;
@@ -107,13 +107,13 @@ int migrate_source_pre(struct ctx *c, struct migrate_meta *m)
}
/**
- * migrate_source() - Perform migration as source: send state to hypervisor
+ * migrate_source_state() - Send device state as migration source
* @fd: Descriptor for state transfer
* @m: Migration metadata
*
* Return: 0 on success, error code on failure
*/
-int migrate_source(int fd, const struct migrate_meta *m)
+static int migrate_source_state(int fd, const struct migrate_meta *m)
{
static struct migrate_data *d;
int count, rc;
@@ -139,7 +139,7 @@ int migrate_source(int fd, const struct migrate_meta *m)
*
* Return: 0 on success, error code on failure
*/
-void migrate_source_post(struct ctx *c, struct migrate_meta *m)
+static void migrate_source_post(struct ctx *c, struct migrate_meta *m)
{
struct migrate_handler *h;
@@ -147,6 +147,34 @@ void migrate_source_post(struct ctx *c, struct migrate_meta *m)
h->fn(c, m);
}
+/**
+ * migrate_source() - Migration as source, send state to hypervisor
+ * @c: Execution context
+ * @fd: File descriptor for state transfer
+ *
+ * Return: 0 on success, positive error code on failure
+ */
+int migrate_source(struct ctx *c, int fd)
+{
+ struct migrate_meta m;
+ int rc;
+
+ if ((rc = migrate_source_pre(c, &m))) {
+ err("Source pre-migration failed: %s, abort", strerror_(rc));
+ return rc;
+ }
+
+ debug("Saving backend state");
+
+ rc = migrate_source_state(fd, &m);
+ if (rc)
+ err("Source migration failed: %s", strerror_(rc));
+ else
+ migrate_source_post(c, &m);
+
+ return rc;
+}
+
/**
* migrate_target_read_header() - Set metadata in target from source header
* @fd: Descriptor for state transfer
@@ -154,7 +182,7 @@ void migrate_source_post(struct ctx *c, struct migrate_meta *m)
*
* Return: 0 on success, error code on failure
*/
-int migrate_target_read_header(int fd, struct migrate_meta *m)
+static int migrate_target_read_header(int fd, struct migrate_meta *m)
{
static struct migrate_data *d;
union migrate_header h;
@@ -204,7 +232,7 @@ int migrate_target_read_header(int fd, struct migrate_meta *m)
*
* Return: 0 on success, error code on failure
*/
-int migrate_target_pre(struct ctx *c, struct migrate_meta *m)
+static int migrate_target_pre(struct ctx *c, struct migrate_meta *m)
{
struct migrate_target_handlers *th;
struct migrate_handler *h;
@@ -222,7 +250,7 @@ int migrate_target_pre(struct ctx *c, struct migrate_meta *m)
}
/**
- * migrate_target() - Perform migration as target: receive state from hypervisor
+ * migrate_target_state() - Receive device state as migration target
* @fd: Descriptor for state transfer
* @m: Migration metadata
*
@@ -230,7 +258,7 @@ int migrate_target_pre(struct ctx *c, struct migrate_meta *m)
*
* #syscalls:vu readv
*/
-int migrate_target(int fd, const struct migrate_meta *m)
+static int migrate_target_state(int fd, const struct migrate_meta *m)
{
static struct migrate_data *d;
unsigned cnt;
@@ -253,7 +281,7 @@ int migrate_target(int fd, const struct migrate_meta *m)
* @c: Execution context
* @m: Migration metadata
*/
-void migrate_target_post(struct ctx *c, struct migrate_meta *m)
+static void migrate_target_post(struct ctx *c, struct migrate_meta *m)
{
struct migrate_target_handlers *th;
struct migrate_handler *h;
@@ -263,3 +291,37 @@ void migrate_target_post(struct ctx *c, struct migrate_meta *m)
for (h = th->post; h->fn; h++)
h->fn(c, m);
}
+
+/**
+ * migrate_target() - Migration as target, receive state from hypervisor
+ * @c: Execution context
+ * @fd: File descriptor for state transfer
+ *
+ * Return: 0 on success, positive error code on failure
+ */
+int migrate_target(struct ctx *c, int fd)
+{
+ struct migrate_meta m;
+ int rc;
+
+ rc = migrate_target_read_header(fd, &m);
+ if (rc) {
+ err("Migration header check failed: %s, abort", strerror_(rc));
+ return rc;
+ }
+
+ if ((rc = migrate_target_pre(c, &m))) {
+ err("Target pre-migration failed: %s, abort", strerror_(rc));
+ return rc;
+ }
+
+ debug("Loading backend state");
+
+ rc = migrate_target_state(fd, &m);
+ if (rc)
+ err("Target migration failed: %s", strerror_(rc));
+ else
+ migrate_target_post(c, &m);
+
+ return rc;
+}
diff --git a/migrate.h b/migrate.h
index f9635ac2..edf6303e 100644
--- a/migrate.h
+++ b/migrate.h
@@ -76,13 +76,7 @@ struct migrate_target_handlers {
struct migrate_handler *post;
};
-int migrate_source_pre(struct ctx *c, struct migrate_meta *m);
-int migrate_source(int fd, const struct migrate_meta *m);
-void migrate_source_post(struct ctx *c, struct migrate_meta *m);
-
-int migrate_target_read_header(int fd, struct migrate_meta *m);
-int migrate_target_pre(struct ctx *c, struct migrate_meta *m);
-int migrate_target(int fd, const struct migrate_meta *m);
-void migrate_target_post(struct ctx *c, struct migrate_meta *m);
+int migrate_source(struct ctx *c, int fd);
+int migrate_target(struct ctx *c, int fd);
#endif /* MIGRATE_H */
diff --git a/vu_common.c b/vu_common.c
index c1980d99..d7e39e63 100644
--- a/vu_common.c
+++ b/vu_common.c
@@ -306,68 +306,6 @@ err:
return -1;
}
-/**
- * vu_migrate_source() - Migration as source, send state to hypervisor
- * @c: Execution context
- * @fd: File descriptor for state transfer
- *
- * Return: 0 on success, positive error code on failure
- */
-static int vu_migrate_source(struct ctx *c, int fd)
-{
- struct migrate_meta m;
- int rc;
-
- if ((rc = migrate_source_pre(c, &m))) {
- err("Source pre-migration failed: %s, abort", strerror_(rc));
- return rc;
- }
-
- debug("Saving backend state");
-
- rc = migrate_source(fd, &m);
- if (rc)
- err("Source migration failed: %s", strerror_(rc));
- else
- migrate_source_post(c, &m);
-
- return rc;
-}
-
-/**
- * vu_migrate_target() - Migration as target, receive state from hypervisor
- * @c: Execution context
- * @fd: File descriptor for state transfer
- *
- * Return: 0 on success, positive error code on failure
- */
-static int vu_migrate_target(struct ctx *c, int fd)
-{
- struct migrate_meta m;
- int rc;
-
- rc = migrate_target_read_header(fd, &m);
- if (rc) {
- err("Migration header check failed: %s, abort", strerror_(rc));
- return rc;
- }
-
- if ((rc = migrate_target_pre(c, &m))) {
- err("Target pre-migration failed: %s, abort", strerror_(rc));
- return rc;
- }
-
- debug("Loading backend state");
-
- rc = migrate_target(fd, &m);
- if (rc)
- err("Target migration failed: %s", strerror_(rc));
- else
- migrate_target_post(c, &m);
-
- return rc;
-}
-
/**
* vu_migrate() - Send/receive passt internal state to/from QEMU
* @c: Execution context
@@ -381,9 +319,9 @@ void vu_migrate(struct ctx *c, uint32_t events)
debug("vu_migrate fd %d events %x", vdev->device_state_fd, events);
if (events & EPOLLOUT)
- rc = vu_migrate_source(c, vdev->device_state_fd);
+ rc = migrate_source(c, vdev->device_state_fd);
else if (events & EPOLLIN)
- rc = vu_migrate_target(c, vdev->device_state_fd);
+ rc = migrate_target(c, vdev->device_state_fd);
/* EPOLLHUP without EPOLLIN/EPOLLOUT, or EPOLLERR? Migration failed */
--
@@ -306,68 +306,6 @@ err:
return -1;
}
-/**
- * vu_migrate_source() - Migration as source, send state to hypervisor
- * @c: Execution context
- * @fd: File descriptor for state transfer
- *
- * Return: 0 on success, positive error code on failure
- */
-static int vu_migrate_source(struct ctx *c, int fd)
-{
- struct migrate_meta m;
- int rc;
-
- if ((rc = migrate_source_pre(c, &m))) {
- err("Source pre-migration failed: %s, abort", strerror_(rc));
- return rc;
- }
-
- debug("Saving backend state");
-
- rc = migrate_source(fd, &m);
- if (rc)
- err("Source migration failed: %s", strerror_(rc));
- else
- migrate_source_post(c, &m);
-
- return rc;
-}
-
-/**
- * vu_migrate_target() - Migration as target, receive state from hypervisor
- * @c: Execution context
- * @fd: File descriptor for state transfer
- *
- * Return: 0 on success, positive error code on failure
- */
-static int vu_migrate_target(struct ctx *c, int fd)
-{
- struct migrate_meta m;
- int rc;
-
- rc = migrate_target_read_header(fd, &m);
- if (rc) {
- err("Migration header check failed: %s, abort", strerror_(rc));
- return rc;
- }
-
- if ((rc = migrate_target_pre(c, &m))) {
- err("Target pre-migration failed: %s, abort", strerror_(rc));
- return rc;
- }
-
- debug("Loading backend state");
-
- rc = migrate_target(fd, &m);
- if (rc)
- err("Target migration failed: %s", strerror_(rc));
- else
- migrate_target_post(c, &m);
-
- return rc;
-}
-
/**
* vu_migrate() - Send/receive passt internal state to/from QEMU
* @c: Execution context
@@ -381,9 +319,9 @@ void vu_migrate(struct ctx *c, uint32_t events)
debug("vu_migrate fd %d events %x", vdev->device_state_fd, events);
if (events & EPOLLOUT)
- rc = vu_migrate_source(c, vdev->device_state_fd);
+ rc = migrate_source(c, vdev->device_state_fd);
else if (events & EPOLLIN)
- rc = vu_migrate_target(c, vdev->device_state_fd);
+ rc = migrate_target(c, vdev->device_state_fd);
/* EPOLLHUP without EPOLLIN/EPOLLOUT, or EPOLLERR? Migration failed */
--
2.48.1
next prev parent reply other threads:[~2025-01-30 8:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 8:33 [PATCH 0/5] RFC: Assorted migration improvements David Gibson
2025-01-30 8:33 ` [PATCH 1/5] migrate: Add passt-repair to .gitignore David Gibson
2025-01-30 8:33 ` David Gibson [this message]
2025-01-30 8:33 ` [PATCH 3/5] migrate: Move repair_sock_init() to vu_init() David Gibson
2025-01-30 8:33 ` [PATCH 4/5] migrate: Make more handling common rather than vhost-user specific David Gibson
2025-01-30 8:33 ` [PATCH 5/5] migrate: Don't handle the migration channel through epoll David Gibson
2025-01-31 5:37 ` Stefano Brivio
2025-01-30 8:46 ` [PATCH 0/5] RFC: Assorted migration improvements Stefano Brivio
2025-01-30 8:55 ` David Gibson
2025-01-31 5:46 ` Stefano Brivio
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=20250130083330.917030-3-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).