[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 11/47] Return path: Open a return path on QEMUFil
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v6 11/47] Return path: Open a return path on QEMUFile for sockets |
Date: |
Tue, 14 Apr 2015 18:03:37 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
Postcopy needs a method to send messages from the destination back to
the source, this is the 'return path'.
Wire it up for 'socket' QEMUFile's using a dup'd fd.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
include/migration/qemu-file.h | 7 +++++
migration/qemu-file-unix.c | 65 +++++++++++++++++++++++++++++++++++++------
migration/qemu-file.c | 12 ++++++++
3 files changed, 75 insertions(+), 9 deletions(-)
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index c14555d..1ff8fbc 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -85,6 +85,11 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f, void *opaque,
uint64_t *bytes_sent);
/*
+ * Return a QEMUFile for comms in the opposite direction
+ */
+typedef QEMUFile *(QEMURetPathFunc)(void *opaque);
+
+/*
* Stop any read or write (depending on flags) on the underlying
* transport on the QEMUFile.
* Existing blocking reads/writes must be woken
@@ -102,6 +107,7 @@ typedef struct QEMUFileOps {
QEMURamHookFunc *after_ram_iterate;
QEMURamHookFunc *hook_ram_load;
QEMURamSaveFunc *save_page;
+ QEMURetPathFunc *get_return_path;
QEMUFileShutdownFunc *shut_down;
} QEMUFileOps;
@@ -189,6 +195,7 @@ int64_t qemu_file_get_rate_limit(QEMUFile *f);
int qemu_file_get_error(QEMUFile *f);
void qemu_file_set_error(QEMUFile *f, int ret);
int qemu_file_shutdown(QEMUFile *f);
+QEMUFile *qemu_file_get_return_path(QEMUFile *f);
void qemu_fflush(QEMUFile *f);
void qemu_file_change_blocking(QEMUFile *f, bool block);
diff --git a/migration/qemu-file-unix.c b/migration/qemu-file-unix.c
index bfbc086..1e7de7b 100644
--- a/migration/qemu-file-unix.c
+++ b/migration/qemu-file-unix.c
@@ -96,6 +96,52 @@ static int socket_shutdown(void *opaque, bool rd, bool wr)
}
}
+/*
+ * Give a QEMUFile* off the same socket but data in the opposite
+ * direction.
+ */
+static QEMUFile *socket_dup_return_path(void *opaque)
+{
+ QEMUFileSocket *qfs = opaque;
+ int revfd;
+ bool this_is_read;
+ QEMUFile *result;
+
+ if (qemu_file_get_error(qfs->file)) {
+ /* If the forward file is in error, don't try and open a return */
+ return NULL;
+ }
+
+ /* I don't think there's a better way to tell which direction 'this' is */
+ this_is_read = qfs->file->ops->get_buffer != NULL;
+
+ revfd = dup(qfs->fd);
+ if (revfd == -1) {
+ error_report("Error duplicating fd for return path: %s",
+ strerror(errno));
+ return NULL;
+ }
+
+ result = qemu_fopen_socket(revfd, this_is_read ? "wb" : "rb");
+
+ if (!result) {
+ close(revfd);
+ }
+
+ if (this_is_read) {
+ /* The qemu_fopen_socket "wb" will mark the socket blocking,
+ * which would be OK for the return path, but the semantics
+ * of non-blocking is that it follows the underlying connection
+ * not the fd number, and thus setting the return path non-blocking
+ * ends up setting the forward path blocking, which we don't want
+ */
+ qemu_set_nonblock(revfd);
+ }
+
+
+ return result;
+}
+
static ssize_t unix_writev_buffer(void *opaque, struct iovec *iov, int iovcnt,
int64_t pos)
{
@@ -204,18 +250,19 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
}
static const QEMUFileOps socket_read_ops = {
- .get_fd = socket_get_fd,
- .get_buffer = socket_get_buffer,
- .close = socket_close,
- .shut_down = socket_shutdown
-
+ .get_fd = socket_get_fd,
+ .get_buffer = socket_get_buffer,
+ .close = socket_close,
+ .shut_down = socket_shutdown,
+ .get_return_path = socket_dup_return_path
};
static const QEMUFileOps socket_write_ops = {
- .get_fd = socket_get_fd,
- .writev_buffer = socket_writev_buffer,
- .close = socket_close,
- .shut_down = socket_shutdown
+ .get_fd = socket_get_fd,
+ .writev_buffer = socket_writev_buffer,
+ .close = socket_close,
+ .shut_down = socket_shutdown,
+ .get_return_path = socket_dup_return_path
};
QEMUFile *qemu_fopen_socket(int fd, const char *mode)
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index d84830f..8b2ae8d 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -42,6 +42,18 @@ int qemu_file_shutdown(QEMUFile *f)
return f->ops->shut_down(f->opaque, true, true);
}
+/*
+ * Result: QEMUFile* for a 'return path' for comms in the opposite direction
+ * NULL if not available
+ */
+QEMUFile *qemu_file_get_return_path(QEMUFile *f)
+{
+ if (!f->ops->get_return_path) {
+ return NULL;
+ }
+ return f->ops->get_return_path(f->opaque);
+}
+
bool qemu_file_mode_is_not_valid(const char *mode)
{
if (mode == NULL ||
--
2.1.0
- [Qemu-devel] [PATCH v6 04/47] Add qemu_get_counted_string to read a string prefixed by a count byte, (continued)
- [Qemu-devel] [PATCH v6 04/47] Add qemu_get_counted_string to read a string prefixed by a count byte, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 03/47] qemu_ram_foreach_block: pass up error value, and down the ramblock name, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 05/47] Create MigrationIncomingState, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 06/47] Provide runtime Target page information, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 09/47] Add wrapper for setting blocking status on a QEMUFile, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 07/47] Move copy out of qemu_peek_buffer, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 13/47] Migration commands, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 10/47] Rename save_live_complete to save_live_complete_precopy, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 12/47] Return path: socket_writev_buffer: Block even on non-blocking fd's, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 08/47] Add qemu_get_buffer_less_copy to avoid copies some of the time, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 11/47] Return path: Open a return path on QEMUFile for sockets,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v6 15/47] Return path: Send responses from destination to source, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 14/47] Return path: Control commands, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 17/47] ram_debug_dump_bitmap: Dump a migration bitmap as text, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 18/47] Move loadvm_handlers into MigrationIncomingState, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 16/47] Return path: Source handling of return path, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 19/47] Rework loadvm path for subloops, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 20/47] Add migration-capability boolean for postcopy-ram., Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 22/47] MIG_CMD_PACKAGED: Send a packaged chunk of migration stream, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 23/47] migrate_init: Call from savevm, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 24/47] Modify save_live_pending for postcopy, Dr. David Alan Gilbert (git), 2015/04/14