qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 05/16] pci-assign: propagate errors from get_real_id()
Date: Thu, 10 Apr 2014 10:24:34 +0200	[thread overview]
Message-ID: <1397118285-11715-6-git-send-email-lersek@redhat.com> (raw)
In-Reply-To: <1397118285-11715-1-git-send-email-lersek@redhat.com>

get_real_id() has two thin wrappers (and no other callers),
get_real_vendor_id() and get_real_device_id(); it's easiest to convert
them in one fell swoop.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 hw/i386/kvm/pci-assign.c | 45 +++++++++++++++++++++++++++------------------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 6b8db25..997ef09 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -497,47 +497,47 @@ static int assigned_dev_register_regions(PCIRegion *io_regions,
 
     /* success */
     return 0;
 }
 
-static int get_real_id(const char *devpath, const char *idname, uint16_t *val)
+static void get_real_id(const char *devpath, const char *idname, uint16_t *val,
+                        Error **errp)
 {
     FILE *f;
     char name[128];
     long id;
 
     snprintf(name, sizeof(name), "%s%s", devpath, idname);
     f = fopen(name, "r");
     if (f == NULL) {
-        error_report("%s: %s: %m", __func__, name);
-        return -1;
+        error_setg_file_open(errp, errno, name);
+        return;
     }
     if (fscanf(f, "%li\n", &id) == 1) {
         *val = id;
     } else {
-        fclose(f);
-        return -1;
+        error_setg(errp, "Failed to parse contents of '%s'", name);
     }
     fclose(f);
-
-    return 0;
 }
 
-static int get_real_vendor_id(const char *devpath, uint16_t *val)
+static void get_real_vendor_id(const char *devpath, uint16_t *val,
+                               Error **errp)
 {
-    return get_real_id(devpath, "vendor", val);
+    get_real_id(devpath, "vendor", val, errp);
 }
 
-static int get_real_device_id(const char *devpath, uint16_t *val)
+static void get_real_device_id(const char *devpath, uint16_t *val,
+                               Error **errp)
 {
-    return get_real_id(devpath, "device", val);
+    get_real_id(devpath, "device", val, errp);
 }
 
 static int get_real_device(AssignedDevice *pci_dev)
 {
     char dir[128], name[128];
-    int fd, r = 0, v;
+    int fd, r = 0;
     FILE *f;
     uint64_t start, end, size, flags;
     uint16_t id;
     PCIRegion *rp;
     PCIDevRegions *dev = &pci_dev->real_device;
@@ -637,20 +637,24 @@ again:
     }
 
     fclose(f);
 
     /* read and fill vendor ID */
-    v = get_real_vendor_id(dir, &id);
-    if (v) {
+    get_real_vendor_id(dir, &id, &local_err);
+    if (local_err) {
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
         return 1;
     }
     pci_dev->dev.config[0] = id & 0xff;
     pci_dev->dev.config[1] = (id & 0xff00) >> 8;
 
     /* read and fill device ID */
-    v = get_real_device_id(dir, &id);
-    if (v) {
+    get_real_device_id(dir, &id, &local_err);
+    if (local_err) {
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
         return 1;
     }
     pci_dev->dev.config[2] = id & 0xff;
     pci_dev->dev.config[3] = (id & 0xff00) >> 8;
 
@@ -739,10 +743,11 @@ static void free_assigned_device(AssignedDevice *dev)
 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;
+    Error *local_err = NULL;
 
     snprintf(dir, sizeof(dir), "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/",
             dev->host.domain, dev->host.bus, dev->host.slot,
             dev->host.function);
 
@@ -759,12 +764,16 @@ static char *assign_failed_examine(const AssignedDevice *dev)
         goto fail;
     }
 
     ns++;
 
-    if (get_real_vendor_id(dir, &vendor_id) ||
-        get_real_device_id(dir, &device_id)) {
+    if ((get_real_vendor_id(dir, &vendor_id, &local_err), local_err) ||
+        (get_real_device_id(dir, &device_id, &local_err), local_err)) {
+        /* We're already analyzing an assignment error, so we suppress this
+         * one just like the others above.
+         */
+        error_free(local_err);
         goto fail;
     }
 
     return g_strdup_printf(
         "*** The driver '%s' is occupying your device %04x:%02x:%02x.%x.\n"
-- 
1.8.3.1

  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 ` [Qemu-devel] [PATCH 04/16] pci-assign: make assign_failed_examine() just format the cause Laszlo Ersek
2014-04-10  8:24 ` Laszlo Ersek [this message]
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-6-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).