Skip to content

Commit

Permalink
migration: extend VMStateInfo
Browse files Browse the repository at this point in the history
Current migration code cannot handle some data structures such as
QTAILQ in qemu/queue.h. Here we extend the signatures of put/get
in VMStateInfo so that customized handling is supported. put now
will return int type.

Reviewed-by: Dr. David Alan Gilbert <[email protected]>

Signed-off-by: Jianjun Duan <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Dr. David Alan Gilbert <[email protected]>
  • Loading branch information
Jianjun Duan authored and dagrh committed Jan 24, 2017
1 parent d7fc72c commit 2c21ee7
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 106 deletions.
8 changes: 6 additions & 2 deletions hw/display/virtio-gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,8 @@ static const VMStateDescription vmstate_virtio_gpu_scanouts = {
},
};

static void virtio_gpu_save(QEMUFile *f, void *opaque, size_t size)
static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
VMStateField *field, QJSON *vmdesc)
{
VirtIOGPU *g = opaque;
struct virtio_gpu_simple_resource *res;
Expand All @@ -1028,9 +1029,12 @@ static void virtio_gpu_save(QEMUFile *f, void *opaque, size_t size)
qemu_put_be32(f, 0); /* end of list */

vmstate_save_state(f, &vmstate_virtio_gpu_scanouts, g, NULL);

return 0;
}

static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size)
static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
VMStateField *field)
{
VirtIOGPU *g = opaque;
struct virtio_gpu_simple_resource *res;
Expand Down
8 changes: 6 additions & 2 deletions hw/intc/s390_flic_kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ static void kvm_s390_release_adapter_routes(S390FLICState *fs,
* increase until buffer is sufficient or maxium size is
* reached
*/
static void kvm_flic_save(QEMUFile *f, void *opaque, size_t size)
static int kvm_flic_save(QEMUFile *f, void *opaque, size_t size,
VMStateField *field, QJSON *vmdesc)
{
KVMS390FLICState *flic = opaque;
int len = FLIC_SAVE_INITIAL_SIZE;
Expand Down Expand Up @@ -319,6 +320,8 @@ static void kvm_flic_save(QEMUFile *f, void *opaque, size_t size)
count * sizeof(struct kvm_s390_irq));
}
g_free(buf);

return 0;
}

