xref: /qemu/include/migration/vmstate.h (revision 20daa90a)
1 /*
2  * QEMU migration/snapshot declarations
3  *
4  * Copyright (c) 2009-2011 Red Hat, Inc.
5  *
6  * Original author: Juan Quintela <quintela@redhat.com>
7  *
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:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
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.
25  */
26 
27 #ifndef QEMU_VMSTATE_H
28 #define QEMU_VMSTATE_H
29 
30 #ifndef CONFIG_USER_ONLY
31 #include "migration/qemu-file.h"
32 #endif
33 #include "migration/qjson.h"
34 
35 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
36 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
37 
38 typedef struct SaveVMHandlers {
39     /* This runs inside the iothread lock.  */
40     void (*set_params)(const MigrationParams *params, void * opaque);
41     SaveStateHandler *save_state;
42 
43     void (*cleanup)(void *opaque);
44     int (*save_live_complete_postcopy)(QEMUFile *f, void *opaque);
45     int (*save_live_complete_precopy)(QEMUFile *f, void *opaque);
46 
47     /* This runs both outside and inside the iothread lock.  */
48     bool (*is_active)(void *opaque);
49 
50     /* This runs outside the iothread lock in the migration case, and
51      * within the lock in the savevm case.  The callback had better only
52      * use data that is local to the migration thread or protected
53      * by other locks.
54      */
55     int (*save_live_iterate)(QEMUFile *f, void *opaque);
56 
57     /* This runs outside the iothread lock!  */
58     int (*save_live_setup)(QEMUFile *f, void *opaque);
59     void (*save_live_pending)(QEMUFile *f, void *opaque, uint64_t max_size,
60                               uint64_t *non_postcopiable_pending,
61                               uint64_t *postcopiable_pending);
62     LoadStateHandler *load_state;
63 } SaveVMHandlers;
64 
65 int register_savevm(DeviceState *dev,
66                     const char *idstr,
67                     int instance_id,
68                     int version_id,
69                     SaveStateHandler *save_state,
70                     LoadStateHandler *load_state,
71                     void *opaque);
72 
73 int register_savevm_live(DeviceState *dev,
74                          const char *idstr,
75                          int instance_id,
76                          int version_id,
77                          SaveVMHandlers *ops,
78                          void *opaque);
79 
80 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
81 
82 typedef struct VMStateInfo VMStateInfo;
83 typedef struct VMStateDescription VMStateDescription;
84 typedef struct VMStateField VMStateField;
85 
86 /* VMStateInfo allows customized migration of objects that don't fit in
87  * any category in VMStateFlags. Additional information is always passed
88  * into get and put in terms of field and vmdesc parameters. However
89  * these two parameters should only be used in cases when customized
90  * handling is needed, such as QTAILQ. For primitive data types such as
91  * integer, field and vmdesc parameters should be ignored inside get/put.
92  */
93 struct VMStateInfo {
94     const char *name;
95     int (*get)(QEMUFile *f, void *pv, size_t size, VMStateField *field);
96     int (*put)(QEMUFile *f, void *pv, size_t size, VMStateField *field,
97                QJSON *vmdesc);
98 };
99 
100 enum VMStateFlags {
101     /* Ignored */
102     VMS_SINGLE           = 0x001,
103 
104     /* The struct member at opaque + VMStateField.offset is a pointer
105      * to the actual field (e.g. struct a { uint8_t *b;
106      * }). Dereference the pointer before using it as basis for
107      * further pointer arithmetic (see e.g. VMS_ARRAY). Does not
108      * affect the meaning of VMStateField.num_offset or
109      * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for
110      * those. */
111     VMS_POINTER          = 0x002,
112 
113     /* The field is an array of fixed size. VMStateField.num contains
114      * the number of entries in the array. The size of each entry is
115      * given by VMStateField.size and / or opaque +
116      * VMStateField.size_offset; see VMS_VBUFFER and
117      * VMS_MULTIPLY. Each array entry will be processed individually
118      * (VMStateField.info.get()/put() if VMS_STRUCT is not set,
119      * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not
120      * be combined with VMS_VARRAY*. */
121     VMS_ARRAY            = 0x004,
122 
123     /* The field is itself a struct, containing one or more
124      * fields. Recurse into VMStateField.vmsd. Most useful in
125      * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each
126      * array entry. */
127     VMS_STRUCT           = 0x008,
128 
129     /* The field is an array of variable size. The int32_t at opaque +
130      * VMStateField.num_offset contains the number of entries in the
131      * array. See the VMS_ARRAY description regarding array handling
132      * in general. May not be combined with VMS_ARRAY or any other
133      * VMS_VARRAY*. */
134     VMS_VARRAY_INT32     = 0x010,
135 
136     /* Ignored */
137     VMS_BUFFER           = 0x020,
138 
139     /* The field is a (fixed-size or variable-size) array of pointers
140      * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry
141      * before using it. Note: Does not imply any one of VMS_ARRAY /
142      * VMS_VARRAY*; these need to be set explicitly. */
143     VMS_ARRAY_OF_POINTER = 0x040,
144 
145     /* The field is an array of variable size. The uint16_t at opaque
146      * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
147      * contains the number of entries in the array. See the VMS_ARRAY
148      * description regarding array handling in general. May not be
149      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
150     VMS_VARRAY_UINT16    = 0x080,
151 
152     /* The size of the individual entries (a single array entry if
153      * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if
154      * neither is set) is variable (i.e. not known at compile-time),
155      * but the same for all entries. Use the int32_t at opaque +
156      * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine
157      * the size of each (and every) entry. */
158     VMS_VBUFFER          = 0x100,
159 
160     /* Multiply the entry size given by the int32_t at opaque +
161      * VMStateField.size_offset (see VMS_VBUFFER description) with
162      * VMStateField.size to determine the number of bytes to be
163      * allocated. Only valid in combination with VMS_VBUFFER. */
164     VMS_MULTIPLY         = 0x200,
165 
166     /* The field is an array of variable size. The uint8_t at opaque +
167      * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
168      * contains the number of entries in the array. See the VMS_ARRAY
169      * description regarding array handling in general. May not be
170      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
171     VMS_VARRAY_UINT8     = 0x400,
172 
173     /* The field is an array of variable size. The uint32_t at opaque
174      * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
175      * contains the number of entries in the array. See the VMS_ARRAY
176      * description regarding array handling in general. May not be
177      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
178     VMS_VARRAY_UINT32    = 0x800,
179 
180     /* Fail loading the serialised VM state if this field is missing
181      * from the input. */
182     VMS_MUST_EXIST       = 0x1000,
183 
184     /* When loading serialised VM state, allocate memory for the
185      * (entire) field. Only valid in combination with
186      * VMS_POINTER. Note: Not all combinations with other flags are
187      * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't
188      * cause the individual entries to be allocated. */
189     VMS_ALLOC            = 0x2000,
190 
191     /* Multiply the number of entries given by the integer at opaque +
192      * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num
193      * to determine the number of entries in the array. Only valid in
194      * combination with one of VMS_VARRAY*. */
195     VMS_MULTIPLY_ELEMENTS = 0x4000,
196 };
197 
198 typedef enum {
199     MIG_PRI_DEFAULT = 0,
200     MIG_PRI_IOMMU,              /* Must happen before PCI devices */
201     MIG_PRI_MAX,
202 } MigrationPriority;
203 
204 struct VMStateField {
205     const char *name;
206     size_t offset;
207     size_t size;
208     size_t start;
209     int num;
210     size_t num_offset;
211     size_t size_offset;
212     const VMStateInfo *info;
213     enum VMStateFlags flags;
214     const VMStateDescription *vmsd;
215     int version_id;
216     bool (*field_exists)(void *opaque, int version_id);
217 };
218 
219 struct VMStateDescription {
220     const char *name;
221     int unmigratable;
222     int version_id;
223     int minimum_version_id;
224     int minimum_version_id_old;
225     MigrationPriority priority;
226     LoadStateHandler *load_state_old;
227     int (*pre_load)(void *opaque);
228     int (*post_load)(void *opaque, int version_id);
229     void (*pre_save)(void *opaque);
230     bool (*needed)(void *opaque);
231     VMStateField *fields;
232     const VMStateDescription **subsections;
233 };
234 
235 extern const VMStateDescription vmstate_dummy;
236 
237 extern const VMStateInfo vmstate_info_bool;
238 
239 extern const VMStateInfo vmstate_info_int8;
240 extern const VMStateInfo vmstate_info_int16;
241 extern const VMStateInfo vmstate_info_int32;
242 extern const VMStateInfo vmstate_info_int64;
243 
244 extern const VMStateInfo vmstate_info_uint8_equal;
245 extern const VMStateInfo vmstate_info_uint16_equal;
246 extern const VMStateInfo vmstate_info_int32_equal;
247 extern const VMStateInfo vmstate_info_uint32_equal;
248 extern const VMStateInfo vmstate_info_uint64_equal;
249 extern const VMStateInfo vmstate_info_int32_le;
250 
251 extern const VMStateInfo vmstate_info_uint8;
252 extern const VMStateInfo vmstate_info_uint16;
253 extern const VMStateInfo vmstate_info_uint32;
254 extern const VMStateInfo vmstate_info_uint64;
255 
256 extern const VMStateInfo vmstate_info_float64;
257 extern const VMStateInfo vmstate_info_cpudouble;
258 
259 extern const VMStateInfo vmstate_info_timer;
260 extern const VMStateInfo vmstate_info_buffer;
261 extern const VMStateInfo vmstate_info_unused_buffer;
262 extern const VMStateInfo vmstate_info_bitmap;
263 extern const VMStateInfo vmstate_info_qtailq;
264 
265 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
266 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
267 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
268 
269 #define vmstate_offset_value(_state, _field, _type)                  \
270     (offsetof(_state, _field) +                                      \
271      type_check(_type, typeof_field(_state, _field)))
272 
273 #define vmstate_offset_pointer(_state, _field, _type)                \
274     (offsetof(_state, _field) +                                      \
275      type_check_pointer(_type, typeof_field(_state, _field)))
276 
277 #define vmstate_offset_array(_state, _field, _type, _num)            \
278     (offsetof(_state, _field) +                                      \
279      type_check_array(_type, typeof_field(_state, _field), _num))
280 
281 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2)      \
282     (offsetof(_state, _field) +                                      \
283      type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
284 
285 #define vmstate_offset_sub_array(_state, _field, _type, _start)      \
286     vmstate_offset_value(_state, _field[_start], _type)
287 
288 #define vmstate_offset_buffer(_state, _field)                        \
289     vmstate_offset_array(_state, _field, uint8_t,                    \
290                          sizeof(typeof_field(_state, _field)))
291 
292 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
293     .name         = (stringify(_field)),                             \
294     .version_id   = (_version),                                      \
295     .field_exists = (_test),                                         \
296     .size         = sizeof(_type),                                   \
297     .info         = &(_info),                                        \
298     .flags        = VMS_SINGLE,                                      \
299     .offset       = vmstate_offset_value(_state, _field, _type),     \
300 }
301 
302 /* Validate state using a boolean predicate. */
303 #define VMSTATE_VALIDATE(_name, _test) { \
304     .name         = (_name),                                         \
305     .field_exists = (_test),                                         \
306     .flags        = VMS_ARRAY | VMS_MUST_EXIST,                      \
307     .num          = 0, /* 0 elements: no data, only run _test */     \
308 }
309 
310 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
311     .name       = (stringify(_field)),                               \
312     .version_id = (_version),                                        \
313     .info       = &(_info),                                          \
314     .size       = sizeof(_type),                                     \
315     .flags      = VMS_SINGLE|VMS_POINTER,                            \
316     .offset     = vmstate_offset_value(_state, _field, _type),       \
317 }
318 
319 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) {  \
320     .name       = (stringify(_field)),                               \
321     .info       = &(_info),                                          \
322     .field_exists = (_test),                                         \
323     .size       = sizeof(_type),                                     \
324     .flags      = VMS_SINGLE|VMS_POINTER,                            \
325     .offset     = vmstate_offset_value(_state, _field, _type),       \
326 }
327 
328 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
329     .name       = (stringify(_field)),                               \
330     .version_id = (_version),                                        \
331     .num        = (_num),                                            \
332     .info       = &(_info),                                          \
333     .size       = sizeof(_type),                                     \
334     .flags      = VMS_ARRAY,                                         \
335     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
336 }
337 
338 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
339     .name       = (stringify(_field)),                                      \
340     .version_id = (_version),                                               \
341     .num        = (_n1) * (_n2),                                            \
342     .info       = &(_info),                                                 \
343     .size       = sizeof(_type),                                            \
344     .flags      = VMS_ARRAY,                                                \
345     .offset     = vmstate_offset_2darray(_state, _field, _type, _n1, _n2),  \
346 }
347 
348 #define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \
349     .name       = (stringify(_field)),                               \
350     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
351     .num        = (_multiply),                                       \
352     .info       = &(_info),                                          \
353     .size       = sizeof(_type),                                     \
354     .flags      = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS,           \
355     .offset     = offsetof(_state, _field),                          \
356 }
357 
358 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
359     .name         = (stringify(_field)),                              \
360     .field_exists = (_test),                                          \
361     .num          = (_num),                                           \
362     .info         = &(_info),                                         \
363     .size         = sizeof(_type),                                    \
364     .flags        = VMS_ARRAY,                                        \
365     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
366 }
367 
368 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
369     .name       = (stringify(_field)),                               \
370     .version_id = (_version),                                        \
371     .num        = (_num),                                            \
372     .info       = &(_info),                                          \
373     .size       = sizeof(_type),                                     \
374     .flags      = VMS_ARRAY,                                         \
375     .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
376 }
377 
378 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
379     .name       = (stringify(_field)),                               \
380     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
381     .info       = &(_info),                                          \
382     .size       = sizeof(_type),                                     \
383     .flags      = VMS_VARRAY_INT32,                                  \
384     .offset     = offsetof(_state, _field),                          \
385 }
386 
387 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
388     .name       = (stringify(_field)),                               \
389     .version_id = (_version),                                        \
390     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
391     .info       = &(_info),                                          \
392     .size       = sizeof(_type),                                     \
393     .flags      = VMS_VARRAY_INT32|VMS_POINTER,                      \
394     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
395 }
396 
397 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
398     .name       = (stringify(_field)),                               \
399     .version_id = (_version),                                        \
400     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
401     .info       = &(_info),                                          \
402     .size       = sizeof(_type),                                     \
403     .flags      = VMS_VARRAY_UINT32|VMS_POINTER,                     \
404     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
405 }
406 
407 #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
408     .name       = (stringify(_field)),                               \
409     .version_id = (_version),                                        \
410     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
411     .info       = &(_info),                                          \
412     .size       = sizeof(_type),                                     \
413     .flags      = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC,           \
414     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
415 }
416 
417 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
418     .name       = (stringify(_field)),                               \
419     .version_id = (_version),                                        \
420     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
421     .info       = &(_info),                                          \
422     .size       = sizeof(_type),                                     \
423     .flags      = VMS_VARRAY_UINT16,                                 \
424     .offset     = offsetof(_state, _field),                          \
425 }
426 
427 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
428     .name         = (stringify(_field)),                             \
429     .version_id   = (_version),                                      \
430     .field_exists = (_test),                                         \
431     .vmsd         = &(_vmsd),                                        \
432     .size         = sizeof(_type),                                   \
433     .flags        = VMS_STRUCT,                                      \
434     .offset       = vmstate_offset_value(_state, _field, _type),     \
435 }
436 
437 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
438     .name         = (stringify(_field)),                             \
439     .version_id   = (_version),                                        \
440     .vmsd         = &(_vmsd),                                        \
441     .size         = sizeof(_type *),                                 \
442     .flags        = VMS_STRUCT|VMS_POINTER,                          \
443     .offset       = vmstate_offset_pointer(_state, _field, _type),   \
444 }
445 
446 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
447     .name         = (stringify(_field)),                             \
448     .version_id   = (_version),                                        \
449     .field_exists = (_test),                                         \
450     .vmsd         = &(_vmsd),                                        \
451     .size         = sizeof(_type *),                                 \
452     .flags        = VMS_STRUCT|VMS_POINTER,                          \
453     .offset       = vmstate_offset_pointer(_state, _field, _type),   \
454 }
455 
456 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
457     .name       = (stringify(_field)),                               \
458     .version_id = (_version),                                        \
459     .num        = (_num),                                            \
460     .info       = &(_info),                                          \
461     .size       = sizeof(_type),                                     \
462     .flags      = VMS_ARRAY|VMS_ARRAY_OF_POINTER,                    \
463     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
464 }
465 
466 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \
467     .name       = (stringify(_f)),                                   \
468     .version_id = (_v),                                              \
469     .num        = (_n),                                              \
470     .vmsd       = &(_vmsd),                                          \
471     .size       = sizeof(_type *),                                    \
472     .flags      = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER,         \
473     .offset     = vmstate_offset_array(_s, _f, _type*, _n),          \
474 }
475 
476 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \
477     .name       = (stringify(_field)),                                     \
478     .version_id = (_version),                                              \
479     .num        = (_num),                                                  \
480     .vmsd       = &(_vmsd),                                                \
481     .size       = sizeof(_type),                                           \
482     .flags      = VMS_STRUCT|VMS_ARRAY,                                    \
483     .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
484 }
485 
486 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
487     .name         = (stringify(_field)),                             \
488     .num          = (_num),                                          \
489     .field_exists = (_test),                                         \
490     .version_id   = (_version),                                      \
491     .vmsd         = &(_vmsd),                                        \
492     .size         = sizeof(_type),                                   \
493     .flags        = VMS_STRUCT|VMS_ARRAY,                            \
494     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
495 }
496 
497 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
498     .name       = (stringify(_field)),                               \
499     .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
500     .version_id = (_version),                                        \
501     .vmsd       = &(_vmsd),                                          \
502     .size       = sizeof(_type),                                     \
503     .flags      = VMS_STRUCT|VMS_VARRAY_UINT8,                       \
504     .offset     = offsetof(_state, _field),                          \
505 }
506 
507 /* a variable length array (i.e. _type *_field) but we know the
508  * length
509  */
510 #define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
511     .name       = (stringify(_field)),                               \
512     .num          = (_num),                                          \
513     .version_id = (_version),                                        \
514     .vmsd       = &(_vmsd),                                          \
515     .size       = sizeof(_type),                                     \
516     .flags      = VMS_STRUCT|VMS_ARRAY|VMS_POINTER,                  \
517     .offset     = offsetof(_state, _field),                          \
518 }
519 
520 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
521     .name       = (stringify(_field)),                               \
522     .version_id = 0,                                                 \
523     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
524     .size       = sizeof(_type),                                     \
525     .vmsd       = &(_vmsd),                                          \
526     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
527     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
528 }
529 
530 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
531     .name       = (stringify(_field)),                               \
532     .version_id = 0,                                                 \
533     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
534     .size       = sizeof(_type),                                     \
535     .vmsd       = &(_vmsd),                                          \
536     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
537     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
538 }
539 
540 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
541     .name       = (stringify(_field)),                               \
542     .version_id = 0,                                                 \
543     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
544     .size       = sizeof(_type),                                     \
545     .vmsd       = &(_vmsd),                                          \
546     .flags      = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT,      \
547     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
548 }
549 
550 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
551     .name       = (stringify(_field)),                               \
552     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
553     .version_id = (_version),                                        \
554     .vmsd       = &(_vmsd),                                          \
555     .size       = sizeof(_type),                                     \
556     .flags      = VMS_STRUCT|VMS_VARRAY_INT32,                       \
557     .offset     = offsetof(_state, _field),                          \
558 }
559 
560 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
561     .name       = (stringify(_field)),                               \
562     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
563     .version_id = (_version),                                        \
564     .vmsd       = &(_vmsd),                                          \
565     .size       = sizeof(_type),                                     \
566     .flags      = VMS_STRUCT|VMS_VARRAY_UINT32,                      \
567     .offset     = offsetof(_state, _field),                          \
568 }
569 
570 #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
571     .name       = (stringify(_field)),                               \
572     .version_id = (_version),                                        \
573     .vmsd       = &(_vmsd),                                          \
574     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
575     .size       = sizeof(_type),                                     \
576     .flags      = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
577     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
578 }
579 
580 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
581     .name         = (stringify(_field)),                             \
582     .version_id   = (_version),                                      \
583     .field_exists = (_test),                                         \
584     .size         = (_size - _start),                                \
585     .info         = &vmstate_info_buffer,                            \
586     .flags        = VMS_BUFFER,                                      \
587     .offset       = vmstate_offset_buffer(_state, _field) + _start,  \
588 }
589 
590 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
591     .name         = (stringify(_field)),                             \
592     .version_id   = (_version),                                      \
593     .field_exists = (_test),                                         \
594     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
595     .size         = (_multiply),                                      \
596     .info         = &vmstate_info_buffer,                            \
597     .flags        = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY,            \
598     .offset       = offsetof(_state, _field),                        \
599     .start        = (_start),                                        \
600 }
601 
602 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
603     .name         = (stringify(_field)),                             \
604     .version_id   = (_version),                                      \
605     .field_exists = (_test),                                         \
606     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
607     .info         = &vmstate_info_buffer,                            \
608     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
609     .offset       = offsetof(_state, _field),                        \
610     .start        = (_start),                                        \
611 }
612 
613 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
614     .name         = (stringify(_field)),                             \
615     .version_id   = (_version),                                      \
616     .field_exists = (_test),                                         \
617     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
618     .info         = &vmstate_info_buffer,                            \
619     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
620     .offset       = offsetof(_state, _field),                        \
621     .start        = (_start),                                        \
622 }
623 
624 #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, _test, _start, _field_size) { \
625     .name         = (stringify(_field)),                             \
626     .version_id   = (_version),                                      \
627     .field_exists = (_test),                                         \
628     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
629     .info         = &vmstate_info_buffer,                            \
630     .flags        = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC,               \
631     .offset       = offsetof(_state, _field),                        \
632     .start        = (_start),                                        \
633 }
634 
635 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \
636     .name       = (stringify(_field)),                               \
637     .version_id = (_version),                                        \
638     .field_exists = (_test),                                         \
639     .size       = (_size),                                           \
640     .info       = &(_info),                                          \
641     .flags      = VMS_BUFFER,                                        \
642     .offset     = offsetof(_state, _field),                          \
643 }
644 
645 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
646     .name       = (stringify(_field)),                               \
647     .version_id = (_version),                                        \
648     .size       = (_size),                                           \
649     .info       = &vmstate_info_buffer,                              \
650     .flags      = VMS_BUFFER|VMS_POINTER,                            \
651     .offset     = offsetof(_state, _field),                          \
652 }
653 
654 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
655     .name         = "unused",                                        \
656     .field_exists = (_test),                                         \
657     .version_id   = (_version),                                      \
658     .size         = (_size),                                         \
659     .info         = &vmstate_info_unused_buffer,                     \
660     .flags        = VMS_BUFFER,                                      \
661 }
662 
663 /* _field_size should be a int32_t field in the _state struct giving the
664  * size of the bitmap _field in bits.
665  */
666 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) {      \
667     .name         = (stringify(_field)),                             \
668     .version_id   = (_version),                                      \
669     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
670     .info         = &vmstate_info_bitmap,                            \
671     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
672     .offset       = offsetof(_state, _field),                        \
673 }
674 
675 /* For migrating a QTAILQ.
676  * Target QTAILQ needs be properly initialized.
677  * _type: type of QTAILQ element
678  * _next: name of QTAILQ entry field in QTAILQ element
679  * _vmsd: VMSD for QTAILQ element
680  * size: size of QTAILQ element
681  * start: offset of QTAILQ entry in QTAILQ element
682  */
683 #define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next)  \
684 {                                                                        \
685     .name         = (stringify(_field)),                                 \
686     .version_id   = (_version),                                          \
687     .vmsd         = &(_vmsd),                                            \
688     .size         = sizeof(_type),                                       \
689     .info         = &vmstate_info_qtailq,                                \
690     .offset       = offsetof(_state, _field),                            \
691     .start        = offsetof(_type, _next),                              \
692 }
693 
694 /* _f : field name
695    _f_n : num of elements field_name
696    _n : num of elements
697    _s : struct state name
698    _v : version
699 */
700 
701 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type)        \
702     VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
703 
704 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)        \
705     VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
706 
707 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)          \
708     VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
709 
710 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type)     \
711     VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
712 
713 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
714     VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
715             _vmsd, _type)
716 
717 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
718     VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
719             _size)
720 
721 #define VMSTATE_BOOL_V(_f, _s, _v)                                    \
722     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
723 
724 #define VMSTATE_INT8_V(_f, _s, _v)                                    \
725     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
726 #define VMSTATE_INT16_V(_f, _s, _v)                                   \
727     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
728 #define VMSTATE_INT32_V(_f, _s, _v)                                   \
729     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
730 #define VMSTATE_INT64_V(_f, _s, _v)                                   \
731     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
732 
733 #define VMSTATE_UINT8_V(_f, _s, _v)                                   \
734     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
735 #define VMSTATE_UINT16_V(_f, _s, _v)                                  \
736     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
737 #define VMSTATE_UINT32_V(_f, _s, _v)                                  \
738     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
739 #define VMSTATE_UINT64_V(_f, _s, _v)                                  \
740     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
741 
742 #define VMSTATE_BOOL(_f, _s)                                          \
743     VMSTATE_BOOL_V(_f, _s, 0)
744 
745 #define VMSTATE_INT8(_f, _s)                                          \
746     VMSTATE_INT8_V(_f, _s, 0)
747 #define VMSTATE_INT16(_f, _s)                                         \
748     VMSTATE_INT16_V(_f, _s, 0)
749 #define VMSTATE_INT32(_f, _s)                                         \
750     VMSTATE_INT32_V(_f, _s, 0)
751 #define VMSTATE_INT64(_f, _s)                                         \
752     VMSTATE_INT64_V(_f, _s, 0)
753 
754 #define VMSTATE_UINT8(_f, _s)                                         \
755     VMSTATE_UINT8_V(_f, _s, 0)
756 #define VMSTATE_UINT16(_f, _s)                                        \
757     VMSTATE_UINT16_V(_f, _s, 0)
758 #define VMSTATE_UINT32(_f, _s)                                        \
759     VMSTATE_UINT32_V(_f, _s, 0)
760 #define VMSTATE_UINT64(_f, _s)                                        \
761     VMSTATE_UINT64_V(_f, _s, 0)
762 
763 #define VMSTATE_UINT8_EQUAL(_f, _s)                                   \
764     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
765 
766 #define VMSTATE_UINT16_EQUAL(_f, _s)                                  \
767     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
768 
769 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v)                            \
770     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
771 
772 #define VMSTATE_INT32_EQUAL(_f, _s)                                   \
773     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
774 
775 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v)                            \
776     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t)
777 
778 #define VMSTATE_UINT32_EQUAL(_f, _s)                                  \
779     VMSTATE_UINT32_EQUAL_V(_f, _s, 0)
780 
781 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v)                            \
782     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
783 
784 #define VMSTATE_UINT64_EQUAL(_f, _s)                                  \
785     VMSTATE_UINT64_EQUAL_V(_f, _s, 0)
786 
787 #define VMSTATE_INT32_POSITIVE_LE(_f, _s)                             \
788     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
789 
790 #define VMSTATE_INT8_TEST(_f, _s, _t)                               \
791     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
792 
793 #define VMSTATE_INT16_TEST(_f, _s, _t)                               \
794     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
795 
796 #define VMSTATE_INT32_TEST(_f, _s, _t)                                  \
797     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
798 
799 #define VMSTATE_INT64_TEST(_f, _s, _t)                                  \
800     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
801 
802 #define VMSTATE_UINT8_TEST(_f, _s, _t)                               \
803     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
804 
805 #define VMSTATE_UINT16_TEST(_f, _s, _t)                               \
806     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
807 
808 #define VMSTATE_UINT32_TEST(_f, _s, _t)                                  \
809     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
810 
811 #define VMSTATE_UINT64_TEST(_f, _s, _t)                                  \
812     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
813 
814 
815 #define VMSTATE_FLOAT64_V(_f, _s, _v)                                 \
816     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
817 
818 #define VMSTATE_FLOAT64(_f, _s)                                       \
819     VMSTATE_FLOAT64_V(_f, _s, 0)
820 
821 #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test)                             \
822     VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
823 
824 #define VMSTATE_TIMER_PTR_V(_f, _s, _v)                                   \
825     VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
826 
827 #define VMSTATE_TIMER_PTR(_f, _s)                                         \
828     VMSTATE_TIMER_PTR_V(_f, _s, 0)
829 
830 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n)                              \
831     VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
832 
833 #define VMSTATE_TIMER_TEST(_f, _s, _test)                             \
834     VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer)
835 
836 #define VMSTATE_TIMER_V(_f, _s, _v)                                   \
837     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer)
838 
839 #define VMSTATE_TIMER(_f, _s)                                         \
840     VMSTATE_TIMER_V(_f, _s, 0)
841 
842 #define VMSTATE_TIMER_ARRAY(_f, _s, _n)                              \
843     VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer)
844 
845 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v)                         \
846     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
847 
848 #define VMSTATE_BOOL_ARRAY(_f, _s, _n)                               \
849     VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
850 
851 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
852     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
853 
854 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
855     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
856 
857 #define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
858     VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
859 
860 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)                      \
861     VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
862 
863 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
864     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
865 
866 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
867     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
868 
869 #define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
870     VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
871 
872 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num)                \
873     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
874 
875 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)                       \
876     VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
877 
878 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
879     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
880 
881 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
882     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)
883 
884 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
885     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
886 
887 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2)                      \
888     VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)
889 
890 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)                        \
891     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
892 
893 #define VMSTATE_UINT64_ARRAY(_f, _s, _n)                              \
894     VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
895 
896 #define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2)                      \
897     VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0)
898 
899 #define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
900     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t)
901 
902 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v)                         \
903     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
904 
905 #define VMSTATE_INT16_ARRAY(_f, _s, _n)                               \
906     VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
907 
908 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v)                         \
909     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
910 
911 #define VMSTATE_INT32_ARRAY(_f, _s, _n)                               \
912     VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
913 
914 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)                \
915     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
916 
917 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v)                         \
918     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
919 
920 #define VMSTATE_INT64_ARRAY(_f, _s, _n)                               \
921     VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
922 
923 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v)                       \
924     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
925 
926 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n)                             \
927     VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
928 
929 #define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v)                     \
930     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU)
931 
932 #define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n)                           \
933     VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0)
934 
935 #define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
936     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
937 
938 #define VMSTATE_BUFFER(_f, _s)                                        \
939     VMSTATE_BUFFER_V(_f, _s, 0)
940 
941 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size)                         \
942     VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
943 
944 #define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \
945     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f)))
946 
947 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
948     VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0)
949 
950 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)                        \
951     VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
952 
953 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)                        \
954     VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
955 
956 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size)                    \
957     VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
958 
959 #define VMSTATE_BUFFER_TEST(_f, _s, _test)                            \
960     VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
961 
962 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size)        \
963     VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
964 
965 #define VMSTATE_UNUSED_V(_v, _size)                                   \
966     VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
967 
968 #define VMSTATE_UNUSED(_size)                                         \
969     VMSTATE_UNUSED_V(0, _size)
970 
971 #define VMSTATE_UNUSED_TEST(_test, _size)                             \
972     VMSTATE_UNUSED_BUFFER(_test, 0, _size)
973 
974 #define VMSTATE_END_OF_LIST()                                         \
975     {}
976 
977 #define SELF_ANNOUNCE_ROUNDS 5
978 
979 void loadvm_free_handlers(MigrationIncomingState *mis);
980 
981 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
982                        void *opaque, int version_id);
983 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
984                         void *opaque, QJSON *vmdesc);
985 
986 bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
987 
988 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
989                                    const VMStateDescription *vmsd,
990                                    void *base, int alias_id,
991                                    int required_for_version);
992 
993 static inline int vmstate_register(DeviceState *dev, int instance_id,
994                                    const VMStateDescription *vmsd,
995                                    void *opaque)
996 {
997     return vmstate_register_with_alias_id(dev, instance_id, vmsd,
998                                           opaque, -1, 0);
999 }
1000 
1001 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
1002                         void *opaque);
1003 
1004 struct MemoryRegion;
1005 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
1006 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
1007 void vmstate_register_ram_global(struct MemoryRegion *memory);
1008 
1009 static inline
1010 int64_t self_announce_delay(int round)
1011 {
1012     assert(round < SELF_ANNOUNCE_ROUNDS && round > 0);
1013     /* delay 50ms, 150ms, 250ms, ... */
1014     return 50 + (SELF_ANNOUNCE_ROUNDS - round - 1) * 100;
1015 }
1016 
1017 void dump_vmstate_json_to_file(FILE *out_fp);
1018 
1019 #endif
1020