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 (*cleanup
)(void *opaque
);
43 int (*save_live_complete_postcopy
)(QEMUFile
*f
, void *opaque
);
44 int (*save_live_complete_precopy
)(QEMUFile
*f
, void *opaque
);
46 /* This runs both outside and inside the iothread lock. */
47 bool (*is_active
)(void *opaque
);
49 /* This runs outside the iothread lock in the migration case, and
50 * within the lock in the savevm case. The callback had better only
51 * use data that is local to the migration thread or protected
54 int (*save_live_iterate
)(QEMUFile
*f
, void *opaque
);
56 /* This runs outside the iothread lock! */
57 int (*save_live_setup
)(QEMUFile
*f
, void *opaque
);
58 void (*save_live_pending
)(QEMUFile
*f
, void *opaque
, uint64_t max_size
,
59 uint64_t *non_postcopiable_pending
,
60 uint64_t *postcopiable_pending
);
61 LoadStateHandler
*load_state
;
64 int register_savevm(DeviceState
*dev
,
68 SaveStateHandler
*save_state
,
69 LoadStateHandler
*load_state
,
72 int register_savevm_live(DeviceState
*dev
,
79 void unregister_savevm(DeviceState
*dev
, const char *idstr
, void *opaque
);
81 typedef struct VMStateInfo VMStateInfo
;
82 typedef struct VMStateDescription VMStateDescription
;
86 int (*get
)(QEMUFile
*f
, void *pv
, size_t size
);
87 void (*put
)(QEMUFile
*f
, void *pv
, size_t size
);
95 VMS_VARRAY_INT32
= 0x010, /* Array with size in int32_t field*/
96 VMS_BUFFER
= 0x020, /* static sized buffer */
97 VMS_ARRAY_OF_POINTER
= 0x040,
98 VMS_VARRAY_UINT16
= 0x080, /* Array with size in uint16_t field */
99 VMS_VBUFFER
= 0x100, /* Buffer with size in int32_t field */
100 VMS_MULTIPLY
= 0x200, /* multiply "size" field by field_size */
101 VMS_VARRAY_UINT8
= 0x400, /* Array with size in uint8_t field*/
102 VMS_VARRAY_UINT32
= 0x800, /* Array with size in uint32_t field*/
103 VMS_MUST_EXIST
= 0x1000, /* Field must exist in input */
104 VMS_ALLOC
= 0x2000, /* Alloc a buffer on the destination */
115 const VMStateInfo
*info
;
116 enum VMStateFlags flags
;
117 const VMStateDescription
*vmsd
;
119 bool (*field_exists
)(void *opaque
, int version_id
);
122 struct VMStateDescription
{
126 int minimum_version_id
;
127 int minimum_version_id_old
;
128 LoadStateHandler
*load_state_old
;
129 int (*pre_load
)(void *opaque
);
130 int (*post_load
)(void *opaque
, int version_id
);
131 void (*pre_save
)(void *opaque
);
132 bool (*needed
)(void *opaque
);
133 VMStateField
*fields
;
134 const VMStateDescription
**subsections
;
137 extern const VMStateDescription vmstate_dummy
;
139 extern const VMStateInfo vmstate_info_bool
;
141 extern const VMStateInfo vmstate_info_int8
;
142 extern const VMStateInfo vmstate_info_int16
;
143 extern const VMStateInfo vmstate_info_int32
;
144 extern const VMStateInfo vmstate_info_int64
;
146 extern const VMStateInfo vmstate_info_uint8_equal
;
147 extern const VMStateInfo vmstate_info_uint16_equal
;
148 extern const VMStateInfo vmstate_info_int32_equal
;
149 extern const VMStateInfo vmstate_info_uint32_equal
;
150 extern const VMStateInfo vmstate_info_uint64_equal
;
151 extern const VMStateInfo vmstate_info_int32_le
;
153 extern const VMStateInfo vmstate_info_uint8
;
154 extern const VMStateInfo vmstate_info_uint16
;
155 extern const VMStateInfo vmstate_info_uint32
;
156 extern const VMStateInfo vmstate_info_uint64
;
158 extern const VMStateInfo vmstate_info_float64
;
160 extern const VMStateInfo vmstate_info_timer
;
161 extern const VMStateInfo vmstate_info_buffer
;
162 extern const VMStateInfo vmstate_info_unused_buffer
;
163 extern const VMStateInfo vmstate_info_bitmap
;
165 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
166 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
167 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
169 #define vmstate_offset_value(_state, _field, _type) \
170 (offsetof(_state, _field) + \
171 type_check(_type, typeof_field(_state, _field)))
173 #define vmstate_offset_pointer(_state, _field, _type) \
174 (offsetof(_state, _field) + \
175 type_check_pointer(_type, typeof_field(_state, _field)))
177 #define vmstate_offset_array(_state, _field, _type, _num) \
178 (offsetof(_state, _field) + \
179 type_check_array(_type, typeof_field(_state, _field), _num))
181 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \
182 (offsetof(_state, _field) + \
183 type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
185 #define vmstate_offset_sub_array(_state, _field, _type, _start) \
186 vmstate_offset_value(_state, _field[_start], _type)
188 #define vmstate_offset_buffer(_state, _field) \
189 vmstate_offset_array(_state, _field, uint8_t, \
190 sizeof(typeof_field(_state, _field)))
192 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
193 .name = (stringify(_field)), \
194 .version_id = (_version), \
195 .field_exists = (_test), \
196 .size = sizeof(_type), \
198 .flags = VMS_SINGLE, \
199 .offset = vmstate_offset_value(_state, _field, _type), \
202 /* Validate state using a boolean predicate. */
203 #define VMSTATE_VALIDATE(_name, _test) { \
205 .field_exists = (_test), \
206 .flags = VMS_ARRAY | VMS_MUST_EXIST, \
207 .num = 0, /* 0 elements: no data, only run _test */ \
210 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
211 .name = (stringify(_field)), \
212 .version_id = (_version), \
214 .size = sizeof(_type), \
215 .flags = VMS_SINGLE|VMS_POINTER, \
216 .offset = vmstate_offset_value(_state, _field, _type), \
219 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \
220 .name = (stringify(_field)), \
222 .field_exists = (_test), \
223 .size = sizeof(_type), \
224 .flags = VMS_SINGLE|VMS_POINTER, \
225 .offset = vmstate_offset_value(_state, _field, _type), \
228 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
229 .name = (stringify(_field)), \
230 .version_id = (_version), \
233 .size = sizeof(_type), \
234 .flags = VMS_ARRAY, \
235 .offset = vmstate_offset_array(_state, _field, _type, _num), \
238 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
239 .name = (stringify(_field)), \
240 .version_id = (_version), \
241 .num = (_n1) * (_n2), \
243 .size = sizeof(_type), \
244 .flags = VMS_ARRAY, \
245 .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \
248 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
249 .name = (stringify(_field)), \
250 .field_exists = (_test), \
253 .size = sizeof(_type), \
254 .flags = VMS_ARRAY, \
255 .offset = vmstate_offset_array(_state, _field, _type, _num),\
258 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
259 .name = (stringify(_field)), \
260 .version_id = (_version), \
263 .size = sizeof(_type), \
264 .flags = VMS_ARRAY, \
265 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
268 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
269 .name = (stringify(_field)), \
270 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
272 .size = sizeof(_type), \
273 .flags = VMS_VARRAY_INT32, \
274 .offset = offsetof(_state, _field), \
277 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
278 .name = (stringify(_field)), \
279 .version_id = (_version), \
280 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
282 .size = sizeof(_type), \
283 .flags = VMS_VARRAY_INT32|VMS_POINTER, \
284 .offset = vmstate_offset_pointer(_state, _field, _type), \
287 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
288 .name = (stringify(_field)), \
289 .version_id = (_version), \
290 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
292 .size = sizeof(_type), \
293 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \
294 .offset = vmstate_offset_pointer(_state, _field, _type), \
297 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
298 .name = (stringify(_field)), \
299 .version_id = (_version), \
300 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
302 .size = sizeof(_type), \
303 .flags = VMS_VARRAY_UINT16, \
304 .offset = offsetof(_state, _field), \
307 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
308 .name = (stringify(_field)), \
309 .version_id = (_version), \
310 .field_exists = (_test), \
312 .size = sizeof(_type), \
313 .flags = VMS_STRUCT, \
314 .offset = vmstate_offset_value(_state, _field, _type), \
317 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
318 .name = (stringify(_field)), \
319 .version_id = (_version), \
321 .size = sizeof(_type *), \
322 .flags = VMS_STRUCT|VMS_POINTER, \
323 .offset = vmstate_offset_pointer(_state, _field, _type), \
326 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
327 .name = (stringify(_field)), \
328 .version_id = (_version), \
329 .field_exists = (_test), \
331 .size = sizeof(_type *), \
332 .flags = VMS_STRUCT|VMS_POINTER, \
333 .offset = vmstate_offset_pointer(_state, _field, _type), \
336 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
337 .name = (stringify(_field)), \
338 .version_id = (_version), \
341 .size = sizeof(_type), \
342 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
343 .offset = vmstate_offset_array(_state, _field, _type, _num), \
346 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \
347 .name = (stringify(_f)), \
348 .version_id = (_v), \
351 .size = sizeof(_type *), \
352 .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \
353 .offset = vmstate_offset_array(_s, _f, _type*, _n), \
356 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \
357 .name = (stringify(_field)), \
358 .version_id = (_version), \
361 .size = sizeof(_type), \
362 .flags = VMS_STRUCT|VMS_ARRAY, \
363 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
366 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
367 .name = (stringify(_field)), \
369 .field_exists = (_test), \
370 .version_id = (_version), \
372 .size = sizeof(_type), \
373 .flags = VMS_STRUCT|VMS_ARRAY, \
374 .offset = vmstate_offset_array(_state, _field, _type, _num),\
377 /* a variable length array (i.e. _type *_field) but we know the
380 #define VMSTATE_STRUCT_VARRAY_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
381 .name = (stringify(_field)), \
383 .version_id = (_version), \
385 .size = sizeof(_type), \
386 .flags = VMS_STRUCT|VMS_ARRAY, \
387 .offset = offsetof(_state, _field), \
390 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
391 .name = (stringify(_field)), \
392 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
393 .version_id = (_version), \
395 .size = sizeof(_type), \
396 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \
397 .offset = offsetof(_state, _field), \
400 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
401 .name = (stringify(_field)), \
403 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
404 .size = sizeof(_type), \
406 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
407 .offset = vmstate_offset_pointer(_state, _field, _type), \
410 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
411 .name = (stringify(_field)), \
413 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
414 .size = sizeof(_type), \
416 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
417 .offset = vmstate_offset_pointer(_state, _field, _type), \
420 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
421 .name = (stringify(_field)), \
423 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
424 .size = sizeof(_type), \
426 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \
427 .offset = vmstate_offset_pointer(_state, _field, _type), \
430 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
431 .name = (stringify(_field)), \
432 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
433 .version_id = (_version), \
435 .size = sizeof(_type), \
436 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \
437 .offset = offsetof(_state, _field), \
440 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
441 .name = (stringify(_field)), \
442 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
443 .version_id = (_version), \
445 .size = sizeof(_type), \
446 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \
447 .offset = offsetof(_state, _field), \
450 #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
451 .name = (stringify(_field)), \
452 .version_id = (_version), \
454 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
455 .size = sizeof(_type), \
456 .flags = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
457 .offset = vmstate_offset_pointer(_state, _field, _type), \
460 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
461 .name = (stringify(_field)), \
462 .version_id = (_version), \
463 .field_exists = (_test), \
464 .size = (_size - _start), \
465 .info = &vmstate_info_buffer, \
466 .flags = VMS_BUFFER, \
467 .offset = vmstate_offset_buffer(_state, _field) + _start, \
470 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
471 .name = (stringify(_field)), \
472 .version_id = (_version), \
473 .field_exists = (_test), \
474 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
475 .size = (_multiply), \
476 .info = &vmstate_info_buffer, \
477 .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \
478 .offset = offsetof(_state, _field), \
482 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
483 .name = (stringify(_field)), \
484 .version_id = (_version), \
485 .field_exists = (_test), \
486 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
487 .info = &vmstate_info_buffer, \
488 .flags = VMS_VBUFFER|VMS_POINTER, \
489 .offset = offsetof(_state, _field), \
493 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
494 .name = (stringify(_field)), \
495 .version_id = (_version), \
496 .field_exists = (_test), \
497 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
498 .info = &vmstate_info_buffer, \
499 .flags = VMS_VBUFFER|VMS_POINTER, \
500 .offset = offsetof(_state, _field), \
504 #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, _test, _start, _field_size) { \
505 .name = (stringify(_field)), \
506 .version_id = (_version), \
507 .field_exists = (_test), \
508 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
509 .info = &vmstate_info_buffer, \
510 .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \
511 .offset = offsetof(_state, _field), \
515 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \
516 .name = (stringify(_field)), \
517 .version_id = (_version), \
518 .field_exists = (_test), \
521 .flags = VMS_BUFFER, \
522 .offset = offsetof(_state, _field), \
525 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
526 .name = (stringify(_field)), \
527 .version_id = (_version), \
529 .info = &vmstate_info_buffer, \
530 .flags = VMS_BUFFER|VMS_POINTER, \
531 .offset = offsetof(_state, _field), \
534 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
536 .field_exists = (_test), \
537 .version_id = (_version), \
539 .info = &vmstate_info_unused_buffer, \
540 .flags = VMS_BUFFER, \
543 /* _field_size should be a int32_t field in the _state struct giving the
544 * size of the bitmap _field in bits.
546 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
547 .name = (stringify(_field)), \
548 .version_id = (_version), \
549 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
550 .info = &vmstate_info_bitmap, \
551 .flags = VMS_VBUFFER|VMS_POINTER, \
552 .offset = offsetof(_state, _field), \
556 _f_n : num of elements field_name
558 _s : struct state name
562 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
563 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
565 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
566 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
568 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \
569 VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
571 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \
572 VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
574 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
575 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \
578 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
579 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
582 #define VMSTATE_BOOL_V(_f, _s, _v) \
583 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
585 #define VMSTATE_INT8_V(_f, _s, _v) \
586 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
587 #define VMSTATE_INT16_V(_f, _s, _v) \
588 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
589 #define VMSTATE_INT32_V(_f, _s, _v) \
590 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
591 #define VMSTATE_INT64_V(_f, _s, _v) \
592 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
594 #define VMSTATE_UINT8_V(_f, _s, _v) \
595 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
596 #define VMSTATE_UINT16_V(_f, _s, _v) \
597 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
598 #define VMSTATE_UINT32_V(_f, _s, _v) \
599 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
600 #define VMSTATE_UINT64_V(_f, _s, _v) \
601 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
603 #define VMSTATE_BOOL(_f, _s) \
604 VMSTATE_BOOL_V(_f, _s, 0)
606 #define VMSTATE_INT8(_f, _s) \
607 VMSTATE_INT8_V(_f, _s, 0)
608 #define VMSTATE_INT16(_f, _s) \
609 VMSTATE_INT16_V(_f, _s, 0)
610 #define VMSTATE_INT32(_f, _s) \
611 VMSTATE_INT32_V(_f, _s, 0)
612 #define VMSTATE_INT64(_f, _s) \
613 VMSTATE_INT64_V(_f, _s, 0)
615 #define VMSTATE_UINT8(_f, _s) \
616 VMSTATE_UINT8_V(_f, _s, 0)
617 #define VMSTATE_UINT16(_f, _s) \
618 VMSTATE_UINT16_V(_f, _s, 0)
619 #define VMSTATE_UINT32(_f, _s) \
620 VMSTATE_UINT32_V(_f, _s, 0)
621 #define VMSTATE_UINT64(_f, _s) \
622 VMSTATE_UINT64_V(_f, _s, 0)
624 #define VMSTATE_UINT8_EQUAL(_f, _s) \
625 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
627 #define VMSTATE_UINT16_EQUAL(_f, _s) \
628 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
630 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \
631 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
633 #define VMSTATE_INT32_EQUAL(_f, _s) \
634 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
636 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v) \
637 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t)
639 #define VMSTATE_UINT32_EQUAL(_f, _s) \
640 VMSTATE_UINT32_EQUAL_V(_f, _s, 0)
642 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v) \
643 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
645 #define VMSTATE_UINT64_EQUAL(_f, _s) \
646 VMSTATE_UINT64_EQUAL_V(_f, _s, 0)
648 #define VMSTATE_INT32_POSITIVE_LE(_f, _s) \
649 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
651 #define VMSTATE_INT8_TEST(_f, _s, _t) \
652 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
654 #define VMSTATE_INT16_TEST(_f, _s, _t) \
655 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
657 #define VMSTATE_INT32_TEST(_f, _s, _t) \
658 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
660 #define VMSTATE_INT64_TEST(_f, _s, _t) \
661 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
663 #define VMSTATE_UINT8_TEST(_f, _s, _t) \
664 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
666 #define VMSTATE_UINT16_TEST(_f, _s, _t) \
667 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
669 #define VMSTATE_UINT32_TEST(_f, _s, _t) \
670 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
672 #define VMSTATE_UINT64_TEST(_f, _s, _t) \
673 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
676 #define VMSTATE_FLOAT64_V(_f, _s, _v) \
677 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
679 #define VMSTATE_FLOAT64(_f, _s) \
680 VMSTATE_FLOAT64_V(_f, _s, 0)
682 #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \
683 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
685 #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \
686 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
688 #define VMSTATE_TIMER_PTR(_f, _s) \
689 VMSTATE_TIMER_PTR_V(_f, _s, 0)
691 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \
692 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
694 #define VMSTATE_TIMER_TEST(_f, _s, _test) \
695 VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer)
697 #define VMSTATE_TIMER_V(_f, _s, _v) \
698 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer)
700 #define VMSTATE_TIMER(_f, _s) \
701 VMSTATE_TIMER_V(_f, _s, 0)
703 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
704 VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer)
706 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
707 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
709 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
710 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
712 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
713 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
715 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \
716 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
718 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
719 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
721 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \
722 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
724 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \
725 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
727 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
728 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
730 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
731 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
733 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \
734 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
736 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \
737 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
739 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
740 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
742 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \
743 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)
745 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
746 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
748 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \
749 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)
751 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
752 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
754 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
755 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
757 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
758 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
760 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \
761 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
763 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
764 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
766 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \
767 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
769 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
770 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
772 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
773 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
775 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \
776 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
778 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \
779 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
781 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
782 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
784 #define VMSTATE_BUFFER_V(_f, _s, _v) \
785 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
787 #define VMSTATE_BUFFER(_f, _s) \
788 VMSTATE_BUFFER_V(_f, _s, 0)
790 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
791 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
793 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
794 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
796 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
797 VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
799 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
800 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
802 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \
803 VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
805 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \
806 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
808 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
809 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
811 #define VMSTATE_UNUSED_V(_v, _size) \
812 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
814 #define VMSTATE_UNUSED(_size) \
815 VMSTATE_UNUSED_V(0, _size)
817 #define VMSTATE_UNUSED_TEST(_test, _size) \
818 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
820 #define VMSTATE_END_OF_LIST() \
823 #define SELF_ANNOUNCE_ROUNDS 5
825 void loadvm_free_handlers(MigrationIncomingState
*mis
);
827 int vmstate_load_state(QEMUFile
*f
, const VMStateDescription
*vmsd
,
828 void *opaque
, int version_id
);
829 void vmstate_save_state(QEMUFile
*f
, const VMStateDescription
*vmsd
,
830 void *opaque
, QJSON
*vmdesc
);
832 bool vmstate_save_needed(const VMStateDescription
*vmsd
, void *opaque
);
834 int vmstate_register_with_alias_id(DeviceState
*dev
, int instance_id
,
835 const VMStateDescription
*vmsd
,
836 void *base
, int alias_id
,
837 int required_for_version
);
839 static inline int vmstate_register(DeviceState
*dev
, int instance_id
,
840 const VMStateDescription
*vmsd
,
843 return vmstate_register_with_alias_id(dev
, instance_id
, vmsd
,
847 void vmstate_unregister(DeviceState
*dev
, const VMStateDescription
*vmsd
,
851 void vmstate_register_ram(struct MemoryRegion
*memory
, DeviceState
*dev
);
852 void vmstate_unregister_ram(struct MemoryRegion
*memory
, DeviceState
*dev
);
853 void vmstate_register_ram_global(struct MemoryRegion
*memory
);
856 int64_t self_announce_delay(int round
)
858 assert(round
< SELF_ANNOUNCE_ROUNDS
&& round
> 0);
859 /* delay 50ms, 150ms, 250ms, ... */
860 return 50 + (SELF_ANNOUNCE_ROUNDS
- round
- 1) * 100;
863 void dump_vmstate_json_to_file(FILE *out_fp
);