int
virConnectClose(virConnectPtr conn)
{
+ int i;
+
if (!VIR_IS_CONNECT(conn))
return (-1);
+ for (i = 0;i < conn->nb_drivers;i++) {
+ if ((conn->drivers[i] != NULL) && (conn->drivers[i]->close != NULL))
+ conn->drivers[i]->close(conn);
+ }
if (virFreeConnect(conn) < 0)
return (-1);
return (0);
return (-1);
}
- *hvVer = 0;
-
for (i = 0;i < conn->nb_drivers;i++) {
if ((conn->drivers[i] != NULL) &&
(conn->drivers[i]->version != NULL)) {
{
int ret = -1;
int i;
- long id;
- char **idlist = NULL;
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
}
}
- /*
- * try then though the Xen Daemon
- */
- idlist = xenDaemonListDomains(conn);
- if (idlist != NULL) {
- for (ret = 0, i = 0; (idlist[i] != NULL) && (ret < maxids); i++) {
- id = xenDaemonDomainLookupByName_ids(conn, idlist[i], NULL);
- if (id >= 0)
- ids[ret++] = (int) id;
- }
- free(idlist);
- return(ret);
- }
-
- /*
- * Then fallback to the XenStore
- */
- ret = xenStoreListDomains(conn, ids, maxids);
- return (ret);
+ return (-1);
}
/**
{
int ret = -1;
int i;
- char **idlist = NULL;
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
}
}
- /*
- * try then with Xend interface
- */
- idlist = xenDaemonListDomains(conn);
- if (idlist != NULL) {
- char **tmp = idlist;
-
- ret = 0;
- while (*tmp != NULL) {
- tmp++;
- ret++;
- }
- free(idlist);
- return(ret);
- }
- /* Then Xen Store */
- return(xenStoreNumOfDomains(conn));
+ return(-1);
}
/**
}
/* path does not contain name, use xend API to retrieve name */
- names = xenDaemonListDomains(conn);
+ names = xenDaemonListDomainsOld(conn);
tmp = names;
if (names != NULL) {
}
}
- names = xenDaemonListDomains(conn);
+ names = xenDaemonListDomainsOld(conn);
tmp = names;
if (names == NULL) {
static const char * xenDaemonGetType(virConnectPtr conn);
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 virDriver xenDaemonDriver = {
"XenDaemon",
xenDaemonGetType, /* type */
xenDaemonGetVersion, /* version */
xenDaemonNodeGetInfo, /* nodeGetInfo */
- NULL, /* listDomains */
- NULL, /* numOfDomains */
+ xenDaemonListDomains, /* listDomains */
+ xenDaemonNumOfDomains, /* numOfDomains */
NULL, /* domainCreateLinux */
NULL, /* domainLookupByID */
NULL, /* domainLookupByUUID */
}
/**
- * xenDaemonListDomains:
+ * xenDaemonListDomainsOld:
* @xend: pointer to the Xem Daemon block
*
* This method will return an array of names of currently running
* Returns a list of names or NULL in case of error.
*/
char **
-xenDaemonListDomains(virConnectPtr xend)
+xenDaemonListDomainsOld(virConnectPtr xend)
{
size_t extra = 0;
struct sexpr *root = NULL;
if (name == NULL)
goto error;
- ret = virGetDomain(conn, name, &uuid[0]);
+ ret = virGetDomain(conn, name, (const unsigned char *) &uuid[0]);
if (ret == NULL) {
virXendError(conn, VIR_ERR_NO_MEMORY, "Allocating domain");
return(NULL);
*hvVer = version;
return(0);
}
+
+/**
+ * xenDaemonListDomains:
+ * @conn: pointer to the hypervisor connection
+ * @ids: array to collect the list of IDs of active domains
+ * @maxids: size of @ids
+ *
+ * Collect the list of active domains, and store their ID in @maxids
+ * TODO: this is quite expensive at the moment since there isn't one
+ * xend RPC providing both name and id for all domains.
+ *
+ * Returns the number of domain found or -1 in case of error
+ */
+static int
+xenDaemonListDomains(virConnectPtr conn, int *ids, int maxids)
+{
+ struct sexpr *root = NULL;
+ int ret = -1;
+ struct sexpr *_for_i, *node;
+ long id;
+
+ if ((ids == NULL) || (maxids <= 0))
+ goto error;
+ root = sexpr_get(conn, "/xend/domain");
+ if (root == NULL)
+ goto error;
+
+ ret = 0;
+
+ for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
+ _for_i = _for_i->cdr, node = _for_i->car) {
+ if (node->kind != SEXPR_VALUE)
+ continue;
+ id = xenDaemonDomainLookupByName_ids(conn, node->value, NULL);
+ if (id >= 0)
+ ids[ret++] = (int) id;
+ }
+
+error:
+ if (root != NULL)
+ sexpr_free(root);
+ return(ret);
+}
+
+/**
+ * xenDaemonNumOfDomains:
+ * @conn: pointer to the hypervisor connection
+ *
+ * Provides the number of active domains.
+ *
+ * Returns the number of domain found or -1 in case of error
+ */
+static int
+xenDaemonNumOfDomains(virConnectPtr conn)
+{
+ struct sexpr *root = NULL;
+ int ret = -1;
+ struct sexpr *_for_i, *node;
+
+ root = sexpr_get(conn, "/xend/domain");
+ if (root == NULL)
+ goto error;
+
+ ret = 0;
+
+ for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
+ _for_i = _for_i->cdr, node = _for_i->car) {
+ if (node->kind != SEXPR_VALUE)
+ continue;
+ ret++;
+ }
+
+error:
+ if (root != NULL)
+ sexpr_free(root);
+ return(ret);
+}