yank_functions.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * migration yank functions
  3. *
  4. * Copyright (c) Lukas Straub <lukasstraub2@web.de>
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. */
  9. #include "qemu/osdep.h"
  10. #include "qapi/error.h"
  11. #include "io/channel.h"
  12. #include "yank_functions.h"
  13. #include "qemu/yank.h"
  14. #include "io/channel-socket.h"
  15. #include "io/channel-tls.h"
  16. #include "qemu-file.h"
  17. void migration_yank_iochannel(void *opaque)
  18. {
  19. QIOChannel *ioc = QIO_CHANNEL(opaque);
  20. qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
  21. }
  22. /* Return whether yank is supported on this ioc */
  23. static bool migration_ioc_yank_supported(QIOChannel *ioc)
  24. {
  25. return object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) ||
  26. object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS);
  27. }
  28. void migration_ioc_register_yank(QIOChannel *ioc)
  29. {
  30. if (migration_ioc_yank_supported(ioc)) {
  31. yank_register_function(MIGRATION_YANK_INSTANCE,
  32. migration_yank_iochannel,
  33. QIO_CHANNEL(ioc));
  34. }
  35. }
  36. void migration_ioc_unregister_yank(QIOChannel *ioc)
  37. {
  38. if (migration_ioc_yank_supported(ioc)) {
  39. yank_unregister_function(MIGRATION_YANK_INSTANCE,
  40. migration_yank_iochannel,
  41. QIO_CHANNEL(ioc));
  42. }
  43. }
  44. void migration_ioc_unregister_yank_from_file(QEMUFile *file)
  45. {
  46. QIOChannel *ioc = qemu_file_get_ioc(file);
  47. if (ioc) {
  48. /*
  49. * For migration qemufiles, we'll always reach here. Though we'll skip
  50. * calls from e.g. savevm/loadvm as they don't use yank.
  51. */
  52. migration_ioc_unregister_yank(ioc);
  53. }
  54. }