diff --git a/ChangeLog b/ChangeLog index 7a9f228330009a66bb43f551a2d7ad5a35156662..f1cca3e869ff32aeba7226a050d2c34e75a89041 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jun 15 14:57:39 EDT 2006 Daniel Veillard + + * 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 * src/test.h, src/test.c: Added implementation of the reboot diff --git a/src/libvirt.c b/src/libvirt.c index 4a6f5c421eec41d2699aaa1310767ffbddb19394..d8b33f57f1d2f9d59ef8cf509039eb9a549858cb 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -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); } diff --git a/src/xend_internal.c b/src/xend_internal.c index 7d21960d651993e44faff208f2c01a67ffa65868..1a4f124971be42a6973ab0a88d8c14abd99bc21b 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -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); +} diff --git a/src/xend_internal.h b/src/xend_internal.h index dba8617e03772720e98587f79acda47242bba9af..258b26d3732f8ecd71c26c670a18681d7750363a 100644 --- a/src/xend_internal.h +++ b/src/xend_internal.h @@ -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 diff --git a/src/xs_internal.c b/src/xs_internal.c index 2c61f4af9fac16ce3fd4f8d0a2559dc0f90620b5..30d97eac35275ed17f67628ae9caaff38f007ee5 100644 --- a/src/xs_internal.c +++ b/src/xs_internal.c @@ -46,7 +46,7 @@ static virDriver xenStoreDriver = { NULL, /* domainCreateLinux */ NULL, /* domainLookupByID */ NULL, /* domainLookupByUUID */ - NULL, /* domainLookupByName */ + xenStoreDomainLookupByName, /* domainLookupByName */ NULL, /* domainSuspend */ NULL, /* domainResume */ xenStoreDomainShutdown, /* domainShutdown */