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

[libvirt] [PATCH v2] qemu: Split ide-drive into ide-cd and ide-hd



A "ide-drive" device can be either a hard disk or a CD-ROM,
if there is ",media=cdrom" specified for the backend, it's
a CD-ROM, otherwise it's a hard disk.

Upstream qemu splitted "ide-drive" into "ide-hd" and "ide-cd"
since commit 1f56e32, and ",media=cdrom" is not required for
ide-cd anymore. "ide-drive" is still supported for backwards
compatibility, but no doubt we should go foward.

---
No changes between v1 and v2, just rebasing.
---
 src/qemu/qemu_capabilities.c                       |    3 ++
 src/qemu/qemu_capabilities.h                       |    1 +
 src/qemu/qemu_command.c                            |   25 ++++++++++++++-
 tests/qemuhelptest.c                               |    3 +-
 .../qemuxml2argv-disk-ide-drive-split.args         |    8 +++++
 .../qemuxml2argv-disk-ide-drive-split.xml          |   32 ++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |    3 ++
 7 files changed, 72 insertions(+), 3 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-drive-split.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-drive-split.xml

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 4e22f3e8..3d1fb43 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -160,6 +160,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
               "block-job-sync", /* 90 */
               "block-job-async",
               "scsi-cd",
+              "ide-cd",
     );
 
 struct qemu_feature_flags {
@@ -1454,6 +1455,8 @@ qemuCapsParseDeviceStr(const char *str, virBitmapPtr flags)
         qemuCapsSet(flags, QEMU_CAPS_SCSI_BLOCK);
     if (strstr(str, "scsi-cd"))
         qemuCapsSet(flags, QEMU_CAPS_SCSI_CD);
+    if (strstr(str, "ide-cd"))
+        qemuCapsSet(flags, QEMU_CAPS_IDE_CD);
 
     return 0;
 }
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 2aba502..7279cdb 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -127,6 +127,7 @@ enum qemuCapsFlags {
     QEMU_CAPS_BLOCKJOB_SYNC      = 90, /* RHEL 6.2 block_job_cancel */
     QEMU_CAPS_BLOCKJOB_ASYNC     = 91, /* qemu 1.1 block-job-cancel */
     QEMU_CAPS_SCSI_CD            = 92, /* -device scsi-cd */
+    QEMU_CAPS_IDE_CD             = 93, /* -device ide-cd */
 
     QEMU_CAPS_LAST,                   /* this must always be the last item */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ff82b26..26f691f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1982,6 +1982,9 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
         if ((disk->bus == VIR_DOMAIN_DISK_BUS_SCSI)) {
             if (!qemuCapsGet(qemuCaps, QEMU_CAPS_SCSI_CD))
                 virBufferAddLit(&opt, ",media=cdrom");
+        } else if (disk->bus == VIR_DOMAIN_DISK_BUS_IDE) {
+            if (!qemuCapsGet(qemuCaps, QEMU_CAPS_IDE_CD))
+                virBufferAddLit(&opt, ",media=cdrom");
         } else {
             virBufferAddLit(&opt, ",media=cdrom");
         }
@@ -2205,7 +2208,16 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
                             _("target must be 0 for ide controller"));
             goto error;
         }
-        virBufferAddLit(&opt, "ide-drive");
+
+        if (qemuCapsGet(qemuCaps, QEMU_CAPS_IDE_CD)) {
+            if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+                virBufferAddLit(&opt, "ide-cd");
+            else
+                virBufferAddLit(&opt, "ide-hd");
+        } else {
+            virBufferAddLit(&opt, "ide-drive");
+        }
+
         virBufferAsprintf(&opt, ",bus=ide.%d,unit=%d",
                           disk->info.addr.drive.bus,
                           disk->info.addr.drive.unit);
@@ -2301,7 +2313,16 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
                             _("target must be 0 for ide controller"));
             goto error;
         }
-        virBufferAddLit(&opt, "ide-drive");
+
+        if (qemuCapsGet(qemuCaps, QEMU_CAPS_IDE_CD)) {
+            if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+                virBufferAddLit(&opt, "ide-cd");
+            else
+                virBufferAddLit(&opt, "ide-hd");
+        } else {
+            virBufferAddLit(&opt, "ide-drive");
+        }
+
         virBufferAsprintf(&opt, ",bus=ahci%d.%d",
                           disk->info.addr.drive.controller,
                           disk->info.addr.drive.unit);
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index a01c389..d23b35a 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -676,7 +676,8 @@ mymain(void)
             QEMU_CAPS_CPU_HOST,
             QEMU_CAPS_FSDEV_WRITEOUT,
             QEMU_CAPS_SCSI_BLOCK,
-            QEMU_CAPS_SCSI_CD);
+            QEMU_CAPS_SCSI_CD,
+            QEMU_CAPS_IDE_CD);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-drive-split.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-drive-split.args
new file mode 100644
index 0000000..e24490d
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-drive-split.args
@@ -0,0 +1,8 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \
+/usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults \
+-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \
+-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-1 \
+-device ide-cd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \
+-drive file=/tmp/idedisk.img,if=none,id=drive-ide0-0-2 \
+-device ide-hd,bus=ide.0,unit=2,drive=drive-ide0-0-2,id=ide0-0-2 \
+-usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-drive-split.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-drive-split.xml
new file mode 100644
index 0000000..b965677
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-drive-split.xml
@@ -0,0 +1,32 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='cdrom'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <source file='/tmp/idedisk.img'/>
+      <target dev='hdc' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='2'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='ide' index='1'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index cc1ac44..ee7a8e1 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -758,6 +758,9 @@ mymain(void)
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
     DO_TEST("pseries-vio-address-clash", true, QEMU_CAPS_DRIVE,
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+    DO_TEST("disk-ide-drive-split", false,
+            QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+            QEMU_CAPS_IDE_CD);
 
     VIR_FREE(driver.stateDir);
     virCapabilitiesFree(driver.caps);
-- 
1.7.7.3


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