From afcb25b9a5182f6c261cf3fd2556baf2ff9f2d45 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 10 Nov 2005 16:12:31 +0000 Subject: [PATCH] * src/makefile.am src/libxen.c src/xensh.c: add a small tool sensh, implement xenopenconnect and xencloseconnect. Daniel --- ChangeLog | 5 +++++ src/Makefile.am | 10 ++++++++++ src/libxen.c | 26 +++++++++++++++++++++----- src/xensh.c | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/xensh.c diff --git a/ChangeLog b/ChangeLog index 2f02aefa42..cf243547da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Nov 10 17:11:03 CET 2005 Daniel Veillard + + * src/makefile.am src/libxen.c src/xensh.c: add a small tool sensh, + implement xenopenconnect and xencloseconnect. + Wed Nov 9 10:57:12 CET 2005 Daniel Veillard * docs/Goals: added a Goals document for the library diff --git a/src/Makefile.am b/src/Makefile.am index c54dd1e410..3ca31023c5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,8 @@ ## Process this file with automake to produce Makefile.in INCLUDES = -I$(top_builddir)/include -I@srcdir@/include +DEPS = libxen.la +LDADDS = libxen.la EXTRA_DIST = libxen_sym.version @@ -9,3 +11,11 @@ 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 + +noinst_PROGRAMS=xensh + +xensh_SOURCES=xensh.c +xensh_LDFLAGS = +xensh_DEPENDENCIES = $(DEPS) +xensh_LDADD= $(LDADDS) + diff --git a/src/libxen.c b/src/libxen.c index 7aba219e9e..ff107ca351 100644 --- a/src/libxen.c +++ b/src/libxen.c @@ -18,6 +18,8 @@ * TODO: * - use lock to protect against concurrent accesses ? * - use reference counting to garantee coherent pointer state ? + * - error reporting layer + * - memory wrappers for malloc/free ? */ #define XEN_CONNECT_MAGIC 0x4F23DEAD @@ -42,7 +44,22 @@ struct _xenConnect { */ xenConnectPtr xenOpenConnect(const char *name) { - return(NULL); + xenConnectPtr ret; + int handle; + + handle = xc_interface_open(); + if (handle == -1) { + return(NULL); + } + ret = (xenConnectPtr) malloc(sizeof(xenConnect)); + if (ret == NULL) { + xc_interface_close(handle); + return(NULL); + } + ret->magic = XEN_CONNECT_MAGIC; + ret->handle = handle; + + return(ret); } /** @@ -60,11 +77,10 @@ int xenCloseConnect(xenConnectPtr conn) { if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC)) return(-1); - /* - * TODO: - * Free the domain pointers associated to this connection - */ + conn->magic = -1; + xc_interface_close(conn->handle); + conn->handle = -1; free(conn); return(0); } diff --git a/src/xensh.c b/src/xensh.c new file mode 100644 index 0000000000..6299892c18 --- /dev/null +++ b/src/xensh.c @@ -0,0 +1,37 @@ +/* + * xensh.c: a Xen shell used to exercise the libxen API + * + * Copyright (C) 2005 Red Hat, Inc. + * + * See COPYING.LIB for the License of this software + * + * Daniel Veillard + */ + +#include "libxen.h" +#include + +int errcode = 0; +xenConnectPtr conn; + +int main(int argc, char **argv) { + int ret; + + conn = xenOpenConnect(NULL); + if (conn == NULL) { + fprintf(stderr, "Failed to connect to the hypervisor\n"); + errcode = 1; + goto done; + } + +done: + if (conn != NULL) { + ret = xenCloseConnect(conn); + if (ret != 0) { + fprintf(stderr, "Failed to connect to the hypervisor\n"); + if (errcode == 0) + errcode = 1; + } + } + exit(errcode); +}