yank_functions.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "io/channel.h"
  11. #include "yank_functions.h"
  12. #include "qemu/yank.h"
  13. #include "qemu-file.h"
  14. void migration_yank_iochannel(void *opaque)
  15. {
  16. QIOChannel *ioc = QIO_CHANNEL(opaque);
  17. qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
  18. }
  19. /* Return whether yank is supported on this ioc */
  20. static bool migration_ioc_yank_supported(QIOChannel *ioc)
  21. {
  22. return qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
  23. }
  24. void migration_ioc_register_yank(QIOChannel *ioc)
  25. {
  26. if (migration_ioc_yank_supported(ioc)) {
  27. yank_register_function(MIGRATION_YANK_INSTANCE,
  28. migration_yank_iochannel,
  29. ioc);
  30. }
  31. }
  32. void migration_ioc_unregister_yank(QIOChannel *ioc)
  33. {
  34. if (migration_ioc_yank_supported(ioc)) {
  35. yank_unregister_function(MIGRATION_YANK_INSTANCE,
  36. migration_yank_iochannel,
  37. ioc);
  38. }
  39. }
  40. void migration_ioc_unregister_yank_from_file(QEMUFile *file)
  41. {
  42. QIOChannel *ioc = qemu_file_get_ioc(file);
  43. if (ioc) {
  44. /*
  45. * For migration qemufiles, we'll always reach here. Though we'll skip
  46. * calls from e.g. savevm/loadvm as they don't use yank.
  47. */
  48. migration_ioc_unregister_yank(ioc);
  49. }
  50. }