* Makefile.am README TODO autogen.sh configure.in libvir.pc.in

libvir.spec.in docs/Makefile.am docs/apibuild.py docs/structures.fig
  include/Makefile.am include/libvir.h src/Makefile.am src/hash.c
  src/hash.h src/internal.h src/libvir.c src/libvir_sym.version
  src/virsh.c: renamed to libvir
Daniel
This commit is contained in:
Daniel Veillard 2005-12-05 11:16:07 +00:00
parent 79b43459ca
commit 1192a2ade3
23 changed files with 358 additions and 350 deletions

View File

@ -1,3 +1,11 @@
Mon Dec 5 12:15:16 CET 2005 Daniel Veillard <veillard@redhat.com>
* Makefile.am README TODO autogen.sh configure.in libvir.pc.in
libvir.spec.in docs/Makefile.am docs/apibuild.py docs/structures.fig
include/Makefile.am include/libvir.h src/Makefile.am src/hash.c
src/hash.h src/internal.h src/libvir.c src/libvir_sym.version
src/virsh.c: renamed to libvir
Fri Dec 2 15:15:26 CET 2005 Daniel Veillard <veillard@redhat.com> Fri Dec 2 15:15:26 CET 2005 Daniel Veillard <veillard@redhat.com>
* include/libxen.h src/libxen.c src/libxen_sym.version: adding * include/libxen.h src/libxen.c src/libxen_sym.version: adding

View File

@ -1,12 +1,12 @@
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
SUBDIRS = src include docs SUBDIRS = src include docs
EXTRA_DIST = libxen.spec.in libxen.spec COPYING.LIB \ EXTRA_DIST = libvir.spec.in libvir.spec COPYING.LIB \
libxen.pc.in libxen.pc TODO AUTHORS ChangeLog \ libvir.pc.in libvir.pc TODO AUTHORS ChangeLog \
NEWS README NEWS README
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libxen.pc pkgconfig_DATA = libvir.pc
rpm: clean rpm: clean
@(unset CDPATH ; $(MAKE) dist && rpmbuild -ta $(distdir).tar.gz) @(unset CDPATH ; $(MAKE) dist && rpmbuild -ta $(distdir).tar.gz)

2
README
View File

@ -1,5 +1,5 @@
LibXen : simple library to use the Xen hypervisor LibVir : simple library to use the Xen hypervisor
As of Wed Nov 2 2005, this is a completely new project, it is not As of Wed Nov 2 2005, this is a completely new project, it is not
usable in any way yet. usable in any way yet.

2
TODO
View File

@ -2,4 +2,4 @@
Done: Done:
- make dist and make rpm targets - make dist and make rpm targets
- set a no public by default policy for libxen symbols - set a no public by default policy for libvir symbols

View File

@ -36,7 +36,7 @@ if test "$DIE" -eq 1; then
exit 1 exit 1
fi fi
test -f src/libxen.c || { test -f src/libvir.c || {
echo "You must run this script in the top-level libxen directory" echo "You must run this script in the top-level libxen directory"
exit 1 exit 1
} }
@ -61,4 +61,4 @@ fi
$srcdir/configure "$@" $srcdir/configure "$@"
echo echo
echo "Now type 'make' to compile libxen." echo "Now type 'make' to compile libvir."

View File

@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/libxen.c) AC_INIT(src/libvir.c)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST AC_CANONICAL_HOST
@ -31,7 +31,7 @@ AC_SUBST(LIBXEN_VERSION_EXTRA)
VERSION=${LIBXEN_VERSION} VERSION=${LIBXEN_VERSION}
AM_INIT_AUTOMAKE(libxen, $VERSION) AM_INIT_AUTOMAKE(libvir, $VERSION)
dnl Checks for programs. dnl Checks for programs.
AC_PROG_CC AC_PROG_CC
@ -50,7 +50,7 @@ AM_PROG_LIBTOOL
dnl dnl
dnl specific tests to setup DV devel environments with debug etc ... dnl specific tests to setup DV devel environments with debug etc ...
dnl dnl
if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/libxen" ]] ; then if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/libvir" ]] ; then
if test "${GCC}" = "yes" ; then if test "${GCC}" = "yes" ; then
CFLAGS="-g -O -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wall" CFLAGS="-g -O -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wall"
fi fi
@ -64,4 +64,4 @@ dnl search for the low level Xen library
AC_SEARCH_LIBS(xc_domain_create, [xenctrl], [], [AC_MSG_ERROR([Xen control library not found])]) AC_SEARCH_LIBS(xc_domain_create, [xenctrl], [], [AC_MSG_ERROR([Xen control library not found])])
AC_SEARCH_LIBS(xs_read, [xenstore], [], [AC_MSG_ERROR([Xen store library not found])]) AC_SEARCH_LIBS(xs_read, [xenstore], [], [AC_MSG_ERROR([Xen store library not found])])
AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile libxen.pc libxen.spec) AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile libvir.pc libvir.spec)

View File

