]> Git Repo - qemu.git/blame - migration/fd.c
iotests: Test case for drive-mirror with unaligned image size
[qemu.git] / migration / fd.c
CommitLineData
5ac1fad3
PB
1/*
2 * QEMU live migration via generic fd
3 *
4 * Copyright Red Hat, Inc. 2009
5 *
6 * Authors:
7 * Chris Lalancette <[email protected]>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
6b620ca3
PB
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
5ac1fad3
PB
14 */
15
1393a485 16#include "qemu/osdep.h"
da34e65c 17#include "qapi/error.h"
5ac1fad3 18#include "qemu-common.h"
6a1751b7 19#include "qemu/main-loop.h"
1de7afc9 20#include "qemu/sockets.h"
caf71f86 21#include "migration/migration.h"
83c9089e 22#include "monitor/monitor.h"
557ec5a0 23#include "migration/qemu-file.h"
737e150e 24#include "block/block.h"
5ac1fad3
PB
25
26//#define DEBUG_MIGRATION_FD
27
28#ifdef DEBUG_MIGRATION_FD
d0f2c4c6 29#define DPRINTF(fmt, ...) \
5ac1fad3
PB
30 do { printf("migration-fd: " fmt, ## __VA_ARGS__); } while (0)
31#else
d0f2c4c6 32#define DPRINTF(fmt, ...) \
5ac1fad3
PB
33 do { } while (0)
34#endif
35
131fe9b8
CK
36static bool fd_is_socket(int fd)
37{
38 struct stat stat;
39 int ret = fstat(fd, &stat);
40 if (ret == -1) {
41 /* When in doubt say no */
42 return false;
43 }
44 return S_ISSOCK(stat.st_mode);
45}
46
f37afb5a 47void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
5ac1fad3 48{
f8bbc128
PB
49 int fd = monitor_get_fd(cur_mon, fdname, errp);
50 if (fd == -1) {
f37afb5a 51 return;
5ac1fad3 52 }
131fe9b8
CK
53
54 if (fd_is_socket(fd)) {
89a02a9f 55 s->to_dst_file = qemu_fopen_socket(fd, "wb");
131fe9b8 56 } else {
89a02a9f 57 s->to_dst_file = qemu_fdopen(fd, "wb");
131fe9b8 58 }
5ac1fad3 59
5ac1fad3 60 migrate_fd_connect(s);
5ac1fad3
PB
61}
62
63static void fd_accept_incoming_migration(void *opaque)
64{
65 QEMUFile *f = opaque;
5ac1fad3 66
82e1cc4b 67 qemu_set_fd_handler(qemu_get_fd(f), NULL, NULL, NULL);
a6ef2909 68 process_incoming_migration(f);
5ac1fad3
PB
69}
70
43eaae28 71void fd_start_incoming_migration(const char *infd, Error **errp)
5ac1fad3
PB
72{
73 int fd;
74 QEMUFile *f;
75
d0f2c4c6 76 DPRINTF("Attempting to start an incoming migration via fd\n");
5ac1fad3
PB
77
78 fd = strtol(infd, NULL, 0);
131fe9b8
CK
79 if (fd_is_socket(fd)) {
80 f = qemu_fopen_socket(fd, "rb");
81 } else {
82 f = qemu_fdopen(fd, "rb");
83 }
5ac1fad3 84 if(f == NULL) {
43eaae28
PB
85 error_setg_errno(errp, errno, "failed to open the source descriptor");
86 return;
5ac1fad3
PB
87 }
88
82e1cc4b 89 qemu_set_fd_handler(fd, fd_accept_incoming_migration, NULL, f);
5ac1fad3 90}
This page took 0.459745 seconds and 4 git commands to generate.