[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V2 18/22] chardev: cpr for sockets
From: |
Steve Sistare |
Subject: |
[PATCH V2 18/22] chardev: cpr for sockets |
Date: |
Tue, 5 Jan 2021 07:42:06 -0800 |
Define qio_channel_socket_reuse to initialize a channel based on an existing
socket fd. Save accepted socket fds in the environment before cprsave, and
look for fds in the environment after cprload. Reject cprsave if a socket
enables the TLS or websocket option.
Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
chardev/char-socket.c | 30 ++++++++++++++++++++++++++++++
include/io/channel-socket.h | 12 ++++++++++++
io/channel-socket.c | 9 +++++++++
stubs/Makefile.objs | 1 +
stubs/cpr.c | 3 +++
5 files changed, 55 insertions(+)
create mode 100644 stubs/cpr.c
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index ef62dbf..0965305 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -36,6 +36,7 @@
#include "qapi/qapi-visit-sockets.h"
#include "chardev/char-io.h"
+#include "qemu/env.h"
/***********************************************************/
/* TCP Net console */
@@ -400,6 +401,7 @@ static void tcp_chr_free_connection(Chardev *chr)
SocketChardev *s = SOCKET_CHARDEV(chr);
int i;
+ unsetenv_fd(chr->label);
if (s->read_msgfds_num) {
for (i = 0; i < s->read_msgfds_num; i++) {
close(s->read_msgfds[i]);
@@ -1157,6 +1159,25 @@ static gboolean socket_reconnect_timeout(gpointer opaque)
return false;
}
+static void load_char_socket_fd(Chardev *chr)
+{
+ SocketChardev *sockchar = SOCKET_CHARDEV(chr);
+ QIOChannelSocket *sioc;
+ int fd = getenv_fd(chr->label);
+
+ if (fd != -1) {
+ sockchar = SOCKET_CHARDEV(chr);
+ sioc = qio_channel_socket_reuse(fd, NULL);
+ if (sioc) {
+ tcp_chr_accept(sockchar->listener, sioc, chr);
+ } else {
+ error_printf("error: could not restore socket for %s\n",
+ chr->label);
+ }
+ } else if (sockchar->sioc && !chr->close_on_cpr) {
+ setenv_fd(chr->label, sockchar->sioc->fd);
+ }
+}
static int qmp_chardev_open_socket_server(Chardev *chr,
bool is_telnet,
@@ -1360,6 +1381,13 @@ static void qmp_chardev_open_socket(Chardev *chr,
qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS);
}
+ if (!s->tls_creds && !s->is_websock) {
+ qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR);
+ } else if (only_cpr_capable) {
+ error_setg(errp, "error: socket %s is not cpr capable due to %s
option",
+ chr->label, (s->tls_creds ? "TLS" : "websocket"));
+ }
+
/* be isn't opened until we get a connection */
*be_opened = false;
@@ -1375,6 +1403,8 @@ static void qmp_chardev_open_socket(Chardev *chr,
return;
}
}
+
+ load_char_socket_fd(chr);
}
static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
index 777ff59..e425a01 100644
--- a/include/io/channel-socket.h
+++ b/include/io/channel-socket.h
@@ -260,5 +260,17 @@ QIOChannelSocket *
qio_channel_socket_accept(QIOChannelSocket *ioc,
Error **errp);
+/**
+ * qio_channel_socket_reuse:
+ * @fd: existing client socket descriptor
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Construct a client channel using @fd.
+ *
+ * Returns: the new client channel, or NULL on error
+ */
+QIOChannelSocket *
+qio_channel_socket_reuse(int fd,
+ Error **errp);
#endif /* QIO_CHANNEL_SOCKET_H */
diff --git a/io/channel-socket.c b/io/channel-socket.c
index de49880..07981be 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -400,6 +400,15 @@ qio_channel_socket_accept(QIOChannelSocket *ioc,
return NULL;
}
+QIOChannelSocket *
+qio_channel_socket_reuse(int fd,
+ Error **errp)
+{
+ QIOChannelSocket *cioc = qio_channel_socket_new();
+ cioc->fd = fd;
+ return qio_channel_socket_post_accept(cioc, errp) ? 0 : cioc;
+}
+
static void qio_channel_socket_init(Object *obj)
{
QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(obj);
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index d42046a..f6c335b 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,5 +1,6 @@
stub-obj-y += blk-commit-all.o
stub-obj-y += cmos.o
+stub-obj-y += cpr.o
stub-obj-y += cpu-get-clock.o
stub-obj-y += cpu-get-icount.o
stub-obj-y += dump.o
diff --git a/stubs/cpr.c b/stubs/cpr.c
new file mode 100644
index 0000000..aaa189e
--- /dev/null
+++ b/stubs/cpr.c
@@ -0,0 +1,3 @@
+#include "qemu/osdep.h"
+
+bool only_cpr_capable;
--
1.8.3.1
- [PATCH V2 09/22] cpr: HMP interfaces, (continued)
[PATCH V2 12/22] vfio-pci: cpr, Steve Sistare, 2021/01/05
[PATCH V2 16/22] chardev: cpr for pty, Steve Sistare, 2021/01/05
[PATCH V2 18/22] chardev: cpr for sockets,
Steve Sistare <=
[PATCH V2 19/22] monitor: cpr support, Steve Sistare, 2021/01/05
[PATCH V2 17/22] chardev: socket accept subroutine, Steve Sistare, 2021/01/05
[PATCH V2 20/22] cpr: only-cpr-capable option, Steve Sistare, 2021/01/05
[PATCH V2 22/22] simplify savevm, Steve Sistare, 2021/01/05
[PATCH V2 14/22] chardev: cpr framework, Steve Sistare, 2021/01/05
[PATCH V2 21/22] cpr: maintainers, Steve Sistare, 2021/01/05
[PATCH V2 02/22] qemu_ram_volatile, Steve Sistare, 2021/01/05
[PATCH V2 13/22] vhost: reset vhost devices upon cprsave, Steve Sistare, 2021/01/05