From nobody Sat May 18 15:08:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1603813521; cv=none; d=zohomail.com; s=zohoarc; b=V5d2+wB4aFUbnNz9gekGOhdTUlk1G9EAY9E0KK8fDrbmvqrNEZY3170ZWM00VH8eQN0WbOAykK2TOjM3LfZH057Csf9kvM5o1OL7eaebdAgoP3Ndzhf3oTK4f8dvX7dI3G6RoXODRRPeDYkDqa3I3HcOQoWB7qjirQ2nLkXNjYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603813521; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=1biQw7E9cgpBtSw0xe5JdCbdT2CikGJ2lslvCTl79v8=; b=AG24aL7BVURM36hO195KbmJucW7mdK/u67JHgjNh4U4znSvxcPoGaf4EkvonpDXL1V/AERu67aN7wjB/sZOulY8Ob58idGaZe7zgAjtgZ1TOsbbQs3bdNTFbokiFrtg4HdEa7RGTch2FtXUgr4VkPgqsScRwt+XBdIcLRXkLfkw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603813521646614.8747580482654; Tue, 27 Oct 2020 08:45:21 -0700 (PDT) Received: from localhost ([::1]:58224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXRA0-00038O-H5 for importer@patchew.org; Tue, 27 Oct 2020 11:45:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXR8g-0001ox-4O; Tue, 27 Oct 2020 11:43:58 -0400 Received: from esa3.hc3370-68.iphmx.com ([216.71.145.155]:44185) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXR8e-0003nW-6I; Tue, 27 Oct 2020 11:43:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1603813436; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WoOGmrQS9IZN20i9qYsoqyHF5ubu8HFEj53ZhwtPxu0=; b=FEKul3JgPghwGwXczE6qvemF5CXnV4q7FCavpwAnAlEOrlLck2BECAoV FjIRHUpo87ionOA6pLvd82a6KwJ7/2JPkGKQZhxVaQ1+NVicuugJnlYnF mwZj2Tjez9nRuNJertlEHoewAFK9xUMOTIDp76eyeefk6/0hcdZmxDFgI g=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 4gJ4E7hxT4O5stWVhOdcpozXklyTgTkAgfmJHO7B4g/x9gJnhTwNLoC/5Vq9HqaDe3AX7noHe6 jH7o9202K7N6LN6UstnoYU8wrA7LSw9fahMl0MhfsIYATbSAM8NnZY3unkayH7/Nsvqmit6KXM wVC1fFx2SrJbuk3pexnylGsxfmDL9lcM9Phb4iYbV59pBpSKMXjavNpIn0HXlr0b6MVgZUK8KQ DltSZ9Ja7xXC2tdFZ14+GfspUyBM9etUKk9HBgO3m7Z4LdRvooeYj5fIByDGf+e3PRgy0Nuof5 /Oo= X-SBRS: None X-MesageID: 29857455 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.77,424,1596513600"; d="scan'208";a="29857455" To: CC: Anthony PERARD , Paul Durrant , Stefano Stabellini , John Snow , Subject: [PATCH v2] xen: rework pci_piix3_xen_ide_unplug Date: Tue, 27 Oct 2020 15:40:58 +0000 Message-ID: <20201027154058.495112-1-anthony.perard@citrix.com> X-Mailer: git-send-email 2.29.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.145.155; envelope-from=anthony.perard@citrix.com; helo=esa3.hc3370-68.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 11:43:52 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Anthony PERARD From: Anthony PERARD via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Anthony PERARD This is to allow IDE disks to be unplugged when adding to QEMU via: -drive file=3D/root/disk_file,if=3Dnone,id=3Dide-disk0,format=3Draw -device ide-hd,drive=3Dide-disk0,bus=3Dide.0,unit=3D0 as the current code only works for disk added with: -drive file=3D/root/disk_file,if=3Dide,index=3D0,media=3Ddisk,format=3D= raw Since the code already have the IDE controller as `dev`, we don't need to use the legacy DriveInfo to find all the drive we want to unplug. We can simply use `blk` from the controller, as it kind of was already assume to be the same, by setting it to NULL. Signed-off-by: Anthony PERARD Acked-by: John Snow Reviewed-by: Paul Durrant --- v2: coding style CC: Paul Durrant CC: Stefano Stabellini --- hw/ide/piix.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/hw/ide/piix.c b/hw/ide/piix.c index b402a936362b..b9860e35a5c4 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -164,30 +164,29 @@ static void pci_piix_ide_realize(PCIDevice *dev, Erro= r **errp) int pci_piix3_xen_ide_unplug(DeviceState *dev, bool aux) { PCIIDEState *pci_ide; - DriveInfo *di; int i; IDEDevice *idedev; + IDEBus *idebus; + BlockBackend *blk; =20 pci_ide =3D PCI_IDE(dev); =20 for (i =3D aux ? 1 : 0; i < 4; i++) { - di =3D drive_get_by_index(IF_IDE, i); - if (di !=3D NULL && !di->media_cd) { - BlockBackend *blk =3D blk_by_legacy_dinfo(di); - DeviceState *ds =3D blk_get_attached_dev(blk); + idebus =3D &pci_ide->bus[i / 2]; + blk =3D idebus->ifs[i % 2].blk; =20 - blk_drain(blk); - blk_flush(blk); - - if (ds) { - blk_detach_dev(blk, ds); - } - pci_ide->bus[di->bus].ifs[di->unit].blk =3D NULL; + if (blk && idebus->ifs[i % 2].drive_kind !=3D IDE_CD) { if (!(i % 2)) { - idedev =3D pci_ide->bus[di->bus].master; + idedev =3D idebus->master; } else { - idedev =3D pci_ide->bus[di->bus].slave; + idedev =3D idebus->slave; } + + blk_drain(blk); + blk_flush(blk); + + blk_detach_dev(blk, DEVICE(idedev)); + idebus->ifs[i % 2].blk =3D NULL; idedev->conf.blk =3D NULL; monitor_remove_blk(blk); blk_unref(blk); --=20 Anthony PERARD