From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrVri-0005RB-6J for qemu-devel@nongnu.org; Wed, 18 Jul 2012 11:08:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrVra-0000hA-AD for qemu-devel@nongnu.org; Wed, 18 Jul 2012 11:08:38 -0400 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:34105) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrVra-0000gq-1q for qemu-devel@nongnu.org; Wed, 18 Jul 2012 11:08:30 -0400 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Jul 2012 16:08:29 +0100 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6IF8PC52277536 for ; Wed, 18 Jul 2012 16:08:25 +0100 Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6IF8OTN003373 for ; Wed, 18 Jul 2012 09:08:25 -0600 From: Stefan Hajnoczi Date: Wed, 18 Jul 2012 16:07:29 +0100 Message-Id: <1342624074-24650-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1342624074-24650-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1342624074-24650-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [RFC v9 02/27] virtio-blk: Set up host notifier for data plane List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , kvm@vger.kernel.org, "Michael S. Tsirkin" , Khoa Huynh , Paolo Bonzini , Asias He Set up the virtqueue notify ioeventfd that the data plane will monitor. Signed-off-by: Stefan Hajnoczi --- hw/virtio-blk.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index a627427..0389294 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -26,6 +26,8 @@ typedef struct VirtIOBlock char *serial; unsigned short sector_mask; DeviceState *qdev; + + bool data_plane_started; } VirtIOBlock; static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) @@ -33,6 +35,39 @@ static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) return (VirtIOBlock *)vdev; } +static void virtio_blk_data_plane_start(VirtIOBlock *s) +{ + if (s->vdev.binding->set_host_notifier(s->vdev.binding_opaque, 0, true) != 0) { + fprintf(stderr, "virtio-blk failed to set host notifier\n"); + return; + } + + s->data_plane_started = true; +} + +static void virtio_blk_data_plane_stop(VirtIOBlock *s) +{ + s->data_plane_started = false; + + s->vdev.binding->set_host_notifier(s->vdev.binding_opaque, 0, false); +} + +static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t val) +{ + VirtIOBlock *s = to_virtio_blk(vdev); + + /* Toggle host notifier only on status change */ + if (s->data_plane_started == !!(val & VIRTIO_CONFIG_S_DRIVER_OK)) { + return; + } + + if (val & VIRTIO_CONFIG_S_DRIVER_OK) { + virtio_blk_data_plane_start(s); + } else { + virtio_blk_data_plane_stop(s); + } +} + static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) { fprintf(stderr, "virtio_blk_handle_output: should never get here," @@ -115,6 +150,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf, s->vdev.get_config = virtio_blk_update_config; s->vdev.get_features = virtio_blk_get_features; + s->vdev.set_status = virtio_blk_set_status; s->bs = conf->bs; s->conf = conf; s->serial = *serial; @@ -122,6 +158,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf, bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output); + s->data_plane_started = false; s->qdev = dev; bdrv_set_buffer_alignment(s->bs, conf->logical_block_size); -- 1.7.10.4