From patchwork Tue Jun 2 03:21:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 479275 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 41D541412E7 for ; Tue, 2 Jun 2015 13:26:58 +1000 (AEST) Received: from localhost ([::1]:55903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yzcqu-0002yB-Dn for incoming@patchwork.ozlabs.org; Mon, 01 Jun 2015 23:26:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yzcn5-0003oq-DZ for qemu-devel@nongnu.org; Mon, 01 Jun 2015 23:23:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yzcn4-0008JA-Bl for qemu-devel@nongnu.org; Mon, 01 Jun 2015 23:22:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38404) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yzcn0-0008I5-BM; Mon, 01 Jun 2015 23:22:54 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 0AB7D8A4BC; Tue, 2 Jun 2015 03:22:54 +0000 (UTC) Received: from dhcp-14-238.nay.redhat.com (dhcp-14-104.nay.redhat.com [10.66.14.104]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t523M4RG016063; Mon, 1 Jun 2015 23:22:50 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 2 Jun 2015 11:21:59 +0800 Message-Id: <1433215322-23529-11-git-send-email-famz@redhat.com> In-Reply-To: <1433215322-23529-1-git-send-email-famz@redhat.com> References: <1433215322-23529-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , Jeff Cody , Stefan Hajnoczi , qemu-block@nongnu.org Subject: [Qemu-devel] [PATCH v2 10/13] virtio-blk: Move complete_request to 'ops' structure 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 Should more ops be added to differentiate code between dataplane and non-dataplane, the new saved_ops approach will be cleaner than messing with N pointers. Signed-off-by: Fam Zheng Reviewed-by: Max Reitz --- hw/block/dataplane/virtio-blk.c | 13 ++++++++----- hw/block/virtio-blk.c | 8 ++++++-- include/hw/virtio/virtio-blk.h | 9 +++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 3db139b..ec0c8f4 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -51,8 +51,7 @@ struct VirtIOBlockDataPlane { /* Operation blocker on BDS */ Error *blocker; - void (*saved_complete_request)(struct VirtIOBlockReq *req, - unsigned char status); + const VirtIOBlockOps *saved_ops; }; /* Raise an interrupt to signal guest, if necessary */ @@ -88,6 +87,10 @@ static void complete_request_vring(VirtIOBlockReq *req, unsigned char status) qemu_bh_schedule(s->bh); } +static const VirtIOBlockOps virtio_blk_data_plane_ops = { + .complete_request = complete_request_vring, +}; + static void handle_notify(EventNotifier *e) { VirtIOBlockDataPlane *s = container_of(e, VirtIOBlockDataPlane, @@ -269,8 +272,8 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) } s->host_notifier = *virtio_queue_get_host_notifier(vq); - s->saved_complete_request = vblk->complete_request; - vblk->complete_request = complete_request_vring; + s->saved_ops = vblk->ops; + vblk->ops = &virtio_blk_data_plane_ops; s->starting = false; s->started = true; @@ -313,7 +316,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s) return; } s->stopping = true; - vblk->complete_request = s->saved_complete_request; + vblk->ops = s->saved_ops; trace_virtio_blk_data_plane_stop(s); aio_context_acquire(s->ctx); diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index cd539aa..af20e78 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -59,9 +59,13 @@ static void virtio_blk_complete_request(VirtIOBlockReq *req, virtio_notify(vdev, s->vq); } +static const VirtIOBlockOps virtio_blk_ops = (VirtIOBlockOps) { + .complete_request = virtio_blk_complete_request, +}; + static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) { - req->dev->complete_request(req, status); + req->dev->ops->complete_request(req, status); } static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, @@ -905,7 +909,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) s->sector_mask = (s->conf.conf.logical_block_size / BDRV_SECTOR_SIZE) - 1; s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output); - s->complete_request = virtio_blk_complete_request; + s->ops = &virtio_blk_ops; virtio_blk_data_plane_create(vdev, conf, &s->dataplane, &err); if (err != NULL) { error_propagate(errp, err); diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 6bf5905..28b3436 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -44,6 +44,12 @@ struct VirtIOBlkConf struct VirtIOBlockDataPlane; struct VirtIOBlockReq; + +typedef struct { + /* Function to push to vq and notify guest */ + void (*complete_request)(struct VirtIOBlockReq *req, unsigned char status); +} VirtIOBlockOps; + typedef struct VirtIOBlock { VirtIODevice parent_obj; BlockBackend *blk; @@ -54,8 +60,7 @@ typedef struct VirtIOBlock { unsigned short sector_mask; bool original_wce; VMChangeStateEntry *change; - /* Function to push to vq and notify guest */ - void (*complete_request)(struct VirtIOBlockReq *req, unsigned char status); + const VirtIOBlockOps *ops; Notifier migration_state_notifier; struct VirtIOBlockDataPlane *dataplane; } VirtIOBlock;