From patchwork Wed Apr 6 10:16:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8760631 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 709659F36E for ; Wed, 6 Apr 2016 10:20:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9172B201E4 for ; Wed, 6 Apr 2016 10:20:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 81991201BB for ; Wed, 6 Apr 2016 10:20:37 +0000 (UTC) Received: from localhost ([::1]:42193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ankZg-0002HA-Pt for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Apr 2016 06:20:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ankVu-0003kK-Vz for qemu-devel@nongnu.org; Wed, 06 Apr 2016 06:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ankVt-0001sE-RX for qemu-devel@nongnu.org; Wed, 06 Apr 2016 06:16:42 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ankVt-0001rk-AS for qemu-devel@nongnu.org; Wed, 06 Apr 2016 06:16:41 -0400 Received: by mail-wm0-x244.google.com with SMTP id i204so11786992wmd.0 for ; Wed, 06 Apr 2016 03:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=yI3OUTqgnrfF9I+bddRjAuX+5NH/tdubn0vRVEkFVN0=; b=nf1qV8yLt0hgUFKVw3oKjN9eNJjC1gcLSygR+vLbHLzIugTo76o1xQUi+yB3b4XVyd Q8//2XNC+cPzLLn2IwjGdeJZARAso9hU0VvG1S8JSQekiWCV57IC/4FBz8io5GU1u7ge i2ie+vEgZjWuCtTgjSZD1u0dHUxilSSvKvq6qC4nJAAnDzoUfZSPZQRS5IH5Fjz9m9/4 Q+Ln4kowGoLE8DFj92p6fJkyXCbGfmET0wwtOU/ZQ9qoAG+d5yQXul1w98nM7Yh9Nz5J jXd4Z0pj9LvUwAPHeMfZzPJ/uH5B60BUXqvfxjnsGfQ4pZKgLNvRBK6sANJLLV+DCo2d QU/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=yI3OUTqgnrfF9I+bddRjAuX+5NH/tdubn0vRVEkFVN0=; b=ZgQVTlUMjKVG3zLKW+XbKfbEO4A+6DjgTy21HXBNs8uGWvKUtgHHMM1qugqpFYUjqH rZg7q9Ttpjtdn79SUg4PQFoSoPl+lmmfqB1S9qd0UqkYd11ZEcD4B3MAx2SmccNUQJEy yMDQ24+IFMwN0V1xnmpKmKKICU5O3eaZRmJAzETsAltFN4qBu9QAPRahD5XPTP84WvMA vhoK9AZgf+nYPzD1WvXvaBHoYqb5HR9xlYMRiU0c+lEWCWB4yY7C7olQ3C2Sqzj2+Zne M3/h1kE2auVIyQNLw9AjERzAxlvmwSt2rH6rt/zC0oGn6dTtTqx+M3GVZfFOTTJ2qIRZ V4VA== X-Gm-Message-State: AD7BkJLoKADW7F31kFLg6QlvB+9nTrKf1J2o05Fzx4j9li7D+1ucd/iyLi2Ts0ODHwKRcw== X-Received: by 10.28.23.70 with SMTP id 67mr22876651wmx.70.1459937800834; Wed, 06 Apr 2016 03:16:40 -0700 (PDT) Received: from 640k.lan (94-39-141-76.adsl-ull.clienti.tiscali.it. [94.39.141.76]) by smtp.gmail.com with ESMTPSA id u3sm24048429wmg.15.2016.04.06.03.16.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Apr 2016 03:16:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 6 Apr 2016 12:16:28 +0200 Message-Id: <1459937788-31904-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1459937788-31904-1-git-send-email-pbonzini@redhat.com> References: <1459937788-31904-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Cc: famz@redhat.com, tubo@linux.vnet.ibm.com, mst@redhat.com, borntraeger@de.ibm.com, stefanha@redhat.com, cornelia.huck@de.ibm.com Subject: [Qemu-devel] [PATCH 7/7] virtio: merge virtio_queue_aio_set_host_notifier_handler with virtio_queue_set_aio 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Eliminating the reentrancy is actually a nice thing that we can do with the API that Michael proposed, so let's make it first class. This also hides the complex assign/set_handler conventions from callers of virtio_queue_aio_set_host_notifier_handler, which in fact was always called with assign=true. Reviewed-by: Cornelia Huck Signed-off-by: Paolo Bonzini --- hw/block/dataplane/virtio-blk.c | 7 +++---- hw/scsi/virtio-scsi-dataplane.c | 12 ++++-------- hw/virtio/virtio.c | 17 +++++------------ include/hw/virtio/virtio.h | 6 ++---- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 65c7f70..3cb97c9 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -237,8 +237,8 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) /* Get this show started by hooking up our callbacks */ aio_context_acquire(s->ctx); - virtio_set_queue_aio(s->vq, virtio_blk_data_plane_handle_output); - virtio_queue_aio_set_host_notifier_handler(s->vq, s->ctx, true, true); + virtio_queue_aio_set_host_notifier_handler(s->vq, s->ctx, + virtio_blk_data_plane_handle_output); aio_context_release(s->ctx); return; @@ -273,8 +273,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s) aio_context_acquire(s->ctx); /* Stop notifications for new requests from guest */ - virtio_queue_aio_set_host_notifier_handler(s->vq, s->ctx, false, false); - virtio_set_queue_aio(s->vq, NULL); + virtio_queue_aio_set_host_notifier_handler(s->vq, s->ctx, NULL); /* Drain and switch bs back to the QEMU main loop */ blk_set_aio_context(s->conf->conf.blk, qemu_get_aio_context()); diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c index 39ad086..1a49f1e 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -81,8 +81,7 @@ static int virtio_scsi_vring_init(VirtIOSCSI *s, VirtQueue *vq, int n, return rc; } - virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, true, true); - virtio_set_queue_aio(vq, fn); + virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, fn); return 0; } @@ -99,13 +98,10 @@ static void virtio_scsi_clear_aio(VirtIOSCSI *s) VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s); int i; - virtio_queue_aio_set_host_notifier_handler(vs->ctrl_vq, s->ctx, false, false); - virtio_set_queue_aio(vs->ctrl_vq, NULL); - virtio_queue_aio_set_host_notifier_handler(vs->event_vq, s->ctx, false, false); - virtio_set_queue_aio(vs->event_vq, NULL); + virtio_queue_aio_set_host_notifier_handler(vs->ctrl_vq, s->ctx, NULL); + virtio_queue_aio_set_host_notifier_handler(vs->event_vq, s->ctx, NULL); for (i = 0; i < vs->conf.num_queues; i++) { - virtio_queue_aio_set_host_notifier_handler(vs->cmd_vqs[i], s->ctx, false, false); - virtio_set_queue_aio(vs->cmd_vqs[i], NULL); + virtio_queue_aio_set_host_notifier_handler(vs->cmd_vqs[i], s->ctx, NULL); } } diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index eb04ac0..f745c4a 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1159,14 +1159,6 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, return &vdev->vq[i]; } -void virtio_set_queue_aio(VirtQueue *vq, - void (*handle_output)(VirtIODevice *, VirtQueue *)) -{ - assert(vq->handle_output); - - vq->handle_aio_output = handle_output; -} - void virtio_del_queue(VirtIODevice *vdev, int n) { if (n < 0 || n >= VIRTIO_QUEUE_MAX) { @@ -1809,18 +1801,19 @@ static void virtio_queue_host_notifier_aio_read(EventNotifier *n) } void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx, - bool assign, bool set_handler) + void (*handle_output)(VirtIODevice *, + VirtQueue *)) { - if (assign && set_handler) { + if (handle_output) { + vq->handle_aio_output = handle_output; aio_set_event_notifier(ctx, &vq->host_notifier, true, virtio_queue_host_notifier_aio_read); } else { aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL); - } - if (!assign) { /* Test and clear notifier before after disabling event, * in case poll callback didn't have time to run. */ virtio_queue_host_notifier_aio_read(&vq->host_notifier); + vq->handle_aio_output = NULL; } } diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index fa3f93b..6a37065 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -142,9 +142,6 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, void (*handle_output)(VirtIODevice *, VirtQueue *)); -void virtio_set_queue_aio(VirtQueue *vq, - void (*handle_output)(VirtIODevice *, VirtQueue *)); - void virtio_del_queue(VirtIODevice *vdev, int n); void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num); @@ -254,7 +251,8 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq); void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign, bool set_handler); void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx, - bool assign, bool set_handler); + void (*fn)(VirtIODevice *, + VirtQueue *)); void virtio_irq(VirtQueue *vq); VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector); VirtQueue *virtio_vector_next_queue(VirtQueue *vq);