migration: Add VMS_NO_STATE flag
There are a few special cases of vmstate usage: The vmstate_msix and vmstate_scsi_device have fields that contain no data, only a vmstate_info structure. The VMSTATE_VALIDATE macro serves only to invoke the .field_exists routine for validation. Regardless whether these scenarios are valid, add a separate flag to identify them so we can enforce common constraints for the normal vmstates such as having a size greater than zero. Note that n_elems is hardcoded to 1 for all vmstates, except VMS_[V]ARRAY, so VMSTATE_VALIDATE needed to set VMS_ARRAY to be able to force n_elems to 0. This patch now checks the flag at vmstate_n_elems(). Acked-by: Peter Xu <peterx@redhat.com> Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
1 parent
028d4ec43d
commit
797b88eddd
6 files changed
+16
-15
No files matched your search
+1
-5
@@ -711,12 +711,8 @@ const VMStateDescription vmstate_msix = {
|
||||
.fields = (const VMStateField[]) {
|
||||
{
|
||||
.name = "msix",
|
||||
.version_id = 0,
|
||||
.field_exists = NULL,
|
||||
.size = 0, /* ouch */
|
||||
.info = &vmstate_info_msix,
|
||||
.flags = VMS_SINGLE,
|
||||
.offset = 0,
|
||||
.flags = VMS_SINGLE | VMS_NO_STATE,
|
||||
},
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
|
||||
+1
-5
@@ -1980,12 +1980,8 @@ const VMStateDescription vmstate_scsi_device = {
|
||||
VMSTATE_UINT32(sense_len, SCSIDevice),
|
||||
{
|
||||
.name = "requests",
|
||||
.version_id = 0,
|
||||
.field_exists = NULL,
|
||||
.size = 0, /* ouch */
|
||||
.info = &vmstate_info_scsi_requests,
|
||||
.flags = VMS_SINGLE,
|
||||
.offset = 0,
|
||||
.flags = VMS_SINGLE | VMS_NO_STATE,
|
||||
},
|
||||
VMSTATE_END_OF_LIST()
|
||||
},
|
||||
|
||||
@@ -109,6 +109,12 @@ enum VMStateFlags {
|
||||
*/
|
||||
VMS_ARRAY_OF_POINTER = 0x040,
|
||||
|
||||
/*
|
||||
* The field contains no data. Used for special cases such as
|
||||
* invoking a custom VMStateInfo.
|
||||
*/
|
||||
VMS_NO_STATE = 0x080,
|
||||
|
||||
/* The size of the individual entries (a single array entry if
|
||||
* VMS_ARRAY or VMS_VARRAY are set, or the field itself if
|
||||
* neither is set) is variable (i.e. not known at compile-time),
|
||||
@@ -454,8 +460,7 @@ extern const VMStateInfo vmstate_info_g_byte_array;
|
||||
#define VMSTATE_VALIDATE(_name, _test) { \
|
||||
.name = (_name), \
|
||||
.field_exists = (_test), \
|
||||
.flags = VMS_ARRAY | VMS_MUST_EXIST, \
|
||||
.num = 0, /* 0 elements: no data, only run _test */ \
|
||||
.flags = VMS_MUST_EXIST | VMS_NO_STATE, \
|
||||
}
|
||||
|
||||
#define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
|
||||
|
||||
+5
-1
@@ -110,12 +110,16 @@ static uint64_t vmstate_read_from_offset(const VMStateStructMember *member,
|
||||
|
||||
static uint64_t vmstate_n_elems(void *opaque, const VMStateField *field)
|
||||
{
|
||||
uint64_t n_elems = 1;
|
||||
uint64_t n_elems;
|
||||
|
||||
if (field->flags & VMS_ARRAY) {
|
||||
n_elems = field->num;
|
||||
} else if (field->flags & VMS_VARRAY) {
|
||||
n_elems = vmstate_read_from_offset(&field->num_indirect, opaque);
|
||||
} else if (field->flags & VMS_MUST_EXIST && field->flags & VMS_NO_STATE) {
|
||||
n_elems = 0;
|
||||
} else {
|
||||
n_elems = 1;
|
||||
}
|
||||
|
||||
trace_vmstate_n_elems(field->name, n_elems);
|
||||
|
||||
@@ -381,7 +381,7 @@ macro_rules! vmstate_validate {
|
||||
field_exists: $crate::vmstate_exist_fn!($struct_name, $test_fn),
|
||||
flags: $crate::bindings::VMStateFlags(
|
||||
$crate::bindings::VMStateFlags::VMS_MUST_EXIST.0
|
||||
| $crate::bindings::VMStateFlags::VMS_ARRAY.0,
|
||||
| $crate::bindings::VMStateFlags::VMS_NO_STATE.0,
|
||||
),
|
||||
num: 0, // 0 elements: no data, only run test_fn callback
|
||||
..::common::zeroable::Zeroable::ZERO
|
||||
|
||||
@@ -461,7 +461,7 @@ fn test_vmstate_validate() {
|
||||
assert_eq!(foo_fields[0].num, 0);
|
||||
assert_eq!(
|
||||
foo_fields[0].flags.0,
|
||||
VMStateFlags::VMS_ARRAY.0 | VMStateFlags::VMS_MUST_EXIST.0
|
||||
VMStateFlags::VMS_NO_STATE.0 | VMStateFlags::VMS_MUST_EXIST.0
|
||||
);
|
||||
assert!(foo_fields[0].vmsd.is_null());
|
||||
assert!(unsafe { foo_fields[0].field_exists.unwrap()(foo_d_p, 0) });
|
||||
|
||||
Reference in new issue
Block a user