blob: d2e523af743f8662e25133455a0c8ec84e3814e8 [file] [log] [blame]
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +02001/*
2 * QEMU live migration via generic fd
3 *
4 * Copyright Red Hat, Inc. 2009
5 *
6 * Authors:
7 * Chris Lalancette <clalance@redhat.com>
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 *
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010012 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020014 */
15
16#include "qemu-common.h"
Alex Bligh6a1751b2013-08-21 16:02:47 +010017#include "qemu/main-loop.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010018#include "qemu/sockets.h"
Paolo Bonzinicaf71f82012-12-17 18:19:50 +010019#include "migration/migration.h"
Paolo Bonzini83c90892012-12-17 18:19:49 +010020#include "monitor/monitor.h"
Juan Quintela557ec5a2012-10-03 14:07:31 +020021#include "migration/qemu-file.h"
Paolo Bonzini737e1502012-12-17 18:19:44 +010022#include "block/block.h"
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020023
24//#define DEBUG_MIGRATION_FD
25
26#ifdef DEBUG_MIGRATION_FD
malcd0f2c4c2010-02-07 02:03:50 +030027#define DPRINTF(fmt, ...) \
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020028 do { printf("migration-fd: " fmt, ## __VA_ARGS__); } while (0)
29#else
malcd0f2c4c2010-02-07 02:03:50 +030030#define DPRINTF(fmt, ...) \
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020031 do { } while (0)
32#endif
33
Paolo Bonzinif37afb52012-10-02 10:02:46 +020034void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020035{
Paolo Bonzinif8bbc122013-02-22 17:36:41 +010036 int fd = monitor_get_fd(cur_mon, fdname, errp);
37 if (fd == -1) {
Paolo Bonzinif37afb52012-10-02 10:02:46 +020038 return;
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020039 }
Paolo Bonzinib3523652013-02-22 17:36:47 +010040 s->file = qemu_fdopen(fd, "wb");
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020041
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020042 migrate_fd_connect(s);
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020043}
44
45static void fd_accept_incoming_migration(void *opaque)
46{
47 QEMUFile *f = opaque;
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020048
Paolo Bonzinid263a202012-08-08 10:21:26 +020049 qemu_set_fd_handler2(qemu_get_fd(f), NULL, NULL, NULL, NULL);
Paolo Bonzinia6ef2902012-08-07 10:49:13 +020050 process_incoming_migration(f);
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020051}
52
Paolo Bonzini43eaae22012-10-02 18:21:18 +020053void fd_start_incoming_migration(const char *infd, Error **errp)
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020054{
55 int fd;
56 QEMUFile *f;
57
malcd0f2c4c2010-02-07 02:03:50 +030058 DPRINTF("Attempting to start an incoming migration via fd\n");
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020059
60 fd = strtol(infd, NULL, 0);
61 f = qemu_fdopen(fd, "rb");
62 if(f == NULL) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +020063 error_setg_errno(errp, errno, "failed to open the source descriptor");
64 return;
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020065 }
66
Juan Quintela1c39e2a2010-03-11 17:55:38 +010067 qemu_set_fd_handler2(fd, NULL, fd_accept_incoming_migration, NULL, f);
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020068}