* include/libvirt/libvirt.h include/libvirt/libvirt.h.in

src/driver.h src/libvirt.c src/openvz_driver.c src/qemu_driver.c
  src/test.c src/xen_unified.c src/xend_internal.c: add new API
  virNodeGetFreeMemory(), extends the driver. Lacks remote and
  QEmu support though.
* src/libvirt.c: allows to fix virNodeGetCellsFreeMemory() adding
  parameter check for startCell.
* proxy/libvirt_proxy.c src/xend_internal.[ch]
  include/libvirt/libvirt.h include/libvirt/libvirt.h.in: applied
  vncpasswd dump patch from Mark Johnson but with the
  virDomainXMLFlags extension as suggested by Daniel Berrange
  this changed a couple of internal APIs too
* tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: fix one of the
  tests affected by bootloader dump change.
Daniel
This commit is contained in:
Daniel Veillard 2007-09-30 13:09:07 +00:00
parent 0e7aa57385
commit 9f211bbf3a
13 changed files with 125 additions and 13 deletions

View File

@ -1,3 +1,20 @@
Sun Sep 30 14:49:27 CEST 2007 Daniel Veillard <veillard@redhat.com>
* include/libvirt/libvirt.h include/libvirt/libvirt.h.in
src/driver.h src/libvirt.c src/openvz_driver.c src/qemu_driver.c
src/test.c src/xen_unified.c src/xend_internal.c: add new API
virNodeGetFreeMemory(), extends the driver. Lacks remote and
QEmu support though.
* src/libvirt.c: allows to fix virNodeGetCellsFreeMemory() adding
parameter check for startCell.
* proxy/libvirt_proxy.c src/xend_internal.[ch]
include/libvirt/libvirt.h include/libvirt/libvirt.h.in: applied
vncpasswd dump patch from Mark Johnson but with the
virDomainXMLFlags extension as suggested by Daniel Berrange
this changed a couple of internal APIs too
* tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: fix one of the
tests affected by bootloader dump change.
Sat Sep 29 14:30:41 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/xen_internal.c, src/xs_internal.c: Solaris hypercall compat

View File

@ -344,6 +344,8 @@ int virNodeGetInfo (virConnectPtr conn,
virNodeInfoPtr info);
char * virConnectGetCapabilities (virConnectPtr conn);
unsigned long long virNodeGetFreeMemory (virConnectPtr conn);
/*
* Gather list of running domains
*/
@ -436,6 +438,17 @@ int virDomainGetMaxVcpus (virDomainPtr domain);
/*
* XML domain description
*/
/**
* virDomainXMLFlags:
*
* Flags available for virDomainGetXMLDesc
*/
typedef enum {
VIR_DOMAIN_XML_SECURE = 1, /* dump security sensitive informations too */
VIR_DOMAIN_XML_INACTIVE = 2/* dump inactive domain informations */
} virDomainXMLFlags;
char * virDomainGetXMLDesc (virDomainPtr domain,
int flags);

View File

@ -344,6 +344,8 @@ int virNodeGetInfo (virConnectPtr conn,
virNodeInfoPtr info);
char * virConnectGetCapabilities (virConnectPtr conn);
unsigned long long virNodeGetFreeMemory (virConnectPtr conn);
/*
* Gather list of running domains
*/
@ -436,6 +438,17 @@ int virDomainGetMaxVcpus (virDomainPtr domain);
/*
* XML domain description
*/
/**
* virDomainXMLFlags:
*
* Flags available for virDomainGetXMLDesc
*/
typedef enum {
VIR_DOMAIN_XML_SECURE = 1, /* dump security sensitive informations too */
VIR_DOMAIN_XML_INACTIVE = 2/* dump inactive domain informations */
} virDomainXMLFlags;
char * virDomainGetXMLDesc (virDomainPtr domain,
int flags);

View File

