All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: <xen-devel@lists.xenproject.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Wei Liu <wl@xen.org>
Subject: [Xen-devel] [PATCH v2 25/35] libxl_pci: Coding style of do_pci_add
Date: Thu, 19 Sep 2019 18:16:45 +0100	[thread overview]
Message-ID: <20190919171656.899649-26-anthony.perard@citrix.com> (raw)
In-Reply-To: <20190919171656.899649-1-anthony.perard@citrix.com>

do_pci_add is going to be asynchronous, so we start by having a single
path out of the function. All `return`s instead set rc and goto out.

While here, some use of `rc' was used to store the return value of
libxc calls, change them to store into `r'. Also, add the value of `r'
in the error message of those calls.

There were an `out' label that was use it seems to skip setting up the
IRQ, the label has been renamed to `out_no_irq'.

No functional changes.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/libxl/libxl_pci.c | 79 ++++++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 33 deletions(-)

diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index 4b1aed1895cc..b9ca69f5f0b3 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -995,15 +995,19 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid,
     uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED;
     uint32_t domainid = domid;
     bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid);
+    int r;
 
-    if (type == LIBXL_DOMAIN_TYPE_INVALID)
-        return ERROR_FAIL;
+    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
 
     if (type == LIBXL_DOMAIN_TYPE_HVM) {
         hvm = 1;
         if (libxl__wait_for_device_model_deprecated(gc, domid, "running",
                                          NULL, NULL, NULL) < 0) {
-            return ERROR_FAIL;
+            rc = ERROR_FAIL;
+            goto out;
         }
         switch (libxl__device_model_version_running(gc, domid)) {
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
@@ -1013,10 +1017,10 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid,
                 rc = libxl__qmp_pci_add(gc, domid, pcidev);
                 break;
             default:
-                return ERROR_INVAL;
+                rc = ERROR_INVAL;
         }
         if ( rc )
-            return ERROR_FAIL;
+            goto out;
     }
 
     sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain,
@@ -1027,7 +1031,8 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid,
 
     if (f == NULL) {
         LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path);
-        return ERROR_FAIL;
+        rc = ERROR_FAIL;
+        goto out;
     }
     for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) {
         if (fscanf(f, "0x%llx 0x%llx 0x%llx\n", &start, &end, &flags) != 3)
@@ -1035,25 +1040,25 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid,
         size = end - start + 1;
         if (start) {
             if (flags & PCI_BAR_IO) {
-                rc = xc_domain_ioport_permission(ctx->xch, domid, start, size, 1);
-                if (rc < 0) {
+                r = xc_domain_ioport_permission(ctx->xch, domid, start, size, 1);
+                if (r < 0) {
                     LOGED(ERROR, domainid,
-                          "Error: xc_domain_ioport_permission error 0x%llx/0x%llx",
-                          start,
-                          size);
+                          "xc_domain_ioport_permission 0x%llx/0x%llx (error %d)",
+                          start, size, r);
                     fclose(f);
-                    return ERROR_FAIL;
+                    rc = ERROR_FAIL;
+                    goto out;
                 }
             } else {
-                rc = xc_domain_iomem_permission(ctx->xch, domid, start>>XC_PAGE_SHIFT,
+                r = xc_domain_iomem_permission(ctx->xch, domid, start>>XC_PAGE_SHIFT,
                                                 (size+(XC_PAGE_SIZE-1))>>XC_PAGE_SHIFT, 1);
-                if (rc < 0) {
+                if (r < 0) {
                     LOGED(ERROR, domainid,
-                          "Error: xc_domain_iomem_permission error 0x%llx/0x%llx",
-                          start,
-                          size);
+                          "xc_domain_iomem_permission 0x%llx/0x%llx (error %d)",
+                          start, size, r);
                     fclose(f);
-                    return ERROR_FAIL;
+                    rc = ERROR_FAIL;
+                    goto out;
                 }
             }
         }
@@ -1064,20 +1069,24 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid,
     f = fopen(sysfs_path, "r");
     if (f == NULL) {
         LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path);
-        goto out;
+        goto out_no_irq;
     }
     if ((fscanf(f, "%u", &irq) == 1) && irq) {
-        rc = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq);
-        if (rc < 0) {
-            LOGED(ERROR, domainid, "Error: xc_physdev_map_pirq irq=%d", irq);
+        r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq);
+        if (r < 0) {
+            LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=%d (error=%d)",
+                  irq, r);
             fclose(f);
-            return ERROR_FAIL;
+            rc = ERROR_FAIL;
+            goto out;
         }
-        rc = xc_domain_irq_permission(ctx->xch, domid, irq, 1);
-        if (rc < 0) {
-            LOGED(ERROR, domainid, "Error: xc_domain_irq_permission irq=%d", irq);
+        r = xc_domain_irq_permission(ctx->xch, domid, irq, 1);
+        if (r < 0) {
+            LOGED(ERROR, domainid,
+                  "xc_domain_irq_permission irq=%d (error=%d)", irq, r);
             fclose(f);
-            return ERROR_FAIL;
+            rc = ERROR_FAIL;
+            goto out;
         }
     }
     fclose(f);
