diff mbox

[v2,5/5] spice-qemu-char: convert qemu_chr_open_spice_vmc to use Error API

Message ID 1415007872-8228-6-git-send-email-zhang.zhanghailiang@huawei.com
State New
Headers show

Commit Message

Zhanghailiang Nov. 3, 2014, 9:44 a.m. UTC
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 include/ui/qemu-spice.h     | 2 +-
 qemu-char.c                 | 2 +-
 spice-qemu-char.c           | 4 ++--
 stubs/qemu-chr-open-spice.c | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

Comments

Michael Tokarev Nov. 3, 2014, 10:04 a.m. UTC | #1
03.11.2014 12:44, zhanghailiang wrote:
[]
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -4252,7 +4252,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
>  #endif
>  #ifdef CONFIG_SPICE
>      case CHARDEV_BACKEND_KIND_SPICEVMC:
> -        chr = qemu_chr_open_spice_vmc(backend->spicevmc->type);
> +        chr = qemu_chr_open_spice_vmc(backend->spicevmc->type, errp);
>          break;
>      case CHARDEV_BACKEND_KIND_SPICEPORT:
>          chr = qemu_chr_open_spice_port(backend->spiceport->fqdn);

Now this is funny.  Why we have two functions nearby using different
error reporting APIs?  Maybe qemu_chr_open_spice_port() should be
converted to Error API too, at the same time (maybe in the same
patch or in a subsequent patch in the same series)?

Thanks,

/mjt
Zhanghailiang Nov. 3, 2014, 11:17 a.m. UTC | #2
On 2014/11/3 18:04, Michael Tokarev wrote:
> 03.11.2014 12:44, zhanghailiang wrote:
> []
>> --- a/qemu-char.c
>> +++ b/qemu-char.c
>> @@ -4252,7 +4252,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
>>   #endif
>>   #ifdef CONFIG_SPICE
>>       case CHARDEV_BACKEND_KIND_SPICEVMC:
>> -        chr = qemu_chr_open_spice_vmc(backend->spicevmc->type);
>> +        chr = qemu_chr_open_spice_vmc(backend->spicevmc->type, errp);
>>           break;
>>       case CHARDEV_BACKEND_KIND_SPICEPORT:
>>           chr = qemu_chr_open_spice_port(backend->spiceport->fqdn);
>
> Now this is funny.  Why we have two functions nearby using different
> error reporting APIs?  Maybe qemu_chr_open_spice_port() should be
> converted to Error API too, at the same time (maybe in the same
> patch or in a subsequent patch in the same series)?
>

Actually, after patch 3, there will be no error case for this function, it can not
fail, so i just leave it. What's your opinion? Thanks.
diff mbox

Patch

diff --git a/include/ui/qemu-spice.h b/include/ui/qemu-spice.h
index a93b4b2..33882aa 100644
--- a/include/ui/qemu-spice.h
+++ b/include/ui/qemu-spice.h
@@ -48,7 +48,7 @@  int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
 void do_info_spice_print(Monitor *mon, const QObject *data);
 void do_info_spice(Monitor *mon, QObject **ret_data);
 
-CharDriverState *qemu_chr_open_spice_vmc(const char *type);
+CharDriverState *qemu_chr_open_spice_vmc(const char *type, Error **errp);
 #if SPICE_SERVER_VERSION >= 0x000c02
 CharDriverState *qemu_chr_open_spice_port(const char *name);
 void qemu_spice_register_ports(void);
diff --git a/qemu-char.c b/qemu-char.c
index 3ebdfe7..aa528ae 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -4252,7 +4252,7 @@  ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
 #endif
 #ifdef CONFIG_SPICE
     case CHARDEV_BACKEND_KIND_SPICEVMC:
-        chr = qemu_chr_open_spice_vmc(backend->spicevmc->type);
+        chr = qemu_chr_open_spice_vmc(backend->spicevmc->type, errp);
         break;
     case CHARDEV_BACKEND_KIND_SPICEPORT:
         chr = qemu_chr_open_spice_port(backend->spiceport->fqdn);
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 48ee37f..5c47287 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -286,7 +286,7 @@  static CharDriverState *chr_open(const char *subtype,
     return chr;
 }
 
-CharDriverState *qemu_chr_open_spice_vmc(const char *type)
+CharDriverState *qemu_chr_open_spice_vmc(const char *type, Error **errp)
 {
     const char **psubtype = spice_server_char_device_recognized_subtypes();
 
@@ -296,7 +296,7 @@  CharDriverState *qemu_chr_open_spice_vmc(const char *type)
         }
     }
     if (*psubtype == NULL) {
-        fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type);
+        error_setg(errp, "spice-qemu-char: unsupported type: %s", type);
         print_allowed_subtypes();
         return NULL;
     }
diff --git a/stubs/qemu-chr-open-spice.c b/stubs/qemu-chr-open-spice.c
index f1c4849..55826ed 100644
--- a/stubs/qemu-chr-open-spice.c
+++ b/stubs/qemu-chr-open-spice.c
@@ -1,7 +1,7 @@ 
 #include "qemu-common.h"
 #include "ui/qemu-spice.h"
 
-CharDriverState *qemu_chr_open_spice_vmc(const char *type)
+CharDriverState *qemu_chr_open_spice_vmc(const char *type, Error **errp)
 {
     return NULL;
 }