From patchwork Thu Apr 10 08:24:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 338046 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 31E2414009D for ; Thu, 10 Apr 2014 18:28:48 +1000 (EST) Received: from localhost ([::1]:49682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYALm-0005c1-Ay for incoming@patchwork.ozlabs.org; Thu, 10 Apr 2014 04:28:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYAIA-0005Oc-VB for qemu-devel@nongnu.org; Thu, 10 Apr 2014 04:25:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYAI1-0003KS-R1 for qemu-devel@nongnu.org; Thu, 10 Apr 2014 04:25:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYAI1-0003KH-Ic for qemu-devel@nongnu.org; Thu, 10 Apr 2014 04:24:53 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3A8OrTf008297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 10 Apr 2014 04:24:53 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3A8OlIU005705 for ; Thu, 10 Apr 2014 04:24:52 -0400 From: Laszlo Ersek To: qemu-devel@nongnu.org Date: Thu, 10 Apr 2014 10:24:33 +0200 Message-Id: <1397118285-11715-5-git-send-email-lersek@redhat.com> In-Reply-To: <1397118285-11715-1-git-send-email-lersek@redhat.com> References: <1397118285-11715-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/16] pci-assign: make assign_failed_examine() just format the cause 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This allows us to report the entire error with one error_report() call, easing future error propagation. Signed-off-by: Laszlo Ersek Reviewed-by: Eric Blake --- hw/i386/kvm/pci-assign.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c index bfce97f..6b8db25 100644 --- a/hw/i386/kvm/pci-assign.c +++ b/hw/i386/kvm/pci-assign.c @@ -729,11 +729,16 @@ static void free_assigned_device(AssignedDevice *dev) } free_msi_virqs(dev); } -static void assign_failed_examine(AssignedDevice *dev) +/* This function tries to determine the cause of the PCI assignment failure. It + * always returns the cause as a dynamically allocated, human readable string. + * If the function fails to determine the cause for any internal reason, then + * the returned string will state that fact. + */ +static char *assign_failed_examine(const AssignedDevice *dev) { char name[PATH_MAX], dir[PATH_MAX], driver[PATH_MAX] = {}, *ns; uint16_t vendor_id, device_id; int r; @@ -759,12 +764,12 @@ static void assign_failed_examine(AssignedDevice *dev) if (get_real_vendor_id(dir, &vendor_id) || get_real_device_id(dir, &device_id)) { goto fail; } - error_printf("*** The driver '%s' is occupying your device " - "%04x:%02x:%02x.%x.\n" + return g_strdup_printf( + "*** The driver '%s' is occupying your device %04x:%02x:%02x.%x.\n" "***\n" "*** You can try the following commands to free it:\n" "***\n" "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/new_id\n" "*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/%s/unbind\n" @@ -776,14 +781,12 @@ static void assign_failed_examine(AssignedDevice *dev) dev->host.function, vendor_id, device_id, dev->host.domain, dev->host.bus, dev->host.slot, dev->host.function, ns, dev->host.domain, dev->host.bus, dev->host.slot, dev->host.function, vendor_id, device_id); - return; - fail: - error_report("Couldn't find out why."); + return g_strdup("Couldn't find out why."); } static int assign_device(AssignedDevice *dev) { uint32_t flags = KVM_DEV_ASSIGN_ENABLE_IOMMU; @@ -808,18 +811,23 @@ static int assign_device(AssignedDevice *dev) flags |= KVM_DEV_ASSIGN_PCI_2_3; } r = kvm_device_pci_assign(kvm_state, &dev->host, flags, &dev->dev_id); if (r < 0) { - error_report("Failed to assign device \"%s\" : %s", - dev->dev.qdev.id, strerror(-r)); - switch (r) { - case -EBUSY: - assign_failed_examine(dev); + case -EBUSY: { + char *cause; + + cause = assign_failed_examine(dev); + error_report("Failed to assign device \"%s\" : %s\n%s", + dev->dev.qdev.id, strerror(-r), cause); + g_free(cause); break; + } default: + error_report("Failed to assign device \"%s\" : %s", + dev->dev.qdev.id, strerror(-r)); break; } } return r; }