From patchwork Tue Jan 11 11:49:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 78376 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 54DE8B7082 for ; Wed, 12 Jan 2011 00:00:03 +1100 (EST) Received: from localhost ([127.0.0.1]:55440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pcclk-0005Fw-I3 for incoming@patchwork.ozlabs.org; Tue, 11 Jan 2011 06:52:08 -0500 Received: from [140.186.70.92] (port=49922 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pccjg-0005DR-DU for qemu-devel@nongnu.org; Tue, 11 Jan 2011 06:50:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PccjY-0004pt-9W for qemu-devel@nongnu.org; Tue, 11 Jan 2011 06:49:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47567) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PccjY-0004pc-2f for qemu-devel@nongnu.org; Tue, 11 Jan 2011 06:49:52 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0BBnYUE002301 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Jan 2011 06:49:34 -0500 Received: from redhat.com (vpn-9-5.rdu.redhat.com [10.11.9.5]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id p0BBnWKb002128; Tue, 11 Jan 2011 06:49:33 -0500 Date: Tue, 11 Jan 2011 13:49:18 +0200 From: "Michael S. Tsirkin" To: Stefan Hajnoczi Message-ID: <20110111114917.GA8269@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] ioeventfd: error handling cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org - Don't return status from start/stop functions where it's ignored - report errors to make debugging easier - assert on unexpected failures - don't disable notifiers on error so that we'll retry when guest driver restarts Signed-off-by: Michael S. Tsirkin Acked-by: Stefan Hajnoczi --- Stefan, could you review/test this and ack/nack appropriately please? diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 70c40ee..d07ff97 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -195,12 +195,16 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy, if (assign) { r = event_notifier_init(notifier, 1); if (r < 0) { + error_report("%s: unable to init event notifier: %d", + __func__, r); return r; } r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier), proxy->addr + VIRTIO_PCI_QUEUE_NOTIFY, n, assign); if (r < 0) { + error_report("%s: unable to map ioeventfd: %d", + __func__, r); event_notifier_cleanup(notifier); } } else { @@ -208,6 +212,8 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy, proxy->addr + VIRTIO_PCI_QUEUE_NOTIFY, n, assign); if (r < 0) { + error_report("%s: unable to unmap ioeventfd: %d", + __func__, r); return r; } @@ -246,14 +252,14 @@ static void virtio_pci_set_host_notifier_fd_handler(VirtIOPCIProxy *proxy, } } -static int virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy) +static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy) { int n, r; if (!(proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) || proxy->ioeventfd_disabled || proxy->ioeventfd_started) { - return 0; + return; } for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) { @@ -269,7 +275,7 @@ static int virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy) virtio_pci_set_host_notifier_fd_handler(proxy, n, true); } proxy->ioeventfd_started = true; - return 0; + return; assign_error: while (--n >= 0) { @@ -278,19 +284,20 @@ assign_error: } virtio_pci_set_host_notifier_fd_handler(proxy, n, false); - virtio_pci_set_host_notifier_internal(proxy, n, false); + r = virtio_pci_set_host_notifier_internal(proxy, n, false); + assert(r >= 0); } proxy->ioeventfd_started = false; - proxy->ioeventfd_disabled = true; - return r; + error_report("%s: failed. Fallback to a userspace (slower).", __func__); } -static int virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy) +static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy) { + int r; int n; if (!proxy->ioeventfd_started) { - return 0; + return; } for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) { @@ -299,10 +306,10 @@ static int virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy) } virtio_pci_set_host_notifier_fd_handler(proxy, n, false); - virtio_pci_set_host_notifier_internal(proxy, n, false); + r = virtio_pci_set_host_notifier_internal(proxy, n, false); + assert(r >= 0); } proxy->ioeventfd_started = false; - return 0; } static void virtio_pci_reset(DeviceState *d) @@ -706,7 +713,6 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY; proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE; proxy->host_features = vdev->get_features(vdev, proxy->host_features); - } static int virtio_blk_init_pci(PCIDevice *pci_dev)