mirror of
https://git.proxmox.com/git/qemu
synced 2025-07-09 10:03:54 +00:00
vmstate: Add support for saving/loading bitmaps
Add support for saving/loading bitmap.h bitmaps in vmstate. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Tested-by: Igor Mitsyanko <i.mitsyanko@samsung.com> Reviewed-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
f2d189d384
commit
08e99e296f
41
savevm.c
41
savevm.c
@ -86,6 +86,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "qmp-commands.h"
|
#include "qmp-commands.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
#include "bitops.h"
|
||||||
|
|
||||||
#define SELF_ANNOUNCE_ROUNDS 5
|
#define SELF_ANNOUNCE_ROUNDS 5
|
||||||
|
|
||||||
@ -1132,6 +1133,46 @@ const VMStateInfo vmstate_info_unused_buffer = {
|
|||||||
.put = put_unused_buffer,
|
.put = put_unused_buffer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* bitmaps (as defined by bitmap.h). Note that size here is the size
|
||||||
|
* of the bitmap in bits. The on-the-wire format of a bitmap is 64
|
||||||
|
* bit words with the bits in big endian order. The in-memory format
|
||||||
|
* is an array of 'unsigned long', which may be either 32 or 64 bits.
|
||||||
|
*/
|
||||||
|
/* This is the number of 64 bit words sent over the wire */
|
||||||
|
#define BITS_TO_U64S(nr) DIV_ROUND_UP(nr, 64)
|
||||||
|
static int get_bitmap(QEMUFile *f, void *pv, size_t size)
|
||||||
|
{
|
||||||
|
unsigned long *bmp = pv;
|
||||||
|
int i, idx = 0;
|
||||||
|
for (i = 0; i < BITS_TO_U64S(size); i++) {
|
||||||
|
uint64_t w = qemu_get_be64(f);
|
||||||
|
bmp[idx++] = w;
|
||||||
|
if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) {
|
||||||
|
bmp[idx++] = w >> 32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void put_bitmap(QEMUFile *f, void *pv, size_t size)
|
||||||
|
{
|
||||||
|
unsigned long *bmp = pv;
|
||||||
|
int i, idx = 0;
|
||||||
|
for (i = 0; i < BITS_TO_U64S(size); i++) {
|
||||||
|
uint64_t w = bmp[idx++];
|
||||||
|
if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) {
|
||||||
|
w |= ((uint64_t)bmp[idx++]) << 32;
|
||||||
|
}
|
||||||
|
qemu_put_be64(f, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const VMStateInfo vmstate_info_bitmap = {
|
||||||
|
.name = "bitmap",
|
||||||
|
.get = get_bitmap,
|
||||||
|
.put = put_bitmap,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct CompatEntry {
|
typedef struct CompatEntry {
|
||||||
char idstr[256];
|
char idstr[256];
|
||||||
int instance_id;
|
int instance_id;
|
||||||
|
13
vmstate.h
13
vmstate.h
@ -139,6 +139,7 @@ extern const VMStateInfo vmstate_info_uint64;
|
|||||||
extern const VMStateInfo vmstate_info_timer;
|
extern const VMStateInfo vmstate_info_timer;
|
||||||
extern const VMStateInfo vmstate_info_buffer;
|
extern const VMStateInfo vmstate_info_buffer;
|
||||||
extern const VMStateInfo vmstate_info_unused_buffer;
|
extern const VMStateInfo vmstate_info_unused_buffer;
|
||||||
|
extern const VMStateInfo vmstate_info_bitmap;
|
||||||
|
|
||||||
#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
|
#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
|
||||||
#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
|
#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
|
||||||
@ -411,6 +412,18 @@ extern const VMStateInfo vmstate_info_unused_buffer;
|
|||||||
.flags = VMS_BUFFER, \
|
.flags = VMS_BUFFER, \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* _field_size should be a int32_t field in the _state struct giving the
|
||||||
|
* size of the bitmap _field in bits.
|
||||||
|
*/
|
||||||
|
#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
|
||||||
|
.name = (stringify(_field)), \
|
||||||
|
.version_id = (_version), \
|
||||||
|
.size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
|
||||||
|
.info = &vmstate_info_bitmap, \
|
||||||
|
.flags = VMS_VBUFFER|VMS_POINTER, \
|
||||||
|
.offset = offsetof(_state, _field), \
|
||||||
|
}
|
||||||
|
|
||||||
/* _f : field name
|
/* _f : field name
|
||||||
_f_n : num of elements field_name
|
_f_n : num of elements field_name
|
||||||
_n : num of elements
|
_n : num of elements
|
||||||
|
Loading…
Reference in New Issue
Block a user