From patchwork Wed Jul 18 15:07:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 1211501 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id A7B96DFFFD for ; Wed, 18 Jul 2012 15:08:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754634Ab2GRPIc (ORCPT ); Wed, 18 Jul 2012 11:08:32 -0400 Received: from e06smtp14.uk.ibm.com ([195.75.94.110]:59097 "EHLO e06smtp14.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753967Ab2GRPIa (ORCPT ); Wed, 18 Jul 2012 11:08:30 -0400 Received: from /spool/local by e06smtp14.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 d06nrmr1806.portsmouth.uk.ibm.com (9.149.39.193) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 18 Jul 2012 16:08:27 +0100 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6IF8Qp52846742 for ; Wed, 18 Jul 2012 16:08:26 +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 q6IF8OTT003373 for ; Wed, 18 Jul 2012 09:08:26 -0600 Received: from localhost (sig-9-145-185-169.de.ibm.com [9.145.185.169]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6IF8NLA003338; Wed, 18 Jul 2012 09:08:24 -0600 From: Stefan Hajnoczi To: Cc: , Anthony Liguori , Kevin Wolf , Paolo Bonzini , "Michael S. Tsirkin" , Asias He , Khoa Huynh , Stefan Hajnoczi Subject: [RFC v9 02/27] virtio-blk: Set up host notifier for data plane Date: Wed, 18 Jul 2012 16:07:29 +0100 Message-Id: <1342624074-24650-3-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 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> x-cbid: 12071815-1948-0000-0000-0000026EE5AE Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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);