From: peterx@redhat.com
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: peterx@redhat.com, "Daniel P . Berrangé" <berrange@redhat.com>,
"Prasad Pandit" <ppandit@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>
Subject: [PULL 20/27] migration/multifd: Add outgoing QIOChannelFile support
Date: Mon, 4 Mar 2024 09:26:27 +0800 [thread overview]
Message-ID: <20240304012634.95520-21-peterx@redhat.com> (raw)
In-Reply-To: <20240304012634.95520-1-peterx@redhat.com>
From: Fabiano Rosas <farosas@suse.de>
Allow multifd to open file-backed channels. This will be used when
enabling the mapped-ram migration stream format which expects a
seekable transport.
The QIOChannel read and write methods will use the preadv/pwritev
versions which don't update the file offset at each call so we can
reuse the fd without re-opening for every channel.
Contrary to the socket migration, the file migration doesn't need an
asynchronous channel creation process, so expose
multifd_channel_connect() and call it directly.
Note that this is just setup code and multifd cannot yet make use of
the file channels.
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Peter Xu <peterx@redhat.com>
Link: https://lore.kernel.org/r/20240229153017.2221-18-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/file.h | 4 ++++
migration/multifd.h | 1 +
migration/file.c | 37 +++++++++++++++++++++++++++++++++++++
migration/multifd.c | 18 +++++++++++++++---
4 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/migration/file.h b/migration/file.h
index 37d6a08bfc..4577f9efdd 100644
--- a/migration/file.h
+++ b/migration/file.h
@@ -9,10 +9,14 @@
#define QEMU_MIGRATION_FILE_H
#include "qapi/qapi-types-migration.h"
+#include "io/task.h"
+#include "channel.h"
void file_start_incoming_migration(FileMigrationArgs *file_args, Error **errp);
void file_start_outgoing_migration(MigrationState *s,
FileMigrationArgs *file_args, Error **errp);
int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp);
+void file_cleanup_outgoing_migration(void);
+bool file_send_channel_create(gpointer opaque, Error **errp);
#endif
diff --git a/migration/multifd.h b/migration/multifd.h
index 1d8bbaf96b..db8887f088 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -227,5 +227,6 @@ static inline void multifd_send_prepare_header(MultiFDSendParams *p)
p->iovs_num++;
}
+void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc);
#endif
diff --git a/migration/file.c b/migration/file.c
index 22d052a71f..a350dd61f0 100644
--- a/migration/file.c
+++ b/migration/file.c
@@ -12,12 +12,17 @@
#include "channel.h"
#include "file.h"
#include "migration.h"
+#include "multifd.h"
#include "io/channel-file.h"
#include "io/channel-util.h"
#include "trace.h"
#define OFFSET_OPTION ",offset="
+static struct FileOutgoingArgs {
+ char *fname;
+} outgoing_args;
+
/* Remove the offset option from @filespec and return it in @offsetp. */
int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp)
@@ -37,6 +42,36 @@ int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp)
return 0;
}
+void file_cleanup_outgoing_migration(void)
+{
+ g_free(outgoing_args.fname);
+ outgoing_args.fname = NULL;
+}
+
+bool file_send_channel_create(gpointer opaque, Error **errp)
+{
+ QIOChannelFile *ioc;
+ int flags = O_WRONLY;
+ bool ret = true;
+
+ ioc = qio_channel_file_new_path(outgoing_args.fname, flags, 0, errp);
+ if (!ioc) {
+ ret = false;
+ goto out;
+ }
+
+ multifd_channel_connect(opaque, QIO_CHANNEL(ioc));
+
+out:
+ /*
+ * File channel creation is synchronous. However posting this
+ * semaphore here is simpler than adding a special case.
+ */
+ multifd_send_channel_created();
+
+ return ret;
+}
+
void file_start_outgoing_migration(MigrationState *s,
FileMigrationArgs *file_args, Error **errp)
{
@@ -53,6 +88,8 @@ void file_start_outgoing_migration(MigrationState *s,
return;
}
+ outgoing_args.fname = g_strdup(filename);
+
ioc = QIO_CHANNEL(fioc);
if (offset && qio_channel_io_seek(ioc, offset, SEEK_SET, errp) < 0) {
return;
diff --git a/migration/multifd.c b/migration/multifd.c
index 3574fd3953..caef1076ca 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -17,6 +17,7 @@
#include "exec/ramblock.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
+#include "file.h"
#include "ram.h"
#include "migration.h"
#include "migration-stats.h"
@@ -28,6 +29,7 @@
#include "threadinfo.h"
#include "options.h"
#include "qemu/yank.h"
+#include "io/channel-file.h"
#include "io/channel-socket.h"
#include "yank_functions.h"
@@ -694,6 +696,7 @@ static bool multifd_send_cleanup_channel(MultiFDSendParams *p, Error **errp)
{
if (p->c) {
migration_ioc_unregister_yank(p->c);
+ qio_channel_close(p->c, &error_abort);
object_unref(OBJECT(p->c));
p->c = NULL;
}
@@ -715,6 +718,7 @@ static bool multifd_send_cleanup_channel(MultiFDSendParams *p, Error **errp)
static void multifd_send_cleanup_state(void)
{
+ file_cleanup_outgoing_migration();
socket_cleanup_outgoing_migration();
qemu_sem_destroy(&multifd_send_state->channels_created);
qemu_sem_destroy(&multifd_send_state->channels_ready);
@@ -977,7 +981,7 @@ static bool multifd_tls_channel_connect(MultiFDSendParams *p,
return true;
}
-static void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc)
+void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc)
{
qio_channel_set_delay(ioc, false);
@@ -1045,9 +1049,14 @@ out:
error_free(local_err);
}
-static void multifd_new_send_channel_create(gpointer opaque)
+static bool multifd_new_send_channel_create(gpointer opaque, Error **errp)
{
+ if (!multifd_use_packets()) {
+ return file_send_channel_create(opaque, errp);
+ }
+
socket_send_channel_create(multifd_new_send_channel_async, opaque);
+ return true;
}
bool multifd_send_setup(void)
@@ -1096,7 +1105,10 @@ bool multifd_send_setup(void)
p->page_size = qemu_target_page_size();
p->page_count = page_count;
p->write_flags = 0;
- multifd_new_send_channel_create(p);
+
+ if (!multifd_new_send_channel_create(p, &local_err)) {
+ return false;
+ }
}
/*
--
2.44.0
next prev parent reply other threads:[~2024-03-04 1:31 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-04 1:26 [PULL 00/27] Migration next patches peterx
2024-03-04 1:26 ` [PULL 01/27] migration: massage cpr-reboot documentation peterx
2024-03-04 1:26 ` [PULL 02/27] migration: Properly apply migration compression level parameters peterx
2024-03-04 1:26 ` [PULL 03/27] tests/migration: Set compression level in migration tests peterx
2024-03-04 1:26 ` [PULL 04/27] migration/multifd: Cleanup multifd_recv_sync_main peterx
2024-03-04 1:26 ` [PULL 05/27] io: add and implement QIO_CHANNEL_FEATURE_SEEKABLE for channel file peterx
2024-03-04 1:26 ` [PULL 06/27] io: Add generic pwritev/preadv interface peterx
2024-03-04 1:26 ` [PULL 07/27] io: implement io_pwritev/preadv for QIOChannelFile peterx
2024-03-04 1:26 ` [PULL 08/27] io: fsync before closing a file channel peterx
2024-03-04 1:26 ` [PULL 09/27] migration/qemu-file: add utility methods for working with seekable channels peterx
2024-03-04 1:26 ` [PULL 10/27] migration/ram: Introduce 'mapped-ram' migration capability peterx
2024-03-04 1:26 ` [PULL 11/27] migration: Add mapped-ram URI compatibility check peterx
2024-03-04 1:26 ` [PULL 12/27] migration/ram: Add outgoing 'mapped-ram' migration peterx
2024-03-04 1:26 ` [PULL 13/27] migration/ram: Add incoming " peterx
2024-03-04 1:26 ` [PULL 14/27] tests/qtest/migration: Add tests for mapped-ram file-based migration peterx
2024-03-04 1:26 ` [PULL 15/27] migration/multifd: Rename MultiFDSend|RecvParams::data to compress_data peterx
2024-03-04 1:26 ` [PULL 16/27] migration/multifd: Decouple recv method from pages peterx
2024-03-04 1:26 ` [PULL 17/27] migration/multifd: Allow multifd without packets peterx
2024-03-04 1:26 ` [PULL 18/27] migration/multifd: Allow receiving pages " peterx
2024-03-04 1:26 ` [PULL 19/27] migration/multifd: Add a wrapper for channels_created peterx
2024-03-04 1:26 ` peterx [this message]
2024-03-04 1:26 ` [PULL 21/27] migration/multifd: Add incoming QIOChannelFile support peterx
2024-03-04 1:26 ` [PULL 22/27] migration/multifd: Prepare multifd sync for mapped-ram migration peterx
2024-03-04 1:26 ` [PULL 23/27] migration/multifd: Support outgoing mapped-ram stream format peterx
2024-03-04 1:26 ` [PULL 24/27] migration/multifd: Support incoming " peterx
2024-03-04 1:26 ` [PULL 25/27] migration/multifd: Add mapped-ram support to fd: URI peterx
2024-03-11 11:50 ` Peter Maydell
2024-03-11 11:54 ` Peter Maydell
2024-03-11 12:03 ` Daniel P. Berrangé
2024-03-11 13:30 ` Peter Xu
2024-03-04 1:26 ` [PULL 26/27] tests/qtest/migration: Add a multifd + mapped-ram migration test peterx
2024-03-04 1:26 ` [PULL 27/27] migration/multifd: Document two places for mapped-ram peterx
2024-03-05 13:44 ` [PULL 00/27] Migration next patches Peter Maydell
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=20240304012634.95520-21-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=peter.maydell@linaro.org \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.