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 /** Put this in the stream when migrating a null pointer.*/ 257 #define VMS_NULLPTR_MARKER (0x30U) /* '0' */ 258 extern const VMStateInfo vmstate_info_nullptr; 259 260 extern const VMStateInfo vmstate_info_float64; 261 extern const VMStateInfo vmstate_info_cpudouble; 262 263 extern const VMStateInfo vmstate_info_timer; 264 extern const VMStateInfo vmstate_info_buffer; 265 extern const VMStateInfo vmstate_info_unused_buffer; 266 extern const VMStateInfo vmstate_info_tmp; 267 extern const VMStateInfo vmstate_info_bitmap; 268 extern const VMStateInfo vmstate_info_qtailq; 269 270 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) 271 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) 272 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) 273 274 #define vmstate_offset_value(_state, _field, _type) \ 275 (offsetof(_state, _field) + \ 276 type_check(_type, typeof_field(_state, _field))) 277 278 #define vmstate_offset_pointer(_state, _field, _type) \ 279 (offsetof(_state, _field) + \ 280 type_check_pointer(_type, typeof_field(_state, _field))) 281 282 #define vmstate_offset_array(_state, _field, _type, _num) \ 283 (offsetof(_state, _field) + \ 284 type_check_array(_type, typeof_field(_state, _field), _num)) 285 286 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \ 287 (offsetof(_state, _field) + \ 288 type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2)) 289 290 #define vmstate_offset_sub_array(_state, _field, _type, _start) \ 291 vmstate_offset_value(_state, _field[_start], _type) 292 293 #define vmstate_offset_buffer(_state, _field) \ 294 vmstate_offset_array(_state, _field, uint8_t, \ 295 sizeof(typeof_field(_state, _field))) 296 297 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \ 298 .name = (stringify(_field)), \ 299 .version_id = (_version), \ 300 .field_exists = (_test), \ 301 .size = sizeof(_type), \ 302 .info = &(_info), \ 303 .flags = VMS_SINGLE, \ 304 .offset = vmstate_offset_value(_state, _field, _type), \ 305 } 306 307 /* Validate state using a boolean predicate. */ 308 #define VMSTATE_VALIDATE(_name, _test) { \ 309 .name = (_name), \ 310 .field_exists = (_test), \ 311 .flags = VMS_ARRAY | VMS_MUST_EXIST, \ 312 .num = 0, /* 0 elements: no data, only run _test */ \ 313 } 314 315 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ 316 .name = (stringify(_field)), \ 317 .version_id = (_version), \ 318 .info = &(_info), \ 319 .size = sizeof(_type), \ 320 .flags = VMS_SINGLE|VMS_POINTER, \ 321 .offset = vmstate_offset_value(_state, _field, _type), \ 322 } 323 324 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \ 325 .name = (stringify(_field)), \ 326 .info = &(_info), \ 327 .field_exists = (_test), \ 328 .size = sizeof(_type), \ 329 .flags = VMS_SINGLE|VMS_POINTER, \ 330 .offset = vmstate_offset_value(_state, _field, _type), \ 331 } 332 333 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\ 334 .name = (stringify(_field)), \ 335 .version_id = (_version), \ 336 .num = (_num), \ 337 .info = &(_info), \ 338 .size = sizeof(_type), \ 339 .flags = VMS_ARRAY, \ 340 .offset = vmstate_offset_array(_state, _field, _type, _num), \ 341 } 342 343 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \ 344 .name = (stringify(_field)), \ 345 .version_id = (_version), \ 346 .num = (_n1) * (_n2), \ 347 .info = &(_info), \ 348 .size = sizeof(_type), \ 349 .flags = VMS_ARRAY, \ 350 .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \ 351 } 352 353 #define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \ 354 .name = (stringify(_field)), \ 355 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 356 .num = (_multiply), \ 357 .info = &(_info), \ 358 .size = sizeof(_type), \ 359 .flags = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS, \ 360 .offset = offsetof(_state, _field), \ 361 } 362 363 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\ 364 .name = (stringify(_field)), \ 365 .field_exists = (_test), \ 366 .num = (_num), \ 367 .info = &(_info), \ 368 .size = sizeof(_type), \ 369 .flags = VMS_ARRAY, \ 370 .offset = vmstate_offset_array(_state, _field, _type, _num),\ 371 } 372 373 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \ 374 .name = (stringify(_field)), \ 375 .version_id = (_version), \ 376 .num = (_num), \ 377 .info = &(_info), \ 378 .size = sizeof(_type), \ 379 .flags = VMS_ARRAY, \ 380 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ 381 } 382 383 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\ 384 .name = (stringify(_field)), \ 385 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 386 .info = &(_info), \ 387 .size = sizeof(_type), \ 388 .flags = VMS_VARRAY_INT32, \ 389 .offset = offsetof(_state, _field), \ 390 } 391 392 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\ 393 .name = (stringify(_field)), \ 394 .version_id = (_version), \ 395 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 396 .info = &(_info), \ 397 .size = sizeof(_type), \ 398 .flags = VMS_VARRAY_INT32|VMS_POINTER, \ 399 .offset = vmstate_offset_pointer(_state, _field, _type), \ 400 } 401 402 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\ 403 .name = (stringify(_field)), \ 404 .version_id = (_version), \ 405 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 406 .info = &(_info), \ 407 .size = sizeof(_type), \ 408 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \ 409 .offset = vmstate_offset_pointer(_state, _field, _type), \ 410 } 411 412 #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\ 413 .name = (stringify(_field)), \ 414 .version_id = (_version), \ 415 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 416 .info = &(_info), \ 417 .size = sizeof(_type), \ 418 .flags = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \ 419 .offset = vmstate_offset_pointer(_state, _field, _type), \ 420 } 421 422 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\ 423 .name = (stringify(_field)), \ 424 .version_id = (_version), \ 425 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ 426 .info = &(_info), \ 427 .size = sizeof(_type), \ 428 .flags = VMS_VARRAY_UINT16, \ 429 .offset = offsetof(_state, _field), \ 430 } 431 432 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \ 433 .name = (stringify(_field)), \ 434 .version_id = (_version), \ 435 .field_exists = (_test), \ 436 .vmsd = &(_vmsd), \ 437 .size = sizeof(_type), \ 438 .flags = VMS_STRUCT, \ 439 .offset = vmstate_offset_value(_state, _field, _type), \ 440 } 441 442 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \ 443 .name = (stringify(_field)), \ 444 .version_id = (_version), \ 445 .vmsd = &(_vmsd), \ 446 .size = sizeof(_type *), \ 447 .flags = VMS_STRUCT|VMS_POINTER, \ 448 .offset = vmstate_offset_pointer(_state, _field, _type), \ 449 } 450 451 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \ 452 .name = (stringify(_field)), \ 453 .version_id = (_version), \ 454 .field_exists = (_test), \ 455 .vmsd = &(_vmsd), \ 456 .size = sizeof(_type *), \ 457 .flags = VMS_STRUCT|VMS_POINTER, \ 458 .offset = vmstate_offset_pointer(_state, _field, _type), \ 459 } 460 461 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\ 462 .name = (stringify(_field)), \ 463 .version_id = (_version), \ 464 .num = (_num), \ 465 .info = &(_info), \ 466 .size = sizeof(_type), \ 467 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ 468 .offset = vmstate_offset_array(_state, _field, _type, _num), \ 469 } 470 471 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \ 472 .name = (stringify(_f)), \ 473 .version_id = (_v), \ 474 .num = (_n), \ 475 .vmsd = &(_vmsd), \ 476 .size = sizeof(_type *), \ 477 .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \ 478 .offset = vmstate_offset_array(_s, _f, _type*, _n), \ 479 } 480 481 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \ 482 .name = (stringify(_field)), \ 483 .version_id = (_version), \ 484 .num = (_num), \ 485 .vmsd = &(_vmsd), \ 486 .size = sizeof(_type), \ 487 .flags = VMS_STRUCT|VMS_ARRAY, \ 488 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ 489 } 490 491 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \ 492 .name = (stringify(_field)), \ 493 .num = (_num), \ 494 .field_exists = (_test), \ 495 .version_id = (_version), \ 496 .vmsd = &(_vmsd), \ 497 .size = sizeof(_type), \ 498 .flags = VMS_STRUCT|VMS_ARRAY, \ 499 .offset = vmstate_offset_array(_state, _field, _type, _num),\ 500 } 501 502 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \ 503 .name = (stringify(_field)), \ 504 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \ 505 .version_id = (_version), \ 506 .vmsd = &(_vmsd), \ 507 .size = sizeof(_type), \ 508 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \ 509 .offset = offsetof(_state, _field), \ 510 } 511 512 /* a variable length array (i.e. _type *_field) but we know the 513 * length 514 */ 515 #define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \ 516 .name = (stringify(_field)), \ 517 .num = (_num), \ 518 .version_id = (_version), \ 519 .vmsd = &(_vmsd), \ 520 .size = sizeof(_type), \ 521 .flags = VMS_STRUCT|VMS_ARRAY|VMS_POINTER, \ 522 .offset = offsetof(_state, _field), \ 523 } 524 525 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \ 526 .name = (stringify(_field)), \ 527 .version_id = 0, \ 528 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 529 .size = sizeof(_type), \ 530 .vmsd = &(_vmsd), \ 531 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ 532 .offset = vmstate_offset_pointer(_state, _field, _type), \ 533 } 534 535 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \ 536 .name = (stringify(_field)), \ 537 .version_id = 0, \ 538 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 539 .size = sizeof(_type), \ 540 .vmsd = &(_vmsd), \ 541 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ 542 .offset = vmstate_offset_pointer(_state, _field, _type), \ 543 } 544 545 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \ 546 .name = (stringify(_field)), \ 547 .version_id = 0, \ 548 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ 549 .size = sizeof(_type), \ 550 .vmsd = &(_vmsd), \ 551 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \ 552 .offset = vmstate_offset_pointer(_state, _field, _type), \ 553 } 554 555 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \ 556 .name = (stringify(_field)), \ 557 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 558 .version_id = (_version), \ 559 .vmsd = &(_vmsd), \ 560 .size = sizeof(_type), \ 561 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \ 562 .offset = offsetof(_state, _field), \ 563 } 564 565 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \ 566 .name = (stringify(_field)), \ 567 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \ 568 .version_id = (_version), \ 569 .vmsd = &(_vmsd), \ 570 .size = sizeof(_type), \ 571 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \ 572 .offset = offsetof(_state, _field), \ 573 } 574 575 #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\ 576 .name = (stringify(_field)), \ 577 .version_id = (_version), \ 578 .vmsd = &(_vmsd), \ 579 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 580 .size = sizeof(_type), \ 581 .flags = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \ 582 .offset = vmstate_offset_pointer(_state, _field, _type), \ 583 } 584 585 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \ 586 .name = (stringify(_field)), \ 587 .version_id = (_version), \ 588 .field_exists = (_test), \ 589 .size = (_size - _start), \ 590 .info = &vmstate_info_buffer, \ 591 .flags = VMS_BUFFER, \ 592 .offset = vmstate_offset_buffer(_state, _field) + _start, \ 593 } 594 595 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, \ 596 _field_size, _multiply) { \ 597 .name = (stringify(_field)), \ 598 .version_id = (_version), \ 599 .field_exists = (_test), \ 600 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 601 .size = (_multiply), \ 602 .info = &vmstate_info_buffer, \ 603 .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ 604 .offset = offsetof(_state, _field), \ 605 } 606 607 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \ 608 .name = (stringify(_field)), \ 609 .version_id = (_version), \ 610 .field_exists = (_test), \ 611 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ 612 .info = &vmstate_info_buffer, \ 613 .flags = VMS_VBUFFER|VMS_POINTER, \ 614 .offset = offsetof(_state, _field), \ 615 } 616 617 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) { \ 618 .name = (stringify(_field)), \ 619 .version_id = (_version), \ 620 .field_exists = (_test), \ 621 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 622 .info = &vmstate_info_buffer, \ 623 .flags = VMS_VBUFFER|VMS_POINTER, \ 624 .offset = offsetof(_state, _field), \ 625 } 626 627 #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \ 628 _test, _field_size) { \ 629 .name = (stringify(_field)), \ 630 .version_id = (_version), \ 631 .field_exists = (_test), \ 632 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 633 .info = &vmstate_info_buffer, \ 634 .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \ 635 .offset = offsetof(_state, _field), \ 636 } 637 638 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \ 639 .name = (stringify(_field)), \ 640 .version_id = (_version), \ 641 .field_exists = (_test), \ 642 .size = (_size), \ 643 .info = &(_info), \ 644 .flags = VMS_BUFFER, \ 645 .offset = offsetof(_state, _field), \ 646 } 647 648 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \ 649 .name = (stringify(_field)), \ 650 .version_id = (_version), \ 651 .size = (_size), \ 652 .info = &vmstate_info_buffer, \ 653 .flags = VMS_BUFFER|VMS_POINTER, \ 654 .offset = offsetof(_state, _field), \ 655 } 656 657 /* Allocate a temporary of type 'tmp_type', set tmp->parent to _state 658 * and execute the vmsd on the temporary. Note that we're working with 659 * the whole of _state here, not a field within it. 660 * We compile time check that: 661 * That _tmp_type contains a 'parent' member that's a pointer to the 662 * '_state' type 663 * That the pointer is right at the start of _tmp_type. 664 */ 665 #define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) { \ 666 .name = "tmp", \ 667 .size = sizeof(_tmp_type) + \ 668 QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \ 669 type_check_pointer(_state, \ 670 typeof_field(_tmp_type, parent)), \ 671 .vmsd = &(_vmsd), \ 672 .info = &vmstate_info_tmp, \ 673 } 674 675 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \ 676 .name = "unused", \ 677 .field_exists = (_test), \ 678 .version_id = (_version), \ 679 .size = (_size), \ 680 .info = &vmstate_info_unused_buffer, \ 681 .flags = VMS_BUFFER, \ 682 } 683 684 /* Discard size * field_num bytes, where field_num is a uint32 member */ 685 #define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, _size) {\ 686 .name = "unused", \ 687 .field_exists = (_test), \ 688 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 689 .version_id = (_version), \ 690 .size = (_size), \ 691 .info = &vmstate_info_unused_buffer, \ 692 .flags = VMS_VARRAY_UINT32 | VMS_BUFFER, \ 693 } 694 695 /* _field_size should be a int32_t field in the _state struct giving the 696 * size of the bitmap _field in bits. 697 */ 698 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \ 699 .name = (stringify(_field)), \ 700 .version_id = (_version), \ 701 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ 702 .info = &vmstate_info_bitmap, \ 703 .flags = VMS_VBUFFER|VMS_POINTER, \ 704 .offset = offsetof(_state, _field), \ 705 } 706 707 /* For migrating a QTAILQ. 708 * Target QTAILQ needs be properly initialized. 709 * _type: type of QTAILQ element 710 * _next: name of QTAILQ entry field in QTAILQ element 711 * _vmsd: VMSD for QTAILQ element 712 * size: size of QTAILQ element 713 * start: offset of QTAILQ entry in QTAILQ element 714 */ 715 #define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next) \ 716 { \ 717 .name = (stringify(_field)), \ 718 .version_id = (_version), \ 719 .vmsd = &(_vmsd), \ 720 .size = sizeof(_type), \ 721 .info = &vmstate_info_qtailq, \ 722 .offset = offsetof(_state, _field), \ 723 .start = offsetof(_type, _next), \ 724 } 725 726 /* _f : field name 727 _f_n : num of elements field_name 728 _n : num of elements 729 _s : struct state name 730 _v : version 731 */ 732 733 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ 734 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) 735 736 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ 737 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) 738 739 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \ 740 VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type) 741 742 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \ 743 VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type) 744 745 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \ 746 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \ 747 _vmsd, _type) 748 749 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \ 750 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \ 751 _size) 752 753 #define VMSTATE_BOOL_V(_f, _s, _v) \ 754 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool) 755 756 #define VMSTATE_INT8_V(_f, _s, _v) \ 757 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) 758 #define VMSTATE_INT16_V(_f, _s, _v) \ 759 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t) 760 #define VMSTATE_INT32_V(_f, _s, _v) \ 761 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t) 762 #define VMSTATE_INT64_V(_f, _s, _v) \ 763 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t) 764 765 #define VMSTATE_UINT8_V(_f, _s, _v) \ 766 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t) 767 #define VMSTATE_UINT16_V(_f, _s, _v) \ 768 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t) 769 #define VMSTATE_UINT32_V(_f, _s, _v) \ 770 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t) 771 #define VMSTATE_UINT64_V(_f, _s, _v) \ 772 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) 773 774 #define VMSTATE_BOOL(_f, _s) \ 775 VMSTATE_BOOL_V(_f, _s, 0) 776 777 #define VMSTATE_INT8(_f, _s) \ 778 VMSTATE_INT8_V(_f, _s, 0) 779 #define VMSTATE_INT16(_f, _s) \ 780 VMSTATE_INT16_V(_f, _s, 0) 781 #define VMSTATE_INT32(_f, _s) \ 782 VMSTATE_INT32_V(_f, _s, 0) 783 #define VMSTATE_INT64(_f, _s) \ 784 VMSTATE_INT64_V(_f, _s, 0) 785 786 #define VMSTATE_UINT8(_f, _s) \ 787 VMSTATE_UINT8_V(_f, _s, 0) 788 #define VMSTATE_UINT16(_f, _s) \ 789 VMSTATE_UINT16_V(_f, _s, 0) 790 #define VMSTATE_UINT32(_f, _s) \ 791 VMSTATE_UINT32_V(_f, _s, 0) 792 #define VMSTATE_UINT64(_f, _s) \ 793 VMSTATE_UINT64_V(_f, _s, 0) 794 795 #define VMSTATE_UINT8_EQUAL(_f, _s) \ 796 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t) 797 798 #define VMSTATE_UINT16_EQUAL(_f, _s) \ 799 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t) 800 801 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \ 802 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t) 803 804 #define VMSTATE_INT32_EQUAL(_f, _s) \ 805 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) 806 807 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v) \ 808 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t) 809 810 #define VMSTATE_UINT32_EQUAL(_f, _s) \ 811 VMSTATE_UINT32_EQUAL_V(_f, _s, 0) 812 813 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v) \ 814 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t) 815 816 #define VMSTATE_UINT64_EQUAL(_f, _s) \ 817 VMSTATE_UINT64_EQUAL_V(_f, _s, 0) 818 819 #define VMSTATE_INT32_POSITIVE_LE(_f, _s) \ 820 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) 821 822 #define VMSTATE_INT8_TEST(_f, _s, _t) \ 823 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t) 824 825 #define VMSTATE_INT16_TEST(_f, _s, _t) \ 826 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t) 827 828 #define VMSTATE_INT32_TEST(_f, _s, _t) \ 829 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t) 830 831 #define VMSTATE_INT64_TEST(_f, _s, _t) \ 832 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t) 833 834 #define VMSTATE_UINT8_TEST(_f, _s, _t) \ 835 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) 836 837 #define VMSTATE_UINT16_TEST(_f, _s, _t) \ 838 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t) 839 840 #define VMSTATE_UINT32_TEST(_f, _s, _t) \ 841 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) 842 843 #define VMSTATE_UINT64_TEST(_f, _s, _t) \ 844 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t) 845 846 847 #define VMSTATE_FLOAT64_V(_f, _s, _v) \ 848 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64) 849 850 #define VMSTATE_FLOAT64(_f, _s) \ 851 VMSTATE_FLOAT64_V(_f, _s, 0) 852 853 #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \ 854 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *) 855 856 #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \ 857 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) 858 859 #define VMSTATE_TIMER_PTR(_f, _s) \ 860 VMSTATE_TIMER_PTR_V(_f, _s, 0) 861 862 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \ 863 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *) 864 865 #define VMSTATE_TIMER_TEST(_f, _s, _test) \ 866 VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer) 867 868 #define VMSTATE_TIMER_V(_f, _s, _v) \ 869 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer) 870 871 #define VMSTATE_TIMER(_f, _s) \ 872 VMSTATE_TIMER_V(_f, _s, 0) 873 874 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \ 875 VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer) 876 877 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \ 878 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool) 879 880 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \ 881 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0) 882 883 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \ 884 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t) 885 886 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 887 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t) 888 889 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \ 890 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0) 891 892 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \ 893 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0) 894 895 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 896 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t) 897 898 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \ 899 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t) 900 901 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \ 902 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0) 903 904 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \ 905 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t) 906 907 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \ 908 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0) 909 910 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \ 911 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t) 912 913 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 914 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t) 915 916 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \ 917 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0) 918 919 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \ 920 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0) 921 922 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \ 923 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t) 924 925 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \ 926 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0) 927 928 #define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2) \ 929 VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0) 930 931 #define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 932 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t) 933 934 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \ 935 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t) 936 937 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \ 938 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0) 939 940 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \ 941 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t) 942 943 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \ 944 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0) 945 946 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \ 947 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t) 948 949 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \ 950 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t) 951 952 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \ 953 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0) 954 955 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \ 956 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64) 957 958 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \ 959 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0) 960 961 #define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v) \ 962 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU) 963 964 #define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n) \ 965 VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0) 966 967 #define VMSTATE_BUFFER_V(_f, _s, _v) \ 968 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) 969 970 #define VMSTATE_BUFFER(_f, _s) \ 971 VMSTATE_BUFFER_V(_f, _s, 0) 972 973 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \ 974 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size) 975 976 #define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \ 977 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f))) 978 979 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \ 980 VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0) 981 982 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \ 983 VMSTATE_VBUFFER(_f, _s, 0, NULL, _size) 984 985 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \ 986 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size) 987 988 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ 989 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f))) 990 991 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \ 992 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size) 993 994 #define VMSTATE_UNUSED_V(_v, _size) \ 995 VMSTATE_UNUSED_BUFFER(NULL, _v, _size) 996 997 #define VMSTATE_UNUSED(_size) \ 998 VMSTATE_UNUSED_V(0, _size) 999 1000 #define VMSTATE_UNUSED_TEST(_test, _size) \ 1001 VMSTATE_UNUSED_BUFFER(_test, 0, _size) 1002 1003 #define VMSTATE_END_OF_LIST() \ 1004 {} 1005 1006 #define SELF_ANNOUNCE_ROUNDS 5 1007 1008 void loadvm_free_handlers(MigrationIncomingState *mis); 1009 1010 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, 1011 void *opaque, int version_id); 1012 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, 1013 void *opaque, QJSON *vmdesc); 1014 1015 bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); 1016 1017 /* Returns: 0 on success, -1 on failure */ 1018 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, 1019 const VMStateDescription *vmsd, 1020 void *base, int alias_id, 1021 int required_for_version, 1022 Error **errp); 1023 1024 /* Returns: 0 on success, -1 on failure */ 1025 static inline int vmstate_register(DeviceState *dev, int instance_id, 1026 const VMStateDescription *vmsd, 1027 void *opaque) 1028 { 1029 return vmstate_register_with_alias_id(dev, instance_id, vmsd, 1030 opaque, -1, 0, NULL); 1031 } 1032 1033 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, 1034 void *opaque); 1035 1036 struct MemoryRegion; 1037 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev); 1038 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev); 1039 void vmstate_register_ram_global(struct MemoryRegion *memory); 1040 1041 static inline 1042 int64_t self_announce_delay(int round) 1043 { 1044 assert(round < SELF_ANNOUNCE_ROUNDS && round > 0); 1045 /* delay 50ms, 150ms, 250ms, ... */ 1046 return 50 + (SELF_ANNOUNCE_ROUNDS - round - 1) * 100; 1047 } 1048 1049 void dump_vmstate_json_to_file(FILE *out_fp); 1050 1051 #endif 1052