@@ -1087,22 +1096,25 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid,
         if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive",
                              pcidev) < 0 ) {
             LOGD(ERROR, domainid, "Setting permissive for device");
-            return ERROR_FAIL;
+            rc = ERROR_FAIL;
+            goto out;
         }
     }
 
-out:
+out_no_irq:
     if (!isstubdom) {
         if (pcidev->rdm_policy == LIBXL_RDM_RESERVE_POLICY_STRICT) {
             flag &= ~XEN_DOMCTL_DEV_RDM_RELAXED;
         } else if (pcidev->rdm_policy != LIBXL_RDM_RESERVE_POLICY_RELAXED) {
             LOGED(ERROR, domainid, "unknown rdm check flag.");
-            return ERROR_FAIL;
+            rc = ERROR_FAIL;
+            goto out;
         }
-        rc = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev), flag);
-        if (rc < 0 && (hvm || errno != ENOSYS)) {
+        r = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev), flag);
+        if (r < 0 && (hvm || errno != ENOSYS)) {
             LOGED(ERROR, domainid, "xc_assign_device failed");
-            return ERROR_FAIL;
+            rc = ERROR_FAIL;
+            goto out;
         }
     }
 
@@ -1110,6 +1122,7 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid,
         rc = libxl__device_pci_add_xenstore(gc, domid, pcidev, starting);
     else
         rc = 0;
+out:
     return rc;
 }
 
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-09-19 17:41 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 17:16 [Xen-devel] [PATCH v2 00/35] libxl refactoring to use ev_qmp (with API changes) Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 01/35] libxl: Make libxl_domain_unpause async Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 02/35] libxl: Make libxl_send_trigger async Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 03/35] libxl: Make libxl_set_vcpuonline async Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 04/35] libxl: Make libxl_retrieve_domain_configuration async Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 05/35] libxl: Make libxl_qemu_monitor_command async Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 06/35] libxl: Use ev_qmp for switch_qemu_xen_logdirty Anthony PERARD
2019-09-19 19:14   ` Ian Jackson
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 07/35] libxl: Move "qmp_initializations" to libxl_dm Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 08/35] libxl: Replace libxl__qmp_initializations by ev_qmp calls Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 09/35] libxl: Deprecate libxl__domain_{unpause, resume} Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 10/35] libxl: Re-introduce libxl__domain_resume Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 11/35] libxl_domain: Convert libxl_domain_resume to use libxl__domain_resume Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 12/35] libxl: Re-introduce libxl__domain_unpause Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 13/35] libxl_dm: Update libxl__spawn_stub_dm to use libxl__domain_unpause Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 14/35] libxl_domain: Convert libxl_domain_unpause " Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 15/35] libxl: Inline do_usbdev_add into libxl__device_usbdev_add Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 16/35] libxl: Inline do_usbdev_remove into libxl__device_usbdev_remove Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 17/35] libxl: Add libxl__ev_qmp to libxl__ao_device Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 18/35] libxl: Add device_{config, type} " Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 19/35] libxl_usb: Make libxl__device_usbctrl_add uses ev_qmp Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 20/35] libxl_usb: Make libxl__initiate_device_usbctrl_remove " Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 21/35] libxl_usb: Make libxl__device_usbdev_add " Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 22/35] libxl: Use aodev for libxl__device_usbdev_remove Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 23/35] libxl: libxl__initiate_device_usbdev_remove now use ev_qmp Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 24/35] libxl: Remove libxl__qmp_run_command_flexarray Anthony PERARD
2019-09-19 17:16 ` Anthony PERARD [this message]
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 26/35] libxl_pci: Only check if qemu-dm is running in qemu-trad case Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 27/35] libxl_pci: Use libxl__ao_device with libxl__device_pci_add Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 28/35] libxl_pci: Use ev_qmp in do_pci_add Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 29/35] libxl_pci: Use libxl__ao_device with pci_remove Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 30/35] libxl_pci: Use ev_qmp for pci_remove Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 31/35] libxl: Use ev_qmp for libxl_send_trigger Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 32/35] libxl: Use ev_qmp in libxl_set_vcpuonline Anthony PERARD
2019-09-19 19:17   ` [Xen-devel] [PATCH v2 00/35] libxl refactoring to use ev_qmp (with API changes) [and 1 more messages] Ian Jackson
2019-09-20  9:48     ` Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 33/35] libxl: libxl_retrieve_domain_configuration now uses ev_qmp Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 34/35] libxl: libxl_qemu_monitor_command " Anthony PERARD
2019-09-19 17:16 ` [Xen-devel] [PATCH v2 35/35] libxl_pci: Extract common part of *qemu_trad_watch_state_cb Anthony PERARD
2019-09-19 19:18   ` Ian Jackson
2019-09-19 19:19 ` [Xen-devel] [PATCH v2 00/35] libxl refactoring to use ev_qmp (with API changes) Ian Jackson

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=20190919171656.899649-26-anthony.perard@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.