mirror of https://gitee.com/openkylin/libvirt.git
add virConnectNumOfDomains()
This commit is contained in:
parent
cf65cf953f
commit
db4caab690
|
@ -124,6 +124,12 @@ int virConnectListDomains (virConnectPtr conn,
|
||||||
int *ids,
|
int *ids,
|
||||||
int maxids);
|
int maxids);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Number of domains
|
||||||
|
*/
|
||||||
|
int virConnectNumOfDomains (virConnectPtr conn);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Domain creation and destruction
|
* Domain creation and destruction
|
||||||
*/
|
*/
|
||||||
|
|
28
src/libvir.c
28
src/libvir.c
|
@ -257,6 +257,34 @@ done:
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virConnectNumOfDomains:
|
||||||
|
* @conn: pointer to the hypervisor connection
|
||||||
|
*
|
||||||
|
* Returns the number of domain found or -1 in case of error
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virConnectNumOfDomains(virConnectPtr conn) {
|
||||||
|
struct xs_transaction_handle* t;
|
||||||
|
int ret = -1;
|
||||||
|
unsigned int num;
|
||||||
|
char **idlist = NULL;
|
||||||
|
|
||||||
|
if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC))
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
t = xs_transaction_start(conn->xshandle);
|
||||||
|
if (t) {
|
||||||
|
idlist = xs_directory(conn->xshandle, t, "/local/domain", &num);
|
||||||
|
if (idlist) {
|
||||||
|
free(idlist);
|
||||||
|
ret = num;
|
||||||
|
}
|
||||||
|
xs_transaction_end(conn->xshandle, t, 0);
|
||||||
|
}
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virDomainCreateLinux:
|
* virDomainCreateLinux:
|
||||||
* @conn: pointer to the hypervisor connection
|
* @conn: pointer to the hypervisor connection
|
||||||
|
|
Loading…
Reference in New Issue