[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 35/40] ivshmem: Replace int role_val by OnOffAuto mas
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 35/40] ivshmem: Replace int role_val by OnOffAuto master |
Date: |
Fri, 18 Mar 2016 18:01:22 +0100 |
In preparation of making it a qdev property.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
---
hw/misc/ivshmem.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index e6282ab..f903fae 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -43,9 +43,6 @@
#define IVSHMEM_IOEVENTFD 0
#define IVSHMEM_MSI 1
-#define IVSHMEM_PEER 0
-#define IVSHMEM_MASTER 1
-
#define IVSHMEM_REG_BAR_SIZE 0x100
#define IVSHMEM_DEBUG 0
@@ -97,12 +94,12 @@ typedef struct IVShmemState {
uint64_t msg_buf; /* buffer for receiving server messages */
int msg_buffered_bytes; /* #bytes in @msg_buf */
+ OnOffAuto master;
Error *migration_blocker;
char * shmobj;
char * sizearg;
char * role;
- int role_val; /* scalar to avoid multiple string comparisons */
} IVShmemState;
/* registers for the Inter-VM shared memory device */
@@ -118,6 +115,12 @@ static inline uint32_t ivshmem_has_feature(IVShmemState
*ivs,
return (ivs->features & (1 << feature));
}
+static inline bool ivshmem_is_master(IVShmemState *s)
+{
+ assert(s->master != ON_OFF_AUTO_AUTO);
+ return s->master == ON_OFF_AUTO_ON;
+}
+
static void ivshmem_update_irq(IVShmemState *s)
{
PCIDevice *d = PCI_DEVICE(s);
@@ -856,15 +859,15 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error
**errp)
/* check that role is reasonable */
if (s->role) {
if (strncmp(s->role, "peer", 5) == 0) {
- s->role_val = IVSHMEM_PEER;
+ s->master = ON_OFF_AUTO_OFF;
} else if (strncmp(s->role, "master", 7) == 0) {
- s->role_val = IVSHMEM_MASTER;
+ s->master = ON_OFF_AUTO_ON;
} else {
error_setg(errp, "'role' must be 'peer' or 'master'");
return;
}
} else {
- s->role_val = IVSHMEM_MASTER; /* default */
+ s->master = ON_OFF_AUTO_AUTO;
}
pci_conf = dev->config;
@@ -926,7 +929,11 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error
**errp)
vmstate_register_ram(s->ivshmem_bar2, DEVICE(s));
pci_register_bar(PCI_DEVICE(s), 2, attr, s->ivshmem_bar2);
- if (s->role_val == IVSHMEM_PEER) {
+ if (s->master == ON_OFF_AUTO_AUTO) {
+ s->master = s->vm_id == 0 ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
+ }
+
+ if (!ivshmem_is_master(s)) {
error_setg(&s->migration_blocker,
"Migration is disabled when using feature 'peer mode' in
device 'ivshmem'");
migrate_add_blocker(s->migration_blocker);
@@ -990,7 +997,7 @@ static int ivshmem_pre_load(void *opaque)
{
IVShmemState *s = opaque;
- if (s->role_val == IVSHMEM_PEER) {
+ if (!ivshmem_is_master(s)) {
error_report("'peer' devices are not migratable");
return -EINVAL;
}
@@ -1020,9 +1027,9 @@ static int ivshmem_load_old(QEMUFile *f, void *opaque,
int version_id)
return -EINVAL;
}
- if (s->role_val == IVSHMEM_PEER) {
- error_report("'peer' devices are not migratable");
- return -EINVAL;
+ ret = ivshmem_pre_load(s);
+ if (ret) {
+ return ret;
}
ret = pci_device_load(pdev, f);
--
2.4.3
- [Qemu-devel] [PULL 38/40] ivshmem: Drop ivshmem property x-memdev, (continued)
- [Qemu-devel] [PULL 38/40] ivshmem: Drop ivshmem property x-memdev, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 20/40] ivshmem: Leave INTx alone when using MSI-X, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 39/40] ivshmem: Require master to have ID zero, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 33/40] ivshmem: Inline check_shm_size() into its only caller, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 26/40] ivshmem: Propagate errors through ivshmem_recv_setup(), Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 10/40] ivshmem: Rewrite specification document, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 32/40] ivshmem: Simplify memory regions for BAR 2 (shared memory), Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 04/40] qemu-doc: Fix ivshmem huge page example, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 29/40] ivshmem: Simplify how we cope with short reads from server, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 19/40] ivshmem: Clean up MSI-X conditions, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 35/40] ivshmem: Replace int role_val by OnOffAuto master,
Markus Armbruster <=
- [Qemu-devel] [PULL 13/40] ivshmem: Clean up after commit 9940c32, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 02/40] ivshmem-server: Fix and clean up command line help, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 23/40] ivshmem: Disentangle ivshmem_read(), Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 16/40] ivshmem: Fix harmless misuse of Error, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 17/40] ivshmem: Failed realize() can leave migration blocker behind, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 25/40] ivshmem: Receive shared memory synchronously in realize(), Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 30/40] ivshmem: Tighten check of property "size", Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 27/40] ivshmem: Rely on server sending the ID right after the version, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 37/40] ivshmem: Clean up after the previous commit, Markus Armbruster, 2016/03/18
- [Qemu-devel] [PULL 28/40] ivshmem: Drop the hackish test for UNIX domain chardev, Markus Armbruster, 2016/03/18