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