* include/libvir.h src/libvir.c src/libvir_sym.version src/virsh.c:

first pass at trying to implement virDomainGetInfo() quite a bit
  of work left to do.
Daniel
This commit is contained in:
Daniel Veillard 2005-12-05 18:14:37 +00:00
parent 1192a2ade3
commit 04130eb824
5 changed files with 170 additions and 9 deletions

View File

@ -1,3 +1,9 @@
Mon Dec 5 19:14:05 CET 2005 Daniel Veillard <veillard@redhat.com>
* include/libvir.h src/libvir.c src/libvir_sym.version src/virsh.c:
first pass at trying to implement virDomainGetInfo() quite a bit
of work left to do.
Mon Dec 5 12:15:16 CET 2005 Daniel Veillard <veillard@redhat.com>
* Makefile.am README TODO autogen.sh configure.in libvir.pc.in

View File

@ -47,6 +47,55 @@ typedef struct _virDomain virDomain;
*/
typedef virDomain *virDomainPtr;
/**
* virDomainState:
*
* A domain may be in different states at a given point in time
*/
typedef enum {
VIR_DOMAIN_NOSTATE = 0, /* no state */
VIR_DOMAIN_RUNNING = 1, /* the domain is running */
VIR_DOMAIN_BLOCKED = 2, /* the domain is blocked on resource */
VIR_DOMAIN_PAUSED = 3, /* the domain is paused by user */
VIR_DOMAIN_SHUTDOWN= 4, /* the domain is being shut down */
VIR_DOMAIN_SHUTOFF = 5 /* the domain is shut off */
} virDomainState;
/**
* virDomainInfoPtr:
*
* a virDomainInfo is a structure filled by virDomainGetInfo()
*/
typedef struct _virDomainInfo virDomainInfo;
struct _virDomainInfo {
unsigned char state; /* the running state, a virDomainFlags */
/*
* Informations below are only available to clients with a connection
* with full access to the hypervisor
*/
unsigned long long cpuTime; /* the CPU time used */
unsigned long pages; /* the number of pages used by the domain */
unsigned long maxPages; /* the maximum number of pages allowed */
/*
* TODO:
* - check what can be extracted publicly from xenstore
* and what's private limited to the hypervisor call.
* - add padding to this structure for ABI long term protection
*/
};
/**
* virDomainInfoPtr:
*
* a virDomainInfoPtr is a pointer to a virDomainInfo structure.
*/
typedef virDomainInfo *virDomainInfoPtr;
/**
* virDomainFlags:
*
@ -93,6 +142,12 @@ int virDomainDestroy (virDomainPtr domain);
int virDomainSuspend (virDomainPtr domain);
int virDomainResume (virDomainPtr domain);
/*
* Domain runtime informations
*/
int virDomainGetInfo (virDomainPtr domain,
virDomainInfoPtr info);
/*
* Dynamic control of domains
*/

View File

@ -521,3 +521,73 @@ virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
return(-1);
}
/**
* virDomainGetInfo:
* @domain: a domain object or NULL
* @info: pointer to a virDomainInfo structure allocated by the user
*
* Extract information about a domain. Note that if the connection
* used to get the domain is limited only a partial set of the informations
* can be extracted.
*
* Returns 0 in case of success and -1 in case of failure.
*/
int
virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
int ret;
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC) ||
(info == NULL))
return(-1);
if (domain->conn->flags & VIR_CONNECT_RO) {
char *tmp;
tmp = virDomainDoStoreQuery(domain, "running");
if (tmp != NULL) {
if (tmp[0] == '1')
info->state = VIR_DOMAIN_RUNNING;
free(tmp);
} else {
info->state = VIR_DOMAIN_NONE;
}
tmp = virDomainDoStoreQuery(domain, "memory/target");
if (tmp != NULL) {
info->pages = atol(tmp) / 4096;
free(tmp);
} else {
info->pages = 0;
info->maxPages = 0;
}
} else {
xc_domaininfo_t dominfo;
dominfo.domain = domain->handle;
ret = xc_domain_getinfolist(domain->conn->handle, domain->handle,
1, &dominfo);
if (ret <= 0)
return(-1);
switch (dominfo.flags & 0xFF) {
case DOMFLAGS_DYING:
info->state = VIR_DOMAIN_SHUTDOWN;
break;
case DOMFLAGS_SHUTDOWN:
info->state = VIR_DOMAIN_SHUTOFF;
break;
case DOMFLAGS_PAUSED:
info->state = VIR_DOMAIN_PAUSED;
break;
case DOMFLAGS_BLOCKED:
info->state = VIR_DOMAIN_BLOCKED;
break;
case DOMFLAGS_RUNNING:
info->state = VIR_DOMAIN_RUNNING;
break;
default:
info->state = VIR_DOMAIN_NONE;
}
info->cpuTime = dominfo.cpu_time;
info->pages = dominfo.tot_pages;
info->maxPages = dominfo.max_pages;
}
return(0);
}

View File

@ -1,19 +1,20 @@
{
global:
virConnectOpen;
virConnectOpenReadOnly;
virConnectClose;
virConnectGetVersion;
virDomainCreateLinux;
virConnectListDomains;
virDomainLookupByName;
virDomainLookupByID;
virConnectOpen;
virConnectOpenReadOnly;
virDomainCreateLinux;
virDomainDestroy;
virDomainSuspend;
virDomainResume;
virDomainGetName;
virDomainGetID;
virDomainGetInfo;
virDomainGetMaxMemory;
virDomainGetName;
virDomainLookupByID;
virDomainLookupByName;
virDomainResume;
virDomainSetMaxMemory;
virDomainSuspend;
local: *;
};

View File

@ -20,7 +20,36 @@ virDomainPtr dom0;
int ids[MAX_DOM];
static void printDomain(virDomainPtr dom) {
printf("id %d: name %s\n", virDomainGetID(dom), virDomainGetName(dom));
virDomainInfo info;
printf("id %d: name %s ", virDomainGetID(dom), virDomainGetName(dom));
virDomainGetInfo(dom, &info);
if (virDomainGetInfo(dom, &info) < 0) {
printf("failed to get informations\n");
} else {
switch (info.state) {
case VIR_DOMAIN_RUNNING:
printf("running ");
break;
case VIR_DOMAIN_BLOCKED:
printf("blocked ");
break;
case VIR_DOMAIN_PAUSED:
printf("paused ");
break;
case VIR_DOMAIN_SHUTDOWN:
printf("in shutdown ");
break;
case VIR_DOMAIN_SHUTOFF:
printf("shut off ");
break;
default:
break;
}
printf("%lu CPU time, %lu mem used, %lu max_mem\n",
info.cpuTime, info.pages * 4096, info.maxPages * 4096);
}
}
int main(int argc, char **argv) {