From patchwork Wed Feb 25 16:51:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 443504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D992B140083 for ; Thu, 26 Feb 2015 03:53:29 +1100 (AEDT) Received: from localhost ([::1]:55013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQfDD-0000zb-7n for incoming@patchwork.ozlabs.org; Wed, 25 Feb 2015 11:53:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQfCT-0007uZ-7K for qemu-devel@nongnu.org; Wed, 25 Feb 2015 11:52:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQfCN-00011K-1b for qemu-devel@nongnu.org; Wed, 25 Feb 2015 11:52:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQfCM-00011D-QT for qemu-devel@nongnu.org; Wed, 25 Feb 2015 11:52:34 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1PGqShN021994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 25 Feb 2015 11:52:28 -0500 Received: from dgilbert-t530.redhat.com (ovpn-116-97.ams2.redhat.com [10.36.116.97]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1PGq8l0032146; Wed, 25 Feb 2015 11:52:26 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Wed, 25 Feb 2015 16:51:30 +0000 Message-Id: <1424883128-9841-8-git-send-email-dgilbert@redhat.com> In-Reply-To: <1424883128-9841-1-git-send-email-dgilbert@redhat.com> References: <1424883128-9841-1-git-send-email-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, quintela@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, yanghy@cn.fujitsu.com, david@gibson.dropbear.id.au Subject: [Qemu-devel] [PATCH v5 07/45] Return path: Open a return path on QEMUFile for sockets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Dr. David Alan Gilbert" 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 --- include/migration/qemu-file.h | 7 +++++ migration/qemu-file-internal.h | 2 ++ migration/qemu-file-unix.c | 58 +++++++++++++++++++++++++++++++++++------- migration/qemu-file.c | 12 +++++++++ 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 6ae0b03..3c38963 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, int *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; @@ -188,6 +194,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); static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) diff --git a/migration/qemu-file-internal.h b/migration/qemu-file-internal.h index d95e853..a39b8e3 100644 --- a/migration/qemu-file-internal.h +++ b/migration/qemu-file-internal.h @@ -48,6 +48,8 @@ struct QEMUFile { unsigned int iovcnt; int last_error; + + struct QEMUFile *return_path; }; #endif diff --git a/migration/qemu-file-unix.c b/migration/qemu-file-unix.c index bfbc086..50291cf 100644 --- a/migration/qemu-file-unix.c +++ b/migration/qemu-file-unix.c @@ -96,6 +96,45 @@ 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; + + /* We should only be called once to get a RP on a file */ + assert(!qfs->file->return_path); + + 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"); + qfs->file->return_path = result; + + if (!result) { + close(revfd); + } + + return result; +} + static ssize_t unix_writev_buffer(void *opaque, struct iovec *iov, int iovcnt, int64_t pos) { @@ -204,18 +243,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 57eb868..02122a5 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 ||