From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202412 header.b=QheiHZLV; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 211DE5A026F for ; Thu, 30 Jan 2025 09:33:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202412; t=1738226003; bh=y1ieGCIv7RO4CF0ZbOnINQpwCH0y5AtZHSTpO4eLyPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QheiHZLVNErP5IzO6f8WGsMAOxhDRRzOWWJfUb35Taj3gS+cuJh7Qx0SPS7/PP5Wp hwb8DKzXsMc0z5J5tSyTfUIIBuvWke7Icknph8LLzEir++G8jO7fsfXKzc5dRGUTdO +p/FENMtF6+nQp753EzR2P+aoUJCBsC+agS3telDoVhd3sk0I3P30dwMLlnvim17iX +WG6bsSTn5Hdfyrl/MAF8lSgJ57ItN4lg/LAh6dGdDpclz0wwypRjQeM5g/jRlo+Qq oS/HJ9+QxPLqCO8ZbFtmo2LJ9pCkziMaSAfQuER0qEhgyqyte2V4K4Yr5sC1aMINT/ xGuN/ZlGshueQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4YkC376sQRz4x5m; Thu, 30 Jan 2025 19:33:23 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/5] migrate: vu_migrate_{source,target}() aren't actually vu speciic Date: Thu, 30 Jan 2025 19:33:27 +1100 Message-ID: <20250130083330.917030-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250130083330.917030-1-david@gibson.dropbear.id.au> References: <20250130083330.917030-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 4CYFV6DV4AYXRPUDX45TIN7DJ277QQ34 X-Message-ID-Hash: 4CYFV6DV4AYXRPUDX45TIN7DJ277QQ34 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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 */ -- 2.48.1