migration/multifd: Add outgoing QIOChannelFile support
Allow multifd to open file-backed channels. This will be used when enabling the fixed-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. 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>
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#define QIO_CHANNEL_FILE_H
|
#define QIO_CHANNEL_FILE_H
|
||||||
|
|
||||||
#include "io/channel.h"
|
#include "io/channel.h"
|
||||||
|
#include "io/task.h"
|
||||||
#include "qom/object.h"
|
#include "qom/object.h"
|
||||||
|
|
||||||
#define TYPE_QIO_CHANNEL_FILE "qio-channel-file"
|
#define TYPE_QIO_CHANNEL_FILE "qio-channel-file"
|
||||||
|
@@ -1,20 +1,77 @@
|
|||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "channel.h"
|
|
||||||
#include "io/channel-file.h"
|
#include "io/channel-file.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "qemu/error-report.h"
|
#include "qemu/error-report.h"
|
||||||
|
|
||||||
|
static struct FileOutgoingArgs {
|
||||||
|
char *fname;
|
||||||
|
int flags;
|
||||||
|
int mode;
|
||||||
|
} outgoing_args;
|
||||||
|
|
||||||
|
static void qio_channel_file_connect_worker(QIOTask *task, gpointer opaque)
|
||||||
|
{
|
||||||
|
/* noop */
|
||||||
|
}
|
||||||
|
|
||||||
|
static void file_migration_cancel(Error *errp)
|
||||||
|
{
|
||||||
|
MigrationState *s;
|
||||||
|
|
||||||
|
s = migrate_get_current();
|
||||||
|
|
||||||
|
migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
|
||||||
|
MIGRATION_STATUS_FAILED);
|
||||||
|
migration_cancel(errp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int file_send_channel_destroy(QIOChannel *ioc)
|
||||||
|
{
|
||||||
|
if (ioc) {
|
||||||
|
qio_channel_close(ioc, NULL);
|
||||||
|
object_unref(OBJECT(ioc));
|
||||||
|
}
|
||||||
|
g_free(outgoing_args.fname);
|
||||||
|
outgoing_args.fname = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void file_send_channel_create(QIOTaskFunc f, void *data)
|
||||||
|
{
|
||||||
|
QIOChannelFile *ioc;
|
||||||
|
QIOTask *task;
|
||||||
|
Error *errp = NULL;
|
||||||
|
|
||||||
|
ioc = qio_channel_file_new_path(outgoing_args.fname,
|
||||||
|
outgoing_args.flags,
|
||||||
|
outgoing_args.mode, &errp);
|
||||||
|
if (!ioc) {
|
||||||
|
file_migration_cancel(errp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
task = qio_task_new(OBJECT(ioc), f, (gpointer)data, NULL);
|
||||||
|
qio_task_run_in_thread(task, qio_channel_file_connect_worker,
|
||||||
|
(gpointer)data, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void file_start_outgoing_migration(MigrationState *s, const char *fname, Error **errp)
|
void file_start_outgoing_migration(MigrationState *s, const char *fname, Error **errp)
|
||||||
{
|
{
|
||||||
QIOChannelFile *ioc;
|
QIOChannelFile *ioc;
|
||||||
|
int flags = O_CREAT | O_TRUNC | O_WRONLY;
|
||||||
|
mode_t mode = 0660;
|
||||||
|
|
||||||
ioc = qio_channel_file_new_path(fname, O_CREAT | O_TRUNC | O_WRONLY, 0660, errp);
|
ioc = qio_channel_file_new_path(fname, flags, mode, errp);
|
||||||
if (!ioc) {
|
if (!ioc) {
|
||||||
error_report("Error creating a channel");
|
error_report("Error creating migration outgoing channel");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outgoing_args.fname = g_strdup(fname);
|
||||||
|
outgoing_args.flags = flags;
|
||||||
|
outgoing_args.mode = mode;
|
||||||
|
|
||||||
qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-outgoing");
|
qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-outgoing");
|
||||||
migration_channel_connect(s, QIO_CHANNEL(ioc), NULL, NULL);
|
migration_channel_connect(s, QIO_CHANNEL(ioc), NULL, NULL);
|
||||||
object_unref(OBJECT(ioc));
|
object_unref(OBJECT(ioc));
|
||||||
|
@@ -1,10 +1,14 @@
|
|||||||
#ifndef QEMU_MIGRATION_FILE_H
|
#ifndef QEMU_MIGRATION_FILE_H
|
||||||
#define QEMU_MIGRATION_FILE_H
|
#define QEMU_MIGRATION_FILE_H
|
||||||
|
|
||||||
|
#include "io/task.h"
|
||||||
|
#include "channel.h"
|
||||||
|
|
||||||
void file_start_outgoing_migration(MigrationState *s,
|
void file_start_outgoing_migration(MigrationState *s,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
|
|
||||||
void file_start_incoming_migration(const char *fname, Error **errp);
|
void file_start_incoming_migration(const char *fname, Error **errp);
|
||||||
|
void file_send_channel_create(QIOTaskFunc f, void *data);
|
||||||
|
int file_send_channel_destroy(QIOChannel *ioc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -106,7 +106,7 @@ static bool migration_needs_multiple_sockets(void)
|
|||||||
static bool uri_supports_multi_channels(const char *uri)
|
static bool uri_supports_multi_channels(const char *uri)
|
||||||
{
|
{
|
||||||
return strstart(uri, "tcp:", NULL) || strstart(uri, "unix:", NULL) ||
|
return strstart(uri, "tcp:", NULL) || strstart(uri, "unix:", NULL) ||
|
||||||
strstart(uri, "vsock:", NULL);
|
strstart(uri, "vsock:", NULL) || strstart(uri, "file:", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include "exec/ramblock.h"
|
#include "exec/ramblock.h"
|
||||||
#include "qemu/error-report.h"
|
#include "qemu/error-report.h"
|
||||||
#include "qapi/error.h"
|
#include "qapi/error.h"
|
||||||
|
#include "file.h"
|
||||||
#include "ram.h"
|
#include "ram.h"
|
||||||
#include "migration.h"
|
#include "migration.h"
|
||||||
#include "migration-stats.h"
|
#include "migration-stats.h"
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
#include "threadinfo.h"
|
#include "threadinfo.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "qemu/yank.h"
|
#include "qemu/yank.h"
|
||||||
|
#include "io/channel-file.h"
|
||||||
#include "io/channel-socket.h"
|
#include "io/channel-socket.h"
|
||||||
#include "yank_functions.h"
|
#include "yank_functions.h"
|
||||||
|
|
||||||
@@ -512,7 +514,11 @@ static void multifd_send_terminate_threads(Error *err)
|
|||||||
|
|
||||||
static int multifd_send_channel_destroy(QIOChannel *send)
|
static int multifd_send_channel_destroy(QIOChannel *send)
|
||||||
{
|
{
|
||||||
return socket_send_channel_destroy(send);
|
if (migrate_to_file()) {
|
||||||
|
return file_send_channel_destroy(send);
|
||||||
|
} else {
|
||||||
|
return socket_send_channel_destroy(send);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void multifd_save_cleanup(void)
|
void multifd_save_cleanup(void)
|
||||||
@@ -919,7 +925,11 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
|
|||||||
|
|
||||||
static void multifd_new_send_channel_create(gpointer opaque)
|
static void multifd_new_send_channel_create(gpointer opaque)
|
||||||
{
|
{
|
||||||
socket_send_channel_create(multifd_new_send_channel_async, opaque);
|
if (migrate_to_file()) {
|
||||||
|
file_send_channel_create(multifd_new_send_channel_async, opaque);
|
||||||
|
} else {
|
||||||
|
socket_send_channel_create(multifd_new_send_channel_async, opaque);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int multifd_save_setup(Error **errp)
|
int multifd_save_setup(Error **errp)
|
||||||
|
@@ -383,6 +383,13 @@ bool migrate_tls(void)
|
|||||||
return s->parameters.tls_creds && *s->parameters.tls_creds;
|
return s->parameters.tls_creds && *s->parameters.tls_creds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool migrate_to_file(void)
|
||||||
|
{
|
||||||
|
MigrationState *s = migrate_get_current();
|
||||||
|
|
||||||
|
return qemu_file_is_seekable(s->to_dst_file);
|
||||||
|
}
|
||||||
|
|
||||||
typedef enum WriteTrackingSupport {
|
typedef enum WriteTrackingSupport {
|
||||||
WT_SUPPORT_UNKNOWN = 0,
|
WT_SUPPORT_UNKNOWN = 0,
|
||||||
WT_SUPPORT_ABSENT,
|
WT_SUPPORT_ABSENT,
|
||||||
|
@@ -59,6 +59,7 @@ bool migrate_live(void);
|
|||||||
bool migrate_multifd_packets(void);
|
bool migrate_multifd_packets(void);
|
||||||
bool migrate_postcopy(void);
|
bool migrate_postcopy(void);
|
||||||
bool migrate_tls(void);
|
bool migrate_tls(void);
|
||||||
|
bool migrate_to_file(void);
|
||||||
|
|
||||||
/* capabilities helpers */
|
/* capabilities helpers */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user