blob: 33e0e9b82f9fdbb7027061bb9833cd1b9517ec50 [file] [log] [blame]
Juan Quinteladd4339c2017-04-17 17:07:04 +02001/*
2 * QEMU live migration channel operations
3 *
4 * Copyright Red Hat, Inc. 2016
5 *
6 * Authors:
7 * Daniel P. Berrange <berrange@redhat.com>
8 *
9 * Contributions after 2012-01-13 are licensed under the terms of the
10 * GNU GPL, version 2 or (at your option) any later version.
11 */
12
13#include "qemu/osdep.h"
14#include "channel.h"
Juan Quintela41d64222017-04-05 17:45:16 +020015#include "tls.h"
Juan Quintela6666c962017-04-24 20:07:27 +020016#include "migration.h"
Juan Quintela40014d82017-04-17 19:34:36 +020017#include "qemu-file-channel.h"
Juan Quinteladd4339c2017-04-17 17:07:04 +020018#include "trace.h"
19#include "qapi/error.h"
20#include "io/channel-tls.h"
21
Juan Quintela8e1a1932017-07-24 12:55:26 +020022/**
23 * @migration_channel_process_incoming - Create new incoming migration channel
24 *
25 * Notice that TLS is special. For it we listen in a listener socket,
26 * and then create a new client socket from the TLS library.
27 *
28 * @ioc: Channel to which we are connecting
29 */
Juan Quintela54314712017-04-17 17:15:02 +020030void migration_channel_process_incoming(QIOChannel *ioc)
Juan Quinteladd4339c2017-04-17 17:07:04 +020031{
Juan Quintela54314712017-04-17 17:15:02 +020032 MigrationState *s = migrate_get_current();
33
Juan Quinteladd4339c2017-04-17 17:07:04 +020034 trace_migration_set_incoming_channel(
35 ioc, object_get_typename(OBJECT(ioc)));
36
37 if (s->parameters.tls_creds &&
38 *s->parameters.tls_creds &&
39 !object_dynamic_cast(OBJECT(ioc),
40 TYPE_QIO_CHANNEL_TLS)) {
41 Error *local_err = NULL;
42 migration_tls_channel_process_incoming(s, ioc, &local_err);
43 if (local_err) {
44 error_report_err(local_err);
45 }
46 } else {
Juan Quintela4f0fae72017-07-24 12:42:02 +020047 migration_ioc_process_incoming(ioc);
Juan Quinteladd4339c2017-04-17 17:07:04 +020048 }
49}
50
51
Juan Quintela8e1a1932017-07-24 12:55:26 +020052/**
53 * @migration_channel_connect - Create new outgoing migration channel
54 *
55 * @s: Current migration state
56 * @ioc: Channel to which we are connecting
57 * @hostname: Where we want to connect
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000058 * @error: Error indicating failure to connect, free'd here
Juan Quintela8e1a1932017-07-24 12:55:26 +020059 */
Juan Quinteladd4339c2017-04-17 17:07:04 +020060void migration_channel_connect(MigrationState *s,
61 QIOChannel *ioc,
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000062 const char *hostname,
63 Error *error)
Juan Quinteladd4339c2017-04-17 17:07:04 +020064{
65 trace_migration_set_outgoing_channel(
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000066 ioc, object_get_typename(OBJECT(ioc)), hostname, error);
Juan Quinteladd4339c2017-04-17 17:07:04 +020067
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000068 if (!error) {
69 if (s->parameters.tls_creds &&
70 *s->parameters.tls_creds &&
71 !object_dynamic_cast(OBJECT(ioc),
72 TYPE_QIO_CHANNEL_TLS)) {
73 migration_tls_channel_connect(s, ioc, hostname, &error);
Dr. David Alan Gilbert8b7bf2b2018-04-30 19:59:43 +010074
75 if (!error) {
76 /* tls_channel_connect will call back to this
77 * function after the TLS handshake,
78 * so we mustn't call migrate_fd_connect until then
79 */
80
81 return;
82 }
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000083 } else {
84 QEMUFile *f = qemu_fopen_channel_output(ioc);
85
Peter Xu62df0662018-05-02 18:47:38 +080086 qemu_mutex_lock(&s->qemu_file_lock);
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000087 s->to_dst_file = f;
Peter Xu62df0662018-05-02 18:47:38 +080088 qemu_mutex_unlock(&s->qemu_file_lock);
Juan Quinteladd4339c2017-04-17 17:07:04 +020089 }
Juan Quinteladd4339c2017-04-17 17:07:04 +020090 }
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000091 migrate_fd_connect(s, error);
92 error_free(error);
Juan Quinteladd4339c2017-04-17 17:07:04 +020093}