qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qio: non-default context for TLS handshake

A new parameter "context" is added to qio_channel_tls_handshake() is to
allow the TLS to be run on a non-default context. Still, no functional
change.

Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

authored by

Peter Xu and committed by
Daniel P. Berrangé
1939ccda 8005fdd8

+47 -12
+1
chardev/char-socket.c
··· 703 703 qio_channel_tls_handshake(tioc, 704 704 tcp_chr_tls_handshake, 705 705 chr, 706 + NULL, 706 707 NULL); 707 708 } 708 709
+4 -1
include/io/channel-tls.h
··· 116 116 * @func: the callback to invoke when completed 117 117 * @opaque: opaque data to pass to @func 118 118 * @destroy: optional callback to free @opaque 119 + * @context: the context that TLS handshake will run with. If %NULL, 120 + * the default context will be used 119 121 * 120 122 * Perform the TLS session handshake. This method 121 123 * will return immediately and the handshake will ··· 126 128 void qio_channel_tls_handshake(QIOChannelTLS *ioc, 127 129 QIOTaskFunc func, 128 130 gpointer opaque, 129 - GDestroyNotify destroy); 131 + GDestroyNotify destroy, 132 + GMainContext *context); 130 133 131 134 /** 132 135 * qio_channel_tls_get_session:
+34 -11
io/channel-tls.c
··· 140 140 return NULL; 141 141 } 142 142 143 + struct QIOChannelTLSData { 144 + QIOTask *task; 145 + GMainContext *context; 146 + }; 147 + typedef struct QIOChannelTLSData QIOChannelTLSData; 143 148 144 149 static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc, 145 150 GIOCondition condition, 146 151 gpointer user_data); 147 152 148 153 static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc, 149 - QIOTask *task) 154 + QIOTask *task, 155 + GMainContext *context) 150 156 { 151 157 Error *err = NULL; 152 158 QCryptoTLSSessionHandshakeStatus status; ··· 171 177 qio_task_complete(task); 172 178 } else { 173 179 GIOCondition condition; 180 + QIOChannelTLSData *data = g_new0(typeof(*data), 1); 181 + 182 + data->task = task; 183 + data->context = context; 184 + 185 + if (context) { 186 + g_main_context_ref(context); 187 + } 188 + 174 189 if (status == QCRYPTO_TLS_HANDSHAKE_SENDING) { 175 190 condition = G_IO_OUT; 176 191 } else { ··· 178 193 } 179 194 180 195 trace_qio_channel_tls_handshake_pending(ioc, status); 181 - qio_channel_add_watch(ioc->master, 182 - condition, 183 - qio_channel_tls_handshake_io, 184 - task, 185 - NULL); 196 + qio_channel_add_watch_full(ioc->master, 197 + condition, 198 + qio_channel_tls_handshake_io, 199 + data, 200 + NULL, 201 + context); 186 202 } 187 203 } 188 204 ··· 191 207 GIOCondition condition, 192 208 gpointer user_data) 193 209 { 194 - QIOTask *task = user_data; 210 + QIOChannelTLSData *data = user_data; 211 + QIOTask *task = data->task; 212 + GMainContext *context = data->context; 195 213 QIOChannelTLS *tioc = QIO_CHANNEL_TLS( 196 214 qio_task_get_source(task)); 197 215 198 - qio_channel_tls_handshake_task( 199 - tioc, task); 216 + g_free(data); 217 + qio_channel_tls_handshake_task(tioc, task, context); 218 + 219 + if (context) { 220 + g_main_context_unref(context); 221 + } 200 222 201 223 return FALSE; 202 224 } ··· 204 226 void qio_channel_tls_handshake(QIOChannelTLS *ioc, 205 227 QIOTaskFunc func, 206 228 gpointer opaque, 207 - GDestroyNotify destroy) 229 + GDestroyNotify destroy, 230 + GMainContext *context) 208 231 { 209 232 QIOTask *task; 210 233 ··· 212 235 func, opaque, destroy); 213 236 214 237 trace_qio_channel_tls_handshake_start(ioc); 215 - qio_channel_tls_handshake_task(ioc, task); 238 + qio_channel_tls_handshake_task(ioc, task, context); 216 239 } 217 240 218 241
+2
migration/tls.c
··· 105 105 qio_channel_tls_handshake(tioc, 106 106 migration_tls_incoming_handshake, 107 107 NULL, 108 + NULL, 108 109 NULL); 109 110 } 110 111 ··· 159 160 qio_channel_tls_handshake(tioc, 160 161 migration_tls_outgoing_handshake, 161 162 s, 163 + NULL, 162 164 NULL); 163 165 }
+1
nbd/client.c
··· 579 579 qio_channel_tls_handshake(tioc, 580 580 nbd_tls_handshake, 581 581 &data, 582 + NULL, 582 583 NULL); 583 584 584 585 if (!data.complete) {
+1
nbd/server.c
··· 599 599 qio_channel_tls_handshake(tioc, 600 600 nbd_tls_handshake, 601 601 &data, 602 + NULL, 602 603 NULL); 603 604 604 605 if (!data.complete) {
+2
tests/test-io-channel-tls.c
··· 203 203 qio_channel_tls_handshake(clientChanTLS, 204 204 test_tls_handshake_done, 205 205 &clientHandshake, 206 + NULL, 206 207 NULL); 207 208 qio_channel_tls_handshake(serverChanTLS, 208 209 test_tls_handshake_done, 209 210 &serverHandshake, 211 + NULL, 210 212 NULL); 211 213 212 214 /*
+1
ui/vnc-auth-vencrypt.c
··· 128 128 qio_channel_tls_handshake(tls, 129 129 vnc_tls_handshake_done, 130 130 vs, 131 + NULL, 131 132 NULL); 132 133 } 133 134 return 0;
+1
ui/vnc-ws.c
··· 81 81 qio_channel_tls_handshake(tls, 82 82 vncws_tls_handshake_done, 83 83 vs, 84 + NULL, 84 85 NULL); 85 86 86 87 return TRUE;