提交 442b733e 编写于 作者: D Daniel Veillard

* src/libvirt.c src/xend_internal.c src/xend_internal.h

  src/xs_internal.c: more cleanups for the driver architecture
Daniel
上级 4ab26461
Thu Jun 15 14:57:39 EDT 2006 Daniel Veillard <veillard@redhat.com>
* src/libvirt.c src/xend_internal.c src/xend_internal.h
src/xs_internal.c: more cleanups for the driver architecture
Wed Jun 14 18:59:30 EDT 2006 Daniel P. Berrange <berrange@redhat.com>
* src/test.h, src/test.c: Added implementation of the reboot
......
......@@ -592,13 +592,7 @@ virDomainCreateLinux(virConnectPtr conn,
virDomainPtr
virDomainLookupByID(virConnectPtr conn, int id)
{
char *path = NULL;
char **names;
char **tmp;
int ident;
virDomainPtr ret;
char *name = NULL;
unsigned char uuid[16];
int i;
if (!VIR_IS_CONNECT(conn)) {
......@@ -620,45 +614,6 @@ virDomainLookupByID(virConnectPtr conn, int id)
}
}
/* retrieve home path of the domain */
if (conn->xshandle != NULL) {
path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
}
/* path does not contain name, use xend API to retrieve name */
names = xenDaemonListDomainsOld(conn);
tmp = names;
if (names != NULL) {
while (*tmp != NULL) {
ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]);
if (ident == id) {
name = strdup(*tmp);
break;
}
tmp++;
}
free(names);
}
if (name == NULL)
goto error;
ret = virGetDomain(conn, name, uuid);
if (ret == NULL) {
virLibConnError(conn, VIR_ERR_NO_MEMORY, "Allocating domain");
goto error;
}
ret->handle = id;
ret->path = path;
if (name != NULL)
free(name);
return (ret);
error:
if (name != NULL)
free(name);
if (path != NULL)
free(path);
return (NULL);
}
......@@ -675,11 +630,6 @@ virDomainPtr
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
virDomainPtr ret;
char *name = NULL;
char **names;
char **tmp;
unsigned char ident[16];
int id = -1;
int i;
if (!VIR_IS_CONNECT(conn)) {
......@@ -701,37 +651,7 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
}
}
names = xenDaemonListDomainsOld(conn);
tmp = names;
if (names == NULL) {
TODO /* try to fallback to xenstore lookup */
return (NULL);
}
while (*tmp != NULL) {
id = xenDaemonDomainLookupByName_ids(conn, *tmp, &ident[0]);
if (id >= 0) {
if (!memcmp(uuid, ident, 16)) {
name = strdup(*tmp);
break;
}
}
tmp++;
}
free(names);
if (name == NULL)
return (NULL);
ret = virGetDomain(conn, name, uuid);
if (ret == NULL) {
if (name != NULL)
free(name);
return (NULL);
}
ret->handle = id;
return (ret);
return (NULL);
}
/**
......@@ -816,20 +736,7 @@ virDomainLookupByName(virConnectPtr conn, const char *name)
return(ret);
}
}
/* try first though Xend */
ret = xenDaemonDomainLookupByName(conn, name);
if (ret != NULL) {
return(ret);
}
/* then though the XenStore */
ret = xenStoreDomainLookupByName(conn, name);
if (ret != NULL) {
return(ret);
}
return (ret);
return (NULL);
}
/**
......@@ -1499,27 +1406,6 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
}
}
/*
* if we have direct access though the hypervisor do a direct call
*/
if (domain->conn->handle >= 0) {
ret = xenHypervisorGetDomainInfo(domain, info);
if (ret == 0)
return (0);
}
/*
* try to extract the informations though access to the Xen Daemon
*/
if (xenDaemonDomainGetInfo(domain, info) == 0)
return (0);
/*
* last fallback, try to get the informations from the Xen store
*/
if (xenStoreGetDomainInfo(domain, info) == 0)
return (0);
return (-1);
}
......
......@@ -41,6 +41,9 @@ static int xenDaemonNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
static int xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer);
static int xenDaemonListDomains(virConnectPtr conn, int *ids, int maxids);
static int xenDaemonNumOfDomains(virConnectPtr conn);
static virDomainPtr xenDaemonLookupByID(virConnectPtr conn, int id);
static virDomainPtr xenDaemonLookupByUUID(virConnectPtr conn,
const unsigned char *uuid);
static virDriver xenDaemonDriver = {
"XenDaemon",
......@@ -56,9 +59,9 @@ static virDriver xenDaemonDriver = {
xenDaemonListDomains, /* listDomains */
xenDaemonNumOfDomains, /* numOfDomains */
NULL, /* domainCreateLinux */
NULL, /* domainLookupByID */
NULL, /* domainLookupByUUID */
NULL, /* domainLookupByName */
xenDaemonLookupByID, /* domainLookupByID */
xenDaemonLookupByUUID, /* domainLookupByUUID */
xenDaemonDomainLookupByName, /* domainLookupByName */
xenDaemonDomainSuspend, /* domainSuspend */
xenDaemonDomainResume, /* domainResume */
xenDaemonDomainShutdown, /* domainShutdown */
......@@ -1007,7 +1010,7 @@ xend_sysrq(virConnectPtr xend, const char *name, const char *key)
*
* Returns a list of names or NULL in case of error.
*/
char **
static char **
xenDaemonListDomainsOld(virConnectPtr xend)
{
size_t extra = 0;
......@@ -2225,3 +2228,115 @@ error:
sexpr_free(root);
return(ret);
}
/**
* xenDaemonLookupByID:
* @conn: pointer to the hypervisor connection
* @id: the domain ID number
*
* Try to find a domain based on the hypervisor ID number
*
* Returns a new domain object or NULL in case of failure
*/
static virDomainPtr
xenDaemonLookupByID(virConnectPtr conn, int id) {
char **names;
char **tmp;
int ident;
char *name = NULL;
unsigned char uuid[16];
virDomainPtr ret;
/*
* Xend API forces to collect the full domain list by names, and then
* query each of them until the id is found
*/
names = xenDaemonListDomainsOld(conn);
tmp = names;
if (names != NULL) {
while (*tmp != NULL) {
ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]);
if (ident == id) {
name = strdup(*tmp);
break;
}
tmp++;
}
free(names);
}
if (name == NULL)
goto error;
ret = virGetDomain(conn, name, uuid);
if (ret == NULL) {
virXendError(conn, VIR_ERR_NO_MEMORY, "Allocating domain");
goto error;
}
ret->handle = id;
if (name != NULL)
free(name);
return (ret);
error:
if (name != NULL)
free(name);
return (NULL);
}
/**
* xenDaemonLookupByUUID:
* @conn: pointer to the hypervisor connection
* @uuid: the raw UUID for the domain
*
* Try to lookup a domain on xend based on its UUID.
*
* Returns a new domain object or NULL in case of failure
*/
static virDomainPtr
xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
virDomainPtr ret;
char *name = NULL;
char **names;
char **tmp;
unsigned char ident[16];
int id = -1;
names = xenDaemonListDomainsOld(conn);
tmp = names;
if (names == NULL) {
TODO /* try to fallback to xenstore lookup */
return (NULL);
}
while (*tmp != NULL) {
id = xenDaemonDomainLookupByName_ids(conn, *tmp, &ident[0]);
if (id >= 0) {
if (!memcmp(uuid, ident, 16)) {
name = strdup(*tmp);
break;
}
}
tmp++;
}
free(names);
if (name == NULL)
goto error;
ret = virGetDomain(conn, name, uuid);
if (ret == NULL) {
virXendError(conn, VIR_ERR_NO_MEMORY, "Allocating domain");
goto error;
}
ret->handle = id;
if (name != NULL)
free(name);
return (ret);
error:
if (name != NULL)
free(name);
return (NULL);
}
......@@ -509,16 +509,6 @@ int xenDaemonOpen_unix(virConnectPtr xend, const char *path);
*/
int xend_sysrq(virConnectPtr xend, const char *name, const char *key);
/**
* \brief Obtain a list of currently running domains
* \param xend A xend instance
* \return a NULL terminated array of names; NULL (with errno) on error
*
* This method will return an array of names of currently running
* domains. The memory should be released will a call to free().
*/
char **xenDaemonListDomainsOld(virConnectPtr xend);
/**
* \brief Create a new domain
* \param xend A xend instance
......
......@@ -46,7 +46,7 @@ static virDriver xenStoreDriver = {
NULL, /* domainCreateLinux */
NULL, /* domainLookupByID */
NULL, /* domainLookupByUUID */
NULL, /* domainLookupByName */
xenStoreDomainLookupByName, /* domainLookupByName */
NULL, /* domainSuspend */
NULL, /* domainResume */
xenStoreDomainShutdown, /* domainShutdown */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册