From patchwork Tue Jan 24 14:05:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 9535273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 255216042D for ; Tue, 24 Jan 2017 14:11:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D9D827F94 for ; Tue, 24 Jan 2017 14:11:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02AB6280FC; Tue, 24 Jan 2017 14:11:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9D28927F94 for ; Tue, 24 Jan 2017 14:11:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cW1m6-0000hr-9w; Tue, 24 Jan 2017 14:08:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cW1m5-0000hX-Bg for xen-devel@lists.xenproject.org; Tue, 24 Jan 2017 14:08:41 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id C7/98-27165-8EF57885; Tue, 24 Jan 2017 14:08:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUvdFfHu EwcLJ3Bbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b2/92sBedEKuY/P8TUwDhfoIuRk0NCwF/i V98hRhCbTUBHYurTS6wgtoiArUT/9+9ANhcHs8A8Jond/9eBJYQF7CWerXzBBGKzCKhK7J56n Q3E5hVwk/h2+gEjxFA5ifPHfzKD2JwC7hL3n98GqxcCqrmyaQkjhK0isX7qLKheQYmTM5+wgN jMAhISB1+8YJ7AyDsLSWoWktQCRqZVjOrFqUVlqUW65npJRZnpGSW5iZk5uoYGZnq5qcXFiem pOYlJxXrJ+bmbGIHBwwAEOxhnXvY/xCjJwaQkyvvIvD1CiC8pP6UyI7E4I76oNCe1+BCjDAeH kgRvTBxQTrAoNT21Ii0zBxjGMGkJDh4lEd51IGne4oLE3OLMdIjUKUZFKXHeySAJAZBERmkeX Bssdi4xykoJ8zICHSLEU5BalJtZgir/ilGcg1FJmHcKyBSezLwSuOmvgBYzAS2+wAy2uCQRIS XVwDi9kjGkdUGMx9ojZbu7Lvcxuc2Y8CE0tzSoamHrzPaqkoTg1SIGHj+1hPmeeTZtuiH/JK5 a7MUsfr31myKc7rP/fesdZ2izvLbN6ddXYUk+LaHljWxlApy/H74IbnJjTbj17YTlOWXmp+2p z651/5Dld50taDXB59KmuZ5fPDREDQLjHlrUKrEUZyQaajEXFScCABuPnryYAgAA X-Env-Sender: prvs=19091db4e=Paul.Durrant@citrix.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1485266917!46268625!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60600 invoked from network); 24 Jan 2017 14:08:39 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-5.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 24 Jan 2017 14:08:39 -0000 X-IronPort-AV: E=Sophos;i="5.33,278,1477958400"; d="scan'208";a="401631239" From: Paul Durrant To: , Date: Tue, 24 Jan 2017 14:05:45 +0000 Message-ID: <1485266747-4694-2-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485266747-4694-1-git-send-email-paul.durrant@citrix.com> References: <1485266747-4694-1-git-send-email-paul.durrant@citrix.com> MIME-Version: 1.0 Cc: Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Paul Durrant , Anthony Perard , Paolo Bonzini , Richard Henderson Subject: [Xen-devel] [PATCH v2 1/3] xen-platform: re-structure unplug_disks X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The current code is poorly structured and potentially leads to multiple config space reads when one is sufficient. Also the UNPLUG_ALL_IDE_DISKS flag is mis-named since it also results in SCSI disks being unplugged. This patch renames the flag and re-structures the code to be more efficient, and readable. Signed-off-by: Paul Durrant Reviewed-by: Stefano Stabellini --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" v2: - Fix style issue --- hw/i386/xen/xen_platform.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index 2e1e543..f50915f 100644 --- a/hw/i386/xen/xen_platform.c +++ b/hw/i386/xen/xen_platform.c @@ -88,7 +88,7 @@ static void log_writeb(PCIXenPlatformState *s, char val) } /* Xen Platform, Fixed IOPort */ -#define UNPLUG_ALL_IDE_DISKS 1 +#define UNPLUG_ALL_DISKS 1 #define UNPLUG_ALL_NICS 2 #define UNPLUG_AUX_IDE_DISKS 4 @@ -110,14 +110,21 @@ static void pci_unplug_nics(PCIBus *bus) static void unplug_disks(PCIBus *b, PCIDevice *d, void *o) { /* We have to ignore passthrough devices */ - if (pci_get_word(d->config + PCI_CLASS_DEVICE) == - PCI_CLASS_STORAGE_IDE - && strcmp(d->name, "xen-pci-passthrough") != 0) { + if (!strcmp(d->name, "xen-pci-passthrough")) { + return; + } + + switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) { + case PCI_CLASS_STORAGE_IDE: pci_piix3_xen_ide_unplug(DEVICE(d)); - } else if (pci_get_word(d->config + PCI_CLASS_DEVICE) == - PCI_CLASS_STORAGE_SCSI - && strcmp(d->name, "xen-pci-passthrough") != 0) { + break; + + case PCI_CLASS_STORAGE_SCSI: object_unparent(OBJECT(d)); + break; + + default: + break; } } @@ -134,9 +141,9 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v case 0: { PCIDevice *pci_dev = PCI_DEVICE(s); /* Unplug devices. Value is a bitmask of which devices to - unplug, with bit 0 the IDE devices, bit 1 the network + unplug, with bit 0 the disk devices, bit 1 the network devices, and bit 2 the non-primary-master IDE devices. */ - if (val & UNPLUG_ALL_IDE_DISKS) { + if (val & UNPLUG_ALL_DISKS) { DPRINTF("unplug disks\n"); pci_unplug_disks(pci_dev->bus); }