mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 05:45:46 +00:00
* src/libvir.c src/xen_internal.c src/xen_internal.h: completing the
API implementation, only CreateLinux is now missing. Daniel
This commit is contained in:
parent
2da25a157c
commit
a8d7d679cc
@ -1,3 +1,8 @@
|
|||||||
|
Mon Dec 12 14:21:18 CET 2005 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* src/libvir.c src/xen_internal.c src/xen_internal.h: completing the
|
||||||
|
API implementation, only CreateLinux is now missing.
|
||||||
|
|
||||||
Fri Dec 9 15:39:18 CET 2005 Daniel Veillard <veillard@redhat.com>
|
Fri Dec 9 15:39:18 CET 2005 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* docs/search.php docs/index.py docs/*.xsl docs/html/*: fixed the
|
* docs/search.php docs/index.py docs/*.xsl docs/html/*: fixed the
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
|
||||||
<link rel="SHORTCUT ICON" href="/favicon.ico" />
|
<link rel="SHORTCUT ICON" href="/favicon.ico" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
TD {font-family: Verdana,Arial,Helvetica}
|
TD {font-family: Verdana,Arial,Helvetica}
|
||||||
|
166
src/libvir.c
166
src/libvir.c
@ -194,6 +194,30 @@ failed:
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virConnectCheckStoreID:
|
||||||
|
* @conn: pointer to the hypervisor connection
|
||||||
|
* @id: the id number as returned from Xenstore
|
||||||
|
*
|
||||||
|
* the xenstore sometimes list non-running domains, double check
|
||||||
|
* from the hypervisor if we have direct access
|
||||||
|
*
|
||||||
|
* Returns -1 if the check failed, 0 if successful or not possible to check
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
virConnectCheckStoreID(virConnectPtr conn, int id) {
|
||||||
|
if (conn->handle >= 0) {
|
||||||
|
dom0_getdomaininfo_t dominfo;
|
||||||
|
int tmp;
|
||||||
|
|
||||||
|
dominfo.domain = id;
|
||||||
|
tmp = xenHypervisorGetDomainInfo(conn->handle, id, &dominfo);
|
||||||
|
if (tmp < 0)
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virDomainFreeName:
|
* virDomainFreeName:
|
||||||
* @domain: a domain object
|
* @domain: a domain object
|
||||||
@ -317,6 +341,9 @@ virConnectListDomains(virConnectPtr conn, int *ids, int maxids) {
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virConnectCheckStoreID(conn, (int) id) < 0)
|
||||||
|
continue;
|
||||||
ids[ret++] = (int) id;
|
ids[ret++] = (int) id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,23 +412,6 @@ virDomainCreateLinux(virConnectPtr conn, const char *kernel_path,
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* virDomainLookupByName:
|
|
||||||
* @conn: pointer to the hypervisor connection
|
|
||||||
* @name: name for the domain
|
|
||||||
*
|
|
||||||
* Try to lookup a domain on the given hypervisor
|
|
||||||
*
|
|
||||||
* Returns a new domain object or NULL in case of failure
|
|
||||||
*/
|
|
||||||
virDomainPtr
|
|
||||||
virDomainLookupByName(virConnectPtr conn, const char *name) {
|
|
||||||
if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) || (name == NULL))
|
|
||||||
return(NULL);
|
|
||||||
TODO
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Not used ATM */
|
/* Not used ATM */
|
||||||
/**
|
/**
|
||||||
@ -525,6 +535,74 @@ virDomainLookupByID(virConnectPtr conn, int id) {
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virDomainLookupByName:
|
||||||
|
* @conn: pointer to the hypervisor connection
|
||||||
|
* @name: name for the domain
|
||||||
|
*
|
||||||
|
* Try to lookup a domain on the given hypervisor
|
||||||
|
*
|
||||||
|
* Returns a new domain object or NULL in case of failure
|
||||||
|
*/
|
||||||
|
virDomainPtr
|
||||||
|
virDomainLookupByName(virConnectPtr conn, const char *name) {
|
||||||
|
struct xs_transaction_handle* t;
|
||||||
|
virDomainPtr ret = NULL;
|
||||||
|
unsigned int num, i, len;
|
||||||
|
long id;
|
||||||
|
char **idlist = NULL, *endptr;
|
||||||
|
char prop[200], *tmp;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) || (name == NULL))
|
||||||
|
return(NULL);
|
||||||
|
|
||||||
|
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 (i = 0;i < num;i++) {
|
||||||
|
id = strtol(idlist[i], &endptr, 10);
|
||||||
|
if ((endptr == idlist[i]) || (*endptr != 0)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if (virConnectCheckStoreID(conn, (int) id) < 0)
|
||||||
|
continue;
|
||||||
|
snprintf(prop, 199, "/local/domain/%s/name", idlist[i]);
|
||||||
|
prop[199] = 0;
|
||||||
|
tmp = xs_read(conn->xshandle, t, prop, &len);
|
||||||
|
if (tmp != NULL) {
|
||||||
|
found = !strcmp(name, tmp);
|
||||||
|
free(tmp);
|
||||||
|
if (found)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
ret = (virDomainPtr) malloc(sizeof(virDomain));
|
||||||
|
if (ret == NULL)
|
||||||
|
goto done;
|
||||||
|
ret->magic = VIR_DOMAIN_MAGIC;
|
||||||
|
ret->conn = conn;
|
||||||
|
ret->handle = id;
|
||||||
|
ret->path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
|
||||||
|
ret->name = strdup(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (t != NULL)
|
||||||
|
xs_transaction_end(conn->xshandle, t, 0);
|
||||||
|
if (idlist != NULL)
|
||||||
|
free(idlist);
|
||||||
|
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virDomainDestroy:
|
* virDomainDestroy:
|
||||||
* @domain: a domain object
|
* @domain: a domain object
|
||||||
@ -655,10 +733,29 @@ virDomainGetID(virDomainPtr domain) {
|
|||||||
*/
|
*/
|
||||||
unsigned long
|
unsigned long
|
||||||
virDomainGetMaxMemory(virDomainPtr domain) {
|
virDomainGetMaxMemory(virDomainPtr domain) {
|
||||||
|
unsigned long ret = 0;
|
||||||
|
|
||||||
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
|
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
|
||||||
return(0);
|
return(0);
|
||||||
TODO
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
||||||
return(0);
|
char *tmp;
|
||||||
|
|
||||||
|
tmp = virDomainDoStoreQuery(domain, "memory/target");
|
||||||
|
if (tmp != NULL) {
|
||||||
|
ret = (unsigned long) atol(tmp);
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dom0_getdomaininfo_t dominfo;
|
||||||
|
int tmp;
|
||||||
|
|
||||||
|
dominfo.domain = domain->handle;
|
||||||
|
tmp = xenHypervisorGetDomainInfo(domain->conn->handle, domain->handle,
|
||||||
|
&dominfo);
|
||||||
|
if (tmp >= 0)
|
||||||
|
ret = dominfo.max_pages * 4;
|
||||||
|
}
|
||||||
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -674,11 +771,38 @@ virDomainGetMaxMemory(virDomainPtr domain) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
|
virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
|
||||||
|
int ret;
|
||||||
|
char s[256], v[30];
|
||||||
|
struct xs_transaction_handle* t;
|
||||||
|
|
||||||
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC) ||
|
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC) ||
|
||||||
(memory < 4096))
|
(memory < 4096))
|
||||||
return(-1);
|
return(-1);
|
||||||
TODO
|
if (domain->conn->flags & VIR_CONNECT_RO)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
ret = xenHypervisorSetMaxMemory(domain->conn->handle, domain->handle,
|
||||||
|
memory);
|
||||||
|
if (ret < 0)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* try to update at the Xenstore level too
|
||||||
|
* Failing to do so should not be considered fatal though as long
|
||||||
|
* as the hypervisor call succeeded
|
||||||
|
*/
|
||||||
|
snprintf(s, 255, "/local/domain/%d/memory/target", domain->handle);
|
||||||
|
s[255] = 0;
|
||||||
|
snprintf(v, 29, "%lu", memory);
|
||||||
|
v[30] = 0;
|
||||||
|
|
||||||
|
t = xs_transaction_start(domain->conn->xshandle);
|
||||||
|
if (t == NULL)
|
||||||
|
return(0);
|
||||||
|
|
||||||
|
xs_write(domain->conn->xshandle, t, &s[0], &v[0], strlen(v));
|
||||||
|
xs_transaction_end(domain->conn->xshandle, t, 0);
|
||||||
|
|
||||||
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -249,3 +249,28 @@ xenHypervisorDestroyDomain(int handle, int domain) {
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xenHypervisorSetMaxMemory:
|
||||||
|
* @handle: the handle to the Xen hypervisor
|
||||||
|
* @domain: the domain ID
|
||||||
|
* @memory: the max memory size in kilobytes.
|
||||||
|
*
|
||||||
|
* Do an hypervisor call to change the maximum amount of memory used
|
||||||
|
*
|
||||||
|
* Returns 0 in case of success, -1 in case of error.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
xenHypervisorSetMaxMemory(int handle, int domain, unsigned long memory) {
|
||||||
|
dom0_op_t op;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
op.cmd = DOM0_SETDOMAINMAXMEM;
|
||||||
|
op.u.setdomainmaxmem.domain = (domid_t) domain;
|
||||||
|
op.u.setdomainmaxmem.max_memkb = memory;
|
||||||
|
|
||||||
|
ret = xenHypervisorDoOp(handle, &op);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
return(-1);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
@ -32,6 +32,9 @@ int xenHypervisorPauseDomain (int handle,
|
|||||||
int xenHypervisorGetDomainInfo (int handle,
|
int xenHypervisorGetDomainInfo (int handle,
|
||||||
int domain,
|
int domain,
|
||||||
dom0_getdomaininfo_t *info);
|
dom0_getdomaininfo_t *info);
|
||||||
|
int xenHypervisorSetMaxMemory (int handle,
|
||||||
|
int domain,
|
||||||
|
unsigned long memory);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user