From: Laszlo Ersek <lersek@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 04/16] pci-assign: make assign_failed_examine() just format the cause
Date: Thu, 10 Apr 2014 10:24:33 +0200 [thread overview]
Message-ID: <1397118285-11715-5-git-send-email-lersek@redhat.com> (raw)
In-Reply-To: <1397118285-11715-1-git-send-email-lersek@redhat.com>
This allows us to report the entire error with one error_report() call,
easing future error propagation.
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
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;
}
--
1.8.3.1
next prev parent reply other threads:[~2014-04-10 8:25 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-10 8:24 [Qemu-devel] [PATCH 00/16] PCI device assignment: improve error reporting over QMP Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 01/16] cutils: tighten qemu_parse_fd() Laszlo Ersek
2014-04-10 11:51 ` Eric Blake
2014-04-10 8:24 ` [Qemu-devel] [PATCH 02/16] monitor: add Error-propagating monitor_handle_fd_param2() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 03/16] pci-assign: accept Error from monitor_handle_fd_param2() Laszlo Ersek
2014-04-10 8:24 ` Laszlo Ersek [this message]
2014-04-10 8:24 ` [Qemu-devel] [PATCH 05/16] pci-assign: propagate errors from get_real_id() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 06/16] pci-assign: propagate Error from check_irqchip_in_kernel() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 07/16] pci: add Error-propagating pci_add_capability2() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 08/16] pci-assign: accept Error from pci_add_capability2() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 09/16] pci-assign: assignment should fail if we can't read config space Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 10/16] pci-assign: propagate errors from get_real_device() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 11/16] pci-assign: propagate errors from assigned_device_pci_cap_init() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 12/16] pci-assign: propagate errors from assigned_dev_register_msix_mmio() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 13/16] pci-assign: propagate errors from assigned_dev_register_regions() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 14/16] pci-assign: propagate errors from assign_device() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 15/16] pci-assign: propagate errors from assign_intx() Laszlo Ersek
2014-04-10 8:24 ` [Qemu-devel] [PATCH 16/16] pci-assign: assigned_initfn(): set monitor error in common error handler Laszlo Ersek
[not found] ` <536034EB.5010400@redhat.com>
[not found] ` <53604550.1000202@redhat.com>
2014-05-07 13:52 ` Luiz Capitulino
2014-05-07 15:17 ` Laszlo Ersek
[not found] ` <5360FF1D.6020300@redhat.com>
2014-05-07 13:52 ` [Qemu-devel] [PATCH 00/16] PCI device assignment: improve error reporting over QMP Luiz Capitulino
2014-05-07 15:18 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1397118285-11715-5-git-send-email-lersek@redhat.com \
--to=lersek@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).