* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
*/
#include "qemu-common.h"
static int fd_close(MigrationState *s)
{
+ struct stat st;
+ int ret;
+
DPRINTF("fd_close\n");
if (s->fd != -1) {
- close(s->fd);
+ ret = fstat(s->fd, &st);
+ if (ret == 0 && S_ISREG(st.st_mode)) {
+ /*
+ * If the file handle is a regular file make sure the
+ * data is flushed to disk before signaling success.
+ */
+ ret = fsync(s->fd);
+ if (ret != 0) {
+ ret = -errno;
+ perror("migration-fd: fsync");
+ return ret;
+ }
+ }
+ ret = close(s->fd);
s->fd = -1;
+ if (ret != 0) {
+ ret = -errno;
+ perror("migration-fd: close");
+ return ret;
+ }
}
return 0;
}
-MigrationState *fd_start_outgoing_migration(Monitor *mon,
- const char *fdname,
- int64_t bandwidth_limit,
- int detach,
- int blk,
- int inc)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
{
- MigrationState *s;
-
- s = migrate_new(mon, bandwidth_limit, detach, blk, inc);
-
- s->fd = monitor_get_fd(mon, fdname);
+ s->fd = monitor_get_fd(cur_mon, fdname);
if (s->fd == -1) {
DPRINTF("fd_migration: invalid file descriptor identifier\n");
- goto err_after_alloc;
+ goto err_after_get_fd;
}
if (fcntl(s->fd, F_SETFL, O_NONBLOCK) == -1) {
s->close = fd_close;
migrate_fd_connect(s);
- return s;
+ return 0;
err_after_open:
close(s->fd);
-err_after_alloc:
- g_free(s);
- return NULL;
+err_after_get_fd:
+ return -1;
}
static void fd_accept_incoming_migration(void *opaque)