Skip to content

Commit

Permalink
Merge tag 'pull-nbd-2024-04-25' of https://repo.or.cz/qemu/ericb into…
Browse files Browse the repository at this point in the history
… staging

NBD patches for 2024-04-25

- Avoid calling poll() within coroutine

# -----BEGIN PGP SIGNATURE-----
#
# iQEzBAABCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAmYqzkMACgkQp6FrSiUn
# Q2ol3wf9HbwiYkyHhqybb4ykEs75N8B2JPbOj6gYRSBn7rz90k1vElDCM2yQhlDN
# Ltuh8lTOaJb+Z4n2dKIF2m5hL2GTm/xtErIIpP7o6A+11mHW9ag/VLaAMdWJxmUr
# WEUIH6mVtuRcxTTCp01l/JAYpUxOoQs1fyQljONH5kg1MAZpTTD61/cuhrXlvPLU
# cVlrLfob90oYhydCq5o6ucW3GhaEYkaZzHIWFy7LphFySebMmnbnPhYf/JD6RZPL
# s5K7njMK1DOyguCLlOzSuRM4gIbYunnr0Ofr/orTlAUZvbhRGKUlH0RTMWVMzgek
# xArnEZYlsqF2wIvrz0GwMDL7BMmG7A==
# =vXJj
# -----END PGP SIGNATURE-----
# gpg: Signature made Thu 25 Apr 2024 02:42:27 PM PDT
# gpg:                using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full]
# gpg:                 aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [full]
# gpg:                 aka "[jpeg image of size 6874]" [full]

* tag 'pull-nbd-2024-04-25' of https://repo.or.cz/qemu/ericb:
  nbd/server: Mark negotiation functions as coroutine_fn
  nbd/server: do not poll within a coroutine context

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Apr 26, 2024
2 parents a118c4a + 4fa333e commit 77bcaf5
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 72 deletions.
28 changes: 24 additions & 4 deletions nbd/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,31 @@ static int nbd_request_simple_option(QIOChannel *ioc, int opt, bool strict,
return 1;
}

/* Callback to learn when QIO TLS upgrade is complete */
struct NBDTLSClientHandshakeData {
bool complete;
Error *error;
GMainLoop *loop;
};

static void nbd_client_tls_handshake(QIOTask *task, void *opaque)
{
struct NBDTLSClientHandshakeData *data = opaque;

qio_task_propagate_error(task, &data->error);
data->complete = true;
if (data->loop) {
g_main_loop_quit(data->loop);
}
}

static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
QCryptoTLSCreds *tlscreds,
const char *hostname, Error **errp)
{
int ret;
QIOChannelTLS *tioc;
struct NBDTLSHandshakeData data = { 0 };
struct NBDTLSClientHandshakeData data = { 0 };

ret = nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, true, errp);
if (ret <= 0) {
Expand All @@ -619,18 +637,20 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
return NULL;
}
qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-client-tls");
data.loop = g_main_loop_new(g_main_context_default(), FALSE);
trace_nbd_receive_starttls_tls_handshake();
qio_channel_tls_handshake(tioc,
nbd_tls_handshake,
nbd_client_tls_handshake,
&data,
NULL,
NULL);

if (!data.complete) {
data.loop = g_main_loop_new(g_main_context_default(), FALSE);
g_main_loop_run(data.loop);
assert(data.complete);
g_main_loop_unref(data.loop);
}
g_main_loop_unref(data.loop);

if (data.error) {
error_propagate(errp, data.error);
object_unref(OBJECT(tioc));
Expand Down
11 changes: 0 additions & 11 deletions nbd/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ int nbd_drop(QIOChannel *ioc, size_t size, Error **errp)
}


void nbd_tls_handshake(QIOTask *task,
void *opaque)
{
struct NBDTLSHandshakeData *data = opaque;

qio_task_propagate_error(task, &data->error);
data->complete = true;
g_main_loop_quit(data->loop);
}


const char *nbd_opt_lookup(uint32_t opt)
{
switch (opt) {
Expand Down
10 changes: 0 additions & 10 deletions nbd/nbd-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ static inline int nbd_write(QIOChannel *ioc, const void *buffer, size_t size,
return qio_channel_write_all(ioc, buffer, size, errp) < 0 ? -EIO : 0;
}

struct NBDTLSHandshakeData {
GMainLoop *loop;
bool complete;
Error *error;
};


void nbd_tls_handshake(QIOTask *task,
void *opaque);

int nbd_drop(QIOChannel *ioc, size_t size, Error **errp);

#endif

0 comments on commit 77bcaf5

Please sign in to comment.