From patchwork Tue Apr 9 03:04:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mrhines@linux.vnet.ibm.com X-Patchwork-Id: 234946 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E625A2C00AE for ; Tue, 9 Apr 2013 13:09:17 +1000 (EST) Received: from localhost ([::1]:55167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPOvr-0005pb-UU for incoming@patchwork.ozlabs.org; Mon, 08 Apr 2013 23:09:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPOsL-0000XT-Kf for qemu-devel@nongnu.org; Mon, 08 Apr 2013 23:05:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPOsI-0004od-UQ for qemu-devel@nongnu.org; Mon, 08 Apr 2013 23:05:37 -0400 Received: from e31.co.us.ibm.com ([32.97.110.149]:60451) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPOsI-0004oP-Me for qemu-devel@nongnu.org; Mon, 08 Apr 2013 23:05:34 -0400 Received: from /spool/local by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 8 Apr 2013 21:05:34 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 8 Apr 2013 21:05:19 -0600 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 2DECA3E4003E for ; Mon, 8 Apr 2013 21:05:06 -0600 (MDT) Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r3935IHx258194 for ; Mon, 8 Apr 2013 21:05:18 -0600 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r39384fw013313 for ; Mon, 8 Apr 2013 21:08:04 -0600 Received: from mrhinesdev.klabtestbed.com (klinux.watson.ibm.com [9.2.208.21]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r3937w29012821; Mon, 8 Apr 2013 21:08:04 -0600 From: mrhines@linux.vnet.ibm.com To: qemu-devel@nongnu.org Date: Mon, 8 Apr 2013 23:04:36 -0400 Message-Id: <1365476681-31593-8-git-send-email-mrhines@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1365476681-31593-1-git-send-email-mrhines@linux.vnet.ibm.com> References: <1365476681-31593-1-git-send-email-mrhines@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13040903-7282-0000-0000-000015FE6D1C X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.110.149 Cc: aliguori@us.ibm.com, mst@redhat.com, owasserm@redhat.com, abali@us.ibm.com, mrhines@us.ibm.com, gokul@us.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [RFC PATCH RDMA support v5: 07/12] additional savevm.c accessors for RDMA 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: "Michael R. Hines" 1. qemu_file_ops_are() 2. qemu_file_update_position() (for f->pos) Also need to be here: rdma_read_ops rdma_write_ops Signed-off-by: Michael R. Hines --- savevm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/savevm.c b/savevm.c index b1d8988..0f5c7aa 100644 --- a/savevm.c +++ b/savevm.c @@ -32,6 +32,7 @@ #include "qemu/timer.h" #include "audio/audio.h" #include "migration/migration.h" +#include "migration/rdma.h" #include "qemu/sockets.h" #include "qemu/queue.h" #include "sysemu/cpus.h" @@ -409,16 +410,24 @@ static const QEMUFileOps socket_write_ops = { .close = socket_close }; -QEMUFile *qemu_fopen_socket(int fd, const char *mode) +bool qemu_file_mode_is_not_valid(const char * mode) { - QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket)); - if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || mode[1] != 'b' || mode[2] != 0) { fprintf(stderr, "qemu_fopen: Argument validity check failed\n"); - return NULL; + return true; } + + return false; +} + +QEMUFile *qemu_fopen_socket(int fd, const char *mode) +{ + QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket)); + + if(qemu_file_mode_is_not_valid(mode)) + return NULL; s->fd = fd; if (mode[0] == 'w') { @@ -430,16 +439,27 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode) return s->file; } +/* + * These have to be here for qemu_file_ops_are() + * The function pointers compile to NULL if + * RDMA is disabled at configure time. + */ +const QEMUFileOps rdma_read_ops = { + .get_buffer = qemu_rdma_get_buffer, + .close = qemu_rdma_close, +}; + +const QEMUFileOps rdma_write_ops = { + .put_buffer = qemu_rdma_put_buffer, + .close = qemu_rdma_close, +}; + QEMUFile *qemu_fopen(const char *filename, const char *mode) { QEMUFileStdio *s; - if (mode == NULL || - (mode[0] != 'r' && mode[0] != 'w') || - mode[1] != 'b' || mode[2] != 0) { - fprintf(stderr, "qemu_fopen: Argument validity check failed\n"); + if(qemu_file_mode_is_not_valid(mode)) return NULL; - } s = g_malloc0(sizeof(QEMUFileStdio)); @@ -790,6 +810,17 @@ int qemu_get_byte(QEMUFile *f) return result; } +/* + * Validate which operations are actually in use + * before attempting to access opaque data. + */ +void * qemu_file_ops_are(QEMUFile *f, const QEMUFileOps *ops) +{ + if (f->ops == ops) + return f->opaque; + return NULL; +} + int64_t qemu_ftell(QEMUFile *f) { qemu_fflush(f); @@ -807,6 +838,14 @@ int qemu_file_rate_limit(QEMUFile *f) return 0; } +/* + * For users, like RDMA, that don't go through the QEMUFile buffer directly. + */ +void qemu_file_update_position(QEMUFile *f, int64_t inc) +{ + f->pos += inc; +} + int64_t qemu_file_get_rate_limit(QEMUFile *f) { return f->xfer_limit;