1
2
3
4
5
6
7
8
9
10
11
12
13#include "qemu/osdep.h"
14#include "channel.h"
15#include "tls.h"
16#include "migration.h"
17#include "qemu-file.h"
18#include "trace.h"
19#include "qapi/error.h"
20#include "io/channel-tls.h"
21#include "io/channel-socket.h"
22#include "qemu/yank.h"
23#include "yank_functions.h"
24
25
26
27
28
29
30
31
32
33void migration_channel_process_incoming(QIOChannel *ioc)
34{
35 MigrationState *s = migrate_get_current();
36 MigrationIncomingState *mis = migration_incoming_get_current();
37 Error *local_err = NULL;
38
39 trace_migration_set_incoming_channel(
40 ioc, object_get_typename(OBJECT(ioc)));
41
42 if (migrate_channel_requires_tls_upgrade(ioc)) {
43 migration_tls_channel_process_incoming(s, ioc, &local_err);
44 } else {
45 migration_ioc_register_yank(ioc);
46 migration_ioc_process_incoming(ioc, &local_err);
47 }
48
49 if (local_err) {
50 error_report_err(local_err);
51 migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED);
52 if (mis->exit_on_error) {
53 exit(EXIT_FAILURE);
54 }
55 }
56}
57
58
59
60
61
62
63
64
65
66
67void migration_channel_connect(MigrationState *s,
68 QIOChannel *ioc,
69 const char *hostname,
70 Error *error)
71{
72 trace_migration_set_outgoing_channel(
73 ioc, object_get_typename(OBJECT(ioc)), hostname, error);
74
75 if (!error) {
76 if (migrate_channel_requires_tls_upgrade(ioc)) {
77 migration_tls_channel_connect(s, ioc, hostname, &error);
78
79 if (!error) {
80
81
82
83
84
85 return;
86 }
87 } else {
88 QEMUFile *f = qemu_file_new_output(ioc);
89
90 migration_ioc_register_yank(ioc);
91
92 qemu_mutex_lock(&s->qemu_file_lock);
93 s->to_dst_file = f;
94 qemu_mutex_unlock(&s->qemu_file_lock);
95 }
96 }
97 migration_connect(s, error);
98 error_free(error);
99}
100
101
102
103
104
105
106
107
108
109
110
111
112
113int migration_channel_read_peek(QIOChannel *ioc,
114 const char *buf,
115 const size_t buflen,
116 Error **errp)
117{
118 ssize_t len = 0;
119 struct iovec iov = { .iov_base = (char *)buf, .iov_len = buflen };
120
121 while (true) {
122 len = qio_channel_readv_full(ioc, &iov, 1, NULL, NULL,
123 QIO_CHANNEL_READ_FLAG_MSG_PEEK, errp);
124
125 if (len < 0 && len != QIO_CHANNEL_ERR_BLOCK) {
126 return -1;
127 }
128
129 if (len == 0) {
130 error_setg(errp, "Failed to peek at channel");
131 return -1;
132 }
133
134 if (len == buflen) {
135 break;
136 }
137
138
139 if (qemu_in_coroutine()) {
140 qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000);
141 } else {
142 g_usleep(1000);
143 }
144 }
145
146 return 0;
147}
148