From patchwork Fri Feb 26 15:10:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 8438061 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5C72BC0553 for ; Fri, 26 Feb 2016 15:12:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B9D7203B1 for ; Fri, 26 Feb 2016 15:12:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA680203B4 for ; Fri, 26 Feb 2016 15:12:26 +0000 (UTC) Received: from localhost ([::1]:50344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZK49-0001u7-U4 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Feb 2016 10:12:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZK2W-00087X-1Z for qemu-devel@nongnu.org; Fri, 26 Feb 2016 10:10:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZK2U-0002iR-HJ for qemu-devel@nongnu.org; Fri, 26 Feb 2016 10:10:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50942) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZK2U-0002iJ-7W for qemu-devel@nongnu.org; Fri, 26 Feb 2016 10:10:42 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id F195273041 for ; Fri, 26 Feb 2016 15:10:41 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-4-93.ams2.redhat.com [10.36.4.93]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1QFAYD7017253; Fri, 26 Feb 2016 10:10:40 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 26 Feb 2016 15:10:07 +0000 Message-Id: <1456499430-8558-5-git-send-email-berrange@redhat.com> In-Reply-To: <1456499430-8558-1-git-send-email-berrange@redhat.com> References: <1456499430-8558-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 26 Feb 2016 15:10:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Cc: Amit Shah , "Dr. David Alan Gilbert" , Juan Quintela Subject: [Qemu-devel] [PATCH v3 04/27] migration: split migration hooks out of QEMUFileOps 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The QEMUFileOps struct contains the I/O subsystem callbacks and the migration stage hooks. Split the hooks out into a separate QEMUFileHooks struct to make it easier to refactor the I/O side of QEMUFile without affecting the hooks. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrange --- include/migration/qemu-file.h | 10 +++++++--- migration/qemu-file-internal.h | 1 + migration/qemu-file.c | 24 +++++++++++++++--------- migration/rdma.c | 8 ++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 5909ff0..1934a64 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -108,13 +108,16 @@ typedef struct QEMUFileOps { QEMUFileCloseFunc *close; QEMUFileGetFD *get_fd; QEMUFileWritevBufferFunc *writev_buffer; + QEMURetPathFunc *get_return_path; + QEMUFileShutdownFunc *shut_down; +} QEMUFileOps; + +typedef struct QEMUFileHooks { QEMURamHookFunc *before_ram_iterate; QEMURamHookFunc *after_ram_iterate; QEMURamHookFunc *hook_ram_load; QEMURamSaveFunc *save_page; - QEMURetPathFunc *get_return_path; - QEMUFileShutdownFunc *shut_down; -} QEMUFileOps; +} QEMUFileHooks; struct QEMUSizedBuffer { struct iovec *iov; @@ -129,6 +132,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode); QEMUFile *qemu_fopen_socket(int fd, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input); +void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); int64_t qemu_ftell(QEMUFile *f); diff --git a/migration/qemu-file-internal.h b/migration/qemu-file-internal.h index d95e853..8fdfa95 100644 --- a/migration/qemu-file-internal.h +++ b/migration/qemu-file-internal.h @@ -33,6 +33,7 @@ struct QEMUFile { const QEMUFileOps *ops; + const QEMUFileHooks *hooks; void *opaque; int64_t bytes_xfer; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 656db4a..b480b72 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -80,6 +80,12 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops) return f; } + +void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks) +{ + f->hooks = hooks; +} + /* * Get last error for stream f * @@ -149,8 +155,8 @@ void ram_control_before_iterate(QEMUFile *f, uint64_t flags) { int ret = 0; - if (f->ops->before_ram_iterate) { - ret = f->ops->before_ram_iterate(f, f->opaque, flags, NULL); + if (f->hooks && f->hooks->before_ram_iterate) { + ret = f->hooks->before_ram_iterate(f, f->opaque, flags, NULL); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -161,8 +167,8 @@ void ram_control_after_iterate(QEMUFile *f, uint64_t flags) { int ret = 0; - if (f->ops->after_ram_iterate) { - ret = f->ops->after_ram_iterate(f, f->opaque, flags, NULL); + if (f->hooks && f->hooks->after_ram_iterate) { + ret = f->hooks->after_ram_iterate(f, f->opaque, flags, NULL); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -173,8 +179,8 @@ void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data) { int ret = -EINVAL; - if (f->ops->hook_ram_load) { - ret = f->ops->hook_ram_load(f, f->opaque, flags, data); + if (f->hooks && f->hooks->hook_ram_load) { + ret = f->hooks->hook_ram_load(f, f->opaque, flags, data); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -193,9 +199,9 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, ram_addr_t offset, size_t size, uint64_t *bytes_sent) { - if (f->ops->save_page) { - int ret = f->ops->save_page(f, f->opaque, block_offset, - offset, size, bytes_sent); + if (f->hooks && f->hooks->save_page) { + int ret = f->hooks->save_page(f, f->opaque, block_offset, + offset, size, bytes_sent); if (ret != RAM_SAVE_CONTROL_DELAYED) { if (bytes_sent && *bytes_sent > 0) { diff --git a/migration/rdma.c b/migration/rdma.c index bcae1e8..187fc1c 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3378,12 +3378,18 @@ static const QEMUFileOps rdma_read_ops = { .get_buffer = qemu_rdma_get_buffer, .get_fd = qemu_rdma_get_fd, .close = qemu_rdma_close, +}; + +static const QEMUFileHooks rdma_read_hooks = { .hook_ram_load = rdma_load_hook, }; static const QEMUFileOps rdma_write_ops = { .put_buffer = qemu_rdma_put_buffer, .close = qemu_rdma_close, +}; + +static const QEMUFileHooks rdma_write_hooks = { .before_ram_iterate = qemu_rdma_registration_start, .after_ram_iterate = qemu_rdma_registration_stop, .save_page = qemu_rdma_save_page, @@ -3402,8 +3408,10 @@ static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode) if (mode[0] == 'w') { r->file = qemu_fopen_ops(r, &rdma_write_ops); + qemu_file_set_hooks(r->file, &rdma_write_hooks); } else { r->file = qemu_fopen_ops(r, &rdma_read_ops); + qemu_file_set_hooks(r->file, &rdma_read_hooks); } return r->file;