qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] ahci: add -drive support


From: Alexander Graf
Subject: [Qemu-devel] [PATCH] ahci: add -drive support
Date: Tue, 12 Jun 2012 11:59:43 +0200

We've had support for creating AHCI devices using -device for a while now,
but it's cumbersome to users. We really should provide an easier way for
them to leverage the power of AHCI!

So let's introduce a new if= option to -drive, bumping it en par with virtio.

Signed-off-by: Alexander Graf <address@hidden>
---
 blockdev.c      |   25 +++++++++++++++++++++++--
 blockdev.h      |    1 +
 qemu-options.hx |    7 ++++++-
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 622ecba..5405f6c 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -32,6 +32,7 @@ static const char *const if_name[IF_COUNT] = {
     [IF_SD] = "sd",
     [IF_VIRTIO] = "virtio",
     [IF_XEN] = "xen",
+    [IF_AHCI] = "ahci",
 };
 
 static const int if_max_devs[IF_COUNT] = {
@@ -519,7 +520,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
     } else {
         /* no id supplied -> create one */
         dinfo->id = g_malloc0(32);
-        if (type == IF_IDE || type == IF_SCSI)
+        if (type == IF_IDE || type == IF_SCSI || type == IF_AHCI)
             mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
         if (max_devs)
             snprintf(dinfo->id, 32, "%s%i%s%i",
@@ -549,6 +550,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
     case IF_IDE:
     case IF_SCSI:
     case IF_XEN:
+    case IF_AHCI:
     case IF_NONE:
         switch(media) {
        case MEDIA_DISK:
@@ -582,6 +584,25 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
     default:
         abort();
     }
+
+    if (type == IF_AHCI) {
+        static int ahci_bus = 0;
+        char devname[] = "ahciXXX";
+        char busname[] = "ahciXXX.0";
+        snprintf(devname, sizeof(devname), "ahci%d", ahci_bus);
+        snprintf(busname, sizeof(busname), "ahci%d.0", ahci_bus++);
+
+        /* add ahci host controller */
+        opts = qemu_opts_create(qemu_find_opts("device"), devname, 0, NULL);
+        qemu_opt_set(opts, "driver", "ich9-ahci");
+
+        /* and attach a single ata disk to its bus */
+        opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL);
+        qemu_opt_set(opts, "driver", "ide-drive");
+        qemu_opt_set(opts, "bus", busname);
+        qemu_opt_set(opts, "drive", dinfo->id);
+    }
+
     if (!file || !*file) {
         return dinfo;
     }
@@ -604,7 +625,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
         ro = 1;
     } else if (ro == 1) {
         if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY &&
-            type != IF_NONE && type != IF_PFLASH) {
+            type != IF_NONE && type != IF_PFLASH && type != IF_AHCI) {
             error_report("readonly not supported by this bus type");
             goto err;
         }
diff --git a/blockdev.h b/blockdev.h
index 260e16b..e14c1d5 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -23,6 +23,7 @@ typedef enum {
     IF_DEFAULT = -1,            /* for use with drive_add() only */
     IF_NONE,
     IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
+    IF_AHCI,
     IF_COUNT
 } BlockInterfaceType;
 
diff --git a/qemu-options.hx b/qemu-options.hx
index 8b66264..9527c51 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -160,7 +160,7 @@ Special files such as iSCSI devices can be specified using 
protocol
 specific URLs. See the section for "Device URL Syntax" for more information.
 @item address@hidden
 This option defines on which type on interface the drive is connected.
-Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio.
+Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio, ahci.
 @item address@hidden,address@hidden
 These options define where is connected the drive by defining the bus number 
and
 the unit id.
@@ -260,6 +260,11 @@ You can connect a SCSI disk with unit ID 6 on the bus #0:
 qemu-system-i386 -drive file=file,if=scsi,bus=0,unit=6
 @end example
 
+You can attach a SATA disk using AHCI:
address@hidden
+qemu-system-i386 -drive file=file,if=ahci
address@hidden example
+
 Instead of @option{-fda}, @option{-fdb}, you can use:
 @example
 qemu-system-i386 -drive file=file,index=0,if=floppy
-- 
1.6.0.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]