[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 3/8] chardev/char-socket.c: Add yank feature
From: |
Lukas Straub |
Subject: |
[PATCH v7 3/8] chardev/char-socket.c: Add yank feature |
Date: |
Tue, 4 Aug 2020 10:11:41 +0200 |
Register a yank function to shutdown the socket on yank.
Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
---
chardev/char-socket.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index ef62dbf3d7..8e2865ca83 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -34,6 +34,7 @@
#include "qapi/error.h"
#include "qapi/clone-visitor.h"
#include "qapi/qapi-visit-sockets.h"
+#include "qemu/yank.h"
#include "chardev/char-io.h"
@@ -69,6 +70,7 @@ typedef struct {
size_t read_msgfds_num;
int *write_msgfds;
size_t write_msgfds_num;
+ char *yank_name;
SocketAddress *addr;
bool is_listen;
@@ -413,6 +415,11 @@ 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) {
+ yank_unregister_function(s->yank_name, yank_generic_iochannel,
+ QIO_CHANNEL(s->sioc));
+ }
object_unref(OBJECT(s->sioc));
s->sioc = NULL;
object_unref(OBJECT(s->ioc));
@@ -916,6 +923,8 @@ 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(s->yank_name, yank_generic_iochannel,
+ QIO_CHANNEL(sioc));
ret = tcp_chr_new_client(chr, sioc);
object_unref(OBJECT(sioc));
return ret;
@@ -930,6 +939,8 @@ 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(s->yank_name, yank_generic_iochannel,
+ QIO_CHANNEL(cioc));
tcp_chr_new_client(chr, cioc);
}
@@ -945,6 +956,8 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error
**errp)
object_unref(OBJECT(sioc));
return -1;
}
+ yank_register_function(s->yank_name, yank_generic_iochannel,
+ QIO_CHANNEL(sioc));
tcp_chr_new_client(chr, sioc);
object_unref(OBJECT(sioc));
return 0;
@@ -960,6 +973,8 @@ 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(s->yank_name, yank_generic_iochannel,
+ QIO_CHANNEL(sioc));
tcp_chr_new_client(chr, sioc);
object_unref(OBJECT(sioc));
}
@@ -1070,6 +1085,10 @@ static void char_socket_finalize(Object *obj)
object_unref(OBJECT(s->tls_creds));
}
g_free(s->tls_authz);
+ if (s->yank_name) {
+ yank_unregister_instance(s->yank_name);
+ g_free(s->yank_name);
+ }
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
}
@@ -1085,6 +1104,8 @@ 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(s->yank_name, yank_generic_iochannel,
+ QIO_CHANNEL(sioc));
check_report_connect_error(chr, err);
goto cleanup;
}
@@ -1118,6 +1139,8 @@ 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(s->yank_name, 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
@@ -1360,6 +1383,14 @@ static void qmp_chardev_open_socket(Chardev *chr,
qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS);
}
+ s->yank_name = g_strconcat("chardev:", chr->label, NULL);
+ yank_register_instance(s->yank_name, errp);
+ if (*errp) {
+ g_free(s->yank_name);
+ s->yank_name = NULL;
+ return;
+ }
+
/* be isn't opened until we get a connection */
*be_opened = false;
--
2.20.1
pgpXfuX68bC1q.pgp
Description: OpenPGP digital signature
- [PATCH v7 0/8] Introduce 'yank' oob qmp command to recover from hanging qemu, Lukas Straub, 2020/08/04
- [PATCH v7 2/8] block/nbd.c: Add yank feature, Lukas Straub, 2020/08/04
- [PATCH v7 3/8] chardev/char-socket.c: Add yank feature,
Lukas Straub <=
- [PATCH v7 4/8] migration: Add yank feature, Lukas Straub, 2020/08/04
- [PATCH v7 5/8] io/channel-tls.c: make qio_channel_tls_shutdown thread-safe, Lukas Straub, 2020/08/04
- [PATCH v7 6/8] io: Document thread-safety of qio_channel_shutdown, Lukas Straub, 2020/08/04
- [PATCH v7 7/8] MAINTAINERS: Add myself as maintainer for yank feature, Lukas Straub, 2020/08/04
- [PATCH v7 8/8] tests/test-char.c: Wait for the chardev to connect in char_socket_client_dupid_test, Lukas Straub, 2020/08/04
- Re: [PATCH v7 0/8] Introduce 'yank' oob qmp command to recover from hanging qemu, Lukas Straub, 2020/08/18