channel.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * QEMU live migration channel operations
  3. *
  4. * Copyright Red Hat, Inc. 2016
  5. *
  6. * Authors:
  7. * Daniel P. Berrange <berrange@redhat.com>
  8. *
  9. * Contributions after 2012-01-13 are licensed under the terms of the
  10. * GNU GPL, version 2 or (at your option) any later version.
  11. */
  12. #include "qemu/osdep.h"
  13. #include "channel.h"
  14. #include "tls.h"
  15. #include "migration.h"
  16. #include "qemu-file-channel.h"
  17. #include "trace.h"
  18. #include "qapi/error.h"
  19. #include "io/channel-tls.h"
  20. /**
  21. * @migration_channel_process_incoming - Create new incoming migration channel
  22. *
  23. * Notice that TLS is special. For it we listen in a listener socket,
  24. * and then create a new client socket from the TLS library.
  25. *
  26. * @ioc: Channel to which we are connecting
  27. */
  28. void migration_channel_process_incoming(QIOChannel *ioc)
  29. {
  30. MigrationState *s = migrate_get_current();
  31. Error *local_err = NULL;
  32. trace_migration_set_incoming_channel(
  33. ioc, object_get_typename(OBJECT(ioc)));
  34. if (s->parameters.tls_creds &&
  35. *s->parameters.tls_creds &&
  36. !object_dynamic_cast(OBJECT(ioc),
  37. TYPE_QIO_CHANNEL_TLS)) {
  38. migration_tls_channel_process_incoming(s, ioc, &local_err);
  39. } else {
  40. migration_ioc_process_incoming(ioc, &local_err);
  41. }
  42. if (local_err) {
  43. error_report_err(local_err);
  44. }
  45. }
  46. /**
  47. * @migration_channel_connect - Create new outgoing migration channel
  48. *
  49. * @s: Current migration state
  50. * @ioc: Channel to which we are connecting
  51. * @hostname: Where we want to connect
  52. * @error: Error indicating failure to connect, free'd here
  53. */
  54. void migration_channel_connect(MigrationState *s,
  55. QIOChannel *ioc,
  56. const char *hostname,
  57. Error *error)
  58. {
  59. trace_migration_set_outgoing_channel(
  60. ioc, object_get_typename(OBJECT(ioc)), hostname, error);
  61. if (!error) {
  62. if (s->parameters.tls_creds &&
  63. *s->parameters.tls_creds &&
  64. !object_dynamic_cast(OBJECT(ioc),
  65. TYPE_QIO_CHANNEL_TLS)) {
  66. migration_tls_channel_connect(s, ioc, hostname, &error);
  67. if (!error) {
  68. /* tls_channel_connect will call back to this
  69. * function after the TLS handshake,
  70. * so we mustn't call migrate_fd_connect until then
  71. */
  72. return;
  73. }
  74. } else {
  75. QEMUFile *f = qemu_fopen_channel_output(ioc);
  76. qemu_mutex_lock(&s->qemu_file_lock);
  77. s->to_dst_file = f;
  78. qemu_mutex_unlock(&s->qemu_file_lock);
  79. }
  80. }
  81. migrate_fd_connect(s, error);
  82. error_free(error);
  83. }