exec.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * QEMU live migration
  3. *
  4. * Copyright IBM, Corp. 2008
  5. * Copyright Dell MessageOne 2008
  6. * Copyright Red Hat, Inc. 2015-2016
  7. *
  8. * Authors:
  9. * Anthony Liguori <aliguori@us.ibm.com>
  10. * Charles Duffy <charles_duffy@messageone.com>
  11. * Daniel P. Berrange <berrange@redhat.com>
  12. *
  13. * This work is licensed under the terms of the GNU GPL, version 2. See
  14. * the COPYING file in the top-level directory.
  15. *
  16. * Contributions after 2012-01-13 are licensed under the terms of the
  17. * GNU GPL, version 2 or (at your option) any later version.
  18. */
  19. #include "qemu/osdep.h"
  20. #include "channel.h"
  21. #include "exec.h"
  22. #include "migration.h"
  23. #include "io/channel-command.h"
  24. #include "trace.h"
  25. void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp)
  26. {
  27. QIOChannel *ioc;
  28. const char *argv[] = { "/bin/sh", "-c", command, NULL };
  29. trace_migration_exec_outgoing(command);
  30. ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv,
  31. O_RDWR,
  32. errp));
  33. if (!ioc) {
  34. return;
  35. }
  36. qio_channel_set_name(ioc, "migration-exec-outgoing");
  37. migration_channel_connect(s, ioc, NULL, NULL);
  38. object_unref(OBJECT(ioc));
  39. }
  40. static gboolean exec_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 exec_start_incoming_migration(const char *command, Error **errp)
  49. {
  50. QIOChannel *ioc;
  51. const char *argv[] = { "/bin/sh", "-c", command, NULL };
  52. trace_migration_exec_incoming(command);
  53. ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv,
  54. O_RDWR,
  55. errp));
  56. if (!ioc) {
  57. return;
  58. }
  59. qio_channel_set_name(ioc, "migration-exec-incoming");
  60. qio_channel_add_watch_full(ioc, G_IO_IN,
  61. exec_accept_incoming_migration,
  62. NULL, NULL,
  63. g_main_context_get_thread_default());
  64. }