Commit c1d366653207033b811c85da8c839729786451a5

Authored by aliguori
1 parent 17e90973

Live migration for Win32 (Hervé Poussineau)

This patch fixes migration so that it works on Win32.  This requires using
socket specific calls since sockets cannot be treated like file descriptors
on win32.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5525 c046a42c-6fe2-441c-8c8c-71466251a162
@@ -34,7 +34,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, @@ -34,7 +34,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
34 QEMUFileCloseFunc *close, 34 QEMUFileCloseFunc *close,
35 QEMUFileRateLimit *rate_limit); 35 QEMUFileRateLimit *rate_limit);
36 QEMUFile *qemu_fopen(const char *filename, const char *mode); 36 QEMUFile *qemu_fopen(const char *filename, const char *mode);
37 -QEMUFile *qemu_fopen_fd(int fd); 37 +QEMUFile *qemu_fopen_socket(int fd);
38 void qemu_fflush(QEMUFile *f); 38 void qemu_fflush(QEMUFile *f);
39 int qemu_fclose(QEMUFile *f); 39 int qemu_fclose(QEMUFile *f);
40 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); 40 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
migration-tcp.c
@@ -85,10 +85,10 @@ static ssize_t fd_put_buffer(void *opaque, const void *data, size_t size) @@ -85,10 +85,10 @@ static ssize_t fd_put_buffer(void *opaque, const void *data, size_t size)
85 85
86 do { 86 do {
87 ret = send(s->fd, data, size, 0); 87 ret = send(s->fd, data, size, 0);
88 - } while (ret == -1 && errno == EINTR); 88 + } while (ret == -1 && (socket_error() == EINTR || socket_error() == EWOULDBLOCK));
89 89
90 if (ret == -1) 90 if (ret == -1)
91 - ret = -errno; 91 + ret = -socket_error();
92 92
93 if (ret == -EAGAIN) 93 if (ret == -EAGAIN)
94 qemu_set_fd_handler2(s->fd, NULL, NULL, fd_put_notify, s); 94 qemu_set_fd_handler2(s->fd, NULL, NULL, fd_put_notify, s);
@@ -123,7 +123,7 @@ static void fd_wait_for_unfreeze(void *opaque) @@ -123,7 +123,7 @@ static void fd_wait_for_unfreeze(void *opaque)
123 FD_SET(s->fd, &wfds); 123 FD_SET(s->fd, &wfds);
124 124
125 ret = select(s->fd + 1, NULL, &wfds, NULL, NULL); 125 ret = select(s->fd + 1, NULL, &wfds, NULL, NULL);
126 - } while (ret == -1 && errno == EINTR); 126 + } while (ret == -1 && socket_error() == EINTR);
127 } 127 }
128 128
129 static void fd_put_ready(void *opaque) 129 static void fd_put_ready(void *opaque)
@@ -178,7 +178,7 @@ static void tcp_wait_for_connect(void *opaque) @@ -178,7 +178,7 @@ static void tcp_wait_for_connect(void *opaque)
178 dprintf("connect completed\n"); 178 dprintf("connect completed\n");
179 do { 179 do {
180 ret = getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &val, &valsize); 180 ret = getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &val, &valsize);
181 - } while (ret == -1 && errno == EINTR); 181 + } while (ret == -1 && socket_error() == EINTR);
182 182
183 if (ret < 0) { 183 if (ret < 0) {
184 tcp_error(s); 184 tcp_error(s);
@@ -273,13 +273,13 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port, @@ -273,13 +273,13 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
273 do { 273 do {
274 ret = connect(s->fd, (struct sockaddr *)&addr, sizeof(addr)); 274 ret = connect(s->fd, (struct sockaddr *)&addr, sizeof(addr));
275 if (ret == -1) 275 if (ret == -1)
276 - ret = -errno; 276 + ret = -socket_error();
277 277
278 - if (ret == -EINPROGRESS) 278 + if (ret == -EINPROGRESS || ret == -EWOULDBLOCK)
279 qemu_set_fd_handler2(s->fd, NULL, NULL, tcp_wait_for_connect, s); 279 qemu_set_fd_handler2(s->fd, NULL, NULL, tcp_wait_for_connect, s);
280 } while (ret == -EINTR); 280 } while (ret == -EINTR);
281 281
282 - if (ret < 0 && ret != -EINPROGRESS) { 282 + if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) {
283 dprintf("connect failed\n"); 283 dprintf("connect failed\n");
284 close(s->fd); 284 close(s->fd);
285 qemu_free(s); 285 qemu_free(s);
@@ -300,7 +300,7 @@ static void tcp_accept_incoming_migration(void *opaque) @@ -300,7 +300,7 @@ static void tcp_accept_incoming_migration(void *opaque)
300 300
301 do { 301 do {
302 c = accept(s, (struct sockaddr *)&addr, &addrlen); 302 c = accept(s, (struct sockaddr *)&addr, &addrlen);
303 - } while (c == -1 && errno == EINTR); 303 + } while (c == -1 && socket_error() == EINTR);
304 304
305 dprintf("accepted migration\n"); 305 dprintf("accepted migration\n");
306 306
@@ -309,7 +309,7 @@ static void tcp_accept_incoming_migration(void *opaque) @@ -309,7 +309,7 @@ static void tcp_accept_incoming_migration(void *opaque)
309 return; 309 return;
310 } 310 }
311 311
312 - f = qemu_fopen_fd(c); 312 + f = qemu_fopen_socket(c);
313 if (f == NULL) { 313 if (f == NULL) {
314 fprintf(stderr, "could not qemu_fopen socket\n"); 314 fprintf(stderr, "could not qemu_fopen socket\n");
315 goto out; 315 goto out;
@@ -349,7 +349,7 @@ int tcp_start_incoming_migration(const char *host_port) @@ -349,7 +349,7 @@ int tcp_start_incoming_migration(const char *host_port)
349 349
350 s = socket(PF_INET, SOCK_STREAM, 0); 350 s = socket(PF_INET, SOCK_STREAM, 0);
351 if (s == -1) 351 if (s == -1)
352 - return -errno; 352 + return -socket_error();
353 353
354 val = 1; 354 val = 1;
355 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val)); 355 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val));
@@ -367,5 +367,5 @@ int tcp_start_incoming_migration(const char *host_port) @@ -367,5 +367,5 @@ int tcp_start_incoming_migration(const char *host_port)
367 367
368 err: 368 err:
369 close(s); 369 close(s);
370 - return -errno; 370 + return -socket_error();
371 } 371 }
@@ -6252,43 +6252,43 @@ struct QEMUFile { @@ -6252,43 +6252,43 @@ struct QEMUFile {
6252 int has_error; 6252 int has_error;
6253 }; 6253 };
6254 6254
6255 -typedef struct QEMUFileFD 6255 +typedef struct QEMUFileSocket
6256 { 6256 {
6257 int fd; 6257 int fd;
6258 QEMUFile *file; 6258 QEMUFile *file;
6259 -} QEMUFileFD; 6259 +} QEMUFileSocket;
6260 6260
6261 -static int fd_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) 6261 +static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
6262 { 6262 {
6263 - QEMUFileFD *s = opaque; 6263 + QEMUFileSocket *s = opaque;
6264 ssize_t len; 6264 ssize_t len;
6265 6265
6266 do { 6266 do {
6267 - len = read(s->fd, buf, size);  
6268 - } while (len == -1 && errno == EINTR); 6267 + len = recv(s->fd, buf, size, 0);
  6268 + } while (len == -1 && socket_error() == EINTR);
6269 6269
6270 if (len == -1) 6270 if (len == -1)
6271 - len = -errno; 6271 + len = -socket_error();
6272 6272
6273 return len; 6273 return len;
6274 } 6274 }
6275 6275
6276 -static int fd_close(void *opaque) 6276 +static int socket_close(void *opaque)
6277 { 6277 {
6278 - QEMUFileFD *s = opaque; 6278 + QEMUFileSocket *s = opaque;
6279 qemu_free(s); 6279 qemu_free(s);
6280 return 0; 6280 return 0;
6281 } 6281 }
6282 6282
6283 -QEMUFile *qemu_fopen_fd(int fd) 6283 +QEMUFile *qemu_fopen_socket(int fd)
6284 { 6284 {
6285 - QEMUFileFD *s = qemu_mallocz(sizeof(QEMUFileFD)); 6285 + QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket));
6286 6286
6287 if (s == NULL) 6287 if (s == NULL)
6288 return NULL; 6288 return NULL;
6289 6289
6290 s->fd = fd; 6290 s->fd = fd;
6291 - s->file = qemu_fopen_ops(s, NULL, fd_get_buffer, fd_close, NULL); 6291 + s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL);
6292 return s->file; 6292 return s->file;
6293 } 6293 }
6294 6294