[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V8 36/39] chardev: cpr for sockets
From: |
Steve Sistare |
Subject: |
[PATCH V8 36/39] chardev: cpr for sockets |
Date: |
Wed, 15 Jun 2022 07:52:23 -0700 |
Save accepted socket fds before cpr-save, and look for them after cpr-load.
Block cpr-exec if a socket enables the TLS or websocket option. Allow a
monitor socket by closing it on exec.
Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
chardev/char-socket.c | 45 +++++++++++++++++++++++++++++++++++++++++++
include/chardev/char-socket.h | 1 +
monitor/hmp.c | 3 +++
monitor/qmp.c | 3 +++
4 files changed, 52 insertions(+)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index dc4e218..3a1e36b 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -26,6 +26,7 @@
#include "chardev/char.h"
#include "io/channel-socket.h"
#include "io/channel-websock.h"
+#include "migration/cpr.h"
#include "qemu/error-report.h"
#include "qemu/module.h"
#include "qemu/option.h"
@@ -33,6 +34,7 @@
#include "qapi/clone-visitor.h"
#include "qapi/qapi-visit-sockets.h"
#include "qemu/yank.h"
+#include "sysemu/sysemu.h"
#include "chardev/char-io.h"
#include "chardev/char-socket.h"
@@ -358,6 +360,11 @@ static void tcp_chr_free_connection(Chardev *chr)
SocketChardev *s = SOCKET_CHARDEV(chr);
int i;
+ if (chr->cpr_enabled) {
+ cpr_delete_fd(chr->label, 0);
+ }
+ cpr_del_blocker(&s->cpr_blocker);
+
if (s->read_msgfds_num) {
for (i = 0; i < s->read_msgfds_num; i++) {
close(s->read_msgfds[i]);
@@ -923,6 +930,10 @@ static void tcp_chr_accept(QIONetListener *listener,
QIO_CHANNEL(cioc));
}
tcp_chr_new_client(chr, cioc);
+
+ if (s->sioc && chr->cpr_enabled) {
+ cpr_resave_fd(chr->label, 0, s->sioc->fd, NULL);
+ }
}
@@ -1178,6 +1189,26 @@ static gboolean socket_reconnect_timeout(gpointer opaque)
return false;
}
+static int load_char_socket_fd(Chardev *chr, Error **errp)
+{
+ SocketChardev *sockchar = SOCKET_CHARDEV(chr);
+ QIOChannelSocket *sioc;
+ const char *label = chr->label;
+ int fd = cpr_find_fd(label, 0);
+
+ if (fd != -1) {
+ sockchar = SOCKET_CHARDEV(chr);
+ sioc = qio_channel_socket_new_fd(fd, errp);
+ if (sioc) {
+ tcp_chr_accept(sockchar->listener, sioc, chr);
+ object_unref(OBJECT(sioc));
+ } else {
+ error_setg(errp, "could not restore socket for %s", label);
+ return -1;
+ }
+ }
+ return 0;
+}
static int qmp_chardev_open_socket_server(Chardev *chr,
bool is_telnet,
@@ -1388,6 +1419,18 @@ static void qmp_chardev_open_socket(Chardev *chr,
}
s->registered_yank = true;
+ if (!s->tls_creds && !s->is_websock) {
+ qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR);
+ } else if (!chr->reopen_on_cpr) {
+ s->cpr_blocker = NULL;
+ error_setg(&s->cpr_blocker,
+ "error: socket %s is not cpr capable due to %s option",
+ chr->label, (s->tls_creds ? "TLS" : "websocket"));
+ if (cpr_add_blocker(&s->cpr_blocker, errp, CPR_MODE_RESTART, 0)) {
+ return;
+ }
+ }
+
/* be isn't opened until we get a connection */
*be_opened = false;
@@ -1403,6 +1446,8 @@ static void qmp_chardev_open_socket(Chardev *chr,
return;
}
}
+
+ load_char_socket_fd(chr, errp);
}
static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
diff --git a/include/chardev/char-socket.h b/include/chardev/char-socket.h
index 0708ca6..1c3abf7 100644
--- a/include/chardev/char-socket.h
+++ b/include/chardev/char-socket.h
@@ -78,6 +78,7 @@ struct SocketChardev {
bool connect_err_reported;
QIOTask *connect_task;
+ Error *cpr_blocker;
};
typedef struct SocketChardev SocketChardev;
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 15ca047..75e6739 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1501,4 +1501,7 @@ void monitor_init_hmp(Chardev *chr, bool use_readline,
Error **errp)
qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read, monitor_read,
monitor_event, NULL, &mon->common, NULL, true);
monitor_list_append(&mon->common);
+
+ /* monitor cannot yet be preserved across cpr */
+ chr->reopen_on_cpr = true;
}
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 092c527..0043459 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -535,4 +535,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error
**errp)
NULL, &mon->common, NULL, true);
monitor_list_append(&mon->common);
}
+
+ /* Monitor cannot yet be preserved across cpr */
+ chr->reopen_on_cpr = true;
}
--
1.8.3.1
- Re: [PATCH V8 14/39] qapi: strList_from_string, (continued)
- [PATCH V8 18/39] vl: helper to request re-exec, Steve Sistare, 2022/06/15
- [PATCH V8 22/39] cpr: ram block blockers, Steve Sistare, 2022/06/15
- [PATCH V8 23/39] hostmem-memfd: cpr for memory-backend-memfd, Steve Sistare, 2022/06/15
- [PATCH V8 19/39] cpr: preserve extra state, Steve Sistare, 2022/06/15
- [PATCH V8 21/39] cpr: restart HMP interfaces, Steve Sistare, 2022/06/15
- [PATCH V8 24/39] pci: export export msix_is_pending, Steve Sistare, 2022/06/15
- [PATCH V8 31/39] vhost: reset vhost devices for cpr, Steve Sistare, 2022/06/15
- [PATCH V8 26/39] vfio-pci: refactor for cpr, Steve Sistare, 2022/06/15
- [PATCH V8 36/39] chardev: cpr for sockets,
Steve Sistare <=
- [PATCH V8 28/39] vfio-pci: cpr part 2 (msi), Steve Sistare, 2022/06/15
- [PATCH V8 33/39] chardev: cpr framework, Steve Sistare, 2022/06/15
- [PATCH V8 35/39] chardev: cpr for pty, Steve Sistare, 2022/06/15
- [PATCH V8 32/39] loader: suppress rom_reset during cpr, Steve Sistare, 2022/06/15
- [PATCH V8 37/39] cpr: only-cpr-capable option, Steve Sistare, 2022/06/15
- [PATCH V8 27/39] vfio-pci: cpr part 1 (fd and dma), Steve Sistare, 2022/06/15
- [PATCH V8 34/39] chardev: cpr for simple devices, Steve Sistare, 2022/06/15
- [PATCH V8 39/39] tests/avocado: add cpr regression test, Steve Sistare, 2022/06/15