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