Patchwork [2/2] ata_piix: defer disks to the Hyper-V drivers by default

login
register
mail settings
Submitter Andy Whitcroft
Date April 19, 2012, 2:33 p.m.
Message ID <1334845990-13418-3-git-send-email-apw@canonical.com>
Download mbox | patch
Permalink /patch/153792/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Andy Whitcroft - April 19, 2012, 2:33 p.m.
When we are hosted on a Microsoft Hyper-V hypervisor the guest disks
are exposed both via the Hyper-V paravirtualised drivers and via an
emulated SATA disk drive.  In this case we want to use the paravirtualised
drivers if we can as they are much more efficient.  Note that the Hyper-V
paravirtualised drivers only expose the virtual hard disk devices, the
CDROM/DVD devices must still be enumerated.

Mark the host controller ATA_HOST_IGNORE_ATA to prevent enumeration of
disk devices.

BugLink: http://bugs.launchpad.net/bugs/929545
BugLink: http://bugs.launchpad.net/bugs/942316
Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 drivers/ata/ata_piix.c |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
Sergei Shtylyov - April 19, 2012, 3:54 p.m.
Hello.

On 04/19/2012 06:33 PM, Andy Whitcroft wrote:

> When we are hosted on a Microsoft Hyper-V hypervisor the guest disks
> are exposed both via the Hyper-V paravirtualised drivers and via an
> emulated SATA disk drive.  In this case we want to use the paravirtualised
> drivers if we can as they are much more efficient.  Note that the Hyper-V
> paravirtualised drivers only expose the virtual hard disk devices, the
> CDROM/DVD devices must still be enumerated.

> Mark the host controller ATA_HOST_IGNORE_ATA to prevent enumeration of
> disk devices.

> BugLink: http://bugs.launchpad.net/bugs/929545
> BugLink: http://bugs.launchpad.net/bugs/942316
> Signed-off-by: Andy Whitcroft<apw@canonical.com>
> ---
>   drivers/ata/ata_piix.c |   36 ++++++++++++++++++++++++++++++++++++
>   1 file changed, 36 insertions(+)

> diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
> index 68013f9..c410ba9 100644
> --- a/drivers/ata/ata_piix.c
> +++ b/drivers/ata/ata_piix.c
> @@ -1552,6 +1552,39 @@ static bool piix_broken_system_poweroff(struct pci_dev *pdev)
>   	return false;
>   }
>
> +static int prefer_ms_hyperv = 1;
> +module_param(prefer_ms_hyperv, int, 0);
> +
> +static void piix_ignore_devices_quirk(struct ata_host *host)
> +{
> +#if defined(CONFIG_HYPERV_STORAGE) || defined(CONFIG_HYPERV_STORAGE_MODULE)

    You could instead use:

#if IS_ENABLED(CONFIG_HYPERV_STORAGE)

> +	static const struct dmi_system_id ignore_hyperv[] = {
> +		{
> +			/* On Hyper-V hypervisors the disks are exposed on
> +			 * both the emulated SATA controller and on the
> +			 * paravirtualised drivers.  The CD/DVD devices
> +			 * are only exposed on the emulated controller.
> +			 * Request we ignore ATA devices on this host.
> +			 */
> +			.ident = "Hyper-V Virtual Machine",
> +			.matches = {
> +				DMI_MATCH(DMI_SYS_VENDOR,
> +						"Microsoft Corporation"),
> +				DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"),
> +			},
> +		},
> +		{ }	/* terminate list */
> +	};
> +	const struct dmi_system_id *dmi = dmi_first_match(ignore_hyperv);
> +
> +	if (dmi&&  prefer_ms_hyperv) {
> +		host->flags |= ATA_HOST_IGNORE_ATA;
> +		dev_info(host->dev, "%s detected, SATA device ignore set\n",

    s/SATA/ATA/.

MBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Whitcroft - May 4, 2012, 9:15 p.m.
Add support for ignoring disks devices on specific host controllers to
libata.  Use this support to trigger us to ignore Hyper-V disk devices
on the emulated SATA device based on the system DMI information.

Fixes based on feedback Sergei Shtylyov, thanks.  Jeff I think this is
about done, any objections to merging?

Comments?

-apw

V5
  - switched to IS_ENABLED
  - fixed device type in device ignored messages

V4
  - only enable the quirk when the paravirtualised drivers are compiled
  - fix up the command line flag to disable this support

V3
  - switch detection method to DMI information

V2 
  - create a generic libata quirk
  - switch detection to piix_init_one

Andy Whitcroft (2):
  libata: add a host flag to ignore detected ATA devices
  ata_piix: defer disks to the Hyper-V drivers by default

 drivers/ata/ata_piix.c    |   20 ++++++++++++++++++++
 drivers/ata/libata-core.c |    7 +++++++
 include/linux/libata.h    |    1 +
 3 files changed, 28 insertions(+)

Patch

diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 68013f9..c410ba9 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -1552,6 +1552,39 @@  static bool piix_broken_system_poweroff(struct pci_dev *pdev)
 	return false;
 }
 
+static int prefer_ms_hyperv = 1;
+module_param(prefer_ms_hyperv, int, 0);
+
+static void piix_ignore_devices_quirk(struct ata_host *host)
+{
+#if defined(CONFIG_HYPERV_STORAGE) || defined(CONFIG_HYPERV_STORAGE_MODULE)
+	static const struct dmi_system_id ignore_hyperv[] = {
+		{
+			/* On Hyper-V hypervisors the disks are exposed on
+			 * both the emulated SATA controller and on the
+			 * paravirtualised drivers.  The CD/DVD devices
+			 * are only exposed on the emulated controller.
+			 * Request we ignore ATA devices on this host.
+			 */
+			.ident = "Hyper-V Virtual Machine",
+			.matches = {
+				DMI_MATCH(DMI_SYS_VENDOR,
+						"Microsoft Corporation"),
+				DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"),
+			},
+		},
+		{ }	/* terminate list */
+	};
+	const struct dmi_system_id *dmi = dmi_first_match(ignore_hyperv);
+
+	if (dmi && prefer_ms_hyperv) {
+		host->flags |= ATA_HOST_IGNORE_ATA;
+		dev_info(host->dev, "%s detected, SATA device ignore set\n",
+			dmi->ident);
+	}
+#endif
+}
+
 /**
  *	piix_init_one - Register PIIX ATA PCI device with kernel services
  *	@pdev: PCI device to register
@@ -1667,6 +1700,9 @@  static int __devinit piix_init_one(struct pci_dev *pdev,
 	}
 	host->flags |= ATA_HOST_PARALLEL_SCAN;
 
+	/* Allow hosts to specify device types to ignore when scanning. */
+	piix_ignore_devices_quirk(host);
+
 	pci_set_master(pdev);
 	return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht);
 }