diff mbox

pci-assign: Fix error_report of pci-stub message

Message ID f00e8e853faf59795e28a64a2c5d2ed9e0441239.1381424309.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson Oct. 10, 2013, 4:58 p.m. UTC
Using multiple calls to error_report here means every line is
prefaced with the (potentially long) pci-assign command line
arguments. Use a single error_report to preserve the intended
formatting.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
 hw/i386/kvm/pci-assign.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

Comments

Alex Williamson Oct. 10, 2013, 5:03 p.m. UTC | #1
On Thu, 2013-10-10 at 12:58 -0400, Cole Robinson wrote:
> Using multiple calls to error_report here means every line is
> prefaced with the (potentially long) pci-assign command line
> arguments. Use a single error_report to preserve the intended
> formatting.
> 
> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
>  hw/i386/kvm/pci-assign.c | 34 +++++++++++++++-------------------
>  1 file changed, 15 insertions(+), 19 deletions(-)

Acked-by: Alex Williamson <alex.williamson@redhat.com>


> diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
> index 5618173..787b86e 100644
> --- a/hw/i386/kvm/pci-assign.c
> +++ b/hw/i386/kvm/pci-assign.c
> @@ -792,25 +792,21 @@ static void assign_failed_examine(AssignedDevice *dev)
>      }
>  
>      error_report("*** The driver '%s' is occupying your device "
> -                 "%04x:%02x:%02x.%x.",
> -                 ns, dev->host.domain, dev->host.bus, dev->host.slot,
> -                 dev->host.function);
> -    error_report("***");
> -    error_report("*** You can try the following commands to free it:");
> -    error_report("***");
> -    error_report("*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/"
> -                 "new_id", vendor_id, device_id);
> -    error_report("*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
> -                 "%s/unbind",
> -                 dev->host.domain, dev->host.bus, dev->host.slot,
> -                 dev->host.function, ns);
> -    error_report("*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
> -                 "pci-stub/bind",
> -                 dev->host.domain, dev->host.bus, dev->host.slot,
> -                 dev->host.function);
> -    error_report("*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub"
> -                 "/remove_id", vendor_id, device_id);
> -    error_report("***");
> +        "%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"
> +        "*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
> +        "pci-stub/bind\n"
> +        "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/remove_id\n"
> +        "***",
> +        ns, dev->host.domain, dev->host.bus, dev->host.slot,
> +        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;
>
Markus Armbruster Oct. 11, 2013, 6:19 a.m. UTC | #2
Cole Robinson <crobinso@redhat.com> writes:

> Using multiple calls to error_report here means every line is
> prefaced with the (potentially long) pci-assign command line
> arguments. Use a single error_report to preserve the intended
> formatting.

The orthodox way to do this is to use error_report() for the
(single-line!) error message, then error_printf() for additional
information.  See commit 2da2e52..312fd5f for an example.
Cole Robinson Oct. 11, 2013, 3:49 p.m. UTC | #3
On 10/11/2013 02:19 AM, Markus Armbruster wrote:
> Cole Robinson <crobinso@redhat.com> writes:
> 
>> Using multiple calls to error_report here means every line is
>> prefaced with the (potentially long) pci-assign command line
>> arguments. Use a single error_report to preserve the intended
>> formatting.
> 
> The orthodox way to do this is to use error_report() for the
> (single-line!) error message, then error_printf() for additional
> information.  See commit 2da2e52..312fd5f for an example.
> 

Sounds good. This code path is always preceded by an error_report() call, we
can just change this massive message to error_printf().

- Cole
diff mbox

Patch

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 5618173..787b86e 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -792,25 +792,21 @@  static void assign_failed_examine(AssignedDevice *dev)
     }
 
     error_report("*** The driver '%s' is occupying your device "
-                 "%04x:%02x:%02x.%x.",
-                 ns, dev->host.domain, dev->host.bus, dev->host.slot,
-                 dev->host.function);
-    error_report("***");
-    error_report("*** You can try the following commands to free it:");
-    error_report("***");
-    error_report("*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/"
-                 "new_id", vendor_id, device_id);
-    error_report("*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
-                 "%s/unbind",
-                 dev->host.domain, dev->host.bus, dev->host.slot,
-                 dev->host.function, ns);
-    error_report("*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
-                 "pci-stub/bind",
-                 dev->host.domain, dev->host.bus, dev->host.slot,
-                 dev->host.function);
-    error_report("*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub"
-                 "/remove_id", vendor_id, device_id);
-    error_report("***");
+        "%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"
+        "*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
+        "pci-stub/bind\n"
+        "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/remove_id\n"
+        "***",
+        ns, dev->host.domain, dev->host.bus, dev->host.slot,
+        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;