chardev: check if the chardev is registered for yanking
Not all chardevs are created via qmp_chardev_open_socket(), and those should not call the yank function registration, as this will eventually assert() not being registered. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20210204105232.834642-20-marcandre.lureau@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
3cddb8b9e0
commit
ebae6477dc
@ -417,8 +417,9 @@ static void tcp_chr_free_connection(Chardev *chr)
|
||||
|
||||
tcp_set_msgfds(chr, NULL, 0);
|
||||
remove_fd_in_watch(chr);
|
||||
if (s->state == TCP_CHARDEV_STATE_CONNECTING
|
||||
|| s->state == TCP_CHARDEV_STATE_CONNECTED) {
|
||||
if (s->registered_yank &&
|
||||
(s->state == TCP_CHARDEV_STATE_CONNECTING
|
||||
|| s->state == TCP_CHARDEV_STATE_CONNECTED)) {
|
||||
yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(s->sioc));
|
||||
@ -940,9 +941,11 @@ static int tcp_chr_add_client(Chardev *chr, int fd)
|
||||
}
|
||||
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
|
||||
tcp_chr_set_client_ioc_name(chr, sioc);
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
if (s->registered_yank) {
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
}
|
||||
ret = tcp_chr_new_client(chr, sioc);
|
||||
object_unref(OBJECT(sioc));
|
||||
return ret;
|
||||
@ -957,9 +960,11 @@ static void tcp_chr_accept(QIONetListener *listener,
|
||||
|
||||
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
|
||||
tcp_chr_set_client_ioc_name(chr, cioc);
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(cioc));
|
||||
if (s->registered_yank) {
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(cioc));
|
||||
}
|
||||
tcp_chr_new_client(chr, cioc);
|
||||
}
|
||||
|
||||
@ -975,9 +980,11 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp)
|
||||
object_unref(OBJECT(sioc));
|
||||
return -1;
|
||||
}
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
if (s->registered_yank) {
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
}
|
||||
tcp_chr_new_client(chr, sioc);
|
||||
object_unref(OBJECT(sioc));
|
||||
return 0;
|
||||
@ -993,9 +1000,11 @@ static void tcp_chr_accept_server_sync(Chardev *chr)
|
||||
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
|
||||
sioc = qio_net_listener_wait_client(s->listener);
|
||||
tcp_chr_set_client_ioc_name(chr, sioc);
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
if (s->registered_yank) {
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
}
|
||||
tcp_chr_new_client(chr, sioc);
|
||||
object_unref(OBJECT(sioc));
|
||||
}
|
||||
@ -1124,9 +1133,11 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque)
|
||||
|
||||
if (qio_task_propagate_error(task, &err)) {
|
||||
tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
|
||||
yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
if (s->registered_yank) {
|
||||
yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
}
|
||||
check_report_connect_error(chr, err);
|
||||
goto cleanup;
|
||||
}
|
||||
@ -1160,9 +1171,11 @@ static void tcp_chr_connect_client_async(Chardev *chr)
|
||||
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
|
||||
sioc = qio_channel_socket_new();
|
||||
tcp_chr_set_client_ioc_name(chr, sioc);
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
if (s->registered_yank) {
|
||||
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
|
||||
yank_generic_iochannel,
|
||||
QIO_CHANNEL(sioc));
|
||||
}
|
||||
/*
|
||||
* Normally code would use the qio_channel_socket_connect_async
|
||||
* method which uses a QIOTask + qio_task_set_error internally
|
||||
|
Loading…
Reference in New Issue
Block a user