I removed a needless part from the former patch.
Add check the maxmum of virtual CPU.
Signed-off-by: Masayuki Sunou <fj1826dm(a)aa.jp.fujitsu.com>
Thanks
-------------------------------------------------------------------------------
Index: libvirt/include/libvirt/libvirt.h
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h,v
retrieving revision 1.38
diff -u -p -r1.38 libvirt.h
--- libvirt/include/libvirt/libvirt.h 23 Feb 2007 08:51:30 -0000 1.38
+++ libvirt/include/libvirt/libvirt.h 5 Mar 2007 05:58:32 -0000
@@ -310,6 +310,8 @@ int virDomainSetMaxMemory (virDomainPt
unsigned long memory);
int virDomainSetMemory (virDomainPtr domain,
unsigned long memory);
+int virDomainGetMaxVcpus (virDomainPtr domain);
+
/*
* XML domain description
*/
Index: libvirt/include/libvirt/libvirt.h.in
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h.in,v
retrieving revision 1.23
diff -u -p -r1.23 libvirt.h.in
--- libvirt/include/libvirt/libvirt.h.in 23 Feb 2007 08:51:30 -0000 1.23
+++ libvirt/include/libvirt/libvirt.h.in 5 Mar 2007 05:58:33 -0000
@@ -310,6 +310,8 @@ int virDomainSetMaxMemory (virDomainPt
unsigned long memory);
int virDomainSetMemory (virDomainPtr domain,
unsigned long memory);
+int virDomainGetMaxVcpus (virDomainPtr domain);
+
/*
* XML domain description
*/
Index: libvirt/src/driver.h
===================================================================
RCS file: /data/cvs/libvirt/src/driver.h,v
retrieving revision 1.21
diff -u -p -r1.21 driver.h
--- libvirt/src/driver.h 23 Feb 2007 08:51:30 -0000 1.21
+++ libvirt/src/driver.h 5 Mar 2007 05:58:33 -0000
@@ -129,6 +129,8 @@ typedef int
unsigned char *cpumaps,
int maplen);
typedef int
+ (*virDrvDomainGetMaxVcpus) (virDomainPtr domain);
+typedef int
(*virDrvDomainAttachDevice) (virDomainPtr domain,
char *xml);
typedef int
@@ -181,6 +183,7 @@ struct _virDriver {
virDrvDomainSetVcpus domainSetVcpus;
virDrvDomainPinVcpu domainPinVcpu;
virDrvDomainGetVcpus domainGetVcpus;
+ virDrvDomainGetMaxVcpus domainGetMaxVcpus;
virDrvDomainDumpXML domainDumpXML;
virDrvListDefinedDomains listDefinedDomains;
virDrvNumOfDefinedDomains numOfDefinedDomains;
Index: libvirt/src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.58
diff -u -p -r1.58 libvirt.c
--- libvirt/src/libvirt.c 23 Feb 2007 08:51:30 -0000 1.58
+++ libvirt/src/libvirt.c 5 Mar 2007 05:58:36 -0000
@@ -2110,6 +2110,40 @@ virDomainGetVcpus(virDomainPtr domain, v
}
/**
+ * virDomainGetMaxVcpus:
+ * @domain: pointer to domain object
+ *
+ * Returns the maximum of virtual CPU of Domain.
+ *
+ * Returns the maximum of virtual CPU or 0 in case of error.
+ */
+int
+virDomainGetMaxVcpus(virDomainPtr domain) {
+ int i;
+ int ret = 0;
+ virConnectPtr conn;
+
+ if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+ virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+ return (0);
+ }
+
+ conn = domain->conn;
+
+ for (i = 0;i < conn->nb_drivers;i++) {
+ if ((conn->drivers[i] != NULL) &&
+ (conn->drivers[i]->domainGetMaxVcpus != NULL)) {
+ ret = conn->drivers[i]->domainGetMaxVcpus(domain);
+ if (ret != 0)
+ return(ret);
+ }
+ }
+ virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return (-1);
+}
+
+
+/**
* virDomainAttachDevice:
* @domain: pointer to domain object
* @xml: pointer to XML description of one device
Index: libvirt/src/libvirt_sym.version
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt_sym.version,v
retrieving revision 1.16
diff -u -p -r1.16 libvirt_sym.version
--- libvirt/src/libvirt_sym.version 23 Feb 2007 08:51:30 -0000 1.16
+++ libvirt/src/libvirt_sym.version 5 Mar 2007 05:58:36 -0000
@@ -56,6 +56,7 @@
virDomainSetVcpus;
virDomainPinVcpu;
virDomainGetVcpus;
+ virDomainGetMaxVcpus;
virDomainAttachDevice;
virDomainDetachDevice;
Index: libvirt/src/proxy_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/proxy_internal.c,v
retrieving revision 1.22
diff -u -p -r1.22 proxy_internal.c
--- libvirt/src/proxy_internal.c 23 Feb 2007 08:51:30 -0000 1.22
+++ libvirt/src/proxy_internal.c 5 Mar 2007 05:58:37 -0000
@@ -73,6 +73,7 @@ static virDriver xenProxyDriver = {
NULL, /* domainSetVcpus */
NULL, /* domainPinVcpu */
NULL, /* domainGetVcpus */
+ NULL, /* domainGetMaxVcpus */
xenProxyDomainDumpXML, /* domainDumpXML */
NULL, /* listDefinedDomains */
NULL, /* numOfDefinedDomains */
Index: libvirt/src/qemu_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_internal.c,v
retrieving revision 1.12
diff -u -p -r1.12 qemu_internal.c
--- libvirt/src/qemu_internal.c 23 Feb 2007 12:46:35 -0000 1.12
+++ libvirt/src/qemu_internal.c 5 Mar 2007 05:58:38 -0000
@@ -1190,6 +1190,7 @@ static virDriver qemuDriver = {
NULL, /* domainSetVcpus */
NULL, /* domainPinVcpu */
NULL, /* domainGetVcpus */
+ NULL, /* domainGetMaxVcpus */
qemuDomainDumpXML, /* domainDumpXML */
qemuListDefinedDomains, /* listDomains */
qemuNumOfDefinedDomains, /* numOfDomains */
Index: libvirt/src/test.c
===================================================================
RCS file: /data/cvs/libvirt/src/test.c,v
retrieving revision 1.20
diff -u -p -r1.20 test.c
--- libvirt/src/test.c 23 Feb 2007 08:51:30 -0000 1.20
+++ libvirt/src/test.c 5 Mar 2007 05:58:38 -0000
@@ -117,6 +117,7 @@ static virDriver testDriver = {
testSetVcpus, /* domainSetVcpus */
NULL, /* domainPinVcpu */
NULL, /* domainGetVcpus */
+ NULL, /* domainGetMaxVcpus */
testDomainDumpXML, /* domainDumpXML */
testListDefinedDomains, /* listDefinedDomains */
testNumOfDefinedDomains, /* numOfDefinedDomains */
Index: libvirt/src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.58
diff -u -p -r1.58 virsh.c
--- libvirt/src/virsh.c 2 Mar 2007 14:22:33 -0000 1.58
+++ libvirt/src/virsh.c 5 Mar 2007 05:58:41 -0000
@@ -1383,6 +1383,7 @@ cmdSetvcpus(vshControl * ctl, vshCmd * c
{
virDomainPtr dom;
int count;
+ int maxcpu;
int ret = TRUE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
@@ -1397,6 +1398,18 @@ cmdSetvcpus(vshControl * ctl, vshCmd * c
return FALSE;
}
+ maxcpu = virDomainGetMaxVcpus(dom);
+ if (!maxcpu) {
+ virDomainFree(dom);
+ return FALSE;
+ }
+
+ if (count > maxcpu) {
+ vshError(ctl, FALSE, _("Too many virtual CPU's."));
+ virDomainFree(dom);
+ return FALSE;
+ }
+
if (virDomainSetVcpus(dom, count) != 0) {
ret = FALSE;
}
Index: libvirt/src/xen_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.c,v
retrieving revision 1.58
diff -u -p -r1.58 xen_internal.c
--- libvirt/src/xen_internal.c 23 Feb 2007 08:51:30 -0000 1.58
+++ libvirt/src/xen_internal.c 5 Mar 2007 05:58:42 -0000
@@ -446,6 +446,7 @@ static virDriver xenHypervisorDriver = {
xenHypervisorSetVcpus, /* domainSetVcpus */
xenHypervisorPinVcpu, /* domainPinVcpu */
xenHypervisorGetVcpus, /* domainGetVcpus */
+ xenHypervisorGetVcpuMax, /* domainGetMaxVcpus */
NULL, /* domainDumpXML */
NULL, /* listDefinedDomains */
NULL, /* numOfDefinedDomains */
@@ -1824,6 +1825,17 @@ xenHypervisorGetVcpus(virDomainPtr domai
}
#endif
+/**
+ * xend_get_cpu_max:
+ *
+ * Returns the maximum of CPU defined by Xen.
+ */
+int
+xenHypervisorGetVcpuMax(virDomainPtr domain)
+{
+ return MAX_VIRT_CPUS;
+}
+
/*
* Local variables:
* indent-tabs-mode: nil
Index: libvirt/src/xen_internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.h,v
retrieving revision 1.14
diff -u -p -r1.14 xen_internal.h
--- libvirt/src/xen_internal.h 4 Aug 2006 10:41:05 -0000 1.14
+++ libvirt/src/xen_internal.h 5 Mar 2007 05:58:42 -0000
@@ -55,6 +55,7 @@ int xenHypervisorGetVcpus (virDomainPtr
int maxinfo,
unsigned char *cpumaps,
int maplen);
+int xenHypervisorGetVcpuMax (virDomainPtr domain);
#ifdef __cplusplus
}
Index: libvirt/src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.97
diff -u -p -r1.97 xend_internal.c
--- libvirt/src/xend_internal.c 2 Mar 2007 20:19:08 -0000 1.97
+++ libvirt/src/xend_internal.c 5 Mar 2007 05:58:44 -0000
@@ -89,6 +89,7 @@ static virDriver xenDaemonDriver = {
xenDaemonDomainSetVcpus, /* domainSetVcpus */
xenDaemonDomainPinVcpu, /* domainPinVcpu */
xenDaemonDomainGetVcpus, /* domainGetVcpus */
+ NULL, /* domainGetMaxVcpus */
xenDaemonDomainDumpXML, /* domainDumpXML */
xenDaemonListDefinedDomains, /* listDefinedDomains */
xenDaemonNumOfDefinedDomains, /* numOfDefinedDomains */
Index: libvirt/src/xm_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xm_internal.c,v
retrieving revision 1.14
diff -u -p -r1.14 xm_internal.c
--- libvirt/src/xm_internal.c 23 Feb 2007 08:51:30 -0000 1.14
+++ libvirt/src/xm_internal.c 5 Mar 2007 05:58:46 -0000
@@ -98,6 +98,7 @@ static virDriver xenXMDriver = {
xenXMDomainSetVcpus, /* domainSetVcpus */
NULL, /* domainPinVcpu */
NULL, /* domainGetVcpus */
+ NULL, /* domainGetMaxVcpus */
xenXMDomainDumpXML, /* domainDumpXML */
xenXMListDefinedDomains, /* listDefinedDomains */
xenXMNumOfDefinedDomains, /* numOfDefinedDomains */
Index: libvirt/src/xs_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xs_internal.c,v
retrieving revision 1.32
diff -u -p -r1.32 xs_internal.c
--- libvirt/src/xs_internal.c 23 Feb 2007 08:51:30 -0000 1.32
+++ libvirt/src/xs_internal.c 5 Mar 2007 05:58:47 -0000
@@ -67,6 +67,7 @@ static virDriver xenStoreDriver = {
NULL, /* domainSetVcpus */
NULL, /* domainPinVcpu */
NULL, /* domainGetVcpus */
+ NULL, /* domainGetMaxVcpus */
NULL, /* domainDumpXML */
NULL, /* listDefinedDomains */
NULL, /* numOfDefinedDomains */
-------------------------------------------------------------------------------
In message <20070302123124.GA1660(a)redhat.com>
"Re: [Libvir] [PATCH] check the maximum of virtual CPU"
""Daniel P. Berrange" <berrange(a)redhat.com>" wrote:
On Fri, Mar 02, 2007 at 09:26:03PM +0900, Atsushi SAKAI wrote:
> Hi, Dan
>
> Please omit follwoing code from Masayuki's patch.
> It reverses Mizushima's
Yes, no problem - noticed that already.
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules:
http://search.cpan.org/~danberr/ -=|
|=- Projects:
http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|