From patchwork Wed Dec 2 12:04:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 40053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0FC06B7BE6 for ; Thu, 3 Dec 2009 01:43:27 +1100 (EST) Received: from localhost ([127.0.0.1]:40360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFqQN-00059V-Df for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2009 09:43:23 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFnyQ-0004hn-F3 for qemu-devel@nongnu.org; Wed, 02 Dec 2009 07:06:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFnyL-0004f0-Ox for qemu-devel@nongnu.org; Wed, 02 Dec 2009 07:06:22 -0500 Received: from [199.232.76.173] (port=42954 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFnyL-0004eu-Dz for qemu-devel@nongnu.org; Wed, 02 Dec 2009 07:06:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16699) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFnyK-0004GX-Tf for qemu-devel@nongnu.org; Wed, 02 Dec 2009 07:06:17 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB2C6GbM002367 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Dec 2009 07:06:16 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB2C5ILc029769; Wed, 2 Dec 2009 07:06:14 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 2 Dec 2009 13:04:38 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: mst@redhat.com Subject: [Qemu-devel] [PATCH 40/41] virtio-blk: port to vmstate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This driver send a struct directly in the wire, where the struct contains: - target_phis_addr_t (can be 32 or 64 bits depending of host) - void * (on host) - size_t. It has no hope of working across 32/64 or big/little endian. This problem exist in previous one. Signed-off-by: Juan Quintela --- hw/virtio-blk.c | 50 +++++++++++++++++++++++++++++++++++++------------- 1 files changed, 37 insertions(+), 13 deletions(-) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 0b04d0d..c618dc6 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -450,28 +450,34 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev) return features; } -static void virtio_blk_save(QEMUFile *f, void *opaque) +static const VMStateDescription vmstate_virtio_blk_req = { + .name = "virtio-blk-req", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField []) { + VMSTATE_BUFFER_UNSAFE(elem, VirtIOBlockReq, 0, sizeof(VirtQueueElement)), + VMSTATE_END_OF_LIST() + } +}; + +static void put_virtio_req(QEMUFile *f, void *pv, size_t size) { - VirtIOBlock *s = opaque; + VirtIOBlockReqHead *rq = pv; VirtIOBlockReq *req;; - virtio_save(&s->vdev, f); - - QLIST_FOREACH(req, &s->rq, next) { + QLIST_FOREACH(req, rq, next) { qemu_put_sbyte(f, 1); qemu_put_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem)); } qemu_put_sbyte(f, 0); } -static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id) +static int get_virtio_req(QEMUFile *f, void *pv, size_t size) { - VirtIOBlock *s = opaque; + VirtIOBlockReqHead *rq = pv; + VirtIOBlock *s = container_of(rq, struct VirtIOBlock, rq); - if (version_id != 2) - return -EINVAL; - - virtio_load(&s->vdev, f); while (qemu_get_sbyte(f)) { VirtIOBlockReq *req = virtio_blk_alloc_request(s); qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem)); @@ -481,6 +487,25 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id) return 0; } +const VMStateInfo vmstate_info_virtio_blk_req = { + .name = "virtio_blk_req", + .get = get_virtio_req, + .put = put_virtio_req, +}; + +static const VMStateDescription vmstate_virtio_blk = { + .name = "virtio-blk", + .version_id = 2, + .minimum_version_id = 2, + .minimum_version_id_old = 2, + .fields = (VMStateField []) { + VMSTATE_VIRTIO(vdev, VirtIOBlock), + VMSTATE_SINGLE(rq, VirtIOBlock, 0, + vmstate_info_virtio_blk_req, VirtIOBlockReqHead), + VMSTATE_END_OF_LIST() + } +}; + VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo) { VirtIOBlock *s; @@ -510,8 +535,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo) s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output); qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s); - register_savevm("virtio-blk", virtio_blk_id++, 2, - virtio_blk_save, virtio_blk_load, s); + vmstate_register(virtio_blk_id++, &vmstate_virtio_blk, s); return &s->vdev; }