1329c9b10SDr. David Alan Gilbert /* 2329c9b10SDr. David Alan Gilbert * QEMU live migration via generic fd 3329c9b10SDr. David Alan Gilbert * 464802ee5SDaniel P. Berrange * Copyright Red Hat, Inc. 2009-2016 5329c9b10SDr. David Alan Gilbert * 6329c9b10SDr. David Alan Gilbert * Authors: 7329c9b10SDr. David Alan Gilbert * Chris Lalancette <clalance@redhat.com> 864802ee5SDaniel P. Berrange * Daniel P. Berrange <berrange@redhat.com> 9329c9b10SDr. David Alan Gilbert * 10329c9b10SDr. David Alan Gilbert * This work is licensed under the terms of the GNU GPL, version 2. See 11329c9b10SDr. David Alan Gilbert * the COPYING file in the top-level directory. 12329c9b10SDr. David Alan Gilbert * 13329c9b10SDr. David Alan Gilbert * Contributions after 2012-01-13 are licensed under the terms of the 14329c9b10SDr. David Alan Gilbert * GNU GPL, version 2 or (at your option) any later version. 15329c9b10SDr. David Alan Gilbert */ 16329c9b10SDr. David Alan Gilbert 171393a485SPeter Maydell #include "qemu/osdep.h" 18da34e65cSMarkus Armbruster #include "qapi/error.h" 19329c9b10SDr. David Alan Gilbert #include "qemu-common.h" 20dd4339c5SJuan Quintela #include "channel.h" 21*7fcac4a2SJuan Quintela #include "fd.h" 22329c9b10SDr. David Alan Gilbert #include "migration/migration.h" 23329c9b10SDr. David Alan Gilbert #include "monitor/monitor.h" 2464802ee5SDaniel P. Berrange #include "io/channel-util.h" 2564802ee5SDaniel P. Berrange #include "trace.h" 26329c9b10SDr. David Alan Gilbert 27131fe9b8SCristian Klein 28329c9b10SDr. David Alan Gilbert void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp) 29329c9b10SDr. David Alan Gilbert { 3064802ee5SDaniel P. Berrange QIOChannel *ioc; 31329c9b10SDr. David Alan Gilbert int fd = monitor_get_fd(cur_mon, fdname, errp); 32329c9b10SDr. David Alan Gilbert if (fd == -1) { 33329c9b10SDr. David Alan Gilbert return; 34329c9b10SDr. David Alan Gilbert } 35131fe9b8SCristian Klein 3664802ee5SDaniel P. Berrange trace_migration_fd_outgoing(fd); 3764802ee5SDaniel P. Berrange ioc = qio_channel_new_fd(fd, errp); 3864802ee5SDaniel P. Berrange if (!ioc) { 3964802ee5SDaniel P. Berrange close(fd); 4064802ee5SDaniel P. Berrange return; 41131fe9b8SCristian Klein } 42329c9b10SDr. David Alan Gilbert 436f01f136SDaniel P. Berrange qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-outgoing"); 4422724f49SDaniel P. Berrange migration_channel_connect(s, ioc, NULL); 4564802ee5SDaniel P. Berrange object_unref(OBJECT(ioc)); 46329c9b10SDr. David Alan Gilbert } 47329c9b10SDr. David Alan Gilbert 4864802ee5SDaniel P. Berrange static gboolean fd_accept_incoming_migration(QIOChannel *ioc, 4964802ee5SDaniel P. Berrange GIOCondition condition, 5064802ee5SDaniel P. Berrange gpointer opaque) 51329c9b10SDr. David Alan Gilbert { 5222724f49SDaniel P. Berrange migration_channel_process_incoming(migrate_get_current(), ioc); 5364802ee5SDaniel P. Berrange object_unref(OBJECT(ioc)); 5464802ee5SDaniel P. Berrange return FALSE; /* unregister */ 55329c9b10SDr. David Alan Gilbert } 56329c9b10SDr. David Alan Gilbert 57329c9b10SDr. David Alan Gilbert void fd_start_incoming_migration(const char *infd, Error **errp) 58329c9b10SDr. David Alan Gilbert { 5964802ee5SDaniel P. Berrange QIOChannel *ioc; 60329c9b10SDr. David Alan Gilbert int fd; 61329c9b10SDr. David Alan Gilbert 62329c9b10SDr. David Alan Gilbert fd = strtol(infd, NULL, 0); 6364802ee5SDaniel P. Berrange trace_migration_fd_incoming(fd); 6464802ee5SDaniel P. Berrange 6564802ee5SDaniel P. Berrange ioc = qio_channel_new_fd(fd, errp); 6664802ee5SDaniel P. Berrange if (!ioc) { 6764802ee5SDaniel P. Berrange close(fd); 68329c9b10SDr. David Alan Gilbert return; 69329c9b10SDr. David Alan Gilbert } 70329c9b10SDr. David Alan Gilbert 716f01f136SDaniel P. Berrange qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-incoming"); 7264802ee5SDaniel P. Berrange qio_channel_add_watch(ioc, 7364802ee5SDaniel P. Berrange G_IO_IN, 7464802ee5SDaniel P. Berrange fd_accept_incoming_migration, 7564802ee5SDaniel P. Berrange NULL, 7664802ee5SDaniel P. Berrange NULL); 77329c9b10SDr. David Alan Gilbert } 78