qemu-file-types.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_TYPES_H
  25. #define MIGRATION_QEMU_FILE_TYPES_H
  26. int qemu_file_get_error(QEMUFile *f);
  27. void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size);
  28. void qemu_put_byte(QEMUFile *f, int v);
  29. #define qemu_put_sbyte qemu_put_byte
  30. void qemu_put_be16(QEMUFile *f, unsigned int v);
  31. void qemu_put_be32(QEMUFile *f, unsigned int v);
  32. void qemu_put_be64(QEMUFile *f, uint64_t v);
  33. size_t coroutine_mixed_fn qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size);
  34. int qemu_get_byte(QEMUFile *f);
  35. static inline unsigned int qemu_get_ubyte(QEMUFile *f)
  36. {
  37. return (unsigned int)qemu_get_byte(f);
  38. }
  39. #define qemu_get_sbyte qemu_get_byte
  40. unsigned int qemu_get_be16(QEMUFile *f);
  41. unsigned int qemu_get_be32(QEMUFile *f);
  42. uint64_t qemu_get_be64(QEMUFile *f);
  43. static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
  44. {
  45. qemu_put_be64(f, *pv);
  46. }
  47. static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
  48. {
  49. qemu_put_be32(f, *pv);
  50. }
  51. static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
  52. {
  53. qemu_put_be16(f, *pv);
  54. }
  55. static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
  56. {
  57. qemu_put_byte(f, *pv);
  58. }
  59. static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
  60. {
  61. *pv = qemu_get_be64(f);
  62. }
  63. static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
  64. {
  65. *pv = qemu_get_be32(f);
  66. }
  67. static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
  68. {
  69. *pv = qemu_get_be16(f);
  70. }
  71. static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
  72. {
  73. *pv = qemu_get_byte(f);
  74. }
  75. /* Signed versions for type safety */
  76. static inline void qemu_put_sbe16(QEMUFile *f, int v)
  77. {
  78. qemu_put_be16(f, (unsigned int)v);
  79. }
  80. static inline void qemu_put_sbe32(QEMUFile *f, int v)
  81. {
  82. qemu_put_be32(f, (unsigned int)v);
  83. }
  84. static inline void qemu_put_sbe64(QEMUFile *f, int64_t v)
  85. {
  86. qemu_put_be64(f, (uint64_t)v);
  87. }
  88. static inline int qemu_get_sbe16(QEMUFile *f)
  89. {
  90. return (int)qemu_get_be16(f);
  91. }
  92. static inline int qemu_get_sbe32(QEMUFile *f)
  93. {
  94. return (int)qemu_get_be32(f);
  95. }
  96. static inline int64_t qemu_get_sbe64(QEMUFile *f)
  97. {
  98. return (int64_t)qemu_get_be64(f);
  99. }
  100. static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv)
  101. {
  102. qemu_put_8s(f, (const uint8_t *)pv);
  103. }
  104. static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv)
  105. {
  106. qemu_put_be16s(f, (const uint16_t *)pv);
  107. }
  108. static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv)
  109. {
  110. qemu_put_be32s(f, (const uint32_t *)pv);
  111. }
  112. static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv)
  113. {
  114. qemu_put_be64s(f, (const uint64_t *)pv);
  115. }
  116. static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv)
  117. {
  118. qemu_get_8s(f, (uint8_t *)pv);
  119. }
  120. static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv)
  121. {
  122. qemu_get_be16s(f, (uint16_t *)pv);
  123. }
  124. static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv)
  125. {
  126. qemu_get_be32s(f, (uint32_t *)pv);
  127. }
  128. static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
  129. {
  130. qemu_get_be64s(f, (uint64_t *)pv);
  131. }
  132. size_t coroutine_mixed_fn qemu_get_counted_string(QEMUFile *f, char buf[256]);
  133. void qemu_put_counted_string(QEMUFile *f, const char *name);
  134. /**
  135. * migration_rate_exceeded: Check if we have exceeded rate for this interval
  136. *
  137. * Checks if we have already transferred more data that we are allowed
  138. * in the current interval.
  139. *
  140. * @f: QEMUFile used for main migration channel
  141. *
  142. * Returns if we should stop sending data for this interval.
  143. */
  144. bool migration_rate_exceeded(QEMUFile *f);
  145. #endif