From patchwork Thu Jan 26 09:37:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 9538693 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 0C840604A0 for ; Thu, 26 Jan 2017 09:40:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0029E20700 for ; Thu, 26 Jan 2017 09:40:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8BF528174; Thu, 26 Jan 2017 09:40:03 +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 9823320700 for ; Thu, 26 Jan 2017 09:40:03 +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 1cWgUn-0004NX-II; Thu, 26 Jan 2017 09:37:33 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWgUl-0004Mm-GI for xen-devel@lists.xenproject.org; Thu, 26 Jan 2017 09:37:31 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 64/52-15112-A53C9885; Thu, 26 Jan 2017 09:37:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42JxWrohUjfqcGe Ewd0XMhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bZW+3MBddFKo4/v8jYwLhCoIuRk0NCwF9i 3rTfTCA2m4COxNSnl1hBbBEBW4n+79+BbC4OZoGPjBKLW2+zgySEBewljhw6B9bAIqAqsfl6G zOIzSvgLvF1z0lGiKFyEueP/wSLcwp4SPy4PI0FxBYCqjmx7A8rhK0isX7qLDaIXkGJkzOfgN UwC0hIHHzxgnkCI+8sJKlZSFILGJlWMWoUpxaVpRbpGhrpJRVlpmeU5CZm5ugaGpjp5aYWFye mp+YkJhXrJefnbmIEhg8DEOxgvLwx4BCjJAeTkijvTe3OCCG+pPyUyozE4oz4otKc1OJDjDIc HEoSvCGHgHKCRanpqRVpmTnAQIZJS3DwKInwTgdJ8xYXJOYWZ6ZDpE4xKkqJ8wqCJARAEhmle XBtsOi5xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWHeeSBTeDLzSuCmvwJazAS0+AJzO8jikk SElFQDI+t3v8/vnjLUXLgy2ya2flp9R7rS251/q7bp+ZV9nXln/tbY/zyLbJO8VXZGP1N+6Lp gk+yqNTcZrUyVmVrCDZtSNVhv3NpxQiGr4d70NRcavj3Na2DX/J80o8LFN+fz0py39jf3RWhr Cf5vNvn2v9ju2NVHdbcW3uz76xZaL1H9TkbH2+R0iBJLcUaioRZzUXEiANN6CO6ZAgAA X-Env-Sender: prvs=192659432=Paul.Durrant@citrix.com X-Msg-Ref: server-11.tower-21.messagelabs.com!1485423448!54491980!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 24424 invoked from network); 26 Jan 2017 09:37:30 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-11.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 26 Jan 2017 09:37:30 -0000 X-IronPort-AV: E=Sophos;i="5.33,288,1477958400"; d="scan'208";a="402090673" From: Paul Durrant To: , Date: Thu, 26 Jan 2017 09:37:23 +0000 Message-ID: <1485423445-12302-2-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485423445-12302-1-git-send-email-paul.durrant@citrix.com> References: <1485423445-12302-1-git-send-email-paul.durrant@citrix.com> MIME-Version: 1.0 Cc: Eduardo Habkost , "Michael S. Tsirkin" , Paul Durrant , Anthony Perard , Paolo Bonzini , Richard Henderson Subject: [Xen-devel] [PATCH v3 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: 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); }