From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, jcody@redhat.com, armbru@redhat.com,
mreitz@redhat.com, Stefan Hajnoczi <stefanha@redhat.com>,
pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v3 04/12] virtio-blk: Move complete_request to 'ops' structure
Date: Fri, 15 May 2015 14:04:20 +0800 [thread overview]
Message-ID: <1431669868-26804-5-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1431669868-26804-1-git-send-email-famz@redhat.com>
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 <famz@redhat.com>
---
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 3ecc8bd..e287e09 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,
@@ -270,8 +273,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;
@@ -314,7 +317,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 e6afe97..f4a9d19 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;
--
2.4.0
next prev parent reply other threads:[~2015-05-15 6:06 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-15 6:04 [Qemu-devel] [PATCH v3 00/12] Fix transactional snapshot with dataplane and NBD export Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 01/12] block: Add op blocker type "device IO" Fam Zheng
2015-05-15 6:22 ` Wen Congyang
2015-05-15 7:06 ` Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 02/12] block: Add op blocker notifier list Fam Zheng
2015-05-18 17:22 ` Max Reitz
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 03/12] block-backend: Add blk_op_blocker_add_notifier Fam Zheng
2015-05-18 17:24 ` Max Reitz
2015-05-15 6:04 ` Fam Zheng [this message]
2015-05-18 17:38 ` [Qemu-devel] [PATCH v3 04/12] virtio-blk: Move complete_request to 'ops' structure Max Reitz
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 05/12] virtio-blk: Don't handle output when there is "device IO" op blocker Fam Zheng
2015-05-18 18:19 ` Max Reitz
2015-05-19 2:58 ` Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 06/12] nbd-server: Clear "can_read" when "device io" blocker is set Fam Zheng
2015-05-18 18:35 ` Max Reitz
2015-05-19 2:26 ` Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 07/12] blockdev: Block device IO during internal snapshot transaction Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 08/12] blockdev: Block device IO during external " Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 09/12] blockdev: Block device IO during drive-backup transaction Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 10/12] blockdev: Block device IO during blockdev-backup transaction Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 11/12] block: Block "device IO" during bdrv_drain and bdrv_drain_all Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 12/12] virtio-scsi-dataplane: Add "device IO" op blocker listener Fam Zheng
2015-05-15 6:50 ` Paolo Bonzini
2015-05-15 7:03 ` Fam Zheng
2015-05-15 7:26 ` Paolo Bonzini
2015-05-15 7:57 ` Fam Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431669868-26804-5-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=armbru@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).