Received: from eggs.gnu.org ([2001:4830:134:3::10]:58811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfRkH-0000av-PB for qemu-devel@nongnu.org; Tue, 07 Apr 2015 07:32:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YfRkD-0006Vi-NW for qemu-devel@nongnu.org; Tue, 07 Apr 2015 07:32:41 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:48979) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfRkD-0006V4-DJ for qemu-devel@nongnu.org; Tue, 07 Apr 2015 07:32:37 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Apr 2015 12:32:34 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8642F17D8042 for ; Tue, 7 Apr 2015 12:33:04 +0100 (BST) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t37BWV0M66257066 for ; Tue, 7 Apr 2015 11:32:31 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t37BWVIS017987 for ; Tue, 7 Apr 2015 05:32:31 -0600 Date: Tue, 7 Apr 2015 13:32:27 +0200 From: Cornelia Huck Message-ID: <20150407133227.3cb5555b.cornelia.huck@de.ibm.com> In-Reply-To: <1428403546-31914-2-git-send-email-mst@redhat.com> References: <1428403546-31914-1-git-send-email-mst@redhat.com> <1428403546-31914-2-git-send-email-mst@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/3] virtio: interface to enable/disable host notifiers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Jason Wang , qemu-devel@nongnu.org On Tue, 7 Apr 2015 12:45:56 +0200 "Michael S. Tsirkin" wrote: > generalize and move these from vhost to virtio. > > Signed-off-by: Michael S. Tsirkin > --- > include/hw/virtio/virtio.h | 3 +++ > hw/virtio/vhost.c | 45 ++-------------------------------------- > hw/virtio/virtio.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 56 insertions(+), 43 deletions(-) > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 17c1260..e7ee069 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -1283,6 +1283,57 @@ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name) > vdev->bus_name = g_strdup(bus_name); > } > > +int virtio_enable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs) I realize that you just move the function, but would it make sense to verify that startvq + nvqs is actually still a valid queue? > +{ > + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); > + VirtioBusState *vbus = VIRTIO_BUS(qbus); > + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); > + int i, r; > + if (!k->set_host_notifier) { > + fprintf(stderr, "binding does not support host notifiers\n"); > + r = -ENOSYS; > + goto fail; > + } > + > + for (i = 0; i < nvqs; ++i) { > + r = k->set_host_notifier(qbus->parent, startvq + i, true); > + if (r < 0) { > + fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r); I think you'll want to get rid of the vhost in the message here. And the number of the failing virtqueue is startvq+i, no? Also: would it make sense to convert this to the error reporting infrastructure? > + goto fail_vq; > + } > + } > + > + return 0; > +fail_vq: > + while (--i >= 0) { > + r = k->set_host_notifier(qbus->parent, startvq + i, false); > + if (r < 0) { > + fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r); > + fflush(stderr); > + } > + assert (r >= 0); > + } > +fail: > + return r; > +} > + > +void virtio_disable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs) > +{ > + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); > + VirtioBusState *vbus = VIRTIO_BUS(qbus); > + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); > + int i, r; > + > + for (i = 0; i < nvqs; ++i) { > + r = k->set_host_notifier(qbus->parent, startvq + i, false); Should a generic function maybe check for ->set_host_notifier and bail out early if it doesn't exist? Probably depends on how the callers want to handle non-existence of host notifiers. > + if (r < 0) { > + fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r); > + fflush(stderr); > + } > + assert (r >= 0); > + } > +} > + > static void virtio_device_realize(DeviceState *dev, Error **errp) > { > VirtIODevice *vdev = VIRTIO_DEVICE(dev);