+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
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)) {
}
}
- /* 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);
}
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)) {
}
}
- 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);
}
/**
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);
}
/**
}
}
- /*
- * 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);
}
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",
xenDaemonListDomains, /* listDomains */
xenDaemonNumOfDomains, /* numOfDomains */
NULL, /* domainCreateLinux */
- NULL, /* domainLookupByID */
- NULL, /* domainLookupByUUID */
- NULL, /* domainLookupByName */
+ xenDaemonLookupByID, /* domainLookupByID */
+ xenDaemonLookupByUUID, /* domainLookupByUUID */
+ xenDaemonDomainLookupByName, /* domainLookupByName */
xenDaemonDomainSuspend, /* domainSuspend */
xenDaemonDomainResume, /* domainResume */
xenDaemonDomainShutdown, /* domainShutdown */
*
* Returns a list of names or NULL in case of error.
*/
-char **
+static char **
xenDaemonListDomainsOld(virConnectPtr xend)
{
size_t extra = 0;
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);
+}
*/
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
NULL, /* domainCreateLinux */
NULL, /* domainLookupByID */
NULL, /* domainLookupByUUID */
- NULL, /* domainLookupByName */
+ xenStoreDomainLookupByName, /* domainLookupByName */
NULL, /* domainSuspend */
NULL, /* domainResume */
xenStoreDomainShutdown, /* domainShutdown */