From: J.B. Joret <jb(a)linux.vnet.ibm.com>
Qemu command line generation for geometry override and testcases.
V2 Changes: squashed qemu code and testcases.
V3 Changes: use virReportError.
V4 Changes: rebase
V5 Changes: Fixed test invocation for geometry.
Signed-off-by: J.B. Joret <jb(a)linux.vnet.ibm.com>
Signed-off-by: Viktor Mihajlovski <mihajlov(a)linux.vnet.ibm.com>
Signed-off-by: Viktor Mihajlovski <mihajlov(a)linux.vnet.ibm.com>
---
src/qemu/qemu_command.c | 59 ++++++++++++++++++++
.../qemuxml2argv-disk-geometry.args | 4 +
.../qemuxml2argv-disk-geometry.xml | 26 +++++++++
tests/qemuxml2argvtest.c | 2 +
4 files changed, 91 insertions(+), 0 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.xml
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9383530..cc44015 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2073,6 +2073,8 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
+ const char *trans =
+ virDomainDiskGeometryTransTypeToString(disk->geometry.trans);
int idx = virDiskNameToIndex(disk->dst);
int busid = -1, unitid = -1;
@@ -2275,6 +2277,24 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
disk->type != VIR_DOMAIN_DISK_TYPE_DIR &&
qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_FORMAT))
virBufferAsprintf(&opt, ",format=%s", disk->driverType);
+
+ /* generate geometry command string*/
+ if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK ||
+ disk->type == VIR_DOMAIN_DISK_TYPE_FILE) {
+ if (disk->geometry.cylinders > 0 &&
+ disk->geometry.heads > 0 &&
+ disk->geometry.sectors > 0) {
+
+ virBufferAsprintf(&opt, ",cyls=%u,heads=%u,secs=%u",
+ disk->geometry.cylinders,
+ disk->geometry.heads,
+ disk->geometry.sectors);
+
+ if (disk->geometry.trans != VIR_DOMAIN_DISK_TRANS_DEFAULT)
+ virBufferEscapeString(&opt, ",trans=%s", trans);
+ }
+ }
+
if (disk->serial &&
qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_SERIAL)) {
if (qemuSafeSerialParamValue(disk->serial) < 0)
@@ -6691,6 +6711,7 @@ qemuParseCommandLineDisk(virCapsPtr caps,
int idx = -1;
int busid = -1;
int unitid = -1;
+ int trans = VIR_DOMAIN_DISK_TRANS_DEFAULT;
if ((nkeywords = qemuParseKeywords(val,
&keywords,
@@ -6895,6 +6916,44 @@ qemuParseCommandLineDisk(virCapsPtr caps,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse io mode '%s'"),
values[i]);
}
+ } else if (STREQ(keywords[i], "cyls")) {
+ if (virStrToLong_ui(values[i], NULL, 10,
+ &(def->geometry.cylinders)) < 0) {
+ virDomainDiskDefFree(def);
+ def = NULL;
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot parse cylinders value'%s'"),
+ values[i]);
+ }
+ } else if (STREQ(keywords[i], "heads")) {
+ if (virStrToLong_ui(values[i], NULL, 10,
+ &(def->geometry.heads)) < 0) {
+ virDomainDiskDefFree(def);
+ def = NULL;
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot parse heads value'%s'"),
+ values[i]);
+ }
+ } else if (STREQ(keywords[i], "secs")) {
+ if (virStrToLong_ui(values[i], NULL, 10,
+ &(def->geometry.sectors)) < 0) {
+ virDomainDiskDefFree(def);
+ def = NULL;
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot parse sectors value'%s'"),
+ values[i]);
+ }
+ } else if (STREQ(keywords[i], "trans")) {
+ def->geometry.trans =
+ virDomainDiskGeometryTransTypeFromString(values[i]);
+ if ((trans < VIR_DOMAIN_DISK_TRANS_DEFAULT) ||
+ (trans >= VIR_DOMAIN_DISK_TRANS_LAST)) {
+ virDomainDiskDefFree(def);
+ def = NULL;
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot parse translation
value'%s'"),
+ values[i]);
+ }
}
}
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args
b/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args
new file mode 100644
index 0000000..7cd6650
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
+pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
+-no-acpi -boot c -drive
file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0,cyls=16383,heads=16,secs=63,trans=lba \
+-net none -serial none -parallel none -usb
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.xml
b/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.xml
new file mode 100644
index 0000000..f0cf4ae
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.xml
@@ -0,0 +1,26 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory>219136</memory>
+ <currentMemory>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='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <geometry cyls='16383' heads='16' secs='63'
trans='lba'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0'
unit='0'/>
+ </disk>
+ <controller type='ide' index='0'/>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index f8d8db5..71513fb 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -788,6 +788,8 @@ mymain(void)
QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
QEMU_CAPS_IDE_CD);
+ DO_TEST("disk-geometry", QEMU_CAPS_DRIVE);
+
VIR_FREE(driver.stateDir);
virCapabilitiesFree(driver.caps);
VIR_FREE(map);
--
1.7.0.4