@ -8,14 +8,14 @@ PAGES= # index.html
APIPAGES=APIconstructors.html APIfiles.html APIfunctions.html \ APIPAGES=APIconstructors.html APIfiles.html APIfunctions.html \
APIsymbols.html APIchunk0.html APIsymbols.html APIchunk0.html
EXTRA_DIST= \ EXTRA_DIST= \
libxen-api.xml apibuild.py libvir-api.xml apibuild.py
man_MANS= man_MANS=
all: web $(man_MANS) all: web $(man_MANS)
api: libxen-api.xml libxen-refs.xml api: libvir-api.xml libvir-refs.xml
web: $(PAGES) web: $(PAGES)
@ -45,14 +45,14 @@ web: $(PAGES)
# echo "Validating the resulting XHTML pages" ; \ # echo "Validating the resulting XHTML pages" ; \
# $(XMLLINT) --nonet --valid --noout html/*.html ; fi ); # $(XMLLINT) --nonet --valid --noout html/*.html ; fi );
libxen-api.xml libxen-refs.xml: apibuild.py ../include/*.h ../src/*.h ../src/*.c libvir-api.xml libvir-refs.xml: apibuild.py ../include/*.h ../src/*.h ../src/*.c
-(./apibuild.py) -(./apibuild.py)
clean-local: clean-local:
rm -f *~ *.bak *.hierarchy *.signals *-unused.txt rm -f *~ *.bak *.hierarchy *.signals *-unused.txt
maintainer-clean-local: clean-local maintainer-clean-local: clean-local
rm -rf libxen-api.xml libxen-refs.xml rm -rf libvir-api.xml libvir-refs.xml
rebuild: api all rebuild: api all

View File

@ -18,7 +18,7 @@ debugsym=None
# C parser analysis code # C parser analysis code
# #
ignored_files = { ignored_files = {
"xensh.c": "testing tool", "virsh.c": "testing tool",
"hash.c": "internal hash table stuff", "hash.c": "internal hash table stuff",
"hash.h": "internal hash table stuff", "hash.h": "internal hash table stuff",
} }
@ -1068,7 +1068,7 @@ class CParser:
if self.collect_ref == 1: if self.collect_ref == 1:
oldtok = token oldtok = token
token = self.token() token = self.token()
if oldtok[0] == "name" and oldtok[1][0:3] == "xen": if oldtok[0] == "name" and oldtok[1][0:3] == "vir":
if token[0] == "sep" and token[1] == "(": if token[0] == "sep" and token[1] == "(":
self.index_add_ref(oldtok[1], self.filename, self.index_add_ref(oldtok[1], self.filename,
0, "function") 0, "function")
@ -2044,13 +2044,13 @@ class docBuilder:
def rebuild(): def rebuild():
builder = None builder = None
if glob.glob("../src/libxen.c") != [] : if glob.glob("../src/libvir.c") != [] :
print "Rebuilding API description for libxen" print "Rebuilding API description for libvir"
builder = docBuilder("libxen", ["../src", "../include"], builder = docBuilder("libvir", ["../src", "../include"],
[]) [])
elif glob.glob("src/parser.c") != [] : elif glob.glob("src/parser.c") != [] :
print "Rebuilding API description for libxml2" print "Rebuilding API description for libvir"
builder = docBuilder("libxen", ["src", "include"], builder = docBuilder("libvir", ["src", "include"],
[]) [])
else: else:
print "rebuild() failed, unable to guess the module" print "rebuild() failed, unable to guess the module"

View File

@ -59,8 +59,8 @@ Single
2250 4800 3900 4800 2250 4800 3900 4800
4 0 0 50 -1 0 18 0.0000 4 195 1005 1275 1125 Domains\001 4 0 0 50 -1 0 18 0.0000 4 195 1005 1275 1125 Domains\001
4 0 0 50 -1 0 18 0.0000 4 195 585 1275 1440 hash \001 4 0 0 50 -1 0 18 0.0000 4 195 585 1275 1440 hash \001
4 0 0 50 -1 0 18 0.0000 4 195 1650 4725 750 xenDomainPtr\001 4 0 0 50 -1 0 18 0.0000 4 195 1650 4725 750 virDomainPtr\001
4 0 0 50 -1 0 18 0.0000 4 195 2055 975 5700 xenConnectionPtr\001 4 0 0 50 -1 0 18 0.0000 4 195 2055 975 5700 virConnectionPtr\001
4 0 0 50 -1 0 18 0.0000 4 195 945 900 4200 domains\001 4 0 0 50 -1 0 18 0.0000 4 195 945 900 4200 domains\001
4 0 0 50 -1 0 18 0.0000 4 135 555 3450 2475 conn\001 4 0 0 50 -1 0 18 0.0000 4 135 555 3450 2475 conn\001
4 0 0 50 -1 0 18 0.0000 4 135 615 6075 1050 name\001 4 0 0 50 -1 0 18 0.0000 4 135 615 6075 1050 name\001

View File

@ -1,9 +1,9 @@
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
xenincdir = $(includedir)/libxen virincdir = $(includedir)/libvir
xeninc_HEADERS = libxen.h virinc_HEADERS = libvir.h
install-exec-hook: install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(xenincdir) $(mkinstalldirs) $(DESTDIR)$(virincdir)

109
include/libvir.h Normal file
View File

@ -0,0 +1,109 @@
/*
* libvir.h: interface for the libvir library to handle Xen domains
* from a process running in domain 0
*
* Copyright (C) 2005 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
* Daniel Veillard <veillard@redhat.com>
*/
#ifndef __VIR_VIRLIB_H__
#define __VIR_VIRLIB_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* virConnect:
*
* a virConnect is a private structure representing a connection to
* the Xen Hypervisor.
*/
typedef struct _virConnect virConnect;
/**
* virConnectPtr:
*
* a virConnectPtr is pointer to a virConnect private structure, this is the
* type used to reference a connection to the Xen Hypervisor in the API.
*/
typedef virConnect *virConnectPtr;
/**
* virDomain:
*
* a virDomain is a private structure representing a Xen domain.
*/
typedef struct _virDomain virDomain;
/**
* virDomainPtr:
*
* a virDomainPtr is pointer to a virDomain private structure, this is the
* type used to reference a Xen domain in the API.
*/
typedef virDomain *virDomainPtr;
/**
* virDomainFlags:
*
* Flags OR'ed together to provide specific behaviour when creating a
* Domain.
*/
typedef enum {
VIR_DOMAIN_NONE = 0
} virDomainFlags;
/*
* Connection and disconnections to the Hypervisor
*/
virConnectPtr virConnectOpen (const char *name);
virConnectPtr virConnectOpenReadOnly (const char *name);
int virConnectClose (virConnectPtr conn);
unsigned long virConnectGetVersion (virConnectPtr conn);
/*
* Gather list of running domains
*/
int virConnectListDomains (virConnectPtr conn,
int *ids,
int maxids);
/*
* Domain creation and destruction
*/
virDomainPtr virDomainCreateLinux (virConnectPtr conn,
const char *kernel_path,
const char *initrd_path,
const char *cmdline,
unsigned long memory,
unsigned int flags);
virDomainPtr virDomainLookupByName (virConnectPtr conn,
const char *name);
virDomainPtr virDomainLookupByID (virConnectPtr conn,
int id);
int virDomainDestroy (virDomainPtr domain);
/*
* Domain suspend/resume
*/
int virDomainSuspend (virDomainPtr domain);
int virDomainResume (virDomainPtr domain);
/*
* Dynamic control of domains
*/
const char * virDomainGetName (virDomainPtr domain);
unsigned int virDomainGetID (virDomainPtr domain);
unsigned long virDomainGetMaxMemory (virDomainPtr domain);
int virDomainSetMaxMemory (virDomainPtr domain,
unsigned long memory);
#ifdef __cplusplus
}
#endif
#endif /* __VIR_VIRLIB_H__ */

View File

@ -1,9 +1,9 @@
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
xenincdir = $(includedir)/libxen virincdir = $(includedir)/libvir
xeninc_HEADERS = libxen.h virinc_HEADERS = libvir.h
install-exec-hook: install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(xenincdir) $(mkinstalldirs) $(DESTDIR)$(virincdir)

View File

@ -1,109 +0,0 @@
/*
* libxen.h: interface for the libxen library to handle Xen domains
* from a process running in domain 0
*
* Copyright (C) 2005 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
* Daniel Veillard <veillard@redhat.com>
*/
#ifndef __XEN_XENLIB_H__
#define __XEN_XENLIB_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* xenConnect:
*
* a xenConnect is a private structure representing a connection to
* the Xen Hypervisor.
*/
typedef struct _xenConnect xenConnect;
/**
* xenConnectPtr:
*
* a xenConnectPtr is pointer to a xenConnect private structure, this is the
* type used to reference a connection to the Xen Hypervisor in the API.
*/
typedef xenConnect *xenConnectPtr;
/**
* xenDomain:
*
* a xenDomain is a private structure representing a Xen domain.
*/
typedef struct _xenDomain xenDomain;
/**
* xenDomainPtr:
*
* a xenDomainPtr is pointer to a xenDomain private structure, this is the
* type used to reference a Xen domain in the API.
*/
typedef xenDomain *xenDomainPtr;
/**
* xenDomainFlags:
*
* Flags OR'ed together to provide specific behaviour when creating a
* Domain.
*/
typedef enum {
XEN_DOMAIN_NONE = 0
} xenDomainFlags;
/*
* Connection and disconnections to the Hypervisor
*/
xenConnectPtr xenConnectOpen (const char *name);
xenConnectPtr xenConnectOpenReadOnly (const char *name);
int xenConnectClose (xenConnectPtr conn);
unsigned long xenConnectGetVersion (xenConnectPtr conn);
/*
* Gather list of running domains
*/
int xenConnectListDomains (xenConnectPtr conn,
int *ids,
int maxids);
/*
* Domain creation and destruction
*/
xenDomainPtr xenDomainCreateLinux (xenConnectPtr conn,
const char *kernel_path,
const char *initrd_path,
const char *cmdline,
unsigned long memory,
unsigned int flags);
xenDomainPtr xenDomainLookupByName (xenConnectPtr conn,
const char *name);
xenDomainPtr xenDomainLookupByID (xenConnectPtr conn,
int id);
int xenDomainDestroy (xenDomainPtr domain);
/*
* Domain suspend/resume
*/
int xenDomainSuspend (xenDomainPtr domain);
int xenDomainResume (xenDomainPtr domain);
/*
* Dynamic control of domains
*/
const char * xenDomainGetName (xenDomainPtr domain);
unsigned int xenDomainGetID (xenDomainPtr domain);
unsigned long xenDomainGetMaxMemory (xenDomainPtr domain);
int xenDomainSetMaxMemory (xenDomainPtr domain,
unsigned long memory);
#ifdef __cplusplus
}
#endif
#endif /* __XEN_XENLIB_H__ */

