qemu-char: cleanup HAVE_CHARDEV_*

Move the #ifdef up into qmp_chardev_add, and avoid duplicating
the code that reports unavailable backends.  Split HAVE_CHARDEV_TTY
into HAVE_CHARDEV_SERIAL and HAVE_CHARDEV_PTY.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2015-10-12 09:46:23 +02:00
parent eaeba65304
commit d809ab9521

View file

@ -1196,7 +1196,8 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
|| defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) \ || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) \
|| defined(__GLIBC__) || defined(__GLIBC__)
#define HAVE_CHARDEV_TTY 1 #define HAVE_CHARDEV_SERIAL 1
#define HAVE_CHARDEV_PTY 1
typedef struct { typedef struct {
GIOChannel *fd; GIOChannel *fd;
@ -1832,6 +1833,8 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd)
#else /* _WIN32 */ #else /* _WIN32 */
#define HAVE_CHARDEV_SERIAL 1
typedef struct { typedef struct {
int max_size; int max_size;
HANDLE hcom, hrecv, hsend; HANDLE hcom, hrecv, hsend;
@ -4069,10 +4072,10 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp)
return qemu_chr_open_fd(in, out); return qemu_chr_open_fd(in, out);
} }
#ifdef HAVE_CHARDEV_SERIAL
static CharDriverState *qmp_chardev_open_serial(ChardevHostdev *serial, static CharDriverState *qmp_chardev_open_serial(ChardevHostdev *serial,
Error **errp) Error **errp)
{ {
#ifdef HAVE_CHARDEV_TTY
int fd; int fd;
fd = qmp_chardev_open_file_source(serial->device, O_RDWR, errp); fd = qmp_chardev_open_file_source(serial->device, O_RDWR, errp);
@ -4081,16 +4084,12 @@ static CharDriverState *qmp_chardev_open_serial(ChardevHostdev *serial,
} }
qemu_set_nonblock(fd); qemu_set_nonblock(fd);
return qemu_chr_open_tty_fd(fd); return qemu_chr_open_tty_fd(fd);
#else
error_setg(errp, "character device backend type 'serial' not supported");
return NULL;
#endif
} }
#ifdef HAVE_CHARDEV_PARPORT
static CharDriverState *qmp_chardev_open_parallel(ChardevHostdev *parallel, static CharDriverState *qmp_chardev_open_parallel(ChardevHostdev *parallel,
Error **errp) Error **errp)
{ {
#ifdef HAVE_CHARDEV_PARPORT
int fd; int fd;
fd = qmp_chardev_open_file_source(parallel->device, O_RDWR, errp); fd = qmp_chardev_open_file_source(parallel->device, O_RDWR, errp);
@ -4098,11 +4097,8 @@ static CharDriverState *qmp_chardev_open_parallel(ChardevHostdev *parallel,
return NULL; return NULL;
} }
return qemu_chr_open_pp_fd(fd); return qemu_chr_open_pp_fd(fd);
#else
error_setg(errp, "character device backend type 'parallel' not supported");
return NULL;
#endif
} }
#endif
#endif /* WIN32 */ #endif /* WIN32 */
@ -4227,12 +4223,16 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
case CHARDEV_BACKEND_KIND_FILE: case CHARDEV_BACKEND_KIND_FILE:
chr = qmp_chardev_open_file(backend->file, &local_err); chr = qmp_chardev_open_file(backend->file, &local_err);
break; break;
#ifdef HAVE_CHARDEV_SERIAL
case CHARDEV_BACKEND_KIND_SERIAL: case CHARDEV_BACKEND_KIND_SERIAL:
chr = qmp_chardev_open_serial(backend->serial, &local_err); chr = qmp_chardev_open_serial(backend->serial, &local_err);
break; break;
#endif
#ifdef HAVE_CHARDEV_PARPORT
case CHARDEV_BACKEND_KIND_PARALLEL: case CHARDEV_BACKEND_KIND_PARALLEL:
chr = qmp_chardev_open_parallel(backend->parallel, &local_err); chr = qmp_chardev_open_parallel(backend->parallel, &local_err);
break; break;
#endif
case CHARDEV_BACKEND_KIND_PIPE: case CHARDEV_BACKEND_KIND_PIPE:
chr = qemu_chr_open_pipe(backend->pipe); chr = qemu_chr_open_pipe(backend->pipe);
break; break;
@ -4242,7 +4242,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
case CHARDEV_BACKEND_KIND_UDP: case CHARDEV_BACKEND_KIND_UDP:
chr = qmp_chardev_open_udp(backend->udp, &local_err); chr = qmp_chardev_open_udp(backend->udp, &local_err);
break; break;
#ifdef HAVE_CHARDEV_TTY #ifdef HAVE_CHARDEV_PTY
case CHARDEV_BACKEND_KIND_PTY: case CHARDEV_BACKEND_KIND_PTY:
chr = qemu_chr_open_pty(id, ret); chr = qemu_chr_open_pty(id, ret);
break; break;