[5525] Live migration for Win32 (Herv?\195?\169 Poussineau)
Revision: 5525
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5525 Author: aliguori Date: 2008-10-24 21:55:17 +0000 (Fri, 24 Oct 2008)
Log Message:
-----------
Live migration for Win32 (Herv?\195?\169 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?\195?\169 Poussineau <[email protected]>
Signed-off-by Anthony Liguori <[email protected]>
Modified Paths:
--------------
trunk/hw/hw.h
trunk/migration-tcp.c
trunk/vl.c
Modified: trunk/hw/hw.h
===================================================================
hw/hw.h +1 -1
@@ -34,7 +34,7 @@ QEMUFileCloseFunc *close, QEMUFileRateLimit *rate_limit);QEMUFile *qemu_fopen (const char *filename,const char *mode); -QEMUFile *qemu_fopen_fd (int fd); +QEMUFile *qemu_fopen_socket (int fd);void qemu_fflush (QEMUFile *f);int qemu_fclose (QEMUFile *f);void qemu_put_buffer (QEMUFile *f,const uint8_t *buf,int size);
Modified: trunk/migration-tcp.c
===================================================================
migration-tcp.c +11 -11
@@ -85,10 +85,10 @@do { ret =send (s->fd, data, size,0 ); - }while (ret ==-1 && errno ==EINTR ); + }while (ret ==-1 && (socket_error () ==EINTR ||socket_error () ==EWOULDBLOCK ));if (ret ==-1 ) - ret = -errno; + ret = -socket_error ();if (ret == -EAGAIN )qemu_set_fd_handler2 (s->fd,NULL ,NULL , fd_put_notify, s);
@@ -123,7 +123,7 @@FD_SET (s->fd, &wfds); ret =select (s->fd +1 ,NULL , &wfds,NULL ,NULL ); - }while (ret ==-1 && errno ==EINTR ); + }while (ret ==-1 &&socket_error () ==EINTR ); }static void fd_put_ready (void *opaque)
@@ -178,7 +178,7 @@dprintf ("connect completed\n" );do { ret =getsockopt (s->fd,SOL_SOCKET ,SO_ERROR , &val, &valsize); - }while (ret ==-1 && errno ==EINTR ); + }while (ret ==-1 &&socket_error () ==EINTR );if (ret <0 ) {tcp_error (s);
@@ -273,13 +273,13 @@do { ret =connect (s->fd, (struct sockaddr *)&addr,sizeof (addr));if (ret ==-1 ) - ret = -errno; + ret = -socket_error (); -if (ret == -EINPROGRESS ) +if (ret == -EINPROGRESS || ret == -EWOULDBLOCK )qemu_set_fd_handler2 (s->fd,NULL ,NULL , tcp_wait_for_connect, s); }while (ret == -EINTR ); -if (ret <0 && ret != -EINPROGRESS ) { +if (ret <0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK ) {dprintf ("connect failed\n" );close (s->fd);qemu_free (s);
@@ -300,7 +300,7 @@do { c =accept (s, (struct sockaddr *)&addr, &addrlen); - }while (c ==-1 && errno ==EINTR ); + }while (c ==-1 &&socket_error () ==EINTR );dprintf ("accepted migration\n" );
@@ -309,7 +309,7 @@return ; } - f =qemu_fopen_fd (c); + f =qemu_fopen_socket (c);if (f ==NULL ) {fprintf (stderr,"could not qemu_fopen socket\n" ); goto out;
@@ -349,7 +349,7 @@ s =socket (PF_INET ,SOCK_STREAM ,0 );if (s ==-1 ) -return -errno; +return -socket_error (); val =1 ;setsockopt (s,SOL_SOCKET ,SO_REUSEADDR , (const char *)&val,sizeof (val));
@@ -367,5 +367,5 @@ err:close (s); -return -errno; +return -socket_error (); }
Modified: trunk/vl.c
===================================================================
vl.c +12 -12
@@ -6252,43 +6252,43 @@int has_error; }; -typedef struct QEMUFileFD +typedef struct QEMUFileSocket {int fd;QEMUFile *file; -}QEMUFileFD ; +}QEMUFileSocket ; -static int fd_get_buffer (void *opaque,uint8_t *buf,int64_t pos,int size) +static int socket_get_buffer (void *opaque,uint8_t *buf,int64_t pos,int size) { -QEMUFileFD *s = opaque; +QEMUFileSocket *s = opaque;ssize_t len;do { - len =read (s->fd, buf, size); - }while (len ==-1 && errno ==EINTR ); + len =recv (s->fd, buf, size,0 ); + }while (len ==-1 &&socket_error () ==EINTR );if (len ==-1 ) - len = -errno; + len = -socket_error ();return len; } -static int fd_close (void *opaque) +static int socket_close (void *opaque) { -QEMUFileFD *s = opaque; +QEMUFileSocket *s = opaque;qemu_free (s);return 0 ; } -QEMUFile *qemu_fopen_fd (int fd) +QEMUFile *qemu_fopen_socket (int fd) { -QEMUFileFD *s =qemu_mallocz (sizeof (QEMUFileFD)); +QEMUFileSocket *s =qemu_mallocz (sizeof (QEMUFileSocket));if (s ==NULL )return NULL ; s->fd = fd; - s->file =qemu_fopen_ops (s,NULL , fd_get_buffer, fd_close,NULL ); + s->file =qemu_fopen_ops (s,NULL , socket_get_buffer, socket_close,NULL );return s->file; }