From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agxmR-0006mu-Is for qemu-devel@nongnu.org; Fri, 18 Mar 2016 13:01:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agxmN-0008B0-1J for qemu-devel@nongnu.org; Fri, 18 Mar 2016 13:01:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55309) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agxmM-0008AM-Hl for qemu-devel@nongnu.org; Fri, 18 Mar 2016 13:01:38 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 1FDC0C05005E for ; Fri, 18 Mar 2016 17:01:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2IH1ZWo031663 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 18 Mar 2016 13:01:37 -0400 From: Markus Armbruster Date: Fri, 18 Mar 2016 18:01:22 +0100 Message-Id: <1458320487-19603-36-git-send-email-armbru@redhat.com> In-Reply-To: <1458320487-19603-1-git-send-email-armbru@redhat.com> References: <1458320487-19603-1-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 35/40] ivshmem: Replace int role_val by OnOffAuto master List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org In preparation of making it a qdev property. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <1458066895-20632-36-git-send-email-armbru@redhat.com> --- 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 =20 -#define IVSHMEM_PEER 0 -#define IVSHMEM_MASTER 1 - #define IVSHMEM_REG_BAR_SIZE 0x100 =20 #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 */ =20 + OnOffAuto master; Error *migration_blocker; =20 char * shmobj; char * sizearg; char * role; - int role_val; /* scalar to avoid multiple string comparisons */ } IVShmemState; =20 /* registers for the Inter-VM shared memory device */ @@ -118,6 +115,12 @@ static inline uint32_t ivshmem_has_feature(IVShmemSt= ate *ivs, return (ivs->features & (1 << feature)); } =20 +static inline bool ivshmem_is_master(IVShmemState *s) +{ + assert(s->master !=3D ON_OFF_AUTO_AUTO); + return s->master =3D=3D ON_OFF_AUTO_ON; +} + static void ivshmem_update_irq(IVShmemState *s) { PCIDevice *d =3D PCI_DEVICE(s); @@ -856,15 +859,15 @@ static void pci_ivshmem_realize(PCIDevice *dev, Err= or **errp) /* check that role is reasonable */ if (s->role) { if (strncmp(s->role, "peer", 5) =3D=3D 0) { - s->role_val =3D IVSHMEM_PEER; + s->master =3D ON_OFF_AUTO_OFF; } else if (strncmp(s->role, "master", 7) =3D=3D 0) { - s->role_val =3D IVSHMEM_MASTER; + s->master =3D ON_OFF_AUTO_ON; } else { error_setg(errp, "'role' must be 'peer' or 'master'"); return; } } else { - s->role_val =3D IVSHMEM_MASTER; /* default */ + s->master =3D ON_OFF_AUTO_AUTO; } =20 pci_conf =3D dev->config; @@ -926,7 +929,11 @@ static void pci_ivshmem_realize(PCIDevice *dev, Erro= r **errp) vmstate_register_ram(s->ivshmem_bar2, DEVICE(s)); pci_register_bar(PCI_DEVICE(s), 2, attr, s->ivshmem_bar2); =20 - if (s->role_val =3D=3D IVSHMEM_PEER) { + if (s->master =3D=3D ON_OFF_AUTO_AUTO) { + s->master =3D s->vm_id =3D=3D 0 ? ON_OFF_AUTO_ON : ON_OFF_AUTO_O= FF; + } + + 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 =3D opaque; =20 - if (s->role_val =3D=3D 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 *opaq= ue, int version_id) return -EINVAL; } =20 - if (s->role_val =3D=3D IVSHMEM_PEER) { - error_report("'peer' devices are not migratable"); - return -EINVAL; + ret =3D ivshmem_pre_load(s); + if (ret) { + return ret; } =20 ret =3D pci_device_load(pdev, f); --=20 2.4.3