Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 1 | /* |
| 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 Quintela | 41d6422 | 2017-04-05 17:45:16 +0200 | [diff] [blame] | 15 | #include "tls.h" |
Juan Quintela | 6666c96 | 2017-04-24 20:07:27 +0200 | [diff] [blame] | 16 | #include "migration.h" |
Juan Quintela | 40014d8 | 2017-04-17 19:34:36 +0200 | [diff] [blame] | 17 | #include "qemu-file-channel.h" |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 18 | #include "trace.h" |
| 19 | #include "qapi/error.h" |
| 20 | #include "io/channel-tls.h" |
Lukas Straub | b5eea99 | 2020-12-28 16:08:52 +0100 | [diff] [blame] | 21 | #include "io/channel-socket.h" |
| 22 | #include "qemu/yank.h" |
Lukas Straub | 1a92d6d | 2021-03-23 18:52:42 +0100 | [diff] [blame] | 23 | #include "yank_functions.h" |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 24 | |
Juan Quintela | 8e1a193 | 2017-07-24 12:55:26 +0200 | [diff] [blame] | 25 | /** |
| 26 | * @migration_channel_process_incoming - Create new incoming migration channel |
| 27 | * |
| 28 | * Notice that TLS is special. For it we listen in a listener socket, |
| 29 | * and then create a new client socket from the TLS library. |
| 30 | * |
| 31 | * @ioc: Channel to which we are connecting |
| 32 | */ |
Juan Quintela | 5431471 | 2017-04-17 17:15:02 +0200 | [diff] [blame] | 33 | void migration_channel_process_incoming(QIOChannel *ioc) |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 34 | { |
Juan Quintela | 5431471 | 2017-04-17 17:15:02 +0200 | [diff] [blame] | 35 | MigrationState *s = migrate_get_current(); |
Fei Li | 49ed0d2 | 2019-01-13 22:08:46 +0800 | [diff] [blame] | 36 | Error *local_err = NULL; |
Juan Quintela | 5431471 | 2017-04-17 17:15:02 +0200 | [diff] [blame] | 37 | |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 38 | trace_migration_set_incoming_channel( |
| 39 | ioc, object_get_typename(OBJECT(ioc))); |
| 40 | |
| 41 | if (s->parameters.tls_creds && |
| 42 | *s->parameters.tls_creds && |
| 43 | !object_dynamic_cast(OBJECT(ioc), |
| 44 | TYPE_QIO_CHANNEL_TLS)) { |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 45 | migration_tls_channel_process_incoming(s, ioc, &local_err); |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 46 | } else { |
Leonardo Bras | 7de2e85 | 2021-06-01 02:40:31 -0300 | [diff] [blame] | 47 | if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) || |
| 48 | object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS)) { |
| 49 | yank_register_function(MIGRATION_YANK_INSTANCE, |
| 50 | migration_yank_iochannel, |
| 51 | QIO_CHANNEL(ioc)); |
| 52 | } |
| 53 | |
Fei Li | 49ed0d2 | 2019-01-13 22:08:46 +0800 | [diff] [blame] | 54 | migration_ioc_process_incoming(ioc, &local_err); |
| 55 | } |
| 56 | |
| 57 | if (local_err) { |
| 58 | error_report_err(local_err); |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | |
Juan Quintela | 8e1a193 | 2017-07-24 12:55:26 +0200 | [diff] [blame] | 63 | /** |
| 64 | * @migration_channel_connect - Create new outgoing migration channel |
| 65 | * |
| 66 | * @s: Current migration state |
| 67 | * @ioc: Channel to which we are connecting |
| 68 | * @hostname: Where we want to connect |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 69 | * @error: Error indicating failure to connect, free'd here |
Juan Quintela | 8e1a193 | 2017-07-24 12:55:26 +0200 | [diff] [blame] | 70 | */ |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 71 | void migration_channel_connect(MigrationState *s, |
| 72 | QIOChannel *ioc, |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 73 | const char *hostname, |
| 74 | Error *error) |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 75 | { |
| 76 | trace_migration_set_outgoing_channel( |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 77 | ioc, object_get_typename(OBJECT(ioc)), hostname, error); |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 78 | |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 79 | if (!error) { |
| 80 | if (s->parameters.tls_creds && |
| 81 | *s->parameters.tls_creds && |
| 82 | !object_dynamic_cast(OBJECT(ioc), |
| 83 | TYPE_QIO_CHANNEL_TLS)) { |
| 84 | migration_tls_channel_connect(s, ioc, hostname, &error); |
Dr. David Alan Gilbert | 8b7bf2b | 2018-04-30 19:59:43 +0100 | [diff] [blame] | 85 | |
| 86 | if (!error) { |
| 87 | /* tls_channel_connect will call back to this |
| 88 | * function after the TLS handshake, |
| 89 | * so we mustn't call migrate_fd_connect until then |
| 90 | */ |
| 91 | |
| 92 | return; |
| 93 | } |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 94 | } else { |
| 95 | QEMUFile *f = qemu_fopen_channel_output(ioc); |
| 96 | |
Leonardo Bras | 7de2e85 | 2021-06-01 02:40:31 -0300 | [diff] [blame] | 97 | if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) || |
| 98 | object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS)) { |
| 99 | yank_register_function(MIGRATION_YANK_INSTANCE, |
| 100 | migration_yank_iochannel, |
| 101 | QIO_CHANNEL(ioc)); |
| 102 | } |
| 103 | |
Peter Xu | 62df066 | 2018-05-02 18:47:38 +0800 | [diff] [blame] | 104 | qemu_mutex_lock(&s->qemu_file_lock); |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 105 | s->to_dst_file = f; |
Peter Xu | 62df066 | 2018-05-02 18:47:38 +0800 | [diff] [blame] | 106 | qemu_mutex_unlock(&s->qemu_file_lock); |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 107 | } |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 108 | } |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 109 | migrate_fd_connect(s, error); |
Chuan Zheng | d8053e7 | 2020-09-15 11:03:57 +0800 | [diff] [blame] | 110 | g_free(s->hostname); |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 111 | error_free(error); |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 112 | } |