/**
Expand All @@ -331,7 +334,8 @@ static void kvm_flic_save(QEMUFile *f, void *opaque, size_t size)
* Note: Do nothing when no interrupts where stored
* in QEMUFile
*/
static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size)
static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size,
VMStateField *field)
{
uint64_t len = 0;
uint64_t count = 0;
Expand Down
24 changes: 18 additions & 6 deletions hw/net/vmxnet3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,8 @@ static void vmxnet3_put_tx_stats_to_file(QEMUFile *f,
qemu_put_be64(f, tx_stat->pktsTxDiscard);
}

static int vmxnet3_get_txq_descr(QEMUFile *f, void *pv, size_t size)
static int vmxnet3_get_txq_descr(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
Vmxnet3TxqDescr *r = pv;

Expand All @@ -2465,7 +2466,8 @@ static int vmxnet3_get_txq_descr(QEMUFile *f, void *pv, size_t size)
return 0;
}

static void vmxnet3_put_txq_descr(QEMUFile *f, void *pv, size_t size)
static int vmxnet3_put_txq_descr(QEMUFile *f, void *pv, size_t size,
VMStateField *field, QJSON *vmdesc)
{
Vmxnet3TxqDescr *r = pv;

Expand All @@ -2474,6 +2476,8 @@ static void vmxnet3_put_txq_descr(QEMUFile *f, void *pv, size_t size)
qemu_put_byte(f, r->intr_idx);
qemu_put_be64(f, r->tx_stats_pa);
vmxnet3_put_tx_stats_to_file(f, &r->txq_stats);

return 0;
}

static const VMStateInfo txq_descr_info = {
Expand Down Expand Up @@ -2512,7 +2516,8 @@ static void vmxnet3_put_rx_stats_to_file(QEMUFile *f,
qemu_put_be64(f, rx_stat->pktsRxError);
}

static int vmxnet3_get_rxq_descr(QEMUFile *f, void *pv, size_t size)
static int vmxnet3_get_rxq_descr(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
Vmxnet3RxqDescr *r = pv;
int i;
Expand All @@ -2530,7 +2535,8 @@ static int vmxnet3_get_rxq_descr(QEMUFile *f, void *pv, size_t size)
return 0;
}

static void vmxnet3_put_rxq_descr(QEMUFile *f, void *pv, size_t size)
static int vmxnet3_put_rxq_descr(QEMUFile *f, void *pv, size_t size,
VMStateField *field, QJSON *vmdesc)
{
Vmxnet3RxqDescr *r = pv;
int i;
Expand All @@ -2543,6 +2549,8 @@ static void vmxnet3_put_rxq_descr(QEMUFile *f, void *pv, size_t size)
qemu_put_byte(f, r->intr_idx);
qemu_put_be64(f, r->rx_stats_pa);
vmxnet3_put_rx_stats_to_file(f, &r->rxq_stats);

return 0;
}

static int vmxnet3_post_load(void *opaque, int version_id)
Expand Down Expand Up @@ -2575,7 +2583,8 @@ static const VMStateInfo rxq_descr_info = {
.put = vmxnet3_put_rxq_descr
};

static int vmxnet3_get_int_state(QEMUFile *f, void *pv, size_t size)
static int vmxnet3_get_int_state(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
Vmxnet3IntState *r = pv;

Expand All @@ -2586,13 +2595,16 @@ static int vmxnet3_get_int_state(QEMUFile *f, void *pv, size_t size)
return 0;
}

static void vmxnet3_put_int_state(QEMUFile *f, void *pv, size_t size)
static int vmxnet3_put_int_state(QEMUFile *f, void *pv, size_t size,
VMStateField *field, QJSON *vmdesc)
{
Vmxnet3IntState *r = pv;

qemu_put_byte(f, r->is_masked);
qemu_put_byte(f, r->is_pending);
qemu_put_byte(f, r->is_asserted);

return 0;
}

static const VMStateInfo int_state_info = {
Expand Down
8 changes: 6 additions & 2 deletions hw/nvram/eeprom93xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,22 @@ struct _eeprom_t {
This is a Big hack, but it is how the old state did it.
*/

static int get_uint16_from_uint8(QEMUFile *f, void *pv, size_t size)
static int get_uint16_from_uint8(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
uint16_t *v = pv;
*v = qemu_get_ubyte(f);
return 0;
}

static void put_unused(QEMUFile *f, void *pv, size_t size)
static int put_unused(QEMUFile *f, void *pv, size_t size, VMStateField *field,
QJSON *vmdesc)
{
fprintf(stderr, "uint16_from_uint8 is used only for backwards compatibility.\n");
fprintf(stderr, "Never should be used to write a new state.\n");
exit(0);

return 0;
}

static const VMStateInfo vmstate_hack_uint16_from_uint8 = {
Expand Down
8 changes: 6 additions & 2 deletions hw/nvram/fw_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,21 @@ static void fw_cfg_reset(DeviceState *d)
Or we broke compatibility in the state, or we can't use struct tm
*/

static int get_uint32_as_uint16(QEMUFile *f, void *pv, size_t size)
static int get_uint32_as_uint16(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
uint32_t *v = pv;
*v = qemu_get_be16(f);
return 0;
}

static void put_unused(QEMUFile *f, void *pv, size_t size)
static int put_unused(QEMUFile *f, void *pv, size_t size, VMStateField *field,
QJSON *vmdesc)
{
fprintf(stderr, "uint32_as_uint16 is only used for backward compatibility.\n");
fprintf(stderr, "This functions shouldn't be called.\n");

return 0;
}

static const VMStateInfo vmstate_hack_uint32_as_uint16 = {
Expand Down
8 changes: 6 additions & 2 deletions hw/pci/msix.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,16 @@ void msix_unset_vector_notifiers(PCIDevice *dev)
dev->msix_vector_poll_notifier = NULL;
}

static void put_msix_state(QEMUFile *f, void *pv, size_t size)
static int put_msix_state(QEMUFile *f, void *pv, size_t size,
VMStateField *field, QJSON *vmdesc)
{
msix_save(pv, f);

return 0;
}

static int get_msix_state(QEMUFile *f, void *pv, size_t size)
static int get_msix_state(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
msix_load(pv, f);
return 0;
Expand Down
16 changes: 12 additions & 4 deletions hw/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ int pci_bus_numa_node(PCIBus *bus)
return PCI_BUS_GET_CLASS(bus)->numa_node(bus);
}

static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
static int get_pci_config_device(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
PCIDevice *s = container_of(pv, PCIDevice, config);
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(s);
Expand Down Expand Up @@ -484,11 +485,14 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
}

/* just put buffer */
static void put_pci_config_device(QEMUFile *f, void *pv, size_t size)
static int put_pci_config_device(QEMUFile *f, void *pv, size_t size,
VMStateField *field, QJSON *vmdesc)
{
const uint8_t **v = pv;
assert(size == pci_config_size(container_of(pv, PCIDevice, config)));
qemu_put_buffer(f, *v, size);

return 0;
}

static VMStateInfo vmstate_info_pci_config = {
Expand All @@ -497,7 +501,8 @@ static VMStateInfo vmstate_info_pci_config = {
.put = put_pci_config_device,
};

static int get_pci_irq_state(QEMUFile *f, void *pv, size_t size)
static int get_pci_irq_state(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
PCIDevice *s = container_of(pv, PCIDevice, irq_state);
uint32_t irq_state[PCI_NUM_PINS];
Expand All @@ -518,14 +523,17 @@ static int get_pci_irq_state(QEMUFile *f, void *pv, size_t size)
return 0;
}

static void put_pci_irq_state(QEMUFile *f, void *pv, size_t size)
static int put_pci_irq_state(QEMUFile *f, void *pv, size_t size,
VMStateField *field, QJSON *vmdesc)
{
int i;
PCIDevice *s = container_of(pv, PCIDevice, irq_state);

for (i = 0; i < PCI_NUM_PINS; ++i) {
qemu_put_be32(f, pci_irq_state(s, i));
}

return 0;
}

static VMStateInfo vmstate_info_pci_irq_state = {
Expand Down
7 changes: 5 additions & 2 deletions hw/pci/shpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,16 @@ void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
shpc_cap_update_dword(d);
}

static void shpc_save(QEMUFile *f, void *pv, size_t size)
static int shpc_save(QEMUFile *f, void *pv, size_t size, VMStateField *field,
QJSON *vmdesc)
{
PCIDevice *d = container_of(pv, PCIDevice, shpc);
qemu_put_buffer(f, d->shpc->config, SHPC_SIZEOF(d));

return 0;
}

static int shpc_load(QEMUFile *f, void *pv, size_t size)
static int shpc_load(QEMUFile *f, void *pv, size_t size, VMStateField *field)
{
PCIDevice *d = container_of(pv, PCIDevice, shpc);
int ret = qemu_get_buffer(f, d->shpc->config, SHPC_SIZEOF(d));
Expand Down
8 changes: 6 additions & 2 deletions hw/scsi/scsi-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,8 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)

/* SCSI request list. For simplicity, pv points to the whole device */

static void put_scsi_requests(QEMUFile *f, void *pv, size_t size)
static int put_scsi_requests(QEMUFile *f, void *pv, size_t size,
VMStateField *field, QJSON *vmdesc)
{
SCSIDevice *s = pv;
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, s->qdev.parent_bus);
Expand All @@ -1968,9 +1969,12 @@ static void put_scsi_requests(QEMUFile *f, void *pv, size_t size)
}
}
qemu_put_sbyte(f, 0);

return 0;
}

static int get_scsi_requests(QEMUFile *f, void *pv, size_t size)
static int get_scsi_requests(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
SCSIDevice *s = pv;
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, s->qdev.parent_bus);
Expand Down
8 changes: 6 additions & 2 deletions hw/timer/twl92230.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,17 +749,21 @@ static int menelaus_rx(I2CSlave *i2c)
Or we broke compatibility in the state, or we can't use struct tm
*/

static int get_int32_as_uint16(QEMUFile *f, void *pv, size_t size)
static int get_int32_as_uint16(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
int *v = pv;
*v = qemu_get_be16(f);
return 0;
}

static void put_int32_as_uint16(QEMUFile *f, void *pv, size_t size)
static int put_int32_as_uint16(QEMUFile *f, void *pv, size_t size,
VMStateField *field, QJSON *vmdesc)
{
int *v = pv;
qemu_put_be16(f, *v);

return 0;
}

static const VMStateInfo vmstate_hack_int32_as_uint16 = {
Expand Down
Loading

0 comments on commit 2c21ee7

Please sign in to comment.