mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
* include/libxen.h src/libxen.c src/libxen_sym.version: adding
xenConnectListDomains() to list active domains * src/xensh.c: integrated a basic test for xenConnectListDomains() Daniel
This commit is contained in:
parent
37ecc62443
commit
79b43459ca
@ -1,3 +1,9 @@
|
||||
Fri Dec 2 15:15:26 CET 2005 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* include/libxen.h src/libxen.c src/libxen_sym.version: adding
|
||||
xenConnectListDomains() to list active domains
|
||||
* src/xensh.c: integrated a basic test for xenConnectListDomains()
|
||||
|
||||
Fri Dec 2 13:10:04 CET 2005 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* configure.in src/Makefile.am: more warnings from compiler and
|
||||
|
@ -65,6 +65,13 @@ xenConnectPtr xenConnectOpenReadOnly (const char *name);
|
||||
int xenConnectClose (xenConnectPtr conn);
|
||||
unsigned long xenConnectGetVersion (xenConnectPtr conn);
|
||||
|
||||
/*
|
||||
* Gather list of running domains
|
||||
*/
|
||||
int xenConnectListDomains (xenConnectPtr conn,
|
||||
int *ids,
|
||||
int maxids);
|
||||
|
||||
/*
|
||||
* Domain creation and destruction
|
||||
*/
|
||||
|
52
src/libxen.c
52
src/libxen.c
@ -122,7 +122,6 @@ failed:
|
||||
xenConnectPtr
|
||||
xenConnectOpenReadOnly(const char *name) {
|
||||
xenConnectPtr ret = NULL;
|
||||
int handle = -1;
|
||||
struct xs_handle *xshandle = NULL;
|
||||
|
||||
/* we can only talk to the local Xen supervisor ATM */
|
||||
@ -205,6 +204,56 @@ unsigned long
|
||||
xenConnectGetVersion(xenConnectPtr conn) {
|
||||
if (conn == NULL)
|
||||
return(-1);
|
||||
TODO
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenConnectListDomains:
|
||||
* @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
|
||||
*
|
||||
* Returns the number of domain found or -1 in case of error
|
||||
*/
|
||||
int
|
||||
xenConnectListDomains(xenConnectPtr conn, int *ids, int maxids) {
|
||||
struct xs_transaction_handle* t;
|
||||
int ret = -1;
|
||||
unsigned int num, i;
|
||||
long id;
|
||||
char **idlist = NULL, *endptr;
|
||||
|
||||
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) ||
|
||||
(ids == NULL) || (maxids <= 0))
|
||||
return(-1);
|
||||
|
||||
t = xs_transaction_start(conn->xshandle);
|
||||
if (t == NULL)
|
||||
goto done;
|
||||
|
||||
idlist = xs_directory(conn->xshandle, t, "/local/domain", &num);
|
||||
if (idlist == NULL)
|
||||
goto done;
|
||||
|
||||
for (ret = 0,i = 0;(i < num) && (ret < maxids);i++) {
|
||||
id = strtol(idlist[i], &endptr, 10);
|
||||
if ((endptr == idlist[i]) || (*endptr != 0)) {
|
||||
ret = -1;
|
||||
goto done;
|
||||
}
|
||||
ids[ret++] = (int) id;
|
||||
}
|
||||
|
||||
done:
|
||||
if (t != NULL)
|
||||
xs_transaction_end(conn->xshandle, t, 0);
|
||||
if (idlist != NULL)
|
||||
free(idlist);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,7 +309,6 @@ xenDomainLookupByName(xenConnectPtr conn, const char *name) {
|
||||
static char *
|
||||
xenConnectDoStoreQuery(xenConnectPtr conn, const char *path) {
|
||||
struct xs_transaction_handle* t;
|
||||
char s[256];
|
||||
char *ret = NULL;
|
||||
unsigned int len = 0;
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
xenConnectClose;
|
||||
xenConnectGetVersion;
|
||||
xenDomainCreateLinux;
|
||||
xenConnectListDomains;
|
||||
xenDomainLookupByName;
|
||||
xenDomainLookupByID;
|
||||
xenDomainDestroy;
|
||||
|
33
src/xensh.c
33
src/xensh.c
@ -13,12 +13,19 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MAX_DOM 100
|
||||
int errcode = 0;
|
||||
xenConnectPtr conn;
|
||||
xenDomainPtr dom0;
|
||||
int ids[MAX_DOM];
|
||||
|
||||
static void printDomain(xenDomainPtr dom) {
|
||||
printf("id %d: name %s\n", xenDomainGetID(dom), xenDomainGetName(dom));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int ret;
|
||||
int ret, i;
|
||||
xenDomainPtr dom;
|
||||
|
||||
if (getuid() == 0) {
|
||||
conn = xenConnectOpen(NULL);
|
||||
@ -36,8 +43,28 @@ int main(int argc, char **argv) {
|
||||
errcode = 2;
|
||||
goto done;
|
||||
}
|
||||
printf("Dom0: name %s, id %d\n", xenDomainGetName(dom0),
|
||||
xenDomainGetID(dom0));
|
||||
|
||||
printf("Dom0: ");
|
||||
printDomain(dom0);
|
||||
|
||||
ret = xenConnectListDomains(conn, &ids[0], MAX_DOM);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Failed to list active domains\n");
|
||||
errcode = 3;
|
||||
goto done;
|
||||
}
|
||||
printf("Found %d more active domains\n", ret - 1);
|
||||
for (i = 0;i < ret;i++) {
|
||||
if (ids[i] == 0)
|
||||
continue;
|
||||
printf(" ");
|
||||
dom = xenDomainLookupByID(conn, ids[i]);
|
||||
if (dom == NULL) {
|
||||
printf("domain %d disapeared\n", ids[i]);
|
||||
} else {
|
||||
printDomain(dom);
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (conn != NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user