mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-18 10:35:20 +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>
|
Tue Nov 22 17:09:11 CET 2005 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* configure.in: checking xenstore library, error out on missing libs
|
* configure.in: checking xenstore library, error out on missing libs
|
||||||
|
@ -73,8 +73,10 @@ xenDomainPtr xenCreateLinuxDomain (xenConnectPtr conn,
|
|||||||
const char *cmdline,
|
const char *cmdline,
|
||||||
unsigned long memory,
|
unsigned long memory,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
xenDomainPtr xenLookupDomain (xenConnectPtr conn,
|
xenDomainPtr xenDomainByName (xenConnectPtr conn,
|
||||||
const char *name);
|
const char *name);
|
||||||
|
xenDomainPtr xenDomainByID (xenConnectPtr conn,
|
||||||
|
int id);
|
||||||
int xenDestroyDomain (xenDomainPtr domain);
|
int xenDestroyDomain (xenDomainPtr domain);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -87,6 +89,7 @@ int xenResumeDomain (xenDomainPtr domain);
|
|||||||
* Dynamic control of domains
|
* Dynamic control of domains
|
||||||
*/
|
*/
|
||||||
const char * xenGetName (xenDomainPtr domain);
|
const char * xenGetName (xenDomainPtr domain);
|
||||||
|
unsigned int xenGetID (xenDomainPtr domain);
|
||||||
unsigned long xenGetMaxMemory (xenDomainPtr domain);
|
unsigned long xenGetMaxMemory (xenDomainPtr domain);
|
||||||
int xenSetMaxMemory (xenDomainPtr domain,
|
int xenSetMaxMemory (xenDomainPtr domain,
|
||||||
unsigned long memory);
|
unsigned long memory);
|
||||||
|
@ -10,7 +10,7 @@ lib_LTLIBRARIES = libxen.la
|
|||||||
libxen_la_LIBADD =
|
libxen_la_LIBADD =
|
||||||
libxen_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libxen_sym.version \
|
libxen_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libxen_sym.version \
|
||||||
-version-info @LIBXEN_VERSION_INFO@
|
-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
|
noinst_PROGRAMS=xensh
|
||||||
|
|
||||||
|
133
src/libxen.c
133
src/libxen.c
@ -12,7 +12,12 @@
|
|||||||
#include "libxen.h"
|
#include "libxen.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <xenctrl.h>
|
||||||
|
#include <xs.h>
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "hash.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO:
|
* TODO:
|
||||||
@ -23,6 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define XEN_CONNECT_MAGIC 0x4F23DEAD
|
#define XEN_CONNECT_MAGIC 0x4F23DEAD
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _xenConnect:
|
* _xenConnect:
|
||||||
*
|
*
|
||||||
@ -31,7 +37,22 @@
|
|||||||
struct _xenConnect {
|
struct _xenConnect {
|
||||||
unsigned int magic; /* specific value to check */
|
unsigned int magic; /* specific value to check */
|
||||||
int handle; /* internal handle used for hypercall */
|
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) {
|
xenOpenConnect(const char *name) {
|
||||||
xenConnectPtr ret;
|
xenConnectPtr ret;
|
||||||
int handle = -1;
|
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();
|
handle = xc_interface_open();
|
||||||
if (handle == -1)
|
if (handle == -1)
|
||||||
goto failed;
|
goto failed;
|
||||||
xshandle = xs_daemon_open();
|
xshandle = xs_daemon_open();
|
||||||
if (xshandle < 0)
|
if (xshandle == NULL)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
ret = (xenConnectPtr) malloc(sizeof(xenConnect));
|
ret = (xenConnectPtr) malloc(sizeof(xenConnect));
|
||||||
@ -62,16 +87,32 @@ xenOpenConnect(const char *name) {
|
|||||||
ret->magic = XEN_CONNECT_MAGIC;
|
ret->magic = XEN_CONNECT_MAGIC;
|
||||||
ret->handle = handle;
|
ret->handle = handle;
|
||||||
ret->xshandle = xshandle;
|
ret->xshandle = xshandle;
|
||||||
|
ret->domains = xenHashCreate(20);
|
||||||
|
if (ret->domains == NULL)
|
||||||
|
goto failed;
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
failed:
|
failed:
|
||||||
if (handle >= 0)
|
if (handle >= 0)
|
||||||
xc_interface_close(handle);
|
xc_interface_close(handle);
|
||||||
if (xshandle >= 0)
|
if (xshandle != NULL)
|
||||||
xs_daemon_close(xshandle);
|
xs_daemon_close(xshandle);
|
||||||
return(NULL);
|
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:
|
* xenCloseConnect:
|
||||||
* @conn: pointer to the hypervisor connection
|
* @conn: pointer to the hypervisor connection
|
||||||
@ -88,9 +129,10 @@ xenCloseConnect(xenConnectPtr conn) {
|
|||||||
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC))
|
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC))
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
|
xenHashFree(conn->domains, (xenHashDeallocator) xenDestroyDomainName);
|
||||||
conn->magic = -1;
|
conn->magic = -1;
|
||||||
xs_daemon_close(conn->xshandle);
|
xs_daemon_close(conn->xshandle);
|
||||||
conn->xshandle = -1;
|
conn->xshandle = NULL;
|
||||||
xc_interface_close(conn->handle);
|
xc_interface_close(conn->handle);
|
||||||
conn->handle = -1;
|
conn->handle = -1;
|
||||||
free(conn);
|
free(conn);
|
||||||
@ -128,14 +170,15 @@ xenDomainPtr
|
|||||||
xenCreateLinuxDomain(xenConnectPtr conn, const char *kernel_path,
|
xenCreateLinuxDomain(xenConnectPtr conn, const char *kernel_path,
|
||||||
const char *initrd_path, const char *cmdline,
|
const char *initrd_path, const char *cmdline,
|
||||||
unsigned long memory, unsigned int flags) {
|
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);
|
return(NULL);
|
||||||
TODO
|
TODO
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xenLookupDomain:
|
* xenDomainByName:
|
||||||
* @conn: pointer to the hypervisor connection
|
* @conn: pointer to the hypervisor connection
|
||||||
* @name: name for the domain
|
* @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
|
* Returns a new domain object or NULL in case of failure
|
||||||
*/
|
*/
|
||||||
xenDomainPtr
|
xenDomainPtr
|
||||||
xenLookupDomain(xenConnectPtr conn, const char *name) {
|
xenDomainByName(xenConnectPtr conn, const char *name) {
|
||||||
if ((conn == NULL) || (name == NULL))
|
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) || (name == NULL))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
TODO
|
TODO
|
||||||
return(NULL);
|
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:
|
* xenDestroyDomain:
|
||||||
* @domain: a domain object
|
* @domain: a domain object
|
||||||
@ -162,7 +246,7 @@ xenLookupDomain(xenConnectPtr conn, const char *name) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xenDestroyDomain(xenDomainPtr domain) {
|
xenDestroyDomain(xenDomainPtr domain) {
|
||||||
if (domain == NULL)
|
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||||
return(-1);
|
return(-1);
|
||||||
TODO
|
TODO
|
||||||
return(-1);
|
return(-1);
|
||||||
@ -181,7 +265,7 @@ xenDestroyDomain(xenDomainPtr domain) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xenSuspendDomain(xenDomainPtr domain) {
|
xenSuspendDomain(xenDomainPtr domain) {
|
||||||
if (domain == NULL)
|
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||||
return(-1);
|
return(-1);
|
||||||
TODO
|
TODO
|
||||||
return(-1);
|
return(-1);
|
||||||
@ -198,7 +282,7 @@ xenSuspendDomain(xenDomainPtr domain) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xenResumeDomain(xenDomainPtr domain) {
|
xenResumeDomain(xenDomainPtr domain) {
|
||||||
if (domain == NULL)
|
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||||
return(-1);
|
return(-1);
|
||||||
TODO
|
TODO
|
||||||
return(-1);
|
return(-1);
|
||||||
@ -215,10 +299,24 @@ xenResumeDomain(xenDomainPtr domain) {
|
|||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
xenGetName(xenDomainPtr domain) {
|
xenGetName(xenDomainPtr domain) {
|
||||||
if (domain == NULL)
|
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||||
return(NULL);
|
|
||||||
TODO
|
|
||||||
return(NULL);
|
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
|
unsigned long
|
||||||
xenGetMaxMemory(xenDomainPtr domain) {
|
xenGetMaxMemory(xenDomainPtr domain) {
|
||||||
if (domain == NULL)
|
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
|
||||||
return(0);
|
return(0);
|
||||||
TODO
|
TODO
|
||||||
return(0);
|
return(0);
|
||||||
@ -252,7 +350,8 @@ xenGetMaxMemory(xenDomainPtr domain) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xenSetMaxMemory(xenDomainPtr domain, unsigned long memory) {
|
xenSetMaxMemory(xenDomainPtr domain, unsigned long memory) {
|
||||||
if ((domain == NULL) || (memory < 4096))
|
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC) ||
|
||||||
|
(memory < 4096))
|
||||||
return(-1);
|
return(-1);
|
||||||
TODO
|
TODO
|
||||||
return(-1);
|
return(-1);
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
xenCloseConnect;
|
xenCloseConnect;
|
||||||
xenGetVersion;
|
xenGetVersion;
|
||||||
xenCreateLinuxDomain;
|
xenCreateLinuxDomain;
|
||||||
xenLookupDomain;
|
xenDomainByName;
|
||||||
|
xenDomainByID;
|
||||||
xenDestroyDomain;
|
xenDestroyDomain;
|
||||||
xenSuspendDomain;
|
xenSuspendDomain;
|
||||||
xenResumeDomain;
|
xenResumeDomain;
|
||||||
xenGetName;
|
xenGetName;
|
||||||
|
xenGetID;
|
||||||
xenGetMaxMemory;
|
xenGetMaxMemory;
|
||||||
xenSetMaxMemory;
|
xenSetMaxMemory;
|
||||||
local: *;
|
local: *;
|
||||||
|
10
src/xensh.c
10
src/xensh.c
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
int errcode = 0;
|
int errcode = 0;
|
||||||
xenConnectPtr conn;
|
xenConnectPtr conn;
|
||||||
|
xenDomainPtr dom0;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int ret;
|
int ret;
|
||||||
@ -23,6 +24,13 @@ int main(int argc, char **argv) {
|
|||||||
errcode = 1;
|
errcode = 1;
|
||||||
goto done;
|
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:
|
done:
|
||||||
if (conn != NULL) {
|
if (conn != NULL) {
|
||||||
@ -33,5 +41,5 @@ done:
|
|||||||
errcode = 1;
|
errcode = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit(errcode);
|
return(errcode);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user