The qemu limit and host limit both should be considered for
the domain vcpu max limits.
Signed-off-by: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
---
docs/formatdomaincaps.html.in | 4 ++--
src/conf/domain_capabilities.c | 10 +++++++---
src/conf/domain_capabilities.h | 1 +
src/qemu/qemu_capabilities.c | 13 ++++++++++---
src/qemu/qemu_capabilities.h | 3 ++-
src/qemu/qemu_driver.c | 2 +-
tests/domaincapstest.c | 3 ++-
7 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/docs/formatdomaincaps.html.in b/docs/formatdomaincaps.html.in
index d5a8414..d28a5b6 100644
--- a/docs/formatdomaincaps.html.in
+++ b/docs/formatdomaincaps.html.in
@@ -86,14 +86,14 @@
<pre>
<domainCapabilities>
...
- <vcpu max='255'/>
+ <vcpu max='255' suggested='96'/>
...
</domainCapabilities>
</pre>
<dl>
<dt><code>vcpu</code></dt>
- <dd>The maximum number of supported virtual CPUs</dd>
+ <dd>The maximum number of supported virtual CPUs. The suggested attribute if
present, gives the recommended maximum vcpus for the KVM host.</dd>
</dl>
<h3><a name="elementsOSBIOS">BIOS
bootloader</a></h3>
diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index 1676f0e..452cad4 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -329,9 +329,13 @@ virDomainCapsFormatInternal(virBufferPtr buf,
virBufferAsprintf(buf, "<machine>%s</machine>\n",
caps->machine);
virBufferAsprintf(buf, "<arch>%s</arch>\n", arch_str);
- if (caps->maxvcpus)
- virBufferAsprintf(buf, "<vcpu max='%d'/>\n",
caps->maxvcpus);
-
+ if (caps->maxvcpus) {
+ if (!caps->suggestedvcpus)
+ virBufferAsprintf(buf, "<vcpu max='%d'/>\n",
caps->maxvcpus);
+ else
+ virBufferAsprintf(buf, "<vcpu max='%d'
suggested='%d'/>\n",
+ caps->maxvcpus, caps->suggestedvcpus);
+ }
virDomainCapsOSFormat(buf, &caps->os);
virBufferAddLit(buf, "<devices>\n");
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 492a9cf..f440436 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -112,6 +112,7 @@ struct _virDomainCaps {
/* Some machine specific info */
int maxvcpus;
+ int suggestedvcpus;
virDomainCapsOS os;
virDomainCapsDeviceDisk disk;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 1ef5937..df10aa8 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -38,6 +38,7 @@
#include "virbitmap.h"
#include "virnodesuspend.h"
#include "virnuma.h"
+#include "virhostcpu.h"
#include "qemu_monitor.h"
#include "virstring.h"
#include "qemu_hostdev.h"
@@ -4333,16 +4334,22 @@ int
virQEMUCapsFillDomainCaps(virDomainCapsPtr domCaps,
virQEMUCapsPtr qemuCaps,
virFirmwarePtr *firmwares,
- size_t nfirmwares)
+ size_t nfirmwares,
+ virDomainVirtType virttype)
{
virDomainCapsOSPtr os = &domCaps->os;
virDomainCapsDeviceDiskPtr disk = &domCaps->disk;
virDomainCapsDeviceHostdevPtr hostdev = &domCaps->hostdev;
virDomainCapsDeviceGraphicsPtr graphics = &domCaps->graphics;
virDomainCapsDeviceVideoPtr video = &domCaps->video;
- int maxvcpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, domCaps->machine);
+ int hostmaxvcpus = 0;
- domCaps->maxvcpus = maxvcpus;
+ domCaps->maxvcpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, domCaps->machine);
+ if (virttype == VIR_DOMAIN_VIRT_KVM) {
+ hostmaxvcpus = virHostCPUGetKVMVCPUs(VIR_HOSTCPU_KVM_MAXVCPUS);
+ domCaps->suggestedvcpus = virHostCPUGetKVMVCPUs(VIR_HOSTCPU_KVM_NR_VCPUS);
+ domCaps->maxvcpus = MIN(domCaps->maxvcpus, hostmaxvcpus);
+ }
if (virQEMUCapsFillDomainOSCaps(os, firmwares, nfirmwares) < 0 ||
virQEMUCapsFillDomainDeviceDiskCaps(qemuCaps,
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index f7ede4a..ffe07e5 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -494,6 +494,7 @@ int virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
int virQEMUCapsFillDomainCaps(virDomainCapsPtr domCaps,
virQEMUCapsPtr qemuCaps,
virFirmwarePtr *firmwares,
- size_t nfirmwares);
+ size_t nfirmwares,
+ virDomainVirtType virttype);
#endif /* __QEMU_CAPABILITIES_H__*/
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6b316a0..21aa053 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18485,7 +18485,7 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
goto cleanup;
if (virQEMUCapsFillDomainCaps(domCaps, qemuCaps,
- cfg->firmwares, cfg->nfirmwares) < 0)
+ cfg->firmwares, cfg->nfirmwares, virttype) <
0)
goto cleanup;
ret = virDomainCapsFormat(domCaps);
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index 9fb2c97..ea438e3 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -129,7 +129,8 @@ fillQemuCaps(virDomainCapsPtr domCaps,
if (virQEMUCapsFillDomainCaps(domCaps, qemuCaps,
cfg->firmwares,
- cfg->nfirmwares) < 0)
+ cfg->nfirmwares,
+ VIR_DOMAIN_VIRT_QEMU) < 0)
goto cleanup;
/* The function above tries to query host's KVM & VFIO capabilities by