From: Michal Privoznik Date: Wed, 24 Jun 2015 16:09:57 +0000 (+0200) Subject: qemuBuildMemoryBackendStr: Fix hugepages lookup process X-Git-Tag: v1.2.17-rc1~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8e9deb1d4c677eea7f22abef580ceb70765abae;p=thirdparty%2Flibvirt.git qemuBuildMemoryBackendStr: Fix hugepages lookup process https://bugzilla.redhat.com/show_bug.cgi?id=1196644 This function constructs the backend (host facing) part of the memory device. At the beginning, the configured hugepages are searched to find the best match for given guest NUMA node. Configured hugepages can have a @nodeset attribute to specify on which guest NUMA nodes should be the hugepages backing used. There is, however, one 'corner case'. Users may just tell 'use hugepages to back all the nodes'. In other words: Our code fails in this case. Well, since there's no @nodeset (nor any child element to ) we fail to lookup the default hugepage size to use. Signed-off-by: Michal Privoznik --- diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 99755f1b8f..f1b7411fc0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4778,23 +4778,28 @@ qemuBuildMemoryBackendStr(unsigned long long size, goto cleanup; } - /* Now lets see, if the huge page we want to use is even mounted - * and ready to use */ - for (i = 0; i < cfg->nhugetlbfs; i++) { - if (cfg->hugetlbfs[i].size == hugepage->size) - break; - } + if (hugepage->size) { + /* Now lets see, if the huge page we want to use is even mounted + * and ready to use */ + for (i = 0; i < cfg->nhugetlbfs; i++) { + if (cfg->hugetlbfs[i].size == hugepage->size) + break; + } - if (i == cfg->nhugetlbfs) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to find any usable hugetlbfs mount for %llu KiB"), - pagesize); - goto cleanup; - } + if (i == cfg->nhugetlbfs) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to find any usable hugetlbfs mount for %llu KiB"), + hugepage->size); + goto cleanup; + } - VIR_FREE(mem_path); - if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[i]))) - goto cleanup; + if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[i]))) + goto cleanup; + } else { + if (!(mem_path = qemuGetDefaultHugepath(cfg->hugetlbfs, + cfg->nhugetlbfs))) + goto cleanup; + } *backendType = "memory-backend-file"; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args new file mode 100644 index 0000000000..c47e09757f --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args @@ -0,0 +1,46 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=spice \ +/usr/bin/qemu-system-x86_64 \ +-S \ +-M pc-i440fx-2.3 \ +-cpu Haswell \ +-m 1024 \ +-smp 2 \ +-object memory-backend-file,id=ram-node0,prealloc=yes,\ +mem-path=/dev/hugepages2M/libvirt/qemu,size=1073741824 \ +-numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-rtc base=utc,driftfix=slew \ +-no-kvm-pit-reinjection \ +-global PIIX4_PM.disable_s3=1 \ +-global PIIX4_PM.disable_s4=1 \ +-boot c \ +-device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x6.0x7 \ +-device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x6 \ +-device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x6.0x1 \ +-device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x6.0x2 \ +-device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 \ +-drive file=/var/lib/libvirt/images/fedora.qcow2,if=none,id=drive-virtio-disk0 \ +-device virtio-blk-pci,bus=pci.0,addr=0x7,drive=drive-virtio-disk0,id=virtio-disk0 \ +-drive if=none,media=cdrom,id=drive-ide0-0-0 \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-serial pty \ +-chardev socket,id=charchannel0,\ +path=/var/lib/libvirt/qemu/channel/target/fedora.org.qemu.guest_agent.0,server,nowait \ +-device virtserialport,bus=virtio-serial0.0,nr=1,\ +chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.0 \ +-chardev spicevmc,id=charchannel1,name=vdagent \ +-device virtserialport,bus=virtio-serial0.0,nr=2,\ +chardev=charchannel1,id=channel1,name=com.redhat.spice.0 \ +-device usb-tablet,id=input0 \ +-spice port=0 \ +-vga qxl \ +-global qxl-vga.ram_size=67108864 \ +-global qxl-vga.vram_size=67108864 \ +-device intel-hda,id=sound0,bus=pci.0,addr=0x4 \ +-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \ +-chardev spicevmc,id=charredir0,name=usbredir \ +-device usb-redir,chardev=charredir0,id=redir0 \ +-chardev spicevmc,id=charredir1,name=usbredir \ +-device usb-redir,chardev=charredir1,id=redir1 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x8 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.xml new file mode 100644 index 0000000000..70a8835d3c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.xml @@ -0,0 +1,107 @@ + + fedora + 63840878-0deb-4095-97e6-fc444d9bc9fa + 1572863 + 1048576 + + + + 2 + + hvm + + + + + + + + + Haswell + + + + + + + + + + destroy + restart + restart + + + + + + /usr/bin/qemu-system-x86_64 + + + + +
+ + + + + +
+ + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + +
+ + + + + + + + + + +
+ + + +
+ + + + + + +
+ +