mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
Added driver backends for ListDefinedDomains, NumOfDefinedDomains, DomainStart, DomainDefineXML, DomainUndefine & hooked up all related infrastructure
This commit is contained in:
parent
c0b1a946a6
commit
25726a0ff4
17
ChangeLog
17
ChangeLog
@ -1,3 +1,16 @@
|
||||
Tue Aug 29 23:48:43 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* src/driver.h: Defined new driver entry points for ListDefinedDomains,
|
||||
NumOfDefinedDomains, DomainStart, DomainUndefine, DomainDefineXML.
|
||||
* src/xen_internal.c, src/xend_internal.c, src/xs_internal.h,
|
||||
src/test.c, src/proxy_internal.c: Added NULL entries for new driver
|
||||
backend APIs.
|
||||
* src/libvirt.c: Hook up new driver entry points to corresponding
|
||||
public API.
|
||||
* src/libvirt_sym.version: Added virConnectNumOfDefinedDomains and
|
||||
previously missing virConnectListDefinedDomains
|
||||
* include/libvirt/libvirt.h: Added virConnectNumOfDefinedDomains
|
||||
|
||||
Tue Aug 29 23:48:43 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* src/conf.c: add missing entry point virConfGetValue()
|
||||
@ -17,10 +30,10 @@ Tue Aug 29 13:14:20 EDT 2006 Daniel Berrange <berrange@redhat.com>
|
||||
* src/xend_internal.c: Add handling of HTTP 500 error code
|
||||
which can be returned by XenD do indicate failure error when
|
||||
performing the requested operation (Identified by Pete Vetere).
|
||||
|
||||
|
||||
Tue Aug 29 15:41:46 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* python/libvir.c: Pete Vetere pointed out a bug in string cast
|
||||
* python/libvir.c: Pete Vetere pointed out a bug in string cast
|
||||
when handling errors in Python
|
||||
|
||||
Sat Aug 26 16:36:15 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
||||
|
@ -297,7 +297,8 @@ char * virDomainGetXMLDesc (virDomainPtr domain,
|
||||
virDomainPtr virDomainDefineXML (virConnectPtr conn,
|
||||
const char *xml);
|
||||
int virDomainUndefine (virDomainPtr domain);
|
||||
int virConnectListDefinedDomains(virConnectPtr conn,
|
||||
int virConnectNumOfDefinedDomains (virConnectPtr conn);
|
||||
int virConnectListDefinedDomains (virConnectPtr conn,
|
||||
const char **names,
|
||||
int maxnames);
|
||||
int virDomainCreate (virDomainPtr domain);
|
||||
|
@ -297,7 +297,8 @@ char * virDomainGetXMLDesc (virDomainPtr domain,
|
||||
virDomainPtr virDomainDefineXML (virConnectPtr conn,
|
||||
const char *xml);
|
||||
int virDomainUndefine (virDomainPtr domain);
|
||||
int virConnectListDefinedDomains(virConnectPtr conn,
|
||||
int virConnectNumOfDefinedDomains (virConnectPtr conn);
|
||||
int virConnectListDefinedDomains (virConnectPtr conn,
|
||||
const char **names,
|
||||
int maxnames);
|
||||
int virDomainCreate (virDomainPtr domain);
|
||||
|
18
src/driver.h
18
src/driver.h
@ -107,7 +107,18 @@ typedef int
|
||||
typedef char *
|
||||
(*virDrvDomainDumpXML) (virDomainPtr dom,
|
||||
int flags);
|
||||
|
||||
typedef int
|
||||
(*virDrvListDefinedDomains) (virConnectPtr conn,
|
||||
const char **names,
|
||||
int maxnames);
|
||||
typedef int
|
||||
(*virDrvNumOfDefinedDomains) (virConnectPtr conn);
|
||||
typedef int
|
||||
(*virDrvDomainCreate) (virDomainPtr dom);
|
||||
typedef virDomainPtr
|
||||
(*virDrvDomainDefineXML)(virConnectPtr conn, const char *xml);
|
||||
typedef int
|
||||
(*virDrvDomainUndefine) (virDomainPtr dom);
|
||||
typedef int
|
||||
(*virDrvDomainSetVcpus) (virDomainPtr domain,
|
||||
unsigned int nvcpus);
|
||||
@ -168,6 +179,11 @@ struct _virDriver {
|
||||
virDrvDomainPinVcpu domainPinVcpu;
|
||||
virDrvDomainGetVcpus domainGetVcpus;
|
||||
virDrvDomainDumpXML domainDumpXML;
|
||||
virDrvListDefinedDomains listDefinedDomains;
|
||||
virDrvNumOfDefinedDomains numOfDefinedDomains;
|
||||
virDrvDomainCreate domainCreate;
|
||||
virDrvDomainDefineXML domainDefineXML;
|
||||
virDrvDomainUndefine domainUndefine;
|
||||
};
|
||||
|
||||
|
||||
|
177
src/libvirt.c
177
src/libvirt.c
@ -1533,10 +1533,7 @@ virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) {
|
||||
virDomainPtr
|
||||
virDomainDefineXML(virConnectPtr conn, const char *xml) {
|
||||
virDomainPtr ret = NULL;
|
||||
const char *name = NULL;
|
||||
xmlDocPtr doc = NULL;
|
||||
xmlXPathObjectPtr obj = NULL;
|
||||
xmlXPathContextPtr ctxt = NULL;
|
||||
int i;
|
||||
|
||||
if (!VIR_IS_CONNECT(conn)) {
|
||||
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
||||
@ -1551,72 +1548,16 @@ virDomainDefineXML(virConnectPtr conn, const char *xml) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the XML description is at least well formed and extract the
|
||||
* name.
|
||||
* TODO: a full validation based on RNG for example should be done there
|
||||
*/
|
||||
doc = xmlReadMemory(xml, strlen(xml), "domain_define.xml", NULL, 0);
|
||||
if (doc == NULL) {
|
||||
virLibConnError(conn, VIR_ERR_XML_ERROR, __FUNCTION__);
|
||||
goto done;
|
||||
/* Go though the driver registered entry points */
|
||||
for (i = 0;i < conn->nb_drivers;i++) {
|
||||
if ((conn->drivers[i] != NULL) &&
|
||||
(conn->drivers[i]->domainDefineXML != NULL)) {
|
||||
ret = conn->drivers[i]->domainDefineXML(conn, xml);
|
||||
if (ret)
|
||||
return(ret);
|
||||
}
|
||||
}
|
||||
ctxt = xmlXPathNewContext(doc);
|
||||
if (ctxt == NULL) {
|
||||
goto done;
|
||||
}
|
||||
obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
|
||||
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
||||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
||||
virLibConnError(conn, VIR_ERR_NO_NAME, xml);
|
||||
goto done;
|
||||
}
|
||||
name = (const char *) obj->stringval;
|
||||
|
||||
/*
|
||||
* Now look it up in the domain pool and check it's not an already run
|
||||
* domain.
|
||||
*/
|
||||
ret = virGetDomain(conn, name, NULL);
|
||||
if (ret == NULL) {
|
||||
goto done;
|
||||
}
|
||||
/*
|
||||
* TODO: the lifecycle of domains, especially predefined ones need to be
|
||||
* explicitely written down
|
||||
*/
|
||||
if (ret->handle != -1) {
|
||||
virLibConnError(conn, VIR_ERR_DOM_EXIST, name);
|
||||
virFreeDomain(conn, ret);
|
||||
ret = NULL;
|
||||
goto done;
|
||||
}
|
||||
if ((ret->uses > 1) && (!(ret->flags & DOMAIN_IS_DEFINED))) {
|
||||
virLibConnError(conn, VIR_ERR_DOM_EXIST, name);
|
||||
virFreeDomain(conn, ret);
|
||||
ret = NULL;
|
||||
goto done;
|
||||
}
|
||||
ret->flags |= DOMAIN_IS_DEFINED;
|
||||
if (ret->xml != NULL) {
|
||||
free(ret->xml);
|
||||
}
|
||||
ret->xml = strdup(xml);
|
||||
if (ret->xml == NULL) {
|
||||
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
||||
virFreeDomain(conn, ret);
|
||||
ret = NULL;
|
||||
goto done;
|
||||
}
|
||||
/* TODO shall we keep a list of defined domains there ? */
|
||||
|
||||
done:
|
||||
if (obj != NULL)
|
||||
xmlXPathFreeObject(obj);
|
||||
if (ctxt != NULL)
|
||||
xmlXPathFreeContext(ctxt);
|
||||
if (doc != NULL)
|
||||
xmlFreeDoc(doc);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@ -1630,23 +1571,62 @@ done:
|
||||
*/
|
||||
int
|
||||
virDomainUndefine(virDomainPtr domain) {
|
||||
int ret;
|
||||
int ret, i;
|
||||
virConnectPtr conn;
|
||||
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
return (-1);
|
||||
}
|
||||
if (domain->conn->flags & VIR_CONNECT_RO) {
|
||||
conn = domain->conn;
|
||||
if (conn->flags & VIR_CONNECT_RO) {
|
||||
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* TODO shall we keep a list of defined domains there ? */
|
||||
/* Go though the driver registered entry points */
|
||||
for (i = 0;i < conn->nb_drivers;i++) {
|
||||
if ((conn->drivers[i] != NULL) &&
|
||||
(conn->drivers[i]->domainUndefine != NULL)) {
|
||||
ret = conn->drivers[i]->domainUndefine(domain);
|
||||
if (ret >= 0)
|
||||
return(ret);
|
||||
}
|
||||
}
|
||||
|
||||
ret = virFreeDomain(domain->conn, domain);
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* virConnectNumOfDefinedDomains:
|
||||
* @conn: pointer to the hypervisor connection
|
||||
*
|
||||
* Provides the number of active domains.
|
||||
*
|
||||
* Returns the number of domain found or -1 in case of error
|
||||
*/
|
||||
int
|
||||
virConnectNumOfDefinedDomains(virConnectPtr conn)
|
||||
{
|
||||
int ret = -1;
|
||||
int i;
|
||||
|
||||
if (!VIR_IS_CONNECT(conn)) {
|
||||
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Go though the driver registered entry points */
|
||||
for (i = 0;i < conn->nb_drivers;i++) {
|
||||
if ((conn->drivers[i] != NULL) &&
|
||||
(conn->drivers[i]->numOfDefinedDomains != NULL)) {
|
||||
ret = conn->drivers[i]->numOfDefinedDomains(conn);
|
||||
if (ret >= 0)
|
||||
return(ret);
|
||||
}
|
||||
}
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1662,8 +1642,30 @@ virDomainUndefine(virDomainPtr domain) {
|
||||
int
|
||||
virConnectListDefinedDomains(virConnectPtr conn, const char **names,
|
||||
int maxnames) {
|
||||
TODO
|
||||
return(-1);
|
||||
int ret = -1;
|
||||
int i;
|
||||
|
||||
if (!VIR_IS_CONNECT(conn)) {
|
||||
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((names == NULL) || (maxnames <= 0)) {
|
||||
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Go though the driver registered entry points */
|
||||
for (i = 0;i < conn->nb_drivers;i++) {
|
||||
if ((conn->drivers[i] != NULL) &&
|
||||
(conn->drivers[i]->listDefinedDomains != NULL)) {
|
||||
ret = conn->drivers[i]->listDefinedDomains(conn, names, maxnames);
|
||||
if (ret >= 0)
|
||||
return(ret);
|
||||
}
|
||||
}
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1677,16 +1679,31 @@ virConnectListDefinedDomains(virConnectPtr conn, const char **names,
|
||||
*/
|
||||
int
|
||||
virDomainCreate(virDomainPtr domain) {
|
||||
|
||||
int i, ret = -1;
|
||||
virConnectPtr conn;
|
||||
if (domain == NULL) {
|
||||
TODO
|
||||
return (-1);
|
||||
}
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
return (-1);
|
||||
}
|
||||
if (domain->conn->flags & VIR_CONNECT_RO) {
|
||||
conn = domain->conn;
|
||||
if (conn->flags & VIR_CONNECT_RO) {
|
||||
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
||||
return (-1);
|
||||
}
|
||||
return(-1);
|
||||
|
||||
for (i = 0;i < conn->nb_drivers;i++) {
|
||||
if ((conn->drivers[i] != NULL) &&
|
||||
(conn->drivers[i]->domainCreate != NULL)) {
|
||||
ret = conn->drivers[i]->domainCreate(domain);
|
||||
if (ret == 0)
|
||||
return(ret);
|
||||
}
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,9 @@
|
||||
virDomainShutdown;
|
||||
virDomainReboot;
|
||||
virDomainSuspend;
|
||||
virDomainUndefine;
|
||||
virConnectListDefinedDomains;
|
||||
virConnectNumOfDefinedDomains;
|
||||
virDomainUndefine;
|
||||
virGetVersion;
|
||||
virCopyLastError;
|
||||
virConnSetErrorFunc;
|
||||
|
@ -77,6 +77,11 @@ static virDriver xenProxyDriver = {
|
||||
NULL, /* domainPinVcpu */
|
||||
NULL, /* domainGetVcpus */
|
||||
xenProxyDomainDumpXML, /* domainDumpXML */
|
||||
NULL, /* listDefinedDomains */
|
||||
NULL, /* numOfDefinedDomains */
|
||||
NULL, /* domainCreate */
|
||||
NULL, /* domainDefineXML */
|
||||
NULL, /* domainUndefine */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -58,6 +58,11 @@ static virDriver testDriver = {
|
||||
NULL, /* domainPinVcpu */
|
||||
NULL, /* domainGetVcpus */
|
||||
testDomainDumpXML, /* domainDumpXML */
|
||||
NULL, /* listDefinedDomains */
|
||||
NULL, /* numOfDefinedDomains */
|
||||
NULL, /* domainCreate */
|
||||
NULL, /* domainDefineXML */
|
||||
NULL, /* domainUndefine */
|
||||
};
|
||||
|
||||
/* Amount of time it takes to shutdown */
|
||||
|
@ -94,6 +94,11 @@ static virDriver xenHypervisorDriver = {
|
||||
xenHypervisorPinVcpu, /* domainPinVcpu */
|
||||
xenHypervisorGetVcpus, /* domainGetVcpus */
|
||||
NULL, /* domainDumpXML */
|
||||
NULL, /* listDefinedDomains */
|
||||
NULL, /* numOfDefinedDomains */
|
||||
NULL, /* domainCreate */
|
||||
NULL, /* domainDefineXML */
|
||||
NULL, /* domainUndefine */
|
||||
};
|
||||
#endif /* !PROXY */
|
||||
|
||||
|
@ -88,6 +88,11 @@ static virDriver xenDaemonDriver = {
|
||||
xenDaemonDomainPinVcpu, /* domainPinVcpu */
|
||||
xenDaemonDomainGetVcpus, /* domainGetVcpus */
|
||||
xenDaemonDomainDumpXML, /* domainDumpXML */
|
||||
NULL, /* listDefinedDomains */
|
||||
NULL, /* numOfDefinedDomains */
|
||||
NULL, /* domainCreate */
|
||||
NULL, /* domainDefineXML */
|
||||
NULL, /* domainUndefine */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -70,6 +70,11 @@ static virDriver xenStoreDriver = {
|
||||
NULL, /* domainPinVcpu */
|
||||
NULL, /* domainGetVcpus */
|
||||
NULL, /* domainDumpXML */
|
||||
NULL, /* listDefinedDomains */
|
||||
NULL, /* numOfDefinedDomains */
|
||||
NULL, /* domainCreate */
|
||||
NULL, /* domainDefineXML */
|
||||
NULL, /* domainUndefine */
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user