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
26 #ifndef QEMU_VMSTATE_H
27 #define QEMU_VMSTATE_H 1
29 #ifndef CONFIG_USER_ONLY
30 #include <migration/qemu-file.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
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
;
62 int register_savevm(DeviceState
*dev
,
66 SaveStateHandler
*save_state
,
67 LoadStateHandler
*load_state
,
70 int register_savevm_live(DeviceState
*dev
,
77 void unregister_savevm(DeviceState
*dev
, const char *idstr
, void *opaque
);
79 typedef struct VMStateInfo VMStateInfo
;
80 typedef struct VMStateDescription VMStateDescription
;
84 int (*get
)(QEMUFile
*f
, void *pv
, size_t size
);
85 void (*put
)(QEMUFile
*f
, void *pv
, size_t size
);
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 */
113 const VMStateInfo
*info
;
114 enum VMStateFlags flags
;
115 const VMStateDescription
*vmsd
;
117 bool (*field_exists
)(void *opaque
, int version_id
);
120 struct VMStateDescription
{
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), \
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) { \
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), \
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)), \
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), \
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), \
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), \
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), \
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), \
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), \
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),\
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),\
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), \
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), \
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), \
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), \
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), \
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), \
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)), \
367 .field_exists = (_test), \
368 .version_id = (_version), \
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), \
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)), \
388 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
389 .size = sizeof(_type), \
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)), \
398 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
399 .size = sizeof(_type), \
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)), \
408 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
409 .size = sizeof(_type), \
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), \
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), \
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), \
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), \
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), \
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), \
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), \
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), \
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), \
514 .info = &vmstate_info_buffer, \
515 .flags = VMS_BUFFER|VMS_POINTER, \
516 .offset = offsetof(_state, _field), \
519 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
521 .field_exists = (_test), \
522 .version_id = (_version), \
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), \
541 _f_n : num of elements field_name
543 _s : struct state name
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, \
563 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
564 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
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_INT64_ARRAY_V(_f, _s, _n, _v) \
758 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
760 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \
761 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
763 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \
764 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
766 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
767 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
769 #define VMSTATE_BUFFER_V(_f, _s, _v) \
770 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
772 #define VMSTATE_BUFFER(_f, _s) \
773 VMSTATE_BUFFER_V(_f, _s, 0)
775 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
776 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
778 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
779 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
781 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
782 VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
784 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
785 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
787 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \
788 VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
790 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \
791 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
793 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
794 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
796 #define VMSTATE_UNUSED_V(_v, _size) \
797 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
799 #define VMSTATE_UNUSED(_size) \
800 VMSTATE_UNUSED_V(0, _size)
802 #define VMSTATE_UNUSED_TEST(_test, _size) \
803 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
805 #define VMSTATE_END_OF_LIST() \
808 #define SELF_ANNOUNCE_ROUNDS 5
810 void loadvm_free_handlers(MigrationIncomingState
*mis
);
812 int vmstate_load_state(QEMUFile
*f
, const VMStateDescription
*vmsd
,
813 void *opaque
, int version_id
);
814 void vmstate_save_state(QEMUFile
*f
, const VMStateDescription
*vmsd
,
815 void *opaque
, QJSON
*vmdesc
);
817 bool vmstate_save_needed(const VMStateDescription
*vmsd
, void *opaque
);
819 int vmstate_register_with_alias_id(DeviceState
*dev
, int instance_id
,
820 const VMStateDescription
*vmsd
,
821 void *base
, int alias_id
,
822 int required_for_version
);
824 static inline int vmstate_register(DeviceState
*dev
, int instance_id
,
825 const VMStateDescription
*vmsd
,
828 return vmstate_register_with_alias_id(dev
, instance_id
, vmsd
,
832 void vmstate_unregister(DeviceState
*dev
, const VMStateDescription
*vmsd
,
836 void vmstate_register_ram(struct MemoryRegion
*memory
, DeviceState
*dev
);
837 void vmstate_unregister_ram(struct MemoryRegion
*memory
, DeviceState
*dev
);
838 void vmstate_register_ram_global(struct MemoryRegion
*memory
);
841 int64_t self_announce_delay(int round
)
843 assert(round
< SELF_ANNOUNCE_ROUNDS
&& round
> 0);
844 /* delay 50ms, 150ms, 250ms, ... */
845 return 50 + (SELF_ANNOUNCE_ROUNDS
- round
- 1) * 100;
848 void dump_vmstate_json_to_file(FILE *out_fp
);