From: antoine.damhet@shadow.tech
To: qemu-devel@nongnu.org
Cc: vm@shadow.tech, "Antoine Damhet" <antoine.damhet@shadow.tech>,
"Charles Frey" <charles.frey@shadow.tech>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PATCH 2/2] io/channel-tls: fix handling of bigger read buffers
Date: Tue, 15 Nov 2022 15:23:29 +0100 [thread overview]
Message-ID: <20221115142329.92524-3-antoine.damhet@shadow.tech> (raw)
In-Reply-To: <20221115142329.92524-1-antoine.damhet@shadow.tech>
From: Antoine Damhet <antoine.damhet@shadow.tech>
Since the TLS backend can read more data from the underlying QIOChannel
we introduce a minimal child GSource to notify if we still have more
data available to be read.
Signed-off-by: Antoine Damhet <antoine.damhet@shadow.tech>
Signed-off-by: Charles Frey <charles.frey@shadow.tech>
---
io/channel-tls.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)
diff --git a/io/channel-tls.c b/io/channel-tls.c
index 4ce890a538..4f2b8828f9 100644
--- a/io/channel-tls.c
+++ b/io/channel-tls.c
@@ -388,12 +388,76 @@ static void qio_channel_tls_set_aio_fd_handler(QIOChannel *ioc,
qio_channel_set_aio_fd_handler(tioc->master, ctx, io_read, io_write, opaque);
}
+typedef struct QIOChannelTLSSource QIOChannelTLSSource;
+struct QIOChannelTLSSource {
+ GSource parent;
+ QIOChannelTLS *tioc;
+};
+
+static gboolean
+qio_channel_tls_source_check(GSource *source)
+{
+ QIOChannelTLSSource *tsource = (QIOChannelTLSSource *)source;
+
+ return qcrypto_tls_session_check_pending(tsource->tioc->session) > 0;
+}
+
+static gboolean
+qio_channel_tls_source_prepare(GSource *source, gint *timeout)
+{
+ *timeout = -1;
+ return qio_channel_tls_source_check(source);
+}
+
+static gboolean
+qio_channel_tls_source_dispatch(GSource *source, GSourceFunc callback,
+ gpointer user_data)
+{
+ return G_SOURCE_CONTINUE;
+}
+
+static void
+qio_channel_tls_source_finalize(GSource *source)
+{
+ QIOChannelTLSSource *tsource = (QIOChannelTLSSource *)source;
+
+ object_unref(OBJECT(tsource->tioc));
+}
+
+static GSourceFuncs qio_channel_tls_source_funcs = {
+ qio_channel_tls_source_prepare,
+ qio_channel_tls_source_check,
+ qio_channel_tls_source_dispatch,
+ qio_channel_tls_source_finalize
+};
+
+static void
+qio_channel_tls_read_watch(QIOChannelTLS *tioc, GSource *source)
+{
+ GSource *child;
+ QIOChannelTLSSource *tlssource;
+
+ child = g_source_new(&qio_channel_tls_source_funcs,
+ sizeof(QIOChannelTLSSource));
+ tlssource = (QIOChannelTLSSource *)child;
+
+ tlssource->tioc = tioc;
+ object_ref(OBJECT(tioc));
+
+ g_source_add_child_source(source, child);
+}
+
static GSource *qio_channel_tls_create_watch(QIOChannel *ioc,
GIOCondition condition)
{
QIOChannelTLS *tioc = QIO_CHANNEL_TLS(ioc);
+ GSource *source = qio_channel_create_watch(tioc->master, condition);
+
+ if (condition & G_IO_IN) {
+ qio_channel_tls_read_watch(tioc, source);
+ }
- return qio_channel_create_watch(tioc->master, condition);
+ return source;
}
QCryptoTLSSession *
--
2.38.1
next prev parent reply other threads:[~2022-11-15 14:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 14:23 [PATCH 0/2] TLS: fix read stall with large buffers antoine.damhet
2022-11-15 14:23 ` [PATCH 1/2] crypto: TLS: introduce `check_pending` antoine.damhet
2022-11-16 10:44 ` Daniel P. Berrangé
2022-11-15 14:23 ` antoine.damhet [this message]
2022-11-16 10:52 ` [PATCH 2/2] io/channel-tls: fix handling of bigger read buffers Daniel P. Berrangé
2022-12-16 10:38 ` Antoine Damhet
2022-12-16 10:55 ` Daniel P. Berrangé
2024-02-28 16:11 ` Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221115142329.92524-3-antoine.damhet@shadow.tech \
--to=antoine.damhet@shadow.tech \
--cc=berrange@redhat.com \
--cc=charles.frey@shadow.tech \
--cc=qemu-devel@nongnu.org \
--cc=vm@shadow.tech \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).