提交 ad70b324 编写于 作者: D Daniel P. Berrange

Support QEMU disk format specification in XML

上级 5f0c7201
Fri Jan 23 16:20:03 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
* src/qemu_conf.c: Support driver format for setting disk
file types
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c,
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-fmt-qcow.args,
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-fmt-qcow.xml:
Add tests for <driver name='qemu' type='qcow2'/>
Fri Jan 23 17:13:47 +0100 2009 Jim Meyering <meyering@redhat.com>
.cvsignore: Add explicit list of generated files.
......
......@@ -48,6 +48,8 @@
#include "xml.h"
#include "nodeinfo.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
VIR_ENUM_DECL(virDomainDiskQEMUBus)
VIR_ENUM_IMPL(virDomainDiskQEMUBus, VIR_DOMAIN_DISK_BUS_LAST,
"ide",
......@@ -862,6 +864,18 @@ int qemudBuildCommandLine(virConnectPtr conn,
ADD_ARG_LIT(vm->def->os.bootloader);
}
for (i = 0 ; i < vm->def->ndisks ; i++) {
virDomainDiskDefPtr disk = vm->def->disks[i];
if (disk->driverName != NULL &&
!STREQ(disk->driverName, "qemu")) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("unsupported driver name '%s' for disk '%s'"),
disk->driverName, disk->src);
goto error;
}
}
/* If QEMU supports -drive param instead of old -hda, -hdb, -cdrom .. */
if (qemuCmdFlags & QEMUD_CMD_FLAG_DRIVE) {
int bootCD = 0, bootFloppy = 0, bootDisk = 0;
......@@ -884,8 +898,8 @@ int qemudBuildCommandLine(virConnectPtr conn,
}
for (i = 0 ; i < vm->def->ndisks ; i++) {
char opt[PATH_MAX];
const char *media = NULL;
virBuffer opt = VIR_BUFFER_INITIALIZER;
char *optstr;
int bootable = 0;
virDomainDiskDefPtr disk = vm->def->disks[i];
int idx = virDiskNameToIndex(disk->dst);
......@@ -912,7 +926,6 @@ int qemudBuildCommandLine(virConnectPtr conn,
case VIR_DOMAIN_DISK_DEVICE_CDROM:
bootable = bootCD;
bootCD = 0;
media = "media=cdrom,";
break;
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
bootable = bootFloppy;
......@@ -924,18 +937,28 @@ int qemudBuildCommandLine(virConnectPtr conn,
break;
}
snprintf(opt, PATH_MAX, "file=%s,if=%s,%sindex=%d%s%s",
disk->src ? disk->src : "", bus,
media ? media : "",
idx,
bootable &&
disk->device == VIR_DOMAIN_DISK_DEVICE_DISK
? ",boot=on" : "",
disk->shared && ! disk->readonly
? ",cache=off" : "");
virBufferVSprintf(&opt, "file=%s", disk->src ? disk->src : "");
virBufferVSprintf(&opt, ",if=%s", bus);
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
virBufferAddLit(&opt, ",media=cdrom");
virBufferVSprintf(&opt, ",index=%d", idx);
if (bootable &&
disk->device == VIR_DOMAIN_DISK_DEVICE_DISK)
virBufferAddLit(&opt, ",boot=on");
if (disk->shared && !disk->readonly)
virBufferAddLit(&opt, ",cache=off");
if (disk->driverType)
virBufferVSprintf(&opt, ",fmt=%s", disk->driverType);
if (virBufferError(&opt)) {
virReportOOMError(conn);
goto error;
}
optstr = virBufferContentAndReset(&opt);
ADD_ARG_LIT("-drive");
ADD_ARG_LIT(opt);
ADD_ARG(optstr);
}
} else {
for (i = 0 ; i < vm->def->ndisks ; i++) {
......
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor pty -pidfile /nowhere/QEMUGuest1.pid -no-acpi -boot c -drive file=/dev/HostVG/QEMUGuest1,if=ide,index=0,boot=on,fmt=qcow2 -drive file=/dev/HostVG/QEMUGuest2,if=ide,media=cdrom,index=2,fmt=raw -net none -serial none -parallel none -usb
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory>219200</memory>
<currentMemory>219200</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'>
<driver name='qemu' type='qcow2'/>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest2'/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>
</devices>
</domain>
......@@ -194,6 +194,8 @@ mymain(int argc, char **argv)
QEMUD_CMD_FLAG_DRIVE_BOOT);
DO_TEST("disk-drive-boot-cdrom", QEMUD_CMD_FLAG_DRIVE |
QEMUD_CMD_FLAG_DRIVE_BOOT);
DO_TEST("disk-drive-fmt-qcow", QEMUD_CMD_FLAG_DRIVE |
QEMUD_CMD_FLAG_DRIVE_BOOT);
DO_TEST("disk-usb", 0);
DO_TEST("graphics-vnc", 0);
DO_TEST("graphics-sdl", 0);
......
......@@ -97,6 +97,7 @@ mymain(int argc, char **argv)
DO_TEST("disk-many");
DO_TEST("disk-xenvbd");
DO_TEST("disk-usb");
DO_TEST("disk-drive-fmt-qcow");
DO_TEST("graphics-vnc");
DO_TEST("graphics-sdl");
DO_TEST("graphics-sdl-fullscreen");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册