mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 01:43:23 +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
13
ChangeLog
13
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>
|
Tue Aug 29 23:48:43 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/conf.c: add missing entry point virConfGetValue()
|
* src/conf.c: add missing entry point virConfGetValue()
|
||||||
|
@ -297,7 +297,8 @@ char * virDomainGetXMLDesc (virDomainPtr domain,
|
|||||||
virDomainPtr virDomainDefineXML (virConnectPtr conn,
|
virDomainPtr virDomainDefineXML (virConnectPtr conn,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
int virDomainUndefine (virDomainPtr domain);
|
int virDomainUndefine (virDomainPtr domain);
|
||||||
int virConnectListDefinedDomains(virConnectPtr conn,
|
int virConnectNumOfDefinedDomains (virConnectPtr conn);
|
||||||
|
int virConnectListDefinedDomains (virConnectPtr conn,
|
||||||
const char **names,
|
const char **names,
|
||||||
int maxnames);
|
int maxnames);
|
||||||
int virDomainCreate (virDomainPtr domain);
|
int virDomainCreate (virDomainPtr domain);
|
||||||
|
@ -297,7 +297,8 @@ char * virDomainGetXMLDesc (virDomainPtr domain,
|
|||||||
virDomainPtr virDomainDefineXML (virConnectPtr conn,
|
virDomainPtr virDomainDefineXML (virConnectPtr conn,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
int virDomainUndefine (virDomainPtr domain);
|
int virDomainUndefine (virDomainPtr domain);
|
||||||
int virConnectListDefinedDomains(virConnectPtr conn,
|
int virConnectNumOfDefinedDomains (virConnectPtr conn);
|
||||||
|
int virConnectListDefinedDomains (virConnectPtr conn,
|
||||||
const char **names,
|
const char **names,
|
||||||
int maxnames);
|
int maxnames);
|
||||||
int virDomainCreate (virDomainPtr domain);
|
int virDomainCreate (virDomainPtr domain);
|
||||||
|
18
src/driver.h
18
src/driver.h
@ -107,7 +107,18 @@ typedef int
|
|||||||
typedef char *
|
typedef char *
|
||||||
(*virDrvDomainDumpXML) (virDomainPtr dom,
|
(*virDrvDomainDumpXML) (virDomainPtr dom,
|
||||||
int flags);
|
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
|
typedef int
|
||||||
(*virDrvDomainSetVcpus) (virDomainPtr domain,
|
(*virDrvDomainSetVcpus) (virDomainPtr domain,
|
||||||
unsigned int nvcpus);
|
unsigned int nvcpus);
|
||||||
@ -168,6 +179,11 @@ struct _virDriver {
|
|||||||
virDrvDomainPinVcpu domainPinVcpu;
|
virDrvDomainPinVcpu domainPinVcpu;
|
||||||
virDrvDomainGetVcpus domainGetVcpus;
|
virDrvDomainGetVcpus domainGetVcpus;
|
||||||
virDrvDomainDumpXML domainDumpXML;
|
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
|
virDomainPtr
|
||||||
virDomainDefineXML(virConnectPtr conn, const char *xml) {
|
virDomainDefineXML(virConnectPtr conn, const char *xml) {
|
||||||
virDomainPtr ret = NULL;
|
virDomainPtr ret = NULL;
|
||||||
const char *name = NULL;
|
int i;
|
||||||
xmlDocPtr doc = NULL;
|
|
||||||
xmlXPathObjectPtr obj = NULL;
|
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
|
||||||
|
|
||||||
if (!VIR_IS_CONNECT(conn)) {
|
if (!VIR_IS_CONNECT(conn)) {
|
||||||
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
||||||
@ -1551,72 +1548,16 @@ virDomainDefineXML(virConnectPtr conn, const char *xml) {
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Go though the driver registered entry points */
|
||||||
* Check the XML description is at least well formed and extract the
|
for (i = 0;i < conn->nb_drivers;i++) {
|
||||||
* name.
|
if ((conn->drivers[i] != NULL) &&
|
||||||
* TODO: a full validation based on RNG for example should be done there
|
(conn->drivers[i]->domainDefineXML != NULL)) {
|
||||||
*/
|
ret = conn->drivers[i]->domainDefineXML(conn, xml);
|
||||||
doc = xmlReadMemory(xml, strlen(xml), "domain_define.xml", NULL, 0);
|
if (ret)
|
||||||
if (doc == NULL) {
|
return(ret);
|
||||||
virLibConnError(conn, VIR_ERR_XML_ERROR, __FUNCTION__);
|
}
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
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);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1630,23 +1571,62 @@ done:
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virDomainUndefine(virDomainPtr domain) {
|
virDomainUndefine(virDomainPtr domain) {
|
||||||
int ret;
|
int ret, i;
|
||||||
|
virConnectPtr conn;
|
||||||
|
|
||||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||||
return (-1);
|
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__);
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
||||||
return (-1);
|
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);
|
return(-1);
|
||||||
if (ret < 0)
|
}
|
||||||
return(-1);
|
|
||||||
return(0);
|
/**
|
||||||
|
* 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
|
int
|
||||||
virConnectListDefinedDomains(virConnectPtr conn, const char **names,
|
virConnectListDefinedDomains(virConnectPtr conn, const char **names,
|
||||||
int maxnames) {
|
int maxnames) {
|
||||||
TODO
|
int ret = -1;
|
||||||
return(-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
|
int
|
||||||
virDomainCreate(virDomainPtr domain) {
|
virDomainCreate(virDomainPtr domain) {
|
||||||
|
int i, ret = -1;
|
||||||
|
virConnectPtr conn;
|
||||||
|
if (domain == NULL) {
|
||||||
|
TODO
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||||
return (-1);
|
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__);
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
||||||
return (-1);
|
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;
|
virDomainShutdown;
|
||||||
virDomainReboot;
|
virDomainReboot;
|
||||||
virDomainSuspend;
|
virDomainSuspend;
|
||||||
virDomainUndefine;
|
virConnectListDefinedDomains;
|
||||||
|
virConnectNumOfDefinedDomains;
|
||||||
|
virDomainUndefine;
|
||||||
virGetVersion;
|
virGetVersion;
|
||||||
virCopyLastError;
|
virCopyLastError;
|
||||||
virConnSetErrorFunc;
|
virConnSetErrorFunc;
|
||||||
|
@ -77,6 +77,11 @@ static virDriver xenProxyDriver = {
|
|||||||
NULL, /* domainPinVcpu */
|
NULL, /* domainPinVcpu */
|
||||||
NULL, /* domainGetVcpus */
|
NULL, /* domainGetVcpus */
|
||||||
xenProxyDomainDumpXML, /* domainDumpXML */
|
xenProxyDomainDumpXML, /* domainDumpXML */
|
||||||
|
NULL, /* listDefinedDomains */
|
||||||
|
NULL, /* numOfDefinedDomains */
|
||||||
|
NULL, /* domainCreate */
|
||||||
|
NULL, /* domainDefineXML */
|
||||||
|
NULL, /* domainUndefine */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,6 +58,11 @@ static virDriver testDriver = {
|
|||||||
NULL, /* domainPinVcpu */
|
NULL, /* domainPinVcpu */
|
||||||
NULL, /* domainGetVcpus */
|
NULL, /* domainGetVcpus */
|
||||||
testDomainDumpXML, /* domainDumpXML */
|
testDomainDumpXML, /* domainDumpXML */
|
||||||
|
NULL, /* listDefinedDomains */
|
||||||
|
NULL, /* numOfDefinedDomains */
|
||||||
|
NULL, /* domainCreate */
|
||||||
|
NULL, /* domainDefineXML */
|
||||||
|
NULL, /* domainUndefine */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Amount of time it takes to shutdown */
|
/* Amount of time it takes to shutdown */
|
||||||
|
@ -94,6 +94,11 @@ static virDriver xenHypervisorDriver = {
|
|||||||
xenHypervisorPinVcpu, /* domainPinVcpu */
|
xenHypervisorPinVcpu, /* domainPinVcpu */
|
||||||
xenHypervisorGetVcpus, /* domainGetVcpus */
|
xenHypervisorGetVcpus, /* domainGetVcpus */
|
||||||
NULL, /* domainDumpXML */
|
NULL, /* domainDumpXML */
|
||||||
|
NULL, /* listDefinedDomains */
|
||||||
|
NULL, /* numOfDefinedDomains */
|
||||||
|
NULL, /* domainCreate */
|
||||||
|
NULL, /* domainDefineXML */
|
||||||
|
NULL, /* domainUndefine */
|
||||||
};
|
};
|
||||||
#endif /* !PROXY */
|
#endif /* !PROXY */
|
||||||
|
|
||||||
|
@ -88,6 +88,11 @@ static virDriver xenDaemonDriver = {
|
|||||||
xenDaemonDomainPinVcpu, /* domainPinVcpu */
|
xenDaemonDomainPinVcpu, /* domainPinVcpu */
|
||||||
xenDaemonDomainGetVcpus, /* domainGetVcpus */
|
xenDaemonDomainGetVcpus, /* domainGetVcpus */
|
||||||
xenDaemonDomainDumpXML, /* domainDumpXML */
|
xenDaemonDomainDumpXML, /* domainDumpXML */
|
||||||
|
NULL, /* listDefinedDomains */
|
||||||
|
NULL, /* numOfDefinedDomains */
|
||||||
|
NULL, /* domainCreate */
|
||||||
|
NULL, /* domainDefineXML */
|
||||||
|
NULL, /* domainUndefine */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,6 +70,11 @@ static virDriver xenStoreDriver = {
|
|||||||
NULL, /* domainPinVcpu */
|
NULL, /* domainPinVcpu */
|
||||||
NULL, /* domainGetVcpus */
|
NULL, /* domainGetVcpus */
|
||||||
NULL, /* domainDumpXML */
|
NULL, /* domainDumpXML */
|
||||||
|
NULL, /* listDefinedDomains */
|
||||||
|
NULL, /* numOfDefinedDomains */
|
||||||
|
NULL, /* domainCreate */
|
||||||
|
NULL, /* domainDefineXML */
|
||||||
|
NULL, /* domainUndefine */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user