qapi: De-duplicate enum code generation
[qemu/kevin.git] / include / migration / vmstate.h
blob2e5a97dec4edac7fc212fd36e9ee2045a031e512
1 /*
2 * QEMU migration/snapshot declarations
4 * Copyright (c) 2009-2011 Red Hat, Inc.
6 * Original author: Juan Quintela <quintela@redhat.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
26 #ifndef QEMU_VMSTATE_H
27 #define QEMU_VMSTATE_H 1
29 #ifndef CONFIG_USER_ONLY
30 #include <migration/qemu-file.h>
31 #endif
32 #include <qjson.h>
34 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
35 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
37 typedef struct SaveVMHandlers {
38 /* This runs inside the iothread lock. */
39 void (*set_params)(const MigrationParams *params, void * opaque);
40 SaveStateHandler *save_state;
42 void (*cancel)(void *opaque);
43 int (*save_live_complete)(QEMUFile *f, void *opaque);
45 /* This runs both outside and inside the iothread lock. */
46 bool (*is_active)(void *opaque);
48 /* This runs outside the iothread lock in the migration case, and
49 * within the lock in the savevm case. The callback had better only
50 * use data that is local to the migration thread or protected
51 * by other locks.
53 int (*save_live_iterate)(QEMUFile *f, void *opaque);
55 /* This runs outside the iothread lock! */
56 int (*save_live_setup)(QEMUFile *f, void *opaque);
57 uint64_t (*save_live_pending)(QEMUFile *f, void *opaque, uint64_t max_size);
59 LoadStateHandler *load_state;
60 } SaveVMHandlers;
62 int register_savevm(DeviceState *dev,
63 const char *idstr,
64 int instance_id,
65 int version_id,
66 SaveStateHandler *save_state,
67 LoadStateHandler *load_state,
68 void *opaque);
70 int register_savevm_live(DeviceState *dev,
71 const char *idstr,
72 int instance_id,
73 int version_id,
74 SaveVMHandlers *ops,
75 void *opaque);
77 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
79 typedef struct VMStateInfo VMStateInfo;
80 typedef struct VMStateDescription VMStateDescription;
82 struct VMStateInfo {
83 const char *name;
84 int (*get)(QEMUFile *f, void *pv, size_t size);
85 void (*put)(QEMUFile *f, void *pv, size_t size);
88 enum VMStateFlags {
89 VMS_SINGLE = 0x001,
90 VMS_POINTER = 0x002,
91 VMS_ARRAY = 0x004,
92 VMS_STRUCT = 0x008,
93 VMS_VARRAY_INT32 = 0x010, /* Array with size in int32_t field*/
94 VMS_BUFFER = 0x020, /* static sized buffer */
95 VMS_ARRAY_OF_POINTER = 0x040,
96 VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_t field */
97 VMS_VBUFFER = 0x100, /* Buffer with size in int32_t field */
98 VMS_MULTIPLY = 0x200, /* multiply "size" field by field_size */
99 VMS_VARRAY_UINT8 = 0x400, /* Array with size in uint8_t field*/
100 VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field*/
101 VMS_MUST_EXIST = 0x1000, /* Field must exist in input */
102 VMS_ALLOC = 0x2000, /* Alloc a buffer on the destination */
105 typedef struct {
106 const char *name;
107 size_t offset;
108 size_t size;
109 size_t start;
110 int num;
111 size_t num_offset;
112 size_t size_offset;
113 const VMStateInfo *info;
114 enum VMStateFlags flags;
115 const VMStateDescription *vmsd;
116 int version_id;
117 bool (*field_exists)(void *opaque, int version_id);
118 } VMStateField;
120 struct VMStateDescription {
121 const char *name;
122 int unmigratable;
123 int version_id;
124 int minimum_version_id;
125 int minimum_version_id_old;
126 LoadStateHandler *load_state_old;
127 int (*pre_load)(void *opaque);
128 int (*post_load)(void *opaque, int version_id);
129 void (*pre_save)(void *opaque);
130 bool (*needed)(void *opaque);
131 VMStateField *fields;
132 const VMStateDescription **subsections;
135 extern const VMStateDescription vmstate_dummy;
137 extern const VMStateInfo vmstate_info_bool;
139 extern const VMStateInfo vmstate_info_int8;
140 extern const VMStateInfo vmstate_info_int16;
141 extern const VMStateInfo vmstate_info_int32;
142 extern const VMStateInfo vmstate_info_int64;
144 extern const VMStateInfo vmstate_info_uint8_equal;
145 extern const VMStateInfo vmstate_info_uint16_equal;
146 extern const VMStateInfo vmstate_info_int32_equal;
147 extern const VMStateInfo vmstate_info_uint32_equal;
148 extern const VMStateInfo vmstate_info_uint64_equal;
149 extern const VMStateInfo vmstate_info_int32_le;
151 extern const VMStateInfo vmstate_info_uint8;
152 extern const VMStateInfo vmstate_info_uint16;
153 extern const VMStateInfo vmstate_info_uint32;
154 extern const VMStateInfo vmstate_info_uint64;
156 extern const VMStateInfo vmstate_info_float64;
158 extern const VMStateInfo vmstate_info_timer;
159 extern const VMStateInfo vmstate_info_buffer;
160 extern const VMStateInfo vmstate_info_unused_buffer;
161 extern const VMStateInfo vmstate_info_bitmap;
163 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
164 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
165 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
167 #define vmstate_offset_value(_state, _field, _type) \
168 (offsetof(_state, _field) + \
169 type_check(_type, typeof_field(_state, _field)))
171 #define vmstate_offset_pointer(_state, _field, _type) \
172 (offsetof(_state, _field) + \
173 type_check_pointer(_type, typeof_field(_state, _field)))
175 #define vmstate_offset_array(_state, _field, _type, _num) \
176 (offsetof(_state, _field) + \
177 type_check_array(_type, typeof_field(_state, _field), _num))
179 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \
180 (offsetof(_state, _field) + \
181 type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
183 #define vmstate_offset_sub_array(_state, _field, _type, _start) \
184 vmstate_offset_value(_state, _field[_start], _type)
186 #define vmstate_offset_buffer(_state, _field) \
187 vmstate_offset_array(_state, _field, uint8_t, \
188 sizeof(typeof_field(_state, _field)))
190 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
191 .name = (stringify(_field)), \
192 .version_id = (_version), \
193 .field_exists = (_test), \
194 .size = sizeof(_type), \
195 .info = &(_info), \
196 .flags = VMS_SINGLE, \
197 .offset = vmstate_offset_value(_state, _field, _type), \
200 /* Validate state using a boolean predicate. */
201 #define VMSTATE_VALIDATE(_name, _test) { \
202 .name = (_name), \
203 .field_exists = (_test), \
204 .flags = VMS_ARRAY | VMS_MUST_EXIST, \
205 .num = 0, /* 0 elements: no data, only run _test */ \
208 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
209 .name = (stringify(_field)), \
210 .version_id = (_version), \
211 .info = &(_info), \
212 .size = sizeof(_type), \
213 .flags = VMS_SINGLE|VMS_POINTER, \
214 .offset = vmstate_offset_value(_state, _field, _type), \
217 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \
218 .name = (stringify(_field)), \
219 .info = &(_info), \
220 .field_exists = (_test), \
221 .size = sizeof(_type), \
222 .flags = VMS_SINGLE|VMS_POINTER, \
223 .offset = vmstate_offset_value(_state, _field, _type), \
226 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
227 .name = (stringify(_field)), \
228 .version_id = (_version), \
229 .num = (_num), \
230 .info = &(_info), \
231 .size = sizeof(_type), \
232 .flags = VMS_ARRAY, \
233 .offset = vmstate_offset_array(_state, _field, _type, _num), \
236 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
237 .name = (stringify(_field)), \
238 .version_id = (_version), \
239 .num = (_n1) * (_n2), \
240 .info = &(_info), \
241 .size = sizeof(_type), \
242 .flags = VMS_ARRAY, \
243 .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \
246 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
247 .name = (stringify(_field)), \
248 .field_exists = (_test), \
249 .num = (_num), \
250 .info = &(_info), \
251 .size = sizeof(_type), \
252 .flags = VMS_ARRAY, \
253 .offset = vmstate_offset_array(_state, _field, _type, _num),\
256 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
257 .name = (stringify(_field)), \
258 .version_id = (_version), \
259 .num = (_num), \
260 .info = &(_info), \
261 .size = sizeof(_type), \
262 .flags = VMS_ARRAY, \
263 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
266 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
267 .name = (stringify(_field)), \
268 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
269 .info = &(_info), \
270 .size = sizeof(_type), \
271 .flags = VMS_VARRAY_INT32, \
272 .offset = offsetof(_state, _field), \
275 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
276 .name = (stringify(_field)), \
277 .version_id = (_version), \
278 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
279 .info = &(_info), \
280 .size = sizeof(_type), \
281 .flags = VMS_VARRAY_INT32|VMS_POINTER, \
282 .offset = vmstate_offset_pointer(_state, _field, _type), \
285 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
286 .name = (stringify(_field)), \
287 .version_id = (_version), \
288 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
289 .info = &(_info), \
290 .size = sizeof(_type), \
291 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \
292 .offset = vmstate_offset_pointer(_state, _field, _type), \
295 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
296 .name = (stringify(_field)), \
297 .version_id = (_version), \
298 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
299 .info = &(_info), \
300 .size = sizeof(_type), \
301 .flags = VMS_VARRAY_UINT16, \
302 .offset = offsetof(_state, _field), \
305 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
306 .name = (stringify(_field)), \
307 .version_id = (_version), \
308 .field_exists = (_test), \
309 .vmsd = &(_vmsd), \
310 .size = sizeof(_type), \
311 .flags = VMS_STRUCT, \
312 .offset = vmstate_offset_value(_state, _field, _type), \
315 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
316 .name = (stringify(_field)), \
317 .version_id = (_version), \
318 .vmsd = &(_vmsd), \
319 .size = sizeof(_type *), \
320 .flags = VMS_STRUCT|VMS_POINTER, \
321 .offset = vmstate_offset_pointer(_state, _field, _type), \
324 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
325 .name = (stringify(_field)), \
326 .version_id = (_version), \
327 .field_exists = (_test), \
328 .vmsd = &(_vmsd), \
329 .size = sizeof(_type *), \
330 .flags = VMS_STRUCT|VMS_POINTER, \
331 .offset = vmstate_offset_pointer(_state, _field, _type), \
334 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
335 .name = (stringify(_field)), \
336 .version_id = (_version), \
337 .num = (_num), \
338 .info = &(_info), \
339 .size = sizeof(_type), \
340 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
341 .offset = vmstate_offset_array(_state, _field, _type, _num), \
344 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \
345 .name = (stringify(_f)), \
346 .version_id = (_v), \
347 .num = (_n), \
348 .vmsd = &(_vmsd), \
349 .size = sizeof(_type *), \
350 .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \
351 .offset = vmstate_offset_array(_s, _f, _type*, _n), \
354 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \
355 .name = (stringify(_field)), \
356 .version_id = (_version), \
357 .num = (_num), \
358 .vmsd = &(_vmsd), \
359 .size = sizeof(_type), \
360 .flags = VMS_STRUCT|VMS_ARRAY, \
361 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
364 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
365 .name = (stringify(_field)), \
366 .num = (_num), \
367 .field_exists = (_test), \
368 .version_id = (_version), \
369 .vmsd = &(_vmsd), \
370 .size = sizeof(_type), \
371 .flags = VMS_STRUCT|VMS_ARRAY, \
372 .offset = vmstate_offset_array(_state, _field, _type, _num),\
375 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
376 .name = (stringify(_field)), \
377 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
378 .version_id = (_version), \
379 .vmsd = &(_vmsd), \
380 .size = sizeof(_type), \
381 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \
382 .offset = offsetof(_state, _field), \
385 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
386 .name = (stringify(_field)), \
387 .version_id = 0, \
388 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
389 .size = sizeof(_type), \
390 .vmsd = &(_vmsd), \
391 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
392 .offset = vmstate_offset_pointer(_state, _field, _type), \
395 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
396 .name = (stringify(_field)), \
397 .version_id = 0, \
398 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
399 .size = sizeof(_type), \
400 .vmsd = &(_vmsd), \
401 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
402 .offset = vmstate_offset_pointer(_state, _field, _type), \
405 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
406 .name = (stringify(_field)), \
407 .version_id = 0, \
408 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
409 .size = sizeof(_type), \
410 .vmsd = &(_vmsd), \
411 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \
412 .offset = vmstate_offset_pointer(_state, _field, _type), \
415 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
416 .name = (stringify(_field)), \
417 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
418 .version_id = (_version), \
419 .vmsd = &(_vmsd), \
420 .size = sizeof(_type), \
421 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \
422 .offset = offsetof(_state, _field), \
425 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
426 .name = (stringify(_field)), \
427 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
428 .version_id = (_version), \
429 .vmsd = &(_vmsd), \
430 .size = sizeof(_type), \
431 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \
432 .offset = offsetof(_state, _field), \
435 #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
436 .name = (stringify(_field)), \
437 .version_id = (_version), \
438 .vmsd = &(_vmsd), \
439 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
440 .size = sizeof(_type), \
441 .flags = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
442 .offset = vmstate_offset_pointer(_state, _field, _type), \
445 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
446 .name = (stringify(_field)), \
447 .version_id = (_version), \
448 .field_exists = (_test), \
449 .size = (_size - _start), \
450 .info = &vmstate_info_buffer, \
451 .flags = VMS_BUFFER, \
452 .offset = vmstate_offset_buffer(_state, _field) + _start, \
455 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
456 .name = (stringify(_field)), \
457 .version_id = (_version), \
458 .field_exists = (_test), \
459 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
460 .size = (_multiply), \
461 .info = &vmstate_info_buffer, \
462 .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \
463 .offset = offsetof(_state, _field), \
464 .start = (_start), \
467 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
468 .name = (stringify(_field)), \
469 .version_id = (_version), \
470 .field_exists = (_test), \
471 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
472 .info = &vmstate_info_buffer, \
473 .flags = VMS_VBUFFER|VMS_POINTER, \
474 .offset = offsetof(_state, _field), \
475 .start = (_start), \
478 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
479 .name = (stringify(_field)), \
480 .version_id = (_version), \
481 .field_exists = (_test), \
482 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
483 .info = &vmstate_info_buffer, \
484 .flags = VMS_VBUFFER|VMS_POINTER, \
485 .offset = offsetof(_state, _field), \
486 .start = (_start), \
489 #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, _test, _start, _field_size) { \
490 .name = (stringify(_field)), \
491 .version_id = (_version), \
492 .field_exists = (_test), \
493 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
494 .info = &vmstate_info_buffer, \
495 .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \
496 .offset = offsetof(_state, _field), \
497 .start = (_start), \
500 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \
501 .name = (stringify(_field)), \
502 .version_id = (_version), \
503 .field_exists = (_test), \
504 .size = (_size), \
505 .info = &(_info), \
506 .flags = VMS_BUFFER, \
507 .offset = offsetof(_state, _field), \
510 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
511 .name = (stringify(_field)), \
512 .version_id = (_version), \
513 .size = (_size), \
514 .info = &vmstate_info_buffer, \
515 .flags = VMS_BUFFER|VMS_POINTER, \
516 .offset = offsetof(_state, _field), \
519 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
520 .name = "unused", \
521 .field_exists = (_test), \
522 .version_id = (_version), \
523 .size = (_size), \
524 .info = &vmstate_info_unused_buffer, \
525 .flags = VMS_BUFFER, \
528 /* _field_size should be a int32_t field in the _state struct giving the
529 * size of the bitmap _field in bits.
531 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
532 .name = (stringify(_field)), \
533 .version_id = (_version), \
534 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
535 .info = &vmstate_info_bitmap, \
536 .flags = VMS_VBUFFER|VMS_POINTER, \
537 .offset = offsetof(_state, _field), \
540 /* _f : field name
541 _f_n : num of elements field_name
542 _n : num of elements
543 _s : struct state name
544 _v : version
547 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
548 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
550 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
551 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
553 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \
554 VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
556 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \
557 VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
559 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
560 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \
561 _vmsd, _type)
563 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
564 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
565 _size)
567 #define VMSTATE_BOOL_V(_f, _s, _v) \
568 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
570 #define VMSTATE_INT8_V(_f, _s, _v) \
571 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
572 #define VMSTATE_INT16_V(_f, _s, _v) \
573 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
574 #define VMSTATE_INT32_V(_f, _s, _v) \
575 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
576 #define VMSTATE_INT64_V(_f, _s, _v) \
577 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
579 #define VMSTATE_UINT8_V(_f, _s, _v) \
580 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
581 #define VMSTATE_UINT16_V(_f, _s, _v) \
582 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
583 #define VMSTATE_UINT32_V(_f, _s, _v) \
584 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
585 #define VMSTATE_UINT64_V(_f, _s, _v) \
586 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
588 #define VMSTATE_BOOL(_f, _s) \
589 VMSTATE_BOOL_V(_f, _s, 0)
591 #define VMSTATE_INT8(_f, _s) \
592 VMSTATE_INT8_V(_f, _s, 0)
593 #define VMSTATE_INT16(_f, _s) \
594 VMSTATE_INT16_V(_f, _s, 0)
595 #define VMSTATE_INT32(_f, _s) \
596 VMSTATE_INT32_V(_f, _s, 0)
597 #define VMSTATE_INT64(_f, _s) \
598 VMSTATE_INT64_V(_f, _s, 0)
600 #define VMSTATE_UINT8(_f, _s) \
601 VMSTATE_UINT8_V(_f, _s, 0)
602 #define VMSTATE_UINT16(_f, _s) \
603 VMSTATE_UINT16_V(_f, _s, 0)
604 #define VMSTATE_UINT32(_f, _s) \
605 VMSTATE_UINT32_V(_f, _s, 0)
606 #define VMSTATE_UINT64(_f, _s) \
607 VMSTATE_UINT64_V(_f, _s, 0)
609 #define VMSTATE_UINT8_EQUAL(_f, _s) \
610 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
612 #define VMSTATE_UINT16_EQUAL(_f, _s) \
613 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
615 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \
616 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
618 #define VMSTATE_INT32_EQUAL(_f, _s) \
619 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
621 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v) \
622 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t)
624 #define VMSTATE_UINT32_EQUAL(_f, _s) \
625 VMSTATE_UINT32_EQUAL_V(_f, _s, 0)
627 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v) \
628 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
630 #define VMSTATE_UINT64_EQUAL(_f, _s) \
631 VMSTATE_UINT64_EQUAL_V(_f, _s, 0)
633 #define VMSTATE_INT32_POSITIVE_LE(_f, _s) \
634 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
636 #define VMSTATE_INT8_TEST(_f, _s, _t) \
637 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
639 #define VMSTATE_INT16_TEST(_f, _s, _t) \
640 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
642 #define VMSTATE_INT32_TEST(_f, _s, _t) \
643 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
645 #define VMSTATE_INT64_TEST(_f, _s, _t) \
646 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
648 #define VMSTATE_UINT8_TEST(_f, _s, _t) \
649 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
651 #define VMSTATE_UINT16_TEST(_f, _s, _t) \
652 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
654 #define VMSTATE_UINT32_TEST(_f, _s, _t) \
655 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
657 #define VMSTATE_UINT64_TEST(_f, _s, _t) \
658 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
661 #define VMSTATE_FLOAT64_V(_f, _s, _v) \
662 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
664 #define VMSTATE_FLOAT64(_f, _s) \
665 VMSTATE_FLOAT64_V(_f, _s, 0)
667 #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \
668 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
670 #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \
671 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
673 #define VMSTATE_TIMER_PTR(_f, _s) \
674 VMSTATE_TIMER_PTR_V(_f, _s, 0)
676 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \
677 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
679 #define VMSTATE_TIMER_TEST(_f, _s, _test) \
680 VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer)
682 #define VMSTATE_TIMER_V(_f, _s, _v) \
683 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer)
685 #define VMSTATE_TIMER(_f, _s) \
686 VMSTATE_TIMER_V(_f, _s, 0)
688 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
689 VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer)
691 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
692 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
694 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
695 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
697 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
698 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
700 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \
701 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
703 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
704 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
706 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \
707 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
709 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \
710 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
712 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
713 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
715 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
716 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
718 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \
719 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
721 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \
722 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
724 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
725 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
727 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \
728 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)
730 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
731 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
733 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \
734 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)
736 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
737 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
739 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
740 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
742 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
743 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
745 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \
746 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
748 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
749 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
751 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \
752 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
754 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
755 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
757 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
758 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
760 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
761 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
763 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \
764 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
766 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \
767 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
769 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
770 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
772 #define VMSTATE_BUFFER_V(_f, _s, _v) \
773 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
775 #define VMSTATE_BUFFER(_f, _s) \
776 VMSTATE_BUFFER_V(_f, _s, 0)
778 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
779 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
781 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
782 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
784 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
785 VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
787 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
788 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
790 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \
791 VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
793 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \
794 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
796 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
797 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
799 #define VMSTATE_UNUSED_V(_v, _size) \
800 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
802 #define VMSTATE_UNUSED(_size) \
803 VMSTATE_UNUSED_V(0, _size)
805 #define VMSTATE_UNUSED_TEST(_test, _size) \
806 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
808 #define VMSTATE_END_OF_LIST() \
811 #define SELF_ANNOUNCE_ROUNDS 5
813 void loadvm_free_handlers(MigrationIncomingState *mis);
815 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
816 void *opaque, int version_id);
817 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
818 void *opaque, QJSON *vmdesc);
820 bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
822 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
823 const VMStateDescription *vmsd,
824 void *base, int alias_id,
825 int required_for_version);
827 static inline int vmstate_register(DeviceState *dev, int instance_id,
828 const VMStateDescription *vmsd,
829 void *opaque)
831 return vmstate_register_with_alias_id(dev, instance_id, vmsd,
832 opaque, -1, 0);
835 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
836 void *opaque);
838 struct MemoryRegion;
839 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
840 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
841 void vmstate_register_ram_global(struct MemoryRegion *memory);
843 static inline
844 int64_t self_announce_delay(int round)
846 assert(round < SELF_ANNOUNCE_ROUNDS && round > 0);
847 /* delay 50ms, 150ms, 250ms, ... */
848 return 50 + (SELF_ANNOUNCE_ROUNDS - round - 1) * 100;
851 void dump_vmstate_json_to_file(FILE *out_fp);
853 #endif