Re: [libvirt] [PATCH] libvirt: lxc: Add Get/Set vcpus for lxc

2014-08-25 Thread Wang Rui
On 2014/8/22 17:50, Li Yang wrote:
 1.Add function to get vcpu count for lxc(vcpucount)
 2.Add function to set vcpu count for lxc(setvcpus)
 
 Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com
 ---
  src/lxc/lxc_driver.c |  159 
 ++
  1 files changed, 159 insertions(+), 0 deletions(-)

Does def-vcpus affect anything?
No matter how much vcpus I set in xml , it seems that the vcpu
count in container is equal to the host pcpu count.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] libvirt: lxc: Add Get/Set vcpus for lxc

2014-08-22 Thread Li Yang
1.Add function to get vcpu count for lxc(vcpucount)
2.Add function to set vcpu count for lxc(setvcpus)

Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com
---
 src/lxc/lxc_driver.c |  159 ++
 1 files changed, 159 insertions(+), 0 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 4741632..4df0738 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -5617,6 +5617,162 @@ lxcDomainGetMetadata(virDomainPtr dom,
 return ret;
 }
 
+static int
+lxcDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
+unsigned int flags)
+{
+virLXCDriverPtr driver = dom-conn-privateData;
+virDomainObjPtr vm = NULL;
+virDomainDefPtr persistentDef;
+int ret = -1;
+bool maximum;
+unsigned int maxvcpus = 0;
+virLXCDriverConfigPtr cfg = NULL;
+virCapsPtr caps = NULL;
+
+virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+  VIR_DOMAIN_AFFECT_CONFIG |
+  VIR_DOMAIN_VCPU_MAXIMUM |
+  VIR_DOMAIN_VCPU_GUEST, -1);
+
+if (!nvcpus || (unsigned short) nvcpus != nvcpus) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _(argument out of range: %d), nvcpus);
+return -1;
+}
+
+if (!(vm = lxcDomObjFromDomain(dom)))
+goto cleanup;
+
+cfg = virLXCDriverGetConfig(driver);
+
+if (virDomainSetVcpusFlagsEnsureACL(dom-conn, vm-def, flags)  0)
+goto cleanup;
+
+if (!(caps = virLXCDriverGetCapabilities(driver, false)))
+goto cleanup;
+
+maximum = (flags  VIR_DOMAIN_VCPU_MAXIMUM) != 0;
+flags = ~VIR_DOMAIN_VCPU_MAXIMUM;
+
+if (virDomainLiveConfigHelperMethod(caps, driver-xmlopt, vm, flags,
+persistentDef)  0)
+goto cleanup;
+
+/* MAXIMUM cannot be mixed with LIVE.  */
+if (maximum  (flags  VIR_DOMAIN_AFFECT_LIVE)) {
+virReportError(VIR_ERR_INVALID_ARG, %s,
+   _(cannot adjust maximum on running domain));
+goto cleanup;
+}
+
+if (flags  VIR_DOMAIN_AFFECT_LIVE)
+maxvcpus = vm-def-maxvcpus;
+if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
+if (!maxvcpus || maxvcpus  persistentDef-maxvcpus)
+maxvcpus = persistentDef-maxvcpus;
+}
+if (!maximum  nvcpus  maxvcpus) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _(requested vcpus is greater than max allowable
+  vcpus for the domain: %d  %d),
+   nvcpus, maxvcpus);
+goto cleanup;
+}
+
+if (flags  VIR_DOMAIN_VCPU_GUEST) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s,
+   _(changing of vCPU count isn't supported 
+ via guest agent));
+goto cleanup;
+} else {
+if (flags  VIR_DOMAIN_AFFECT_LIVE) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s,
+   _(Cannot hotplug vCPUS for LXC hypervisor));
+goto cleanup;
+}
+
+if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
+if (maximum) {
+persistentDef-maxvcpus = nvcpus;
+if (nvcpus  persistentDef-vcpus)
+persistentDef-vcpus = nvcpus;
+} else {
+persistentDef-vcpus = nvcpus;
+}
+
+if (virDomainSaveConfig(cfg-configDir, persistentDef)  0)
+goto cleanup;
+}
+}
+
+ret = 0;
+
+ cleanup:
+if (vm)
+virObjectUnlock(vm);
+virObjectUnref(caps);
+virObjectUnref(cfg);
+return ret;
+}
+
+
+static int
+lxcDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
+{
+return lxcDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_AFFECT_LIVE);
+}
+
+
+static int
+lxcDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
+{
+virLXCDriverPtr driver = dom-conn-privateData;
+virDomainObjPtr vm;
+virDomainDefPtr def;
+int ret = -1;
+virCapsPtr caps = NULL;
+
+virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+  VIR_DOMAIN_AFFECT_CONFIG |
+  VIR_DOMAIN_VCPU_MAXIMUM |
+  VIR_DOMAIN_VCPU_GUEST, -1);
+
+if (!(vm = lxcDomObjFromDomain(dom)))
+return -1;
+
+if (virDomainGetVcpusFlagsEnsureACL(dom-conn, vm-def, flags)  0)
+goto cleanup;
+
+if (!(caps = virLXCDriverGetCapabilities(driver, false)))
+goto cleanup;
+
+if (virDomainLiveConfigHelperMethod(caps, driver-xmlopt,
+vm, flags, def)  0)
+goto cleanup;
+
+if (flags  VIR_DOMAIN_AFFECT_LIVE)
+def = vm-def;
+
+if (flags  VIR_DOMAIN_VCPU_GUEST) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s,
+   _(vCPU count cannot be provided by the guest agent
+  for LXC hypervisor));
+goto cleanup;
+} else {
+if (flags  VIR_DOMAIN_VCPU_MAXIMUM)
+