[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 22/39] ivshmem: migrate with VMStateDescription
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH 22/39] ivshmem: migrate with VMStateDescription |
Date: |
Fri, 26 Jun 2015 16:49:28 +0200 |
If necessary, load_state_old() could be used to keep compatibility with
verison 0.
Signed-off-by: Marc-André Lureau <address@hidden>
---
hw/misc/ivshmem.c | 107 +++++++++++++++++++++++++++---------------------------
1 file changed, 54 insertions(+), 53 deletions(-)
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 34da11a..199086d 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -650,56 +650,6 @@ static int ivshmem_setup_msi(IVShmemState * s)
return 0;
}
-static void ivshmem_save(QEMUFile* f, void *opaque)
-{
- IVShmemState *proxy = opaque;
- PCIDevice *pci_dev = PCI_DEVICE(proxy);
-
- IVSHMEM_DPRINTF("ivshmem_save\n");
- pci_device_save(pci_dev, f);
-
- if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) {
- msix_save(pci_dev, f);
- } else {
- qemu_put_be32(f, proxy->intrstatus);
- qemu_put_be32(f, proxy->intrmask);
- }
-
-}
-
-static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
-{
- IVSHMEM_DPRINTF("ivshmem_load\n");
-
- IVShmemState *proxy = opaque;
- PCIDevice *pci_dev = PCI_DEVICE(proxy);
- int ret;
-
- if (version_id > 0) {
- return -EINVAL;
- }
-
- if (proxy->role_val == IVSHMEM_PEER) {
- error_report("'peer' devices are not migratable");
- return -EINVAL;
- }
-
- ret = pci_device_load(pci_dev, f);
- if (ret) {
- return ret;
- }
-
- if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) {
- msix_load(pci_dev, f);
- ivshmem_use_msix(proxy);
- } else {
- proxy->intrstatus = qemu_get_be32(f);
- proxy->intrmask = qemu_get_be32(f);
- }
-
- return 0;
-}
-
static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
uint32_t val, int len)
{
@@ -725,8 +675,7 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error
**errp)
}
fifo8_create(&s->incoming_fifo, sizeof(long));
- register_savevm(DEVICE(dev), "ivshmem", 0, 0, ivshmem_save, ivshmem_load,
- dev);
+
/* IRQFD requires MSI */
if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) &&
!ivshmem_has_feature(s, IVSHMEM_MSI)) {
@@ -852,10 +801,61 @@ static void pci_ivshmem_exit(PCIDevice *dev)
memory_region_del_subregion(&s->bar, &s->ivshmem);
vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
- unregister_savevm(DEVICE(dev), "ivshmem", s);
fifo8_destroy(&s->incoming_fifo);
}
+static bool test_msix(void *opaque, int version_id)
+{
+ IVShmemState *s = opaque;
+
+ return ivshmem_has_feature(s, IVSHMEM_MSI);
+}
+
+static bool test_no_msix(void *opaque, int version_id)
+{
+ return !test_msix(opaque, version_id);
+}
+
+static int ivshmem_pre_load(void *opaque)
+{
+ IVShmemState *s = opaque;
+
+ if (s->role_val == IVSHMEM_PEER) {
+ error_report("'peer' devices are not migratable");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int ivshmem_post_load(void *opaque, int version_id)
+{
+ IVShmemState *s = opaque;
+
+ if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
+ ivshmem_use_msix(s);
+ }
+
+ return 0;
+}
+
+static const VMStateDescription ivshmem_vmsd = {
+ .name = "ivshmem",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .pre_load = ivshmem_pre_load,
+ .post_load = ivshmem_post_load,
+ .fields = (VMStateField[]) {
+ VMSTATE_PCI_DEVICE(parent_obj, IVShmemState),
+
+ VMSTATE_MSIX_TEST(parent_obj, IVShmemState, test_msix),
+ VMSTATE_UINT32_TEST(intrstatus, IVShmemState, test_no_msix),
+ VMSTATE_UINT32_TEST(intrmask, IVShmemState, test_no_msix),
+
+ VMSTATE_END_OF_LIST()
+ }
+};
+
static Property ivshmem_properties[] = {
DEFINE_PROP_CHR("chardev", IVShmemState, server_chr),
DEFINE_PROP_STRING("size", IVShmemState, sizearg),
@@ -881,6 +881,7 @@ static void ivshmem_class_init(ObjectClass *klass, void
*data)
k->class_id = PCI_CLASS_MEMORY_RAM;
dc->reset = ivshmem_reset;
dc->props = ivshmem_properties;
+ dc->vmsd = &ivshmem_vmsd;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
}
--
2.4.3
- [Qemu-devel] [PATCH 11/39] ivshmem: increase_dynamic_storage() improvements, (continued)
- [Qemu-devel] [PATCH 11/39] ivshmem: increase_dynamic_storage() improvements, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 13/39] ivshmem: initialize max_peer to -1, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 12/39] ivshmem: remove useless ivshmem_update_irq() val argument, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 14/39] ivshmem: remove max_peer field, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 15/39] ivshmem: improve debug messages, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 16/39] ivshmem: improve error, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 17/39] ivshmem: print error on invalid peer id, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 18/39] ivshmem: add a warning if eventfd value is 0, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 19/39] ivshmem: beautify a bit the code, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 20/39] ivshmem: use common return, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 22/39] ivshmem: migrate with VMStateDescription,
Marc-André Lureau <=
- [Qemu-devel] [PATCH 21/39] ivshmem: use common is_power_of_2(), Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 24/39] ivshmem: check shm isn't already initialized, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 23/39] ivshmem: shmfd can be 0, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 25/39] ivshmem: add device description, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 26/39] ivshmem: fix pci_ivshmem_exit(), Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 28/39] ivshmem: error on too many eventfd received, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 27/39] ivshmem: replace 'guest' for 'peer' appropriately, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 29/39] ivshmem: reset mask on device reset, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 31/39] ivshmem-client: check the number of vectors, Marc-André Lureau, 2015/06/26
- [Qemu-devel] [PATCH 32/39] ivshmem-server: use a uint16 for client ID, Marc-André Lureau, 2015/06/26