[PATCH 2/2] qemu: Support for Block Device IO Limits.

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

 



Implementation of iolimits for the qemu driver with
capability probing for block size attribute and
command line generation for block sizes.
Including testcase for qemuxml2argvtest.

Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c                       |   11 ++++++
 src/qemu/qemu_capabilities.h                       |    1 +
 src/qemu/qemu_command.c                            |    8 +++++
 tests/qemuhelptest.c                               |   12 +++++--
 .../qemuxml2argv-disk-iolimits.args                |    9 +++++
 .../qemuxml2argv-disk-iolimits.xml                 |   33 ++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |    3 ++
 7 files changed, 73 insertions(+), 4 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.xml

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 5472267..7b29a81 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -172,6 +172,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
               "bridge", /* 100 */
               "lsi",
               "virtio-scsi-pci",
+              "iolimits",
 
     );
 
@@ -1499,6 +1500,16 @@ qemuCapsParseDeviceStr(const char *str, virBitmapPtr flags)
         qemuCapsSet(flags, QEMU_CAPS_SCSI_CD);
     if (strstr(str, "ide-cd"))
         qemuCapsSet(flags, QEMU_CAPS_IDE_CD);
+    /*
+     * the iolimit detection is not really straight forward:
+     * in qemu this is a capability of the block layer, if
+     * present any of -device scsi-disk, virtio-blk-*, ...
+     * will offer to specify logical and physical block size
+     * and other properties...
+     */
+    if (strstr(str, ".logical_block_size") &&
+        strstr(str, ".physical_block_size"))
+        qemuCapsSet(flags, QEMU_CAPS_IOLIMITS);
 
     return 0;
 }
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index d606890..b0e41ba 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -138,6 +138,7 @@ enum qemuCapsFlags {
     QEMU_CAPS_NETDEV_BRIDGE      = 100, /* bridge helper support */
     QEMU_CAPS_SCSI_LSI           = 101, /* -device lsi */
     QEMU_CAPS_VIRTIO_SCSI_PCI    = 102, /* -device virtio-scsi-pci */
+    QEMU_CAPS_IOLIMITS           = 103, /* -device ...logical_block_size & co */
 
     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 8c32a4d..f2dab2f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2637,6 +2637,14 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
     virBufferAsprintf(&opt, ",id=%s", disk->info.alias);
     if (bootindex && qemuCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
         virBufferAsprintf(&opt, ",bootindex=%d", bootindex);
+    if (qemuCapsGet(qemuCaps, QEMU_CAPS_IOLIMITS)) {
+        if (disk->iolimits.logical_block_size > 0)
+            virBufferAsprintf(&opt, ",logical_block_size=%u",
+                              disk->iolimits.logical_block_size);
+        if (disk->iolimits.physical_block_size > 0)
+            virBufferAsprintf(&opt, ",physical_block_size=%u",
+                              disk->iolimits.physical_block_size);
+    }
 
     if (virBufferError(&opt)) {
         virReportOOMError();
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index 2d15c94..a391edd 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -540,7 +540,8 @@ mymain(void)
             QEMU_CAPS_NO_ACPI,
             QEMU_CAPS_VIRTIO_BLK_SCSI,
             QEMU_CAPS_VIRTIO_BLK_SG_IO,
-            QEMU_CAPS_CPU_HOST);
+            QEMU_CAPS_CPU_HOST,
+            QEMU_CAPS_IOLIMITS);
     DO_TEST("qemu-kvm-0.12.1.2-rhel62-beta", 12001, 1, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -607,7 +608,8 @@ mymain(void)
             QEMU_CAPS_VIRTIO_BLK_SG_IO,
             QEMU_CAPS_DRIVE_COPY_ON_READ,
             QEMU_CAPS_CPU_HOST,
-            QEMU_CAPS_SCSI_CD);
+            QEMU_CAPS_SCSI_CD,
+            QEMU_CAPS_IOLIMITS);
     DO_TEST("qemu-1.0", 1000000, 0, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -679,7 +681,8 @@ mymain(void)
             QEMU_CAPS_SCSI_BLOCK,
             QEMU_CAPS_SCSI_CD,
             QEMU_CAPS_IDE_CD,
-            QEMU_CAPS_SCSI_LSI);
+            QEMU_CAPS_SCSI_LSI,
+            QEMU_CAPS_IOLIMITS);
     DO_TEST("qemu-1.1.0", 1001000, 0, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -759,7 +762,8 @@ mymain(void)
             QEMU_CAPS_NEC_USB_XHCI,
             QEMU_CAPS_NETDEV_BRIDGE,
             QEMU_CAPS_SCSI_LSI,
-            QEMU_CAPS_VIRTIO_SCSI_PCI);
+            QEMU_CAPS_VIRTIO_SCSI_PCI,
+            QEMU_CAPS_IOLIMITS);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.args
new file mode 100644
index 0000000..5fb1367
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.args
@@ -0,0 +1,9 @@
+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,\
+logical_block_size=512,physical_block_size=512 \
+-usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.xml
new file mode 100644
index 0000000..440984b
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.xml
@@ -0,0 +1,33 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>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'/>
+      <iolimits logical_block_size='512' physical_block_size='512'/>
+    </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 71513fb..cc5b2c1 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -789,6 +789,9 @@ mymain(void)
             QEMU_CAPS_IDE_CD);
 
     DO_TEST("disk-geometry", QEMU_CAPS_DRIVE);
+    DO_TEST("disk-iolimits",
+            QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+            QEMU_CAPS_IDE_CD, QEMU_CAPS_IOLIMITS);
 
     VIR_FREE(driver.stateDir);
     virCapabilitiesFree(driver.caps);
-- 
1.7.0.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]