View File

@ -1,10 +1,10 @@
Summary: Library providing an API to use the Xen virtualization Summary: Library providing an API to use the Xen virtualization
Name: libxen Name: libvir
Version: @VERSION@ Version: @VERSION@
Release: 1 Release: 1
License: LGPL License: LGPL
Group: Development/Libraries Group: Development/Libraries
Source: libxen-%{version}.tar.gz Source: libvir-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-root BuildRoot: %{_tmppath}/%{name}-%{version}-root
URL: http://www.gnome.org/~veillard/gamin/ URL: http://www.gnome.org/~veillard/gamin/
BuildRequires: xen BuildRequires: xen
@ -14,9 +14,9 @@ Requires: xen
This C library provides an API to use the Xen virtualization framework This C library provides an API to use the Xen virtualization framework
%package devel %package devel
Summary: Libraries, includes, etc. to compile with the libxen library Summary: Libraries, includes, etc. to compile with the libvir library
Group: Development/Libraries Group: Development/Libraries
Requires: libxen = %{version} Requires: libvir = %{version}
%description devel %description devel
This C library provides an API to use the Xen virtualization framework This C library provides an API to use the Xen virtualization framework
@ -54,8 +54,8 @@ rm -fr %{buildroot}
%{_libdir}/lib*.so %{_libdir}/lib*.so
%{_libdir}/*a %{_libdir}/*a
%{_includedir}/libxen/*.h %{_includedir}/libvir/*.h
%{_libdir}/pkgconfig/libxen.pc %{_libdir}/pkgconfig/libvir.pc
%changelog %changelog
* Wed Nov 2 2005 Daniel Veillard <veillard@redhat.com> 0.0.1-1 * Wed Nov 2 2005 Daniel Veillard <veillard@redhat.com> 0.0.1-1

View File

@ -1,21 +1,21 @@
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
INCLUDES = -I$(top_builddir)/include -I@srcdir@/include INCLUDES = -I$(top_builddir)/include -I@srcdir@/include
DEPS = libxen.la DEPS = libvir.la
LDADDS = @STATIC_BINARIES@ libxen.la LDADDS = @STATIC_BINARIES@ libvir.la
EXTRA_DIST = libxen_sym.version EXTRA_DIST = libvir_sym.version
lib_LTLIBRARIES = libxen.la lib_LTLIBRARIES = libvir.la
libxen_la_LIBADD = libvir_la_LIBADD =
libxen_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libxen_sym.version \ libvir_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvir_sym.version \
-version-info @LIBXEN_VERSION_INFO@ -version-info @LIBXEN_VERSION_INFO@
libxen_la_SOURCES = libxen.c internal.h hash.c hash.h libvir_la_SOURCES = libvir.c internal.h hash.c hash.h
noinst_PROGRAMS=xensh noinst_PROGRAMS=virsh
xensh_SOURCES=xensh.c virsh_SOURCES=virsh.c
xensh_LDFLAGS = virsh_LDFLAGS =
xensh_DEPENDENCIES = $(DEPS) virsh_DEPENDENCIES = $(DEPS)
xensh_LDADD= $(LDADDS) virsh_LDADD= $(LDADDS)

View File

@ -29,10 +29,10 @@
/* /*
* A single entry in the hash table * A single entry in the hash table
*/ */
typedef struct _xenHashEntry xenHashEntry; typedef struct _virHashEntry virHashEntry;
typedef xenHashEntry *xenHashEntryPtr; typedef virHashEntry *virHashEntryPtr;
struct _xenHashEntry { struct _virHashEntry {
struct _xenHashEntry *next; struct _virHashEntry *next;
char *name; char *name;
void *payload; void *payload;
int valid; int valid;
@ -41,18 +41,18 @@ struct _xenHashEntry {
/* /*
* The entire hash table * The entire hash table
*/ */
struct _xenHashTable { struct _virHashTable {
struct _xenHashEntry *table; struct _virHashEntry *table;
int size; int size;
int nbElems; int nbElems;
}; };
/* /*
* xenHashComputeKey: * virHashComputeKey:
* Calculate the hash key * Calculate the hash key
*/ */
static unsigned long static unsigned long
xenHashComputeKey(xenHashTablePtr table, const char *name) { virHashComputeKey(virHashTablePtr table, const char *name) {
unsigned long value = 0L; unsigned long value = 0L;
char ch; char ch;
@ -66,27 +66,27 @@ xenHashComputeKey(xenHashTablePtr table, const char *name) {
} }
/** /**
* xenHashCreate: * virHashCreate:
* @size: the size of the hash table * @size: the size of the hash table
* *
* Create a new xenHashTablePtr. * Create a new virHashTablePtr.
* *
* Returns the newly created object, or NULL if an error occured. * Returns the newly created object, or NULL if an error occured.
*/ */
xenHashTablePtr virHashTablePtr
xenHashCreate(int size) { virHashCreate(int size) {
xenHashTablePtr table; virHashTablePtr table;
if (size <= 0) if (size <= 0)
size = 256; size = 256;
table = malloc(sizeof(xenHashTable)); table = malloc(sizeof(virHashTable));
if (table) { if (table) {
table->size = size; table->size = size;
table->nbElems = 0; table->nbElems = 0;
table->table = malloc(size * sizeof(xenHashEntry)); table->table = malloc(size * sizeof(virHashEntry));
if (table->table) { if (table->table) {
memset(table->table, 0, size * sizeof(xenHashEntry)); memset(table->table, 0, size * sizeof(virHashEntry));
return(table); return(table);
} }
free(table); free(table);
@ -95,7 +95,7 @@ xenHashCreate(int size) {
} }
/** /**
* xenHashGrow: * virHashGrow:
* @table: the hash table * @table: the hash table
* @size: the new size of the hash table * @size: the new size of the hash table
* *
@ -104,11 +104,11 @@ xenHashCreate(int size) {
* Returns 0 in case of success, -1 in case of failure * Returns 0 in case of success, -1 in case of failure
*/ */
static int static int
xenHashGrow(xenHashTablePtr table, int size) { virHashGrow(virHashTablePtr table, int size) {
unsigned long key; unsigned long key;
int oldsize, i; int oldsize, i;
xenHashEntryPtr iter, next; virHashEntryPtr iter, next;
struct _xenHashEntry *oldtable; struct _virHashEntry *oldtable;
#ifdef DEBUG_GROW #ifdef DEBUG_GROW
unsigned long nbElem = 0; unsigned long nbElem = 0;
#endif #endif
@ -125,12 +125,12 @@ xenHashGrow(xenHashTablePtr table, int size) {
if (oldtable == NULL) if (oldtable == NULL)
return(-1); return(-1);
table->table = malloc(size * sizeof(xenHashEntry)); table->table = malloc(size * sizeof(virHashEntry));
if (table->table == NULL) { if (table->table == NULL) {
table->table = oldtable; table->table = oldtable;
return(-1); return(-1);
} }
memset(table->table, 0, size * sizeof(xenHashEntry)); memset(table->table, 0, size * sizeof(virHashEntry));
table->size = size; table->size = size;
/* If the two loops are merged, there would be situations where /* If the two loops are merged, there would be situations where
@ -142,8 +142,8 @@ xenHashGrow(xenHashTablePtr table, int size) {
for (i = 0; i < oldsize; i++) { for (i = 0; i < oldsize; i++) {
if (oldtable[i].valid == 0) if (oldtable[i].valid == 0)
continue; continue;
key = xenHashComputeKey(table, oldtable[i].name); key = virHashComputeKey(table, oldtable[i].name);
memcpy(&(table->table[key]), &(oldtable[i]), sizeof(xenHashEntry)); memcpy(&(table->table[key]), &(oldtable[i]), sizeof(virHashEntry));
table->table[key].next = NULL; table->table[key].next = NULL;
} }
@ -156,9 +156,9 @@ xenHashGrow(xenHashTablePtr table, int size) {
* put back the entry in the new table * put back the entry in the new table
*/ */
key = xenHashComputeKey(table, iter->name); key = virHashComputeKey(table, iter->name);
if (table->table[key].valid == 0) { if (table->table[key].valid == 0) {
memcpy(&(table->table[key]), iter, sizeof(xenHashEntry)); memcpy(&(table->table[key]), iter, sizeof(virHashEntry));
table->table[key].next = NULL; table->table[key].next = NULL;
free(iter); free(iter);
} else { } else {
@ -178,14 +178,14 @@ xenHashGrow(xenHashTablePtr table, int size) {
#ifdef DEBUG_GROW #ifdef DEBUG_GROW
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xenHashGrow : from %d to %d, %d elems\n", oldsize, size, nbElem); "virHashGrow : from %d to %d, %d elems\n", oldsize, size, nbElem);
#endif #endif
return(0); return(0);
} }
/** /**
* xenHashFree: * virHashFree:
* @table: the hash table * @table: the hash table
* @f: the deallocator function for items in the hash * @f: the deallocator function for items in the hash
* *
@ -193,10 +193,10 @@ xenHashGrow(xenHashTablePtr table, int size) {
* deallocated with @f if provided. * deallocated with @f if provided.
*/ */
void void
xenHashFree(xenHashTablePtr table, xenHashDeallocator f) { virHashFree(virHashTablePtr table, virHashDeallocator f) {
int i; int i;
xenHashEntryPtr iter; virHashEntryPtr iter;
xenHashEntryPtr next; virHashEntryPtr next;
int inside_table = 0; int inside_table = 0;
int nbElems; int nbElems;
@ -230,7 +230,7 @@ xenHashFree(xenHashTablePtr table, xenHashDeallocator f) {
} }
/** /**
* xenHashAddEntry3: * virHashAddEntry3:
* @table: the hash table * @table: the hash table
* @name: the name of the userdata * @name: the name of the userdata
* @userdata: a pointer to the userdata * @userdata: a pointer to the userdata
@ -241,11 +241,11 @@ xenHashFree(xenHashTablePtr table, xenHashDeallocator f) {
* Returns 0 the addition succeeded and -1 in case of error. * Returns 0 the addition succeeded and -1 in case of error.
*/ */
int int
xenHashAddEntry(xenHashTablePtr table, const char *name, virHashAddEntry(virHashTablePtr table, const char *name,
void *userdata) { void *userdata) {
unsigned long key, len = 0; unsigned long key, len = 0;
xenHashEntryPtr entry; virHashEntryPtr entry;
xenHashEntryPtr insert; virHashEntryPtr insert;
if ((table == NULL) || (name == NULL)) if ((table == NULL) || (name == NULL))
return(-1); return(-1);
@ -253,7 +253,7 @@ xenHashAddEntry(xenHashTablePtr table, const char *name,
/* /*
* Check for duplicate and insertion location. * Check for duplicate and insertion location.
*/ */
key = xenHashComputeKey(table, name); key = virHashComputeKey(table, name);
if (table->table[key].valid == 0) { if (table->table[key].valid == 0) {
insert = NULL; insert = NULL;
} else { } else {
@ -270,7 +270,7 @@ xenHashAddEntry(xenHashTablePtr table, const char *name,
if (insert == NULL) { if (insert == NULL) {
entry = &(table->table[key]); entry = &(table->table[key]);
} else { } else {
entry = malloc(sizeof(xenHashEntry)); entry = malloc(sizeof(virHashEntry));
if (entry == NULL) if (entry == NULL)
return(-1); return(-1);
} }
@ -287,13 +287,13 @@ xenHashAddEntry(xenHashTablePtr table, const char *name,
table->nbElems++; table->nbElems++;
if (len > MAX_HASH_LEN) if (len > MAX_HASH_LEN)
xenHashGrow(table, MAX_HASH_LEN * table->size); virHashGrow(table, MAX_HASH_LEN * table->size);
return(0); return(0);
} }
/** /**
* xenHashUpdateEntry: * virHashUpdateEntry:
* @table: the hash table * @table: the hash table
* @name: the name of the userdata * @name: the name of the userdata
* @userdata: a pointer to the userdata * @userdata: a pointer to the userdata
@ -306,11 +306,11 @@ xenHashAddEntry(xenHashTablePtr table, const char *name,
* Returns 0 the addition succeeded and -1 in case of error. * Returns 0 the addition succeeded and -1 in case of error.
*/ */
int int
xenHashUpdateEntry(xenHashTablePtr table, const char *name, virHashUpdateEntry(virHashTablePtr table, const char *name,
void *userdata, xenHashDeallocator f) { void *userdata, virHashDeallocator f) {
unsigned long key; unsigned long key;
xenHashEntryPtr entry; virHashEntryPtr entry;
xenHashEntryPtr insert; virHashEntryPtr insert;
if ((table == NULL) || name == NULL) if ((table == NULL) || name == NULL)
return(-1); return(-1);
@ -318,7 +318,7 @@ xenHashUpdateEntry(xenHashTablePtr table, const char *name,
/* /*
* Check for duplicate and insertion location. * Check for duplicate and insertion location.
*/ */
key = xenHashComputeKey(table, name); key = virHashComputeKey(table, name);
if (table->table[key].valid == 0) { if (table->table[key].valid == 0) {
insert = NULL; insert = NULL;
} else { } else {
@ -342,7 +342,7 @@ xenHashUpdateEntry(xenHashTablePtr table, const char *name,
if (insert == NULL) { if (insert == NULL) {
entry = &(table->table[key]); entry = &(table->table[key]);
} else { } else {
entry = malloc(sizeof(xenHashEntry)); entry = malloc(sizeof(virHashEntry));
if (entry == NULL) if (entry == NULL)
return(-1); return(-1);
} }
@ -361,7 +361,7 @@ xenHashUpdateEntry(xenHashTablePtr table, const char *name,
} }
/** /**
* xenHashLookup: * virHashLookup:
* @table: the hash table * @table: the hash table
* @name: the name of the userdata * @name: the name of the userdata
* *
@ -370,15 +370,15 @@ xenHashUpdateEntry(xenHashTablePtr table, const char *name,
* Returns the a pointer to the userdata * Returns the a pointer to the userdata
*/ */
void * void *
xenHashLookup(xenHashTablePtr table, const char *name) { virHashLookup(virHashTablePtr table, const char *name) {
unsigned long key; unsigned long key;
xenHashEntryPtr entry; virHashEntryPtr entry;
if (table == NULL) if (table == NULL)
return(NULL); return(NULL);
if (name == NULL) if (name == NULL)
return(NULL); return(NULL);
key = xenHashComputeKey(table, name); key = virHashComputeKey(table, name);
if (table->table[key].valid == 0) if (table->table[key].valid == 0)
return(NULL); return(NULL);
for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
@ -389,7 +389,7 @@ xenHashLookup(xenHashTablePtr table, const char *name) {
} }
/** /**
* xenHashSize: * virHashSize:
* @table: the hash table * @table: the hash table
* *
* Query the number of elements installed in the hash @table. * Query the number of elements installed in the hash @table.
@ -398,14 +398,14 @@ xenHashLookup(xenHashTablePtr table, const char *name) {
* -1 in case of error * -1 in case of error
*/ */
int int
xenHashSize(xenHashTablePtr table) { virHashSize(virHashTablePtr table) {
if (table == NULL) if (table == NULL)
return(-1); return(-1);
return(table->nbElems); return(table->nbElems);
} }
/** /**
* xenHashRemoveEntry: * virHashRemoveEntry:
* @table: the hash table * @table: the hash table
* @name: the name of the userdata * @name: the name of the userdata
* @f: the deallocator function for removed item (if any) * @f: the deallocator function for removed item (if any)
@ -417,16 +417,16 @@ xenHashSize(xenHashTablePtr table) {
* Returns 0 if the removal succeeded and -1 in case of error or not found. * Returns 0 if the removal succeeded and -1 in case of error or not found.
*/ */
int int
xenHashRemoveEntry(xenHashTablePtr table, const char *name, virHashRemoveEntry(virHashTablePtr table, const char *name,
xenHashDeallocator f) { virHashDeallocator f) {
unsigned long key; unsigned long key;
xenHashEntryPtr entry; virHashEntryPtr entry;
xenHashEntryPtr prev = NULL; virHashEntryPtr prev = NULL;
if (table == NULL || name == NULL) if (table == NULL || name == NULL)
return(-1); return(-1);
key = xenHashComputeKey(table, name); key = virHashComputeKey(table, name);
if (table->table[key].valid == 0) { if (table->table[key].valid == 0) {
return(-1); return(-1);
} else { } else {
@ -445,7 +445,7 @@ xenHashRemoveEntry(xenHashTablePtr table, const char *name,
entry->valid = 0; entry->valid = 0;
} else { } else {
entry = entry->next; entry = entry->next;
memcpy(&(table->table[key]), entry, sizeof(xenHashEntry)); memcpy(&(table->table[key]), entry, sizeof(virHashEntry));
free(entry); free(entry);
} }
} }

View File

@ -8,8 +8,8 @@
* Author: Bjorn Reese <bjorn.reese@systematic.dk> * Author: Bjorn Reese <bjorn.reese@systematic.dk>
*/ */
#ifndef __XEN_HASH_H__ #ifndef __VIR_HASH_H__
#define __XEN_HASH_H__ #define __VIR_HASH_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -18,54 +18,54 @@ extern "C" {
/* /*
* The hash table. * The hash table.
*/ */
typedef struct _xenHashTable xenHashTable; typedef struct _virHashTable virHashTable;
typedef xenHashTable *xenHashTablePtr; typedef virHashTable *virHashTablePtr;
/* /*
* function types: * function types:
*/ */
/** /**
* xenHashDeallocator: * virHashDeallocator:
* @payload: the data in the hash * @payload: the data in the hash
* @name: the name associated * @name: the name associated
* *
* Callback to free data from a hash. * Callback to free data from a hash.
*/ */
typedef void (*xenHashDeallocator)(void *payload, char *name); typedef void (*virHashDeallocator)(void *payload, char *name);
/* /*
* Constructor and destructor. * Constructor and destructor.
*/ */
xenHashTablePtr xenHashCreate (int size); virHashTablePtr virHashCreate (int size);
void void
xenHashFree (xenHashTablePtr table, virHashFree (virHashTablePtr table,
xenHashDeallocator f); virHashDeallocator f);
int xenHashSize (xenHashTablePtr table); int virHashSize (virHashTablePtr table);
/* /*
* Add a new entry to the hash table. * Add a new entry to the hash table.
*/ */
int xenHashAddEntry (xenHashTablePtr table, int virHashAddEntry (virHashTablePtr table,
const char *name, const char *name,
void *userdata); void *userdata);
int xenHashUpdateEntry(xenHashTablePtr table, int virHashUpdateEntry(virHashTablePtr table,
const char *name, const char *name,
void *userdata, void *userdata,
xenHashDeallocator f); virHashDeallocator f);
/* /*
* Remove an entry from the hash table. * Remove an entry from the hash table.
*/ */
int xenHashRemoveEntry(xenHashTablePtr table, int virHashRemoveEntry(virHashTablePtr table,
const char *name, const char *name,
xenHashDeallocator f); virHashDeallocator f);
/* /*
* Retrieve the userdata. * Retrieve the userdata.
*/ */
void * xenHashLookup (xenHashTablePtr table, void * virHashLookup (virHashTablePtr table,
const char *name); const char *name);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* ! __XEN_HASH_H__ */ #endif /* ! __VIR_HASH_H__ */

View File

@ -2,8 +2,8 @@
* internal.h: internal definitions just used by code from the library * internal.h: internal definitions just used by code from the library
*/ */
#ifndef __XEN_INTERNAL_H__ #ifndef __VIR_INTERNAL_H__
#define __XEN_INTERNAL_H__ #define __VIR_INTERNAL_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -38,4 +38,4 @@ extern "C" {
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __XEN_INTERNAL_H__ */ #endif /* __VIR_INTERNAL_H__ */

View File

@ -1,5 +1,5 @@
/* /*
* libxen.h: Main interfaces for the libxen library to handle virtualization * libvir.h: Main interfaces for the libvir library to handle virtualization
* domains from a process running in domain 0 * domains from a process running in domain 0
* *
* Copyright (C) 2005 Red Hat, Inc. * Copyright (C) 2005 Red Hat, Inc.
@ -9,7 +9,7 @@
* Daniel Veillard <veillard@redhat.com> * Daniel Veillard <veillard@redhat.com>
*/ */
#include "libxen.h" #include "libvir.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -27,43 +27,43 @@
* - memory wrappers for malloc/free ? * - memory wrappers for malloc/free ?
*/ */
#define XEN_CONNECT_MAGIC 0x4F23DEAD #define VIR_CONNECT_MAGIC 0x4F23DEAD
/* /*
* Flags for Xen connections * Flags for Xen connections
*/ */
#define XEN_CONNECT_RO 1 #define VIR_CONNECT_RO 1
/** /**
* _xenConnect: * _virConnect:
* *
* Internal structure associated to a connection * Internal structure associated to a connection
*/ */
struct _xenConnect { struct _virConnect {
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 */
struct xs_handle *xshandle; /* handle to talk to the xenstore */ struct xs_handle *xshandle; /* handle to talk to the xenstore */
xenHashTablePtr domains; /* hash table for known domains */ virHashTablePtr domains; /* hash table for known domains */
int flags; /* a set of connection flags */ int flags; /* a set of connection flags */
}; };
#define XEN_DOMAIN_MAGIC 0xDEAD4321 #define VIR_DOMAIN_MAGIC 0xDEAD4321
/** /**
* _xenDomain: * _virDomain:
* *
* Internal structure associated to a domain * Internal structure associated to a domain
*/ */
struct _xenDomain { struct _virDomain {
unsigned int magic; /* specific value to check */ unsigned int magic; /* specific value to check */
xenConnectPtr conn; /* pointer back to the connection */ virConnectPtr conn; /* pointer back to the connection */
char *name; /* the domain external name */ char *name; /* the domain external name */
char *path; /* the domain internal path */ char *path; /* the domain internal path */
int handle; /* internal handle for the dmonain ID */ int handle; /* internal handle for the dmonain ID */
}; };
/** /**
* xenConnectOpen: * virConnectOpen:
* @name: optional argument currently unused, pass NULL * @name: optional argument currently unused, pass NULL
* *
* This function should be called first to get a connection to the * This function should be called first to get a connection to the
@ -71,9 +71,9 @@ struct _xenDomain {
* *
* Returns a pointer to the hypervisor connection or NULL in case of error * Returns a pointer to the hypervisor connection or NULL in case of error
*/ */
xenConnectPtr virConnectPtr
xenConnectOpen(const char *name) { virConnectOpen(const char *name) {
xenConnectPtr ret = NULL; virConnectPtr ret = NULL;
int handle = -1; int handle = -1;
struct xs_handle *xshandle = NULL; struct xs_handle *xshandle = NULL;
@ -88,13 +88,13 @@ xenConnectOpen(const char *name) {
if (xshandle == NULL) if (xshandle == NULL)
goto failed; goto failed;
ret = (xenConnectPtr) malloc(sizeof(xenConnect)); ret = (virConnectPtr) malloc(sizeof(virConnect));
if (ret == NULL) if (ret == NULL)
goto failed; goto failed;
ret->magic = XEN_CONNECT_MAGIC; ret->magic = VIR_CONNECT_MAGIC;
ret->handle = handle; ret->handle = handle;
ret->xshandle = xshandle; ret->xshandle = xshandle;
ret->domains = xenHashCreate(20); ret->domains = virHashCreate(20);
ret->flags = 0; ret->flags = 0;
if (ret->domains == NULL) if (ret->domains == NULL)
goto failed; goto failed;
@ -111,7 +111,7 @@ failed:
} }
/** /**
* xenConnectOpenReadOnly: * virConnectOpenReadOnly:
* @name: optional argument currently unused, pass NULL * @name: optional argument currently unused, pass NULL
* *
* This function should be called first to get a read-only connection to the * This function should be called first to get a read-only connection to the
@ -119,9 +119,9 @@ failed:
* *
* Returns a pointer to the hypervisor connection or NULL in case of error * Returns a pointer to the hypervisor connection or NULL in case of error
*/ */
xenConnectPtr virConnectPtr
xenConnectOpenReadOnly(const char *name) { virConnectOpenReadOnly(const char *name) {
xenConnectPtr ret = NULL; virConnectPtr ret = NULL;
struct xs_handle *xshandle = NULL; struct xs_handle *xshandle = NULL;
/* we can only talk to the local Xen supervisor ATM */ /* we can only talk to the local Xen supervisor ATM */
@ -132,14 +132,14 @@ xenConnectOpenReadOnly(const char *name) {
if (xshandle == NULL) if (xshandle == NULL)
goto failed; goto failed;
ret = (xenConnectPtr) malloc(sizeof(xenConnect)); ret = (virConnectPtr) malloc(sizeof(virConnect));
if (ret == NULL) if (ret == NULL)
goto failed; goto failed;
ret->magic = XEN_CONNECT_MAGIC; ret->magic = VIR_CONNECT_MAGIC;
ret->handle = -1; ret->handle = -1;
ret->xshandle = xshandle; ret->xshandle = xshandle;
ret->domains = xenHashCreate(20); ret->domains = virHashCreate(20);
ret->flags = XEN_CONNECT_RO; ret->flags = VIR_CONNECT_RO;
if (ret->domains == NULL) if (ret->domains == NULL)
goto failed; goto failed;
@ -153,7 +153,7 @@ failed:
} }
/** /**
* xenDomainDestroyName: * virDomainDestroyName:
* @domain: a domain object * @domain: a domain object
* *
* Destroy the domain object, this is just used by the domain hash callback. * Destroy the domain object, this is just used by the domain hash callback.
@ -161,12 +161,12 @@ failed:
* Returns 0 in case of success and -1 in case of failure. * Returns 0 in case of success and -1 in case of failure.
*/ */
static int static int
xenDomainDestroyName(xenDomainPtr domain, const char *name ATTRIBUTE_UNUSED) { virDomainDestroyName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
return(xenDomainDestroy(domain)); return(virDomainDestroy(domain));
} }
/** /**
* xenConnectClose: * virConnectClose:
* @conn: pointer to the hypervisor connection * @conn: pointer to the hypervisor connection
* *
* This function closes the connection to the Hypervisor. This should * This function closes the connection to the Hypervisor. This should
@ -177,11 +177,11 @@ xenDomainDestroyName(xenDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
* Returns 0 in case of success or -1 in case of error. * Returns 0 in case of success or -1 in case of error.
*/ */
int int
xenConnectClose(xenConnectPtr conn) { virConnectClose(virConnectPtr conn) {
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC)) if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC))
return(-1); return(-1);
xenHashFree(conn->domains, (xenHashDeallocator) xenDomainDestroyName); virHashFree(conn->domains, (virHashDeallocator) virDomainDestroyName);
conn->magic = -1; conn->magic = -1;
xs_daemon_close(conn->xshandle); xs_daemon_close(conn->xshandle);
conn->xshandle = NULL; conn->xshandle = NULL;
@ -193,7 +193,7 @@ xenConnectClose(xenConnectPtr conn) {
} }
/** /**
* xenConnectGetVersion: * virConnectGetVersion:
* @conn: pointer to the hypervisor connection * @conn: pointer to the hypervisor connection
* *
* Get the version level of the Hypervisor running. * Get the version level of the Hypervisor running.
@ -201,7 +201,7 @@ xenConnectClose(xenConnectPtr conn) {
* Returns -1 in case of error or major * 10,000 + minor * 100 + rev otherwise * Returns -1 in case of error or major * 10,000 + minor * 100 + rev otherwise
*/ */
unsigned long unsigned long
xenConnectGetVersion(xenConnectPtr conn) { virConnectGetVersion(virConnectPtr conn) {
if (conn == NULL) if (conn == NULL)
return(-1); return(-1);
TODO TODO
@ -209,7 +209,7 @@ xenConnectGetVersion(xenConnectPtr conn) {
} }
/** /**
* xenConnectListDomains: * virConnectListDomains:
* @conn: pointer to the hypervisor connection * @conn: pointer to the hypervisor connection
* @ids: array to collect the list of IDs of active domains * @ids: array to collect the list of IDs of active domains
* @maxids: size of @ids * @maxids: size of @ids
@ -219,14 +219,14 @@ xenConnectGetVersion(xenConnectPtr conn) {
* Returns the number of domain found or -1 in case of error * Returns the number of domain found or -1 in case of error
*/ */
int int
xenConnectListDomains(xenConnectPtr conn, int *ids, int maxids) { virConnectListDomains(virConnectPtr conn, int *ids, int maxids) {
struct xs_transaction_handle* t; struct xs_transaction_handle* t;
int ret = -1; int ret = -1;
unsigned int num, i; unsigned int num, i;
long id; long id;
char **idlist = NULL, *endptr; char **idlist = NULL, *endptr;
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) || if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) ||
(ids == NULL) || (maxids <= 0)) (ids == NULL) || (maxids <= 0))
return(-1); return(-1);
@ -257,23 +257,23 @@ done:
} }
/** /**
* xenDomainCreateLinux: * virDomainCreateLinux:
* @conn: pointer to the hypervisor connection * @conn: pointer to the hypervisor connection
* @kernel_path: the file path to the kernel image * @kernel_path: the file path to the kernel image
* @initrd_path: an optional file path to an initrd * @initrd_path: an optional file path to an initrd
* @cmdline: optional command line parameters for the kernel * @cmdline: optional command line parameters for the kernel
* @memory: the memory size in kilobytes * @memory: the memory size in kilobytes
* @flags: an optional set of xenDomainFlags * @flags: an optional set of virDomainFlags
* *
* Launch a new Linux guest domain * Launch a new Linux guest domain
* *
* Returns a new domain object or NULL in case of failure * Returns a new domain object or NULL in case of failure
*/ */
xenDomainPtr virDomainPtr
xenDomainCreateLinux(xenConnectPtr conn, const char *kernel_path, virDomainCreateLinux(virConnectPtr 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) || (conn->magic != XEN_CONNECT_MAGIC) || if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) ||
(kernel_path == NULL) || (memory < 4096)) (kernel_path == NULL) || (memory < 4096))
return(NULL); return(NULL);
TODO TODO
@ -281,7 +281,7 @@ xenDomainCreateLinux(xenConnectPtr conn, const char *kernel_path,
} }
/** /**
* xenDomainLookupByName: * virDomainLookupByName:
* @conn: pointer to the hypervisor connection * @conn: pointer to the hypervisor connection
* @name: name for the domain * @name: name for the domain
* *
@ -289,16 +289,16 @@ xenDomainCreateLinux(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 virDomainPtr
xenDomainLookupByName(xenConnectPtr conn, const char *name) { virDomainLookupByName(virConnectPtr conn, const char *name) {
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) || (name == NULL)) if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) || (name == NULL))
return(NULL); return(NULL);
TODO TODO
return(NULL); return(NULL);
} }
/** /**
* xenConnectDoStoreQuery: * virConnectDoStoreQuery:
* @conn: pointer to the hypervisor connection * @conn: pointer to the hypervisor connection
* @path: the absolute path of the data in the store to retrieve * @path: the absolute path of the data in the store to retrieve
* *
@ -307,7 +307,7 @@ xenDomainLookupByName(xenConnectPtr conn, const char *name) {
* Returns a string which must be freed by the caller or NULL in case of error * Returns a string which must be freed by the caller or NULL in case of error
*/ */
static char * static char *
xenConnectDoStoreQuery(xenConnectPtr conn, const char *path) { virConnectDoStoreQuery(virConnectPtr conn, const char *path) {
struct xs_transaction_handle* t; struct xs_transaction_handle* t;
char *ret = NULL; char *ret = NULL;
unsigned int len = 0; unsigned int len = 0;
@ -325,7 +325,7 @@ done:
} }
/** /**
* xenDomainDoStoreQuery: * virDomainDoStoreQuery:
* @domain: a domain object * @domain: a domain object
* @path: the relative path of the data in the store to retrieve * @path: the relative path of the data in the store to retrieve
* *
@ -334,7 +334,7 @@ done:
* Returns a string which must be freed by the caller or NULL in case of error * Returns a string which must be freed by the caller or NULL in case of error
*/ */
static char * static char *
xenDomainDoStoreQuery(xenDomainPtr domain, const char *path) { virDomainDoStoreQuery(virDomainPtr domain, const char *path) {
struct xs_transaction_handle* t; struct xs_transaction_handle* t;
char s[256]; char s[256];
char *ret = NULL; char *ret = NULL;
@ -356,7 +356,7 @@ done:
} }
/** /**
* xenDomainLookupByID: * virDomainLookupByID:
* @conn: pointer to the hypervisor connection * @conn: pointer to the hypervisor connection
* @id: the domain ID number * @id: the domain ID number
* *
@ -364,17 +364,17 @@ done:
* *
* Returns a new domain object or NULL in case of failure * Returns a new domain object or NULL in case of failure
*/ */
xenDomainPtr virDomainPtr
xenDomainLookupByID(xenConnectPtr conn, int id) { virDomainLookupByID(virConnectPtr conn, int id) {
char *path; char *path;
xenDomainPtr ret; virDomainPtr ret;
xc_dominfo_t info; xc_dominfo_t info;
int res; int res;
if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) || (id < 0)) if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) || (id < 0))
return(NULL); return(NULL);
if ((conn->flags & XEN_CONNECT_RO) == 0) { if ((conn->flags & VIR_CONNECT_RO) == 0) {
res = xc_domain_getinfo(conn->handle, (uint32_t) id, 1, &info); res = xc_domain_getinfo(conn->handle, (uint32_t) id, 1, &info);
if (res != 1) { if (res != 1) {
return(NULL); return(NULL);
@ -385,22 +385,22 @@ xenDomainLookupByID(xenConnectPtr conn, int id) {
if (path == NULL) { if (path == NULL) {
return(NULL); return(NULL);
} }
ret = (xenDomainPtr) malloc(sizeof(xenDomain)); ret = (virDomainPtr) malloc(sizeof(virDomain));
if (ret == NULL) { if (ret == NULL) {
free(path); free(path);
return(NULL); return(NULL);
} }
ret->magic = XEN_DOMAIN_MAGIC; ret->magic = VIR_DOMAIN_MAGIC;
ret->conn = conn; ret->conn = conn;
ret->handle = id; ret->handle = id;
ret->path = path; ret->path = path;
ret->name = xenDomainDoStoreQuery(ret, "name"); ret->name = virDomainDoStoreQuery(ret, "name");
return(ret); return(ret);
} }
/** /**
* xenDomainDestroy: * virDomainDestroy:
* @domain: a domain object * @domain: a domain object
* *
* Destroy the domain object. The running instance is shutdown if not down * Destroy the domain object. The running instance is shutdown if not down
@ -409,51 +409,51 @@ xenDomainLookupByID(xenConnectPtr conn, int id) {
* Returns 0 in case of success and -1 in case of failure. * Returns 0 in case of success and -1 in case of failure.
*/ */
int int
xenDomainDestroy(xenDomainPtr domain) { virDomainDestroy(virDomainPtr domain) {
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC)) if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
return(-1); return(-1);
TODO TODO
return(-1); return(-1);
} }
/** /**
* xenDomainSuspend: * virDomainSuspend:
* @domain: a domain object * @domain: a domain object
* *
* Suspends an active domain, the process is frozen without further access * Suspends an active domain, the process is frozen without further access
* to CPU resources and I/O but the memory used by the domain at the * to CPU resources and I/O but the memory used by the domain at the
* hypervisor level will stay allocated. Use xenDomainResume() to reactivate * hypervisor level will stay allocated. Use virDomainResume() to reactivate
* the domain. * the domain.
* *
* Returns 0 in case of success and -1 in case of failure. * Returns 0 in case of success and -1 in case of failure.
*/ */
int int
xenDomainSuspend(xenDomainPtr domain) { virDomainSuspend(virDomainPtr domain) {
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC)) if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
return(-1); return(-1);
TODO TODO
return(-1); return(-1);
} }
/** /**
* xenDomainResume: * virDomainResume:
* @domain: a domain object * @domain: a domain object
* *
* Resume an suspended domain, the process is restarted from the state where * Resume an suspended domain, the process is restarted from the state where
* it was frozen by calling xenSuspendDomain(). * it was frozen by calling virSuspendDomain().
* *
* Returns 0 in case of success and -1 in case of failure. * Returns 0 in case of success and -1 in case of failure.
*/ */
int int
xenDomainResume(xenDomainPtr domain) { virDomainResume(virDomainPtr domain) {
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC)) if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
return(-1); return(-1);
TODO TODO
return(-1); return(-1);
} }
/** /**
* xenDomainGetName: * virDomainGetName:
* @domain: a domain object * @domain: a domain object
* *
* Get the public name for that domain * Get the public name for that domain
@ -462,14 +462,14 @@ xenDomainResume(xenDomainPtr domain) {
* its lifetime will be the same as the domain object. * its lifetime will be the same as the domain object.
*/ */
const char * const char *
xenDomainGetName(xenDomainPtr domain) { virDomainGetName(virDomainPtr domain) {
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC)) if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
return(NULL); return(NULL);
return(domain->name); return(domain->name);
} }
/** /**
* xenDomainGetID: * virDomainGetID:
* @domain: a domain object * @domain: a domain object
* *
* Get the hypervisor ID number for the domain * Get the hypervisor ID number for the domain
@ -477,14 +477,14 @@ xenDomainGetName(xenDomainPtr domain) {
* Returns the domain ID number or (unsigned int) -1 in case of error * Returns the domain ID number or (unsigned int) -1 in case of error
*/ */
unsigned int unsigned int
xenDomainGetID(xenDomainPtr domain) { virDomainGetID(virDomainPtr domain) {
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC)) if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
return((unsigned int) -1); return((unsigned int) -1);
return(domain->handle); return(domain->handle);
} }
/** /**
* xenDomainGetMaxMemory: * virDomainGetMaxMemory:
* @domain: a domain object or NULL * @domain: a domain object or NULL
* *
* Retrieve the maximum amount of physical memory allocated to a * Retrieve the maximum amount of physical memory allocated to a
@ -494,15 +494,15 @@ xenDomainGetID(xenDomainPtr domain) {
* Returns the memory size in kilobytes or 0 in case of error. * Returns the memory size in kilobytes or 0 in case of error.
*/ */
unsigned long unsigned long
xenDomainGetMaxMemory(xenDomainPtr domain) { virDomainGetMaxMemory(virDomainPtr domain) {
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC)) if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
return(0); return(0);
TODO TODO
return(0); return(0);
} }
/** /**
* xenDomainSetMaxMemory: * virDomainSetMaxMemory:
* @domain: a domain object or NULL * @domain: a domain object or NULL
* @memory: the memory size in kilobytes * @memory: the memory size in kilobytes
* *
@ -513,8 +513,8 @@ xenDomainGetMaxMemory(xenDomainPtr domain) {
* Returns 0 in case of success and -1 in case of failure. * Returns 0 in case of success and -1 in case of failure.
*/ */
int int
xenDomainSetMaxMemory(xenDomainPtr domain, unsigned long memory) { virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC) || if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC) ||
(memory < 4096)) (memory < 4096))
return(-1); return(-1);
TODO TODO

19
src/libvir_sym.version Normal file
View File

@ -0,0 +1,19 @@
{
global:
virConnectOpen;
virConnectOpenReadOnly;
virConnectClose;
virConnectGetVersion;
virDomainCreateLinux;
virConnectListDomains;
virDomainLookupByName;
virDomainLookupByID;
virDomainDestroy;
virDomainSuspend;
virDomainResume;
virDomainGetName;
virDomainGetID;
virDomainGetMaxMemory;
virDomainSetMaxMemory;
local: *;
};

View File

@ -1,19 +0,0 @@
{
global:
xenConnectOpen;
xenConnectOpenReadOnly;
xenConnectClose;
xenConnectGetVersion;
xenDomainCreateLinux;
xenConnectListDomains;
xenDomainLookupByName;
xenDomainLookupByID;
xenDomainDestroy;
xenDomainSuspend;
xenDomainResume;
xenDomainGetName;
xenDomainGetID;
xenDomainGetMaxMemory;
xenDomainSetMaxMemory;
local: *;
};

View File

@ -1,5 +1,5 @@
/* /*
* xensh.c: a Xen shell used to exercise the libxen API * virsh.c: a Xen shell used to exercise the libvir API
* *
* Copyright (C) 2005 Red Hat, Inc. * Copyright (C) 2005 Red Hat, Inc.
* *
@ -8,36 +8,36 @@
* Daniel Veillard <veillard@redhat.com> * Daniel Veillard <veillard@redhat.com>
*/ */
#include "libxen.h" #include "libvir.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#define MAX_DOM 100 #define MAX_DOM 100
int errcode = 0; int errcode = 0;
xenConnectPtr conn; virConnectPtr conn;
xenDomainPtr dom0; virDomainPtr dom0;
int ids[MAX_DOM]; int ids[MAX_DOM];
static void printDomain(xenDomainPtr dom) { static void printDomain(virDomainPtr dom) {
printf("id %d: name %s\n", xenDomainGetID(dom), xenDomainGetName(dom)); printf("id %d: name %s\n", virDomainGetID(dom), virDomainGetName(dom));
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int ret, i; int ret, i;
xenDomainPtr dom; virDomainPtr dom;
if (getuid() == 0) { if (getuid() == 0) {
conn = xenConnectOpen(NULL); conn = virConnectOpen(NULL);
} else { } else {
conn = xenConnectOpenReadOnly(NULL); conn = virConnectOpenReadOnly(NULL);
} }
if (conn == NULL) { if (conn == NULL) {
fprintf(stderr, "Failed to connect to the hypervisor\n"); fprintf(stderr, "Failed to connect to the hypervisor\n");
errcode = 1; errcode = 1;
goto done; goto done;
} }
dom0 = xenDomainLookupByID(conn, 0); dom0 = virDomainLookupByID(conn, 0);
if (dom0 == NULL) { if (dom0 == NULL) {
fprintf(stderr, "Failed to get domain 0 informations\n"); fprintf(stderr, "Failed to get domain 0 informations\n");
errcode = 2; errcode = 2;
@ -47,7 +47,7 @@ int main(int argc, char **argv) {
printf("Dom0: "); printf("Dom0: ");
printDomain(dom0); printDomain(dom0);
ret = xenConnectListDomains(conn, &ids[0], MAX_DOM); ret = virConnectListDomains(conn, &ids[0], MAX_DOM);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Failed to list active domains\n"); fprintf(stderr, "Failed to list active domains\n");
errcode = 3; errcode = 3;
@ -58,7 +58,7 @@ int main(int argc, char **argv) {
if (ids[i] == 0) if (ids[i] == 0)
continue; continue;
printf(" "); printf(" ");
dom = xenDomainLookupByID(conn, ids[i]); dom = virDomainLookupByID(conn, ids[i]);
if (dom == NULL) { if (dom == NULL) {
printf("domain %d disapeared\n", ids[i]); printf("domain %d disapeared\n", ids[i]);
} else { } else {
@ -68,7 +68,7 @@ int main(int argc, char **argv) {
done: done:
if (conn != NULL) { if (conn != NULL) {
ret = xenConnectClose(conn); ret = virConnectClose(conn);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, "Failed to connect to the hypervisor\n"); fprintf(stderr, "Failed to connect to the hypervisor\n");
if (errcode == 0) if (errcode == 0)