@ -614,7 +614,7 @@ retry2:
if (req->len != sizeof(virProxyPacket))
goto comm_error;
xml = xenDaemonDomainDumpXMLByID(conn, request.data.arg);
xml = xenDaemonDomainDumpXMLByID(conn, request.data.arg, 0);
if (!xml) {
req->data.arg = -1;
req->len = sizeof(virProxyPacket);

View File

@ -262,6 +262,10 @@ typedef int
int startCell,
int maxCells);
typedef unsigned long long
(*virDrvNodeGetFreeMemory)
(virConnectPtr conn);
/**
* _virDriver:
*
@ -330,6 +334,7 @@ struct _virDriver {
virDrvDomainBlockStats domainBlockStats;
virDrvDomainInterfaceStats domainInterfaceStats;
virDrvNodeGetCellsFreeMemory nodeGetCellsFreeMemory;
virDrvNodeGetFreeMemory getFreeMemory;
};
typedef int

View File

@ -1642,7 +1642,7 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
/**
* virDomainGetXMLDesc:
* @domain: a domain object
* @flags: and OR'ed set of extraction flags, not used yet
* @flags: an OR'ed set of virDomainXMLFlags
*
* Provide an XML description of the domain. The description may be reused
* later to relaunch the domain with virDomainCreateLinux().
@ -1949,6 +1949,29 @@ virConnectGetCapabilities (virConnectPtr conn)
return NULL;
}
/**
* virNodeGetFreeMemory:
* @conn: pointer to the hypervisor connection
*
* provides the free memory availble on the Node
*
* Returns the available free memory in kilobytes or 0 in case of error
*/
unsigned long long
virNodeGetFreeMemory(virConnectPtr conn)
{
if (!VIR_IS_CONNECT (conn)) {
virLibConnError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return 0;
}
if (conn->driver->getFreeMemory)
return conn->driver->getFreeMemory (conn);
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
return 0;
}
/**
* virDomainGetSchedulerType:
* @domain: pointer to domain object

View File

@ -754,6 +754,7 @@ static virDriver openvzDriver = {
NULL, /* domainBlockStats */
NULL, /* domainInterfaceStats */
NULL, /* nodeGetCellsFreeMemory */
NULL, /* nodeGetFreeMemory */
};
static virNetworkDriver openvzNetworkDriver = {

View File

@ -2705,6 +2705,7 @@ static virDriver qemuDriver = {
NULL, /* domainBlockStats */
NULL, /* domainInterfaceStats */
NULL, /* nodeGetCellsFreeMemory */
NULL, /* getFreeMemory */
};
static virNetworkDriver qemuNetworkDriver = {

View File

@ -1970,6 +1970,7 @@ static virDriver testDriver = {
NULL, /* domainBlockStats */
NULL, /* domainInterfaceStats */
NULL, /* nodeGetCellsFreeMemory */
NULL, /* getFreeMemory */
};
static virNetworkDriver testNetworkDriver = {

View File

@ -1067,6 +1067,25 @@ xenUnifiedNodeGetCellsFreeMemory (virConnectPtr conn, unsigned long long *freeMe
return -1;
}
static unsigned long long
xenUnifiedNodeGetFreeMemory (virConnectPtr conn)
{
unsigned long long freeMem = 0;
int ret;
GET_PRIVATE (conn);
if (priv->opened[XEN_UNIFIED_HYPERVISOR_OFFSET]) {
ret = xenHypervisorNodeGetCellsFreeMemory (conn, &freeMem,
-1, 1);
if (ret != 1)
return (0);
return(freeMem);
}
xenUnifiedError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
return(0);
}
/*----- Register with libvirt.c, and initialise Xen drivers. -----*/
#define VERSION ((DOM0_INTERFACE_VERSION >> 24) * 1000000 + \
@ -1128,6 +1147,7 @@ static virDriver xenUnifiedDriver = {
.domainBlockStats = xenUnifiedDomainBlockStats,
.domainInterfaceStats = xenUnifiedDomainInterfaceStats,
.nodeGetCellsFreeMemory = xenUnifiedNodeGetCellsFreeMemory,
.getFreeMemory = xenUnifiedNodeGetFreeMemory,
};
/**

View File

@ -1338,6 +1338,8 @@ xend_parse_sexp_desc_os(virConnectPtr xend, struct sexpr *node, virBufferPtr buf
* xend_parse_sexp_desc:
* @conn: the connection associated with the XML
* @root: the root of the parsed S-Expression
* @xendConfigVersion: version of xend
* @flags: a combination of virDomainXMLFlags
*
* Parse the xend sexp description and turn it into the XML format similar
* to the one unsed for creation.
@ -1346,7 +1348,8 @@ xend_parse_sexp_desc_os(virConnectPtr xend, struct sexpr *node, virBufferPtr buf
* the caller must free() the returned value.
*/
static char *
xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersion)
xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
int xendConfigVersion, int flags)
{
struct sexpr *cur, *node;
const char *tmp;
@ -1661,11 +1664,17 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi
} else if (tmp && !strcmp(tmp, "vnc")) {
int port = xenStoreDomainGetVNCPort(conn, domid);
const char *listenAddr = sexpr_node(node, "device/vfb/vnclisten");
const char *vncPasswd = NULL;
const char *keymap = sexpr_node(node, "device/vfb/keymap");
virBufferVSprintf(&buf, " <input type='mouse' bus='%s'/>\n", hvm ? "ps2": "xen");
virBufferVSprintf(&buf, " <graphics type='vnc' port='%d'", port);
if (listenAddr)
virBufferVSprintf(&buf, " listen='%s'", listenAddr);
if (flags & VIR_DOMAIN_XML_SECURE) {
vncPasswd = sexpr_node(node, "device/vfb/vncpasswd");
if (vncPasswd)
virBufferVSprintf(&buf, " passwd='%s'", vncPasswd);
}
if (keymap)
virBufferVSprintf(&buf, " keymap='%s'", keymap);
virBufferAdd(&buf, "/>\n", 3);
@ -1727,6 +1736,7 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi
if (tmp[0] == '1') {
int port = xenStoreDomainGetVNCPort(conn, domid);
const char *listenAddr = sexpr_fmt_node(root, "domain/image/%s/vnclisten", hvm ? "hvm" : "linux");
const char *vncPasswd = NULL;
const char *keymap = sexpr_fmt_node(root, "domain/image/%s/keymap", hvm ? "hvm" : "linux");
/* For Xen >= 3.0.3, don't generate a fixed port mapping
* because it will almost certainly be wrong ! Just leave
@ -1740,6 +1750,11 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi
virBufferVSprintf(&buf, " <graphics type='vnc' port='%d'", port);
if (listenAddr)
virBufferVSprintf(&buf, " listen='%s'", listenAddr);
if (flags & VIR_DOMAIN_XML_SECURE) {
vncPasswd = sexpr_fmt_node(root, "domain/image/%s/vncpasswd", hvm ? "hvm" : "linux");
if (vncPasswd)
virBufferVSprintf(&buf, " passwd='%s'", vncPasswd);
}
if (keymap)
virBufferVSprintf(&buf, " keymap='%s'", keymap);
virBufferAdd(&buf, "/>\n", 3);
@ -1782,7 +1797,7 @@ xend_parse_domain_sexp(virConnectPtr conn, char *sexpr, int xendConfigVersion) {
if (!root)
return NULL;
data = xend_parse_sexp_desc(conn, root, xendConfigVersion);
data = xend_parse_sexp_desc(conn, root, xendConfigVersion, 0);
sexpr_free(root);
@ -2601,7 +2616,7 @@ xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory)
dumpxml will work over proxy for inactive domains
and this can be removed */
char *
xenDaemonDomainDumpXMLByID(virConnectPtr conn, int domid)
xenDaemonDomainDumpXMLByID(virConnectPtr conn, int domid, int flags)
{
char *ret = NULL;
struct sexpr *root;
@ -2616,14 +2631,14 @@ xenDaemonDomainDumpXMLByID(virConnectPtr conn, int domid)
priv = (xenUnifiedPrivatePtr) conn->privateData;
ret = xend_parse_sexp_desc(conn, root, priv->xendConfigVersion);
ret = xend_parse_sexp_desc(conn, root, priv->xendConfigVersion, flags);
sexpr_free(root);
return (ret);
}
char *
xenDaemonDomainDumpXMLByName(virConnectPtr conn, const char *name)
xenDaemonDomainDumpXMLByName(virConnectPtr conn, const char *name, int flags)
{
char *ret = NULL;
struct sexpr *root;
@ -2638,7 +2653,7 @@ xenDaemonDomainDumpXMLByName(virConnectPtr conn, const char *name)
priv = (xenUnifiedPrivatePtr) conn->privateData;
ret = xend_parse_sexp_desc(conn, root, priv->xendConfigVersion);
ret = xend_parse_sexp_desc(conn, root, priv->xendConfigVersion, flags);
sexpr_free(root);
return (ret);
@ -2656,7 +2671,7 @@ xenDaemonDomainDumpXMLByName(virConnectPtr conn, const char *name)
* the caller must free() the returned value.
*/
char *
xenDaemonDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED)
xenDaemonDomainDumpXML(virDomainPtr domain, int flags)
{
xenUnifiedPrivatePtr priv;
@ -2673,9 +2688,9 @@ xenDaemonDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED)
}
if (domain->id < 0)
return xenDaemonDomainDumpXMLByName(domain->conn, domain->name);
return xenDaemonDomainDumpXMLByName(domain->conn, domain->name, flags);
else
return xenDaemonDomainDumpXMLByID(domain->conn, domain->id);
return xenDaemonDomainDumpXMLByID(domain->conn, domain->id, flags);
}
#endif /* !PROXY */

View File

@ -109,10 +109,12 @@ int xenDaemonDomainLookupByID(virConnectPtr xend,
char *xenDaemonDomainDumpXMLByID(virConnectPtr xend,
int domid);
int domid,
int flags);
char *xenDaemonDomainDumpXMLByName(virConnectPtr xend,
const char *name);
const char *name,
int flags);
/**
* \brief Lookup information about the host machine

View File

@ -1,6 +1,7 @@
<domain type='xen' id='6'>
<name>test</name>
<uuid>cc2315e7-d26a-307a-438c-6d188ec4c09c</uuid>
<bootloader/>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>