From patchwork Mon Feb 29 18:40:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 8457461 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 24C3F9F65E for ; Mon, 29 Feb 2016 18:57:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7458420204 for ; Mon, 29 Feb 2016 18:57:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B50D2200E6 for ; Mon, 29 Feb 2016 18:57:37 +0000 (UTC) Received: from localhost ([::1]:38528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaT0j-0005cK-0L for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Feb 2016 13:57:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaSkj-000251-Mv for qemu-devel@nongnu.org; Mon, 29 Feb 2016 13:41:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaSki-0007sq-AZ for qemu-devel@nongnu.org; Mon, 29 Feb 2016 13:41:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaSki-0007sI-3z for qemu-devel@nongnu.org; Mon, 29 Feb 2016 13:41:04 -0500 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 B58598F4E3; Mon, 29 Feb 2016 18:41:03 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1TIf0Vv011474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 29 Feb 2016 13:41:02 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4010130052FE; Mon, 29 Feb 2016 19:40:56 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 29 Feb 2016 19:40:49 +0100 Message-Id: <1456771254-17511-34-git-send-email-armbru@redhat.com> In-Reply-To: <1456771254-17511-1-git-send-email-armbru@redhat.com> References: <1456771254-17511-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: claudio.fontana@huawei.com, cam@cs.ualberta.ca, mlureau@redhat.com, david.marchand@6wind.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 33/38] ivshmem: Replace int role_val by OnOffAuto master X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(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); @@ -861,15 +864,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; @@ -931,7 +934,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); @@ -993,7 +1000,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; } @@ -1019,9 +1026,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);