mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
* src/Makefile.am src/hash.[ch]: added hash module based on libxml2
one. * include/libxen.h src/libxen.c src/libxen_sym.version: extend API start to access libxenctrl directly (need xen update to get includes) * src/xensh.c: access to both xenstore and hypervisor Daniel
This commit is contained in:
parent
aa60580097
commit
978d57bbe4
@ -1,3 +1,11 @@
|
||||
Wed Nov 30 14:18:19 CET 2005 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* src/Makefile.am src/hash.[ch]: added hash module based on libxml2
|
||||
one.
|
||||
* include/libxen.h src/libxen.c src/libxen_sym.version: extend API
|
||||
start to access libxenctrl directly (need xen update to get includes)
|
||||
* src/xensh.c: access to both xenstore and hypervisor
|
||||
|
||||
Tue Nov 22 17:09:11 CET 2005 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* configure.in: checking xenstore library, error out on missing libs
|
||||
|
@ -73,8 +73,10 @@ xenDomainPtr xenCreateLinuxDomain (xenConnectPtr conn,
|
||||
const char *cmdline,
|
||||
unsigned long memory,
|
||||
unsigned int flags);
|
||||
xenDomainPtr xenLookupDomain (xenConnectPtr conn,
|
||||
xenDomainPtr xenDomainByName (xenConnectPtr conn,
|
||||
const char *name);
|
||||
xenDomainPtr xenDomainByID (xenConnectPtr conn,
|
||||
int id);
|
||||
int xenDestroyDomain (xenDomainPtr domain);
|
||||
|
||||
/*
|
||||
@ -87,6 +89,7 @@ int xenResumeDomain (xenDomainPtr domain);
|
||||
* Dynamic control of domains
|
||||
*/
|
||||
const char * xenGetName (xenDomainPtr domain);
|
||||
unsigned int xenGetID (xenDomainPtr domain);
|
||||
unsigned long xenGetMaxMemory (xenDomainPtr domain);
|
||||
int xenSetMaxMemory (xenDomainPtr domain,
|
||||
unsigned long memory);
|
||||
|
@ -10,7 +10,7 @@ lib_LTLIBRARIES = libxen.la
|
||||
libxen_la_LIBADD =
|
||||
libxen_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libxen_sym.version \
|
||||
-version-info @LIBXEN_VERSION_INFO@
|
||||
libxen_la_SOURCES = libxen.c internal.h
|
||||
libxen_la_SOURCES = libxen.c internal.h hash.c hash.h
|
||||
|
||||
noinst_PROGRAMS=xensh
|
||||
|
||||
|
133
src/libxen.c
133
src/libxen.c
@ -12,7 +12,12 @@
|
||||
#include "libxen.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <xenctrl.h>
|
||||
#include <xs.h>
|
||||
#include "internal.h"
|
||||
#include "hash.h"
|
||||
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
@ -23,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#define XEN_CONNECT_MAGIC 0x4F23DEAD
|
||||
|
||||
/**
|
||||
* _xenConnect:
|
||||
*
|
||||
@ -31,7 +37,22 @@
|
||||
struct _xenConnect {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int handle; /* internal handle used for hypercall */
|
||||
int xshandle; /* handle to talk to the xenstore */
|
||||
struct xs_handle *xshandle; /* handle to talk to the xenstore */
|
||||
xenHashTablePtr domains; /* hash table for known domains */
|
||||
};
|
||||
|
||||
#define XEN_DOMAIN_MAGIC 0xDEAD4321
|
||||
|
||||
/**
|
||||
* _xenDomain:
|
||||
*
|
||||
* Internal structure associated to a domain
|
||||
*/
|
||||
struct _xenDomain {
|
||||
unsigned int magic; /* specific value to check */
|
||||
xenConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* the domain external name */
|
||||
int handle; /* internal handle for the dmonain ID */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -47,13 +68,17 @@ xenConnectPtr
|
||||
xenOpenConnect(const char *name) {
|
||||
xenConnectPtr ret;
|
||||
int handle = -1;
|
||||
int xshandle = -1;
|
||||
struct xs_handle *xshandle = NULL;
|
||||
|
||||
/* we can only talk to the local Xen supervisor ATM */
|
||||
if (name != NULL)
|
||||
return(NULL);
|
||||
|
||||
handle = xc_interface_open();
|
||||
if (handle == -1)
|
||||
goto failed;
|
||||
xshandle = xs_daemon_open();
|
||||
if (xshandle < 0)
|
||||
if (xshandle == NULL)
|
||||
goto failed;
|
||||
|
||||
ret = (xenConnectPtr) malloc(sizeof(xenConnect));
|
||||
@ -62,16 +87,32 @@ xenOpenConnect(const char *name) {
|
||||
ret->magic = XEN_CONNECT_MAGIC;
|
||||
ret->handle = handle;
|
||||
ret->xshandle = xshandle;
|
||||
ret->domains = xenHashCreate(20);
|
||||
if (ret->domains == NULL)
|
||||
goto failed;
|
||||
|
||||
return(ret);
|
||||
failed:
|
||||
if (handle >= 0)
|
||||
xc_interface_close(handle);
|
||||
if (xshandle >= 0)
|
||||
if (xshandle != NULL)
|
||||
xs_daemon_close(xshandle);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenDestroyDomainName:
|
||||
* @domain: a domain object
|
||||
*
|
||||
* Destroy the domain object, this is just used by the domain hash callback.
|
||||
*
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
static int
|
||||
xenDestroyDomainName(xenDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
|
||||
return(xenDestroyDomain(domain));
|
||||
}
|
||||
|
||||
/**
|
||||
* xenCloseConnect:
|
||||
* @conn: pointer to the hypervisor connection
|
||||
@ -88,9 +129,10 @@ xenCloseConnect(xenConnectPtr conn) {
|
||||
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC))
|
||||
return(-1);
|
||||
|
||||
xenHashFree(conn->domains, (xenHashDeallocator) xenDestroyDomainName);
|
||||
conn->magic = -1;
|
||||
xs_daemon_close(conn->xshandle);
|
||||
conn->xshandle = -1;
|
||||
conn->xshandle = NULL;
|
||||
xc_interface_close(conn->handle);
|
||||
conn->handle = -1;
|
||||
free(conn);
|
||||
@ -128,14 +170,15 @@ xenDomainPtr
|
||||
xenCreateLinuxDomain(xenConnectPtr conn, const char *kernel_path,
|
||||
const char *initrd_path, const char *cmdline,
|
||||
unsigned long memory, unsigned int flags) {
|
||||
if ((conn == NULL) || (kernel_path == NULL) || (memory < 4096))
|
||||
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) ||
|
||||
(kernel_path == NULL) || (memory < 4096))
|
||||
return(NULL);
|
||||
TODO
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenLookupDomain:
|
||||
* xenDomainByName:
|
||||
* @conn: pointer to the hypervisor connection
|
||||
* @name: name for the domain
|
||||
*
|
||||
@ -144,13 +187,54 @@ xenCreateLinuxDomain(xenConnectPtr conn, const char *kernel_path,
|
||||
* Returns a new domain object or NULL in case of failure
|
||||
*/
|
||||
xenDomainPtr
|
||||
xenLookupDomain(xenConnectPtr conn, const char *name) {
|
||||
if ((conn == NULL) || (name == NULL))
|
||||
xenDomainByName(xenConnectPtr conn, const char *name) {
|
||||
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) || (name == NULL))
|
||||
return(NULL);
|
||||
TODO
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenDomainByID:
|
||||
* @conn: pointer to the hypervisor connection
|
||||
* @id: the domain ID number
|
||||
*
|
||||
* Try to find a domain based on the hypervisor ID number
|
||||
*
|
||||
* Returns a new domain object or NULL in case of failure
|
||||
*/
|
||||
xenDomainPtr
|
||||
xenDomainByID(xenConnectPtr conn, int id) {
|
||||
char *path;
|
||||
xenDomainPtr ret;
|
||||
xc_dominfo_t info;
|
||||
int res;
|
||||
|
||||
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) || (id < 0))
|
||||
return(NULL);
|
||||
|
||||
res = xc_domain_getinfo(conn->handle, (uint32_t) id, 1, &info);
|
||||
if (res != 1) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
|
||||
if (path == NULL) {
|
||||
return(NULL);
|
||||
}
|
||||
ret = (xenDomainPtr) malloc(sizeof(xenDomain));
|
||||
if (ret == NULL) {
|
||||
free(path);
|
||||
return(NULL);
|
||||
}
|
||||
ret->magic = XEN_DOMAIN_MAGIC;
|
||||
ret->conn = conn;
|
||||
ret->handle = id;
|
||||
ret->name = path;
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenDestroyDomain:
|
||||
* @domain: a domain object
|
||||
@ -162,7 +246,7 @@ xenLookupDomain(xenConnectPtr conn, const char *name) {
|
||||
*/
|
||||
int
|
||||
xenDestroyDomain(xenDomainPtr domain) {
|
||||
if (domain == NULL)
|
||||
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||
return(-1);
|
||||
TODO
|
||||
return(-1);
|
||||
@ -181,7 +265,7 @@ xenDestroyDomain(xenDomainPtr domain) {
|
||||
*/
|
||||
int
|
||||
xenSuspendDomain(xenDomainPtr domain) {
|
||||
if (domain == NULL)
|
||||
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||
return(-1);
|
||||
TODO
|
||||
return(-1);
|
||||
@ -198,7 +282,7 @@ xenSuspendDomain(xenDomainPtr domain) {
|
||||
*/
|
||||
int
|
||||
xenResumeDomain(xenDomainPtr domain) {
|
||||
if (domain == NULL)
|
||||
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||
return(-1);
|
||||
TODO
|
||||
return(-1);
|
||||
@ -215,10 +299,24 @@ xenResumeDomain(xenDomainPtr domain) {
|
||||
*/
|
||||
const char *
|
||||
xenGetName(xenDomainPtr domain) {
|
||||
if (domain == NULL)
|
||||
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||
return(NULL);
|
||||
TODO
|
||||
return(NULL);
|
||||
return(domain->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenGetID:
|
||||
* @domain: a domain object
|
||||
*
|
||||
* Get the hypervisor ID number for the domain
|
||||
*
|
||||
* Returns the domain ID number or (unsigned int) -1 in case of error
|
||||
*/
|
||||
unsigned int
|
||||
xenGetID(xenDomainPtr domain) {
|
||||
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||
return((unsigned int) -1);
|
||||
return(domain->handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,7 +331,7 @@ xenGetName(xenDomainPtr domain) {
|
||||
*/
|
||||
unsigned long
|
||||
xenGetMaxMemory(xenDomainPtr domain) {
|
||||
if (domain == NULL)
|
||||
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||
return(0);
|
||||
TODO
|
||||
return(0);
|
||||
@ -252,7 +350,8 @@ xenGetMaxMemory(xenDomainPtr domain) {
|
||||
*/
|
||||
int
|
||||
xenSetMaxMemory(xenDomainPtr domain, unsigned long memory) {
|
||||
if ((domain == NULL) || (memory < 4096))
|
||||
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC) ||
|
||||
(memory < 4096))
|
||||
return(-1);
|
||||
TODO
|
||||
return(-1);
|
||||
|
@ -4,11 +4,13 @@
|
||||
xenCloseConnect;
|
||||
xenGetVersion;
|
||||
xenCreateLinuxDomain;
|
||||
xenLookupDomain;
|
||||
xenDomainByName;
|
||||
xenDomainByID;
|
||||
xenDestroyDomain;
|
||||
xenSuspendDomain;
|
||||
xenResumeDomain;
|
||||
xenGetName;
|
||||
xenGetID;
|
||||
xenGetMaxMemory;
|
||||
xenSetMaxMemory;
|
||||
local: *;
|
||||
|
10
src/xensh.c
10
src/xensh.c
@ -13,6 +13,7 @@
|
||||
|
||||
int errcode = 0;
|
||||
xenConnectPtr conn;
|
||||
xenDomainPtr dom0;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int ret;
|
||||
@ -23,6 +24,13 @@ int main(int argc, char **argv) {
|
||||
errcode = 1;
|
||||
goto done;
|
||||
}
|
||||
dom0 = xenDomainByID(conn, 0);
|
||||
if (dom0 == NULL) {
|
||||
fprintf(stderr, "Failed to get domain 0 informations\n");
|
||||
errcode = 2;
|
||||
goto done;
|
||||
}
|
||||
printf("Dom0: name %s, id %d\n", xenGetName(dom0), xenGetID(dom0));
|
||||
|
||||
done:
|
||||
if (conn != NULL) {
|
||||
@ -33,5 +41,5 @@ done:
|
||||
errcode = 1;
|
||||
}
|
||||
}
|
||||
exit(errcode);
|
||||
return(errcode);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user