Received: from eggs.gnu.org ([2001:4830:134:3::10]:47329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abCcr-0003OL-1z for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:40:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abCcn-00038g-NC for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:40:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abCcn-00038b-Fh for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:39:57 -0500 From: Markus Armbruster References: <1456771254-17511-1-git-send-email-armbru@redhat.com> <1456771254-17511-34-git-send-email-armbru@redhat.com> Date: Wed, 02 Mar 2016 20:39:54 +0100 In-Reply-To: (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Wed, 2 Mar 2016 19:56:57 +0100") Message-ID: <8760x4d5yt.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 33/38] ivshmem: Replace int role_val by OnOffAuto master List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Cc: Paolo Bonzini , cam , Claudio Fontana , QEMU , David Marchand Marc-Andr=C3=A9 Lureau writes: > Hi > > On Mon, Feb 29, 2016 at 7:40 PM, Markus Armbruster wr= ote: >> In preparation of making it a qdev property. >> >> Signed-off-by: Markus Armbruster >> -- >> 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 785ed1c..b39ea27 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 >> @@ -96,12 +93,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 */ >> @@ -117,6 +114,12 @@ static inline uint32_t ivshmem_has_feature(IVShmemS= tate *ivs, >> return (ivs->features & (1 << feature)); >> } >> >> +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); >> @@ -861,15 +864,15 @@ static void pci_ivshmem_realize(PCIDevice *dev, Er= ror **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; >> } >> >> pci_conf =3D dev->config; >> @@ -931,7 +934,11 @@ static void pci_ivshmem_realize(PCIDevice *dev, Err= or **errp) >> vmstate_register_ram(s->ivshmem_bar2, DEVICE(s)); >> pci_register_bar(PCI_DEVICE(s), 2, attr, s->ivshmem_bar2); >> >> - 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_= OFF; >> + } >> + >> + if (ivshmem_is_master(s)) { > > !ivshmem_is_master() instead, or ivshmem_is_peer(). Another stupid mistake... >> error_setg(&s->migration_blocker, >> "Migration is disabled when using feature 'peer mode= ' in device 'ivshmem'"); Note to self: improve this message while there. >> migrate_add_blocker(s->migration_blocker); >> @@ -993,7 +1000,7 @@ static int ivshmem_pre_load(void *opaque) >> { >> IVShmemState *s =3D opaque; >> >> - if (s->role_val =3D=3D IVSHMEM_PEER) { >> + if (ivshmem_is_master(s)) { > > same here Yup. Thanks! >> error_report("'peer' devices are not migratable"); >> return -EINVAL; >> } >> @@ -1019,9 +1026,9 @@ static int ivshmem_load_old(QEMUFile *f, void *opa= que, int version_id) >> return -EINVAL; >> } >> >> - 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; >> } >> >> ret =3D pci_device_load(pdev, f); >> -- >> 2.4.3 >> >>