diff mbox

[v3,18/46] ivshmem: improve error

Message ID 1442333283-13119-19-git-send-email-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Sept. 15, 2015, 4:07 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

The test whether the chardev is an AF_UNIX socket rejects
"-chardev socket,id=chr0,path=/tmp/foo,server,nowait -device
ivshmem,chardev=chr0", but fails to explain why.

Use an explicit error on why a chardev may be rejected.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/misc/ivshmem.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Claudio Fontana Sept. 22, 2015, 2:26 p.m. UTC | #1
Subject: ivshmem: improve error

Seems an interrupted sentence...

... improve error handling? improve error messages?

Ciao

Claudio

On 15.09.2015 18:07, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> The test whether the chardev is an AF_UNIX socket rejects
> "-chardev socket,id=chr0,path=/tmp/foo,server,nowait -device
> ivshmem,chardev=chr0", but fails to explain why.
> 
> Use an explicit error on why a chardev may be rejected.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  hw/misc/ivshmem.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index 084bc89..52e1e63 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -301,7 +301,7 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *
>      chr = qemu_chr_open_eventfd(eventfd);
>  
>      if (chr == NULL) {
> -        error_report("creating eventfd for eventfd %d failed", eventfd);
> +        error_report("creating chardriver for eventfd %d failed", eventfd);
>          return NULL;
>      }
>      qemu_chr_fe_claim_no_fail(chr);
> @@ -778,8 +778,12 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
>          attr |= PCI_BASE_ADDRESS_MEM_TYPE_64;
>      }
>  
> -    if ((s->server_chr != NULL) &&
> -                        (strncmp(s->server_chr->filename, "unix:", 5) == 0)) {
> +    if (s->server_chr != NULL) {
> +        if (strncmp(s->server_chr->filename, "unix:", 5)) {
> +            error_setg(errp, "chardev is not a unix client socket");
> +            return;
> +        }
> +
>          /* if we get a UNIX socket as the parameter we will talk
>           * to the ivshmem server to receive the memory region */
>  
>
Marc-André Lureau Sept. 23, 2015, 10:30 a.m. UTC | #2
On Tue, Sep 22, 2015 at 4:26 PM, Claudio Fontana
<claudio.fontana@huawei.com> wrote:
> Seems an interrupted sentence...
>
> ... improve error handling? improve error messages?


ack
diff mbox

Patch

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 084bc89..52e1e63 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -301,7 +301,7 @@  static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *
     chr = qemu_chr_open_eventfd(eventfd);
 
     if (chr == NULL) {
-        error_report("creating eventfd for eventfd %d failed", eventfd);
+        error_report("creating chardriver for eventfd %d failed", eventfd);
         return NULL;
     }
     qemu_chr_fe_claim_no_fail(chr);
@@ -778,8 +778,12 @@  static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
         attr |= PCI_BASE_ADDRESS_MEM_TYPE_64;
     }
 
-    if ((s->server_chr != NULL) &&
-                        (strncmp(s->server_chr->filename, "unix:", 5) == 0)) {
+    if (s->server_chr != NULL) {
+        if (strncmp(s->server_chr->filename, "unix:", 5)) {
+            error_setg(errp, "chardev is not a unix client socket");
+            return;
+        }
+
         /* if we get a UNIX socket as the parameter we will talk
          * to the ivshmem server to receive the memory region */