aboutsummaryrefslogtreecommitdiff
path: root/migration/file.c
diff options
context:
space:
mode:
authorSteve Sistare <steven.sistare@oracle.com>2023-09-08 07:22:10 -0700
committerJuan Quintela <quintela@redhat.com>2023-10-04 13:16:58 +0200
commit2a9e2e595f2bc81c07e2f06ef9ba7d4c68897f1c (patch)
tree9737946cbcc59a268faa9c186e3cf4e4a3eaf8dc /migration/file.c
parentb28e3ecf0de1bc77b6a1a520e3c223f37b5afce2 (diff)
downloadqemu-2a9e2e595f2bc81c07e2f06ef9ba7d4c68897f1c.zip
qemu-2a9e2e595f2bc81c07e2f06ef9ba7d4c68897f1c.tar.gz
qemu-2a9e2e595f2bc81c07e2f06ef9ba7d4c68897f1c.tar.bz2
migration: file URI
Extend the migration URI to support file:<filename>. This can be used for any migration scenario that does not require a reverse path. It can be used as an alternative to 'exec:cat > file' in minimized containers that do not contain /bin/sh, and it is easier to use than the fd:<fdname> URI. It can be used in HMP commands, and as a qemu command-line parameter. For best performance, guest ram should be shared and x-ignore-shared should be true, so guest pages are not written to the file, in which case the guest may remain running. If ram is not so configured, then the user is advised to stop the guest first. Otherwise, a busy guest may re-dirty the same page, causing it to be appended to the file multiple times, and the file may grow unboundedly. That issue is being addressed in the "fixed-ram" patch series. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Tested-by: Michael Galaxy <mgalaxy@akamai.com> Reviewed-by: Michael Galaxy <mgalaxy@akamai.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com> Message-ID: <1694182931-61390-2-git-send-email-steven.sistare@oracle.com>
Diffstat (limited to 'migration/file.c')
-rw-r--r--migration/file.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/migration/file.c b/migration/file.c
new file mode 100644
index 0000000..0a65c43
--- /dev/null
+++ b/migration/file.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2021-2023 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "channel.h"
+#include "file.h"
+#include "migration.h"
+#include "io/channel-file.h"
+#include "io/channel-util.h"
+#include "trace.h"
+
+void file_start_outgoing_migration(MigrationState *s, const char *filename,
+ Error **errp)
+{
+ g_autoptr(QIOChannelFile) fioc = NULL;
+ QIOChannel *ioc;
+
+ trace_migration_file_outgoing(filename);
+
+ fioc = qio_channel_file_new_path(filename, O_CREAT | O_WRONLY | O_TRUNC,
+ 0600, errp);
+ if (!fioc) {
+ return;
+ }
+
+ ioc = QIO_CHANNEL(fioc);
+ qio_channel_set_name(ioc, "migration-file-outgoing");
+ migration_channel_connect(s, ioc, NULL, NULL);
+}
+
+static gboolean file_accept_incoming_migration(QIOChannel *ioc,
+ GIOCondition condition,
+ gpointer opaque)
+{
+ migration_channel_process_incoming(ioc);
+ object_unref(OBJECT(ioc));
+ return G_SOURCE_REMOVE;
+}
+
+void file_start_incoming_migration(const char *filename, Error **errp)
+{
+ QIOChannelFile *fioc = NULL;
+ QIOChannel *ioc;
+
+ trace_migration_file_incoming(filename);
+
+ fioc = qio_channel_file_new_path(filename, O_RDONLY, 0, errp);
+ if (!fioc) {
+ return;
+ }
+
+ ioc = QIO_CHANNEL(fioc);
+ qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-incoming");
+ qio_channel_add_watch_full(ioc, G_IO_IN,
+ file_accept_incoming_migration,
+ NULL, NULL,
+ g_main_context_get_thread_default());
+}