qemu: parse: Handle suffixes for -m memory

According to QEMU docs, the '-m' option for specifying RAM is by default
in MiB, and a suffix of "M" or "G" may be passed for values in MiB and
GiB respectively. This commit adds support and a test for the same.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=812295

Signed-off-by: Nishith Shah <nishithshah.2211@gmail.com>
This commit is contained in:
Nishith Shah 2016-05-20 07:09:03 +00:00 committed by Cole Robinson
parent 30677a78ab
commit 701b0f1867
4 changed files with 69 additions and 2 deletions

View File

@ -1645,8 +1645,15 @@ qemuParseCommandLineMem(virDomainDefPtr dom,
return -1;
}
virDomainDefSetMemoryTotal(dom, mem * 1024);
dom->mem.cur_balloon = mem * 1024;
if (virScaleInteger(&mem, end, 1024*1024, ULLONG_MAX) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot scale memory: %s"),
virGetLastErrorMessage());
return -1;
}
virDomainDefSetMemoryTotal(dom, mem / 1024);
dom->mem.cur_balloon = mem / 1024;
return 0;
}

View File

@ -0,0 +1,22 @@
LC_ALL=C \
PATH=/bin \
HOME=/home/test \
USER=test \
LOGNAME=test \
QEMU_AUDIO_DRV=none \
/usr/bin/qemu \
-name QEMUGuest1 \
-S \
-M pc \
-m 2G \
-smp 1,maxcpus=2,sockets=2,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
-nographic \
-monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi \
-boot c \
-usb \
-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=ide,bus=0,unit=0 \
-net none \
-serial none \
-parallel none

View File

@ -0,0 +1,37 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static' current='1'>2</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<cpu>
<topology sockets='2' cores='1' threads='1'/>
</cpu>
<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='raw'/>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<memballoon model='none'/>
</devices>
</domain>

View File

@ -263,6 +263,7 @@ mymain(void)
DO_TEST("hostdev-pci-address");
DO_TEST("mem-scale");
DO_TEST("smp");
DO_TEST("hyperv");