fd.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * QEMU live migration via generic fd
  3. *
  4. * Copyright Red Hat, Inc. 2009-2016
  5. *
  6. * Authors:
  7. * Chris Lalancette <clalance@redhat.com>
  8. * Daniel P. Berrange <berrange@redhat.com>
  9. *
  10. * This work is licensed under the terms of the GNU GPL, version 2. See
  11. * the COPYING file in the top-level directory.
  12. *
  13. * Contributions after 2012-01-13 are licensed under the terms of the
  14. * GNU GPL, version 2 or (at your option) any later version.
  15. */
  16. #include "qemu/osdep.h"
  17. #include "channel.h"
  18. #include "fd.h"
  19. #include "migration.h"
  20. #include "monitor/monitor.h"
  21. #include "io/channel-util.h"
  22. #include "trace.h"
  23. void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
  24. {
  25. QIOChannel *ioc;
  26. int fd = monitor_get_fd(cur_mon, fdname, errp);
  27. if (fd == -1) {
  28. return;
  29. }
  30. trace_migration_fd_outgoing(fd);
  31. ioc = qio_channel_new_fd(fd, errp);
  32. if (!ioc) {
  33. close(fd);
  34. return;
  35. }
  36. qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-outgoing");
  37. migration_channel_connect(s, ioc, NULL, NULL);
  38. object_unref(OBJECT(ioc));
  39. }
  40. static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
  41. GIOCondition condition,
  42. gpointer opaque)
  43. {
  44. migration_channel_process_incoming(ioc);
  45. object_unref(OBJECT(ioc));
  46. return G_SOURCE_REMOVE;
  47. }
  48. void fd_start_incoming_migration(const char *fdname, Error **errp)
  49. {
  50. QIOChannel *ioc;
  51. int fd = monitor_fd_param(cur_mon, fdname, errp);
  52. if (fd == -1) {
  53. return;
  54. }
  55. trace_migration_fd_incoming(fd);
  56. ioc = qio_channel_new_fd(fd, errp);
  57. if (!ioc) {
  58. close(fd);
  59. return;
  60. }
  61. qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-incoming");
  62. qio_channel_add_watch_full(ioc, G_IO_IN,
  63. fd_accept_incoming_migration,
  64. NULL, NULL,
  65. g_main_context_get_thread_default());
  66. }