2
0

qemu-file.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * QEMU System Emulator
  3. *
  4. * Copyright (c) 2003-2008 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #ifndef MIGRATION_QEMU_FILE_H
  25. #define MIGRATION_QEMU_FILE_H
  26. #include <zlib.h>
  27. #include "exec/cpu-common.h"
  28. #include "io/channel.h"
  29. /*
  30. * This function provides hooks around different
  31. * stages of RAM migration.
  32. * 'data' is call specific data associated with the 'flags' value
  33. */
  34. typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, void *data);
  35. /*
  36. * Constants used by ram_control_* hooks
  37. */
  38. #define RAM_CONTROL_SETUP 0
  39. #define RAM_CONTROL_ROUND 1
  40. #define RAM_CONTROL_HOOK 2
  41. #define RAM_CONTROL_FINISH 3
  42. #define RAM_CONTROL_BLOCK_REG 4
  43. /*
  44. * This function allows override of where the RAM page
  45. * is saved (such as RDMA, for example.)
  46. */
  47. typedef size_t (QEMURamSaveFunc)(QEMUFile *f,
  48. ram_addr_t block_offset,
  49. ram_addr_t offset,
  50. size_t size,
  51. uint64_t *bytes_sent);
  52. typedef struct QEMUFileHooks {
  53. QEMURamHookFunc *before_ram_iterate;
  54. QEMURamHookFunc *after_ram_iterate;
  55. QEMURamHookFunc *hook_ram_load;
  56. QEMURamSaveFunc *save_page;
  57. } QEMUFileHooks;
  58. QEMUFile *qemu_file_new_input(QIOChannel *ioc);
  59. QEMUFile *qemu_file_new_output(QIOChannel *ioc);
  60. void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
  61. int qemu_fclose(QEMUFile *f);
  62. /*
  63. * qemu_file_total_transferred:
  64. *
  65. * Report the total number of bytes transferred with
  66. * this file.
  67. *
  68. * For writable files, any pending buffers will be
  69. * flushed, so the reported value will be equal to
  70. * the number of bytes transferred on the wire.
  71. *
  72. * For readable files, the reported value will be
  73. * equal to the number of bytes transferred on the
  74. * wire.
  75. *
  76. * Returns: the total bytes transferred
  77. */
  78. int64_t qemu_file_total_transferred(QEMUFile *f);
  79. /*
  80. * qemu_file_total_transferred_fast:
  81. *
  82. * As qemu_file_total_transferred except for writable
  83. * files, where no flush is performed and the reported
  84. * amount will include the size of any queued buffers,
  85. * on top of the amount actually transferred.
  86. *
  87. * Returns: the total bytes transferred and queued
  88. */
  89. int64_t qemu_file_total_transferred_fast(QEMUFile *f);
  90. /*
  91. * put_buffer without copying the buffer.
  92. * The buffer should be available till it is sent asynchronously.
  93. */
  94. void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size,
  95. bool may_free);
  96. bool qemu_file_mode_is_not_valid(const char *mode);
  97. bool qemu_file_is_writable(QEMUFile *f);
  98. #include "migration/qemu-file-types.h"
  99. size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset);
  100. size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size);
  101. ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,
  102. const uint8_t *p, size_t size);
  103. int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src);
  104. /*
  105. * Note that you can only peek continuous bytes from where the current pointer
  106. * is; you aren't guaranteed to be able to peak to +n bytes unless you've
  107. * previously peeked +n-1.
  108. */
  109. int qemu_peek_byte(QEMUFile *f, int offset);
  110. void qemu_file_skip(QEMUFile *f, int size);
  111. /*
  112. * qemu_file_credit_transfer:
  113. *
  114. * Report on a number of bytes that have been transferred
  115. * out of band from the main file object I/O methods. This
  116. * accounting information tracks the total migration traffic.
  117. */
  118. void qemu_file_credit_transfer(QEMUFile *f, size_t size);
  119. void qemu_file_reset_rate_limit(QEMUFile *f);
  120. /*
  121. * qemu_file_acct_rate_limit:
  122. *
  123. * Report on a number of bytes the have been transferred
  124. * out of band from the main file object I/O methods, and
  125. * need to be applied to the rate limiting calcuations
  126. */
  127. void qemu_file_acct_rate_limit(QEMUFile *f, int64_t len);
  128. void qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
  129. int64_t qemu_file_get_rate_limit(QEMUFile *f);
  130. int qemu_file_get_error_obj(QEMUFile *f, Error **errp);
  131. int qemu_file_get_error_obj_any(QEMUFile *f1, QEMUFile *f2, Error **errp);
  132. void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err);
  133. void qemu_file_set_error(QEMUFile *f, int ret);
  134. int qemu_file_shutdown(QEMUFile *f);
  135. QEMUFile *qemu_file_get_return_path(QEMUFile *f);
  136. void qemu_fflush(QEMUFile *f);
  137. void qemu_file_set_blocking(QEMUFile *f, bool block);
  138. int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
  139. void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
  140. void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
  141. void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data);
  142. /* Whenever this is found in the data stream, the flags
  143. * will be passed to ram_control_load_hook in the incoming-migration
  144. * side. This lets before_ram_iterate/after_ram_iterate add
  145. * transport-specific sections to the RAM migration data.
  146. */
  147. #define RAM_SAVE_FLAG_HOOK 0x80
  148. #define RAM_SAVE_CONTROL_NOT_SUPP -1000
  149. #define RAM_SAVE_CONTROL_DELAYED -2000
  150. size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
  151. ram_addr_t offset, size_t size,
  152. uint64_t *bytes_sent);
  153. QIOChannel *qemu_file_get_ioc(QEMUFile *file);
  154. #endif