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