]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
* Makefile.am README TODO autogen.sh configure.in libvir.pc.in
authorDaniel Veillard <veillard@redhat.com>
Mon, 5 Dec 2005 11:16:07 +0000 (11:16 +0000)
committerDaniel Veillard <veillard@redhat.com>
Mon, 5 Dec 2005 11:16:07 +0000 (11:16 +0000)
  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

27 files changed:
ChangeLog
Makefile.am
README
TODO
autogen.sh
configure.in
docs/Makefile.am
docs/apibuild.py
docs/structures.fig
include/Makefile.am
include/libvir.h [new file with mode: 0644]
include/libvirt/Makefile.am
include/libxen.h [deleted file]
libvir.pc.in [new file with mode: 0644]
libvir.spec.in [new file with mode: 0644]
libxen.pc.in [deleted file]
libxen.spec.in [deleted file]
src/Makefile.am
src/hash.c
src/hash.h
src/internal.h
src/libvir.c [new file with mode: 0644]
src/libvir_sym.version [new file with mode: 0644]
src/libxen.c [deleted file]
src/libxen_sym.version [deleted file]
src/virsh.c [new file with mode: 0644]
src/xensh.c [deleted file]

index 83d1b7f4b7e23276d8f2216317a183411437ed40..f4bc864ab80dae6471d09e8d64ca63dcea869342 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * include/libxen.h src/libxen.c src/libxen_sym.version: adding
index 9c6812c7c9a12837a63c714c4419890488b7d502..1a83a139de340338f77a1cbe84db5bc6f144d88b 100644 (file)
@@ -1,12 +1,12 @@
 ## Process this file with automake to produce Makefile.in
 
 SUBDIRS = src include docs
-EXTRA_DIST = libxen.spec.in libxen.spec COPYING.LIB \
-             libxen.pc.in libxen.pc TODO AUTHORS ChangeLog \
+EXTRA_DIST = libvir.spec.in libvir.spec COPYING.LIB \
+             libvir.pc.in libvir.pc TODO AUTHORS ChangeLog \
             NEWS README 
 
 pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libxen.pc
+pkgconfig_DATA = libvir.pc
 
 rpm: clean
        @(unset CDPATH ; $(MAKE) dist && rpmbuild -ta $(distdir).tar.gz)
diff --git a/README b/README
index 94c569fda3d58275a869ae9ad6293e195ee85694..ce2fca79781814169a35dcc6f16b704fdd29d205 100644 (file)
--- a/README
+++ b/README
@@ -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
 usable in any way yet.
diff --git a/TODO b/TODO
index 7902d5624d6f34bf42c0550dbc9cc45eb1922f9b..3c30be02fa70e8ee89c0b61e2bdfdd251ec72422 100644 (file)
--- a/TODO
+++ b/TODO
@@ -2,4 +2,4 @@
 
 Done:
 - 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
index 60e36c64fe34b6dc624446c18b21acff772f2cf9..7e8656595c60a5c2af09340366e88897271c23d9 100755 (executable)
@@ -36,7 +36,7 @@ if test "$DIE" -eq 1; then
        exit 1
 fi
 
-test -f src/libxen.c || {
+test -f src/libvir.c || {
        echo "You must run this script in the top-level libxen directory"
        exit 1
 }
@@ -61,4 +61,4 @@ fi
 $srcdir/configure "$@"
 
 echo 
-echo "Now type 'make' to compile libxen."
+echo "Now type 'make' to compile libvir."
index bd57d6e0a2e6a39c7bd80f7c01ec71aebc33c700..29dfde1361018a3de613664b33f8c6ad2aed62c4 100644 (file)
@@ -1,5 +1,5 @@
 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)
 AC_CANONICAL_HOST
 
@@ -31,7 +31,7 @@ AC_SUBST(LIBXEN_VERSION_EXTRA)
 
 VERSION=${LIBXEN_VERSION}
 
-AM_INIT_AUTOMAKE(libxen, $VERSION)
+AM_INIT_AUTOMAKE(libvir, $VERSION)
 
 dnl Checks for programs.
 AC_PROG_CC
@@ -50,7 +50,7 @@ AM_PROG_LIBTOOL
 dnl
 dnl specific tests to setup DV devel environments with debug etc ...
 dnl
-if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/libxen" ]] ; then
+if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/libvir" ]] ; 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"
     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(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)
index cf041cfdc66758c6f42e12c560f20d2908e4e3d3..783a492661d3dc3de89616bd10e486dbd6f353fe 100644 (file)
@@ -8,14 +8,14 @@ PAGES= # index.html
 APIPAGES=APIconstructors.html APIfiles.html APIfunctions.html \
     APIsymbols.html APIchunk0.html
 EXTRA_DIST=                                                    \
-          libxen-api.xml apibuild.py
+          libvir-api.xml apibuild.py
 
 
 man_MANS=
 
 all: web $(man_MANS)
 
-api: libxen-api.xml libxen-refs.xml
+api: libvir-api.xml libvir-refs.xml
 
 web: $(PAGES)
 
@@ -45,14 +45,14 @@ web: $(PAGES)
 #        echo "Validating the resulting XHTML pages" ; \
 #        $(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)
 
 clean-local:
        rm -f *~ *.bak *.hierarchy *.signals *-unused.txt
 
 maintainer-clean-local: clean-local
-       rm -rf libxen-api.xml libxen-refs.xml
+       rm -rf libvir-api.xml libvir-refs.xml
 
 rebuild: api all
 
index b7efe1e32272fdd6441584ccfbcd751d4e3020fa..972f500b8da82c21608a6f9267ec44fd98fc2d3e 100755 (executable)
@@ -18,7 +18,7 @@ debugsym=None
 # C parser analysis code
 #
 ignored_files = {
-  "xensh.c": "testing tool",
+  "virsh.c": "testing tool",
   "hash.c": "internal hash table stuff",
   "hash.h": "internal hash table stuff",
 }
@@ -1068,7 +1068,7 @@ class CParser:
                if self.collect_ref == 1:
                    oldtok = 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] == "(":
                            self.index_add_ref(oldtok[1], self.filename,
                                                0, "function")
@@ -2044,13 +2044,13 @@ class docBuilder:
 
 def rebuild():
     builder = None
-    if glob.glob("../src/libxen.c") != [] :
-        print "Rebuilding API description for libxen"
-       builder = docBuilder("libxen", ["../src", "../include"],
+    if glob.glob("../src/libvir.c") != [] :
+        print "Rebuilding API description for libvir"
+       builder = docBuilder("libvir", ["../src", "../include"],
                             [])
     elif glob.glob("src/parser.c") != [] :
-        print "Rebuilding API description for libxml2"
-       builder = docBuilder("libxen", ["src", "include"],
+        print "Rebuilding API description for libvir"
+       builder = docBuilder("libvir", ["src", "include"],
                             [])
     else:
         print "rebuild() failed, unable to guess the module"
index b6d3cce2166eed9818697c4c5c0c816c01072a72..b5596acf6ad9ff0a0e928678b1bbdfa2bbfabf0c 100644 (file)
@@ -59,8 +59,8 @@ Single
         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 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 2055 975 5700 xenConnectionPtr\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 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 135 555 3450 2475 conn\001
 4 0 0 50 -1 0 18 0.0000 4 135 615 6075 1050 name\001
index 14aaf754bc13a7b7d8da2321cdc5a9357b2e0b2a..ccbed6c0da53b74e8db1c939f09022c860af924d 100644 (file)
@@ -1,9 +1,9 @@
 ## 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:
-       $(mkinstalldirs) $(DESTDIR)$(xenincdir)
+       $(mkinstalldirs) $(DESTDIR)$(virincdir)
 
diff --git a/include/libvir.h b/include/libvir.h
new file mode 100644 (file)
index 0000000..6894d1b
--- /dev/null
@@ -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__ */
index 14aaf754bc13a7b7d8da2321cdc5a9357b2e0b2a..ccbed6c0da53b74e8db1c939f09022c860af924d 100644 (file)
@@ -1,9 +1,9 @@
 ## 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:
-       $(mkinstalldirs) $(DESTDIR)$(xenincdir)
+       $(mkinstalldirs) $(DESTDIR)$(virincdir)
 
diff --git a/include/libxen.h b/include/libxen.h
deleted file mode 100644 (file)
index b30f399..0000000
+++ /dev/null
@@ -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__ */
diff --git a/libvir.pc.in b/libvir.pc.in
new file mode 100644 (file)
index 0000000..2997db0
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libxen
+Version: @VERSION@
+Description: libxen library
+Requires:
+Libs: -L${libdir} -lxen @LIBS@
+Cflags:
diff --git a/libvir.spec.in b/libvir.spec.in
new file mode 100644 (file)
index 0000000..9c6a397
--- /dev/null
@@ -0,0 +1,62 @@
+Summary: Library providing an API to use the Xen virtualization
+Name: libvir
+Version: @VERSION@
+Release: 1
+License: LGPL
+Group: Development/Libraries
+Source: libvir-%{version}.tar.gz
+BuildRoot: %{_tmppath}/%{name}-%{version}-root
+URL: http://www.gnome.org/~veillard/gamin/
+BuildRequires: xen
+Requires: xen
+
+%description
+This C library provides an API to use the Xen virtualization framework
+
+%package devel
+Summary: Libraries, includes, etc. to compile with the libvir library
+Group: Development/Libraries
+Requires: libvir = %{version}
+
+%description devel
+This C library provides an API to use the Xen virtualization framework
+
+%prep
+%setup -q
+
+%build
+%configure
+make
+
+%install
+rm -fr %{buildroot}
+
+%makeinstall
+rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
+
+%clean
+rm -fr %{buildroot}
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+%files
+%defattr(-, root, root)
+
+%doc AUTHORS ChangeLog NEWS README COPYING.LIB TODO
+%{_libdir}/lib*.so.*
+
+%files devel
+%defattr(-, root, root)
+
+%{_libdir}/lib*.so
+%{_libdir}/*a
+%{_includedir}/libvir/*.h
+%{_libdir}/pkgconfig/libvir.pc
+
+%changelog
+* Wed Nov  2 2005 Daniel Veillard <veillard@redhat.com> 0.0.1-1
+- created
diff --git a/libxen.pc.in b/libxen.pc.in
deleted file mode 100644 (file)
index 2997db0..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: libxen
-Version: @VERSION@
-Description: libxen library
-Requires:
-Libs: -L${libdir} -lxen @LIBS@
-Cflags:
diff --git a/libxen.spec.in b/libxen.spec.in
deleted file mode 100644 (file)
index 3eac05e..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-Summary: Library providing an API to use the Xen virtualization
-Name: libxen
-Version: @VERSION@
-Release: 1
-License: LGPL
-Group: Development/Libraries
-Source: libxen-%{version}.tar.gz
-BuildRoot: %{_tmppath}/%{name}-%{version}-root
-URL: http://www.gnome.org/~veillard/gamin/
-BuildRequires: xen
-Requires: xen
-
-%description
-This C library provides an API to use the Xen virtualization framework
-
-%package devel
-Summary: Libraries, includes, etc. to compile with the libxen library
-Group: Development/Libraries
-Requires: libxen = %{version}
-
-%description devel
-This C library provides an API to use the Xen virtualization framework
-
-%prep
-%setup -q
-
-%build
-%configure
-make
-
-%install
-rm -fr %{buildroot}
-
-%makeinstall
-rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
-
-%clean
-rm -fr %{buildroot}
-
-%post
-/sbin/ldconfig
-
-%postun
-/sbin/ldconfig
-
-%files
-%defattr(-, root, root)
-
-%doc AUTHORS ChangeLog NEWS README COPYING.LIB TODO
-%{_libdir}/lib*.so.*
-
-%files devel
-%defattr(-, root, root)
-
-%{_libdir}/lib*.so
-%{_libdir}/*a
-%{_includedir}/libxen/*.h
-%{_libdir}/pkgconfig/libxen.pc
-
-%changelog
-* Wed Nov  2 2005 Daniel Veillard <veillard@redhat.com> 0.0.1-1
-- created
index 8ee97eb827b9e04c3dfdb9f15f805dcd0dd67b81..ae7f299bec557cbd1d19d52328d0b5dbc4398ea0 100644 (file)
@@ -1,21 +1,21 @@
 ## Process this file with automake to produce Makefile.in
 
 INCLUDES = -I$(top_builddir)/include -I@srcdir@/include
-DEPS = libxen.la
-LDADDS = @STATIC_BINARIES@ libxen.la
+DEPS = libvir.la
+LDADDS = @STATIC_BINARIES@ libvir.la
 
-EXTRA_DIST = libxen_sym.version
+EXTRA_DIST = libvir_sym.version
 
-lib_LTLIBRARIES = libxen.la
-libxen_la_LIBADD = 
-libxen_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libxen_sym.version \
+lib_LTLIBRARIES = libvir.la
+libvir_la_LIBADD = 
+libvir_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvir_sym.version \
                     -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
-xensh_LDFLAGS =
-xensh_DEPENDENCIES = $(DEPS)
-xensh_LDADD= $(LDADDS)
+virsh_SOURCES=virsh.c
+virsh_LDFLAGS =
+virsh_DEPENDENCIES = $(DEPS)
+virsh_LDADD= $(LDADDS)
 
index 3673b60d2fccbe2f043af3b24f906a7bb1c8a3d8..4614f7a82172164daec6561acf1233151648a07e 100644 (file)
 /*
  * A single entry in the hash table
  */
-typedef struct _xenHashEntry xenHashEntry;
-typedef xenHashEntry *xenHashEntryPtr;
-struct _xenHashEntry {
-    struct _xenHashEntry *next;
+typedef struct _virHashEntry virHashEntry;
+typedef virHashEntry *virHashEntryPtr;
+struct _virHashEntry {
+    struct _virHashEntry *next;
     char *name;
     void *payload;
     int valid;
@@ -41,18 +41,18 @@ struct _xenHashEntry {
 /*
  * The entire hash table
  */
-struct _xenHashTable {
-    struct _xenHashEntry *table;
+struct _virHashTable {
+    struct _virHashEntry *table;
     int size;
     int nbElems;
 };
 
 /*
- * xenHashComputeKey:
+ * virHashComputeKey:
  * Calculate the hash key
  */
 static unsigned long
-xenHashComputeKey(xenHashTablePtr table, const char *name) {
+virHashComputeKey(virHashTablePtr table, const char *name) {
     unsigned long value = 0L;
     char ch;
     
@@ -66,27 +66,27 @@ xenHashComputeKey(xenHashTablePtr table, const char *name) {
 }
 
 /**
- * xenHashCreate:
+ * virHashCreate:
  * @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.
  */
-xenHashTablePtr
-xenHashCreate(int size) {
-    xenHashTablePtr table;
+virHashTablePtr
+virHashCreate(int size) {
+    virHashTablePtr table;
   
     if (size <= 0)
         size = 256;
   
-    table = malloc(sizeof(xenHashTable));
+    table = malloc(sizeof(virHashTable));
     if (table) {
         table->size = size;
        table->nbElems = 0;
-        table->table = malloc(size * sizeof(xenHashEntry));
+        table->table = malloc(size * sizeof(virHashEntry));
         if (table->table) {
-           memset(table->table, 0, size * sizeof(xenHashEntry));
+           memset(table->table, 0, size * sizeof(virHashEntry));
            return(table);
         }
         free(table);
@@ -95,7 +95,7 @@ xenHashCreate(int size) {
 }
 
 /**
- * xenHashGrow:
+ * virHashGrow:
  * @table: 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
  */
 static int
-xenHashGrow(xenHashTablePtr table, int size) {
+virHashGrow(virHashTablePtr table, int size) {
     unsigned long key;
     int oldsize, i;
-    xenHashEntryPtr iter, next;
-    struct _xenHashEntry *oldtable;
+    virHashEntryPtr iter, next;
+    struct _virHashEntry *oldtable;
 #ifdef DEBUG_GROW
     unsigned long nbElem = 0;
 #endif
@@ -125,12 +125,12 @@ xenHashGrow(xenHashTablePtr table, int size) {
     if (oldtable == NULL)
         return(-1);
   
-    table->table = malloc(size * sizeof(xenHashEntry));
+    table->table = malloc(size * sizeof(virHashEntry));
     if (table->table == NULL) {
        table->table = oldtable;
        return(-1);
     }
-    memset(table->table, 0, size * sizeof(xenHashEntry));
+    memset(table->table, 0, size * sizeof(virHashEntry));
     table->size = size;
 
     /* 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++) {
        if (oldtable[i].valid == 0) 
            continue;
-       key = xenHashComputeKey(table, oldtable[i].name);
-       memcpy(&(table->table[key]), &(oldtable[i]), sizeof(xenHashEntry));
+       key = virHashComputeKey(table, oldtable[i].name);
+       memcpy(&(table->table[key]), &(oldtable[i]), sizeof(virHashEntry));
        table->table[key].next = NULL;
     }
 
@@ -156,9 +156,9 @@ xenHashGrow(xenHashTablePtr table, int size) {
             * put back the entry in the new table
             */
 
-           key = xenHashComputeKey(table, iter->name);
+           key = virHashComputeKey(table, iter->name);
            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;
                free(iter);
            } else {
@@ -178,14 +178,14 @@ xenHashGrow(xenHashTablePtr table, int size) {
 
 #ifdef DEBUG_GROW
     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
 
     return(0);
 }
 
 /**
- * xenHashFree:
+ * virHashFree:
  * @table: the hash table
  * @f:  the deallocator function for items in the hash
  *
@@ -193,10 +193,10 @@ xenHashGrow(xenHashTablePtr table, int size) {
  * deallocated with @f if provided.
  */
 void
-xenHashFree(xenHashTablePtr table, xenHashDeallocator f) {
+virHashFree(virHashTablePtr table, virHashDeallocator f) {
     int i;
-    xenHashEntryPtr iter;
-    xenHashEntryPtr next;
+    virHashEntryPtr iter;
+    virHashEntryPtr next;
     int inside_table = 0;
     int nbElems;
 
@@ -230,7 +230,7 @@ xenHashFree(xenHashTablePtr table, xenHashDeallocator f) {
 }
 
 /**
- * xenHashAddEntry3:
+ * virHashAddEntry3:
  * @table: the hash table
  * @name: the name of 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.
  */
 int
-xenHashAddEntry(xenHashTablePtr table, const char *name,
+virHashAddEntry(virHashTablePtr table, const char *name,
                 void *userdata) {
     unsigned long key, len = 0;
-    xenHashEntryPtr entry;
-    xenHashEntryPtr insert;
+    virHashEntryPtr entry;
+    virHashEntryPtr insert;
 
     if ((table == NULL) || (name == NULL))
        return(-1);
@@ -253,7 +253,7 @@ xenHashAddEntry(xenHashTablePtr table, const char *name,
     /*
      * Check for duplicate and insertion location.
      */
-    key = xenHashComputeKey(table, name);
+    key = virHashComputeKey(table, name);
     if (table->table[key].valid == 0) {
        insert = NULL;
     } else {
@@ -270,7 +270,7 @@ xenHashAddEntry(xenHashTablePtr table, const char *name,
     if (insert == NULL) {
        entry = &(table->table[key]);
     } else {
-       entry = malloc(sizeof(xenHashEntry));
+       entry = malloc(sizeof(virHashEntry));
        if (entry == NULL)
             return(-1);
     }
@@ -287,13 +287,13 @@ xenHashAddEntry(xenHashTablePtr table, const char *name,
     table->nbElems++;
 
     if (len > MAX_HASH_LEN)
-       xenHashGrow(table, MAX_HASH_LEN * table->size);
+       virHashGrow(table, MAX_HASH_LEN * table->size);
 
     return(0);
 }
 
 /**
- * xenHashUpdateEntry:
+ * virHashUpdateEntry:
  * @table: the hash table
  * @name: the name of 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.
  */
 int
-xenHashUpdateEntry(xenHashTablePtr table, const char *name,
-                  void *userdata, xenHashDeallocator f) {
+virHashUpdateEntry(virHashTablePtr table, const char *name,
+                  void *userdata, virHashDeallocator f) {
     unsigned long key;
-    xenHashEntryPtr entry;
-    xenHashEntryPtr insert;
+    virHashEntryPtr entry;
+    virHashEntryPtr insert;
 
     if ((table == NULL) || name == NULL)
        return(-1);
@@ -318,7 +318,7 @@ xenHashUpdateEntry(xenHashTablePtr table, const char *name,
     /*
      * Check for duplicate and insertion location.
      */
-    key = xenHashComputeKey(table, name);
+    key = virHashComputeKey(table, name);
     if (table->table[key].valid == 0) {
        insert = NULL;
     } else {
@@ -342,7 +342,7 @@ xenHashUpdateEntry(xenHashTablePtr table, const char *name,
     if (insert == NULL) {
        entry =  &(table->table[key]);
     } else {
-       entry = malloc(sizeof(xenHashEntry));
+       entry = malloc(sizeof(virHashEntry));
        if (entry == NULL)
             return(-1);
     }
@@ -361,7 +361,7 @@ xenHashUpdateEntry(xenHashTablePtr table, const char *name,
 }
 
 /**
- * xenHashLookup:
+ * virHashLookup:
  * @table: the hash table
  * @name: the name of the userdata
  *
@@ -370,15 +370,15 @@ xenHashUpdateEntry(xenHashTablePtr table, const char *name,
  * Returns the a pointer to the userdata
  */
 void *
-xenHashLookup(xenHashTablePtr table, const char *name) {
+virHashLookup(virHashTablePtr table, const char *name) {
     unsigned long key;
-    xenHashEntryPtr entry;
+    virHashEntryPtr entry;
 
     if (table == NULL)
        return(NULL);
     if (name == NULL)
        return(NULL);
-    key = xenHashComputeKey(table, name);
+    key = virHashComputeKey(table, name);
     if (table->table[key].valid == 0)
        return(NULL);
     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
  *
  * 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
  */
 int
-xenHashSize(xenHashTablePtr table) {
+virHashSize(virHashTablePtr table) {
     if (table == NULL)
        return(-1);
     return(table->nbElems);
 }
 
 /**
- * xenHashRemoveEntry:
+ * virHashRemoveEntry:
  * @table: the hash table
  * @name: the name of the userdata
  * @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.
  */
 int
-xenHashRemoveEntry(xenHashTablePtr table, const char *name,
-                   xenHashDeallocator f) {
+virHashRemoveEntry(virHashTablePtr table, const char *name,
+                   virHashDeallocator f) {
     unsigned long key;
-    xenHashEntryPtr entry;
-    xenHashEntryPtr prev = NULL;
+    virHashEntryPtr entry;
+    virHashEntryPtr prev = NULL;
 
     if (table == NULL || name == NULL)
         return(-1);
 
-    key = xenHashComputeKey(table, name);
+    key = virHashComputeKey(table, name);
     if (table->table[key].valid == 0) {
         return(-1);
     } else {
@@ -445,7 +445,7 @@ xenHashRemoveEntry(xenHashTablePtr table, const char *name,
                        entry->valid = 0;
                    } else {
                        entry = entry->next;
-                       memcpy(&(table->table[key]), entry, sizeof(xenHashEntry));
+                       memcpy(&(table->table[key]), entry, sizeof(virHashEntry));
                        free(entry);
                    }
                }
index 6ebb571c220bf73d026590b6d7815a0d047628cb..d6eb42187da740a7a2d0ef0c3f21d5d89de13f69 100644 (file)
@@ -8,8 +8,8 @@
  * Author: Bjorn Reese <bjorn.reese@systematic.dk>
  */
 
-#ifndef __XEN_HASH_H__
-#define __XEN_HASH_H__
+#ifndef __VIR_HASH_H__
+#define __VIR_HASH_H__
 
 #ifdef __cplusplus
 extern "C" {
@@ -18,54 +18,54 @@ extern "C" {
 /*
  * The hash table.
  */
-typedef struct _xenHashTable xenHashTable;
-typedef xenHashTable *xenHashTablePtr;
+typedef struct _virHashTable virHashTable;
+typedef virHashTable *virHashTablePtr;
 
 /*
  * function types:
  */
 /**
- * xenHashDeallocator:
+ * virHashDeallocator:
  * @payload:  the data in the hash
  * @name:  the name associated
  *
  * Callback to free data from a hash.
  */
-typedef void (*xenHashDeallocator)(void *payload, char *name);
+typedef void (*virHashDeallocator)(void *payload, char *name);
 
 /*
  * Constructor and destructor.
  */
-xenHashTablePtr                xenHashCreate   (int size);
+virHashTablePtr                virHashCreate   (int size);
 void                   
-                       xenHashFree     (xenHashTablePtr table,
-                                        xenHashDeallocator f);
-int                    xenHashSize     (xenHashTablePtr table);
+                       virHashFree     (virHashTablePtr table,
+                                        virHashDeallocator f);
+int                    virHashSize     (virHashTablePtr table);
 
 /*
  * Add a new entry to the hash table.
  */
-int                    xenHashAddEntry (xenHashTablePtr table,
+int                    virHashAddEntry (virHashTablePtr table,
                                         const char *name,
                                         void *userdata);
-int                    xenHashUpdateEntry(xenHashTablePtr table,
+int                    virHashUpdateEntry(virHashTablePtr table,
                                         const char *name,
                                         void *userdata,
-                                        xenHashDeallocator f);
+                                        virHashDeallocator f);
 
 /*
  * Remove an entry from the hash table.
  */
-int                            xenHashRemoveEntry(xenHashTablePtr table,
+int                            virHashRemoveEntry(virHashTablePtr table,
                                         const char *name,
-                                        xenHashDeallocator f);
+                                        virHashDeallocator f);
 /*
  * Retrieve the userdata.
  */
-void *                 xenHashLookup   (xenHashTablePtr table,
+void *                 virHashLookup   (virHashTablePtr table,
                                         const char *name);
 
 #ifdef __cplusplus
 }
 #endif
-#endif /* ! __XEN_HASH_H__ */
+#endif /* ! __VIR_HASH_H__ */
index e79fe47b14632a0402e246ed4d1975d36bf64268..4591e8b5de4caef16e95d057eb1d201008b72e56 100644 (file)
@@ -2,8 +2,8 @@
  * internal.h: internal definitions just used by code from the library
  */
 
-#ifndef __XEN_INTERNAL_H__
-#define __XEN_INTERNAL_H__
+#ifndef __VIR_INTERNAL_H__
+#define __VIR_INTERNAL_H__
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,4 +38,4 @@ extern "C" {
 }
 #endif /* __cplusplus */
 
-#endif /* __XEN_INTERNAL_H__ */
+#endif /* __VIR_INTERNAL_H__ */
diff --git a/src/libvir.c b/src/libvir.c
new file mode 100644 (file)
index 0000000..28032d3
--- /dev/null
@@ -0,0 +1,523 @@
+/*
+ * libvir.h: Main interfaces for the libvir library to handle virtualization
+ *           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>
+ */
+
+#include "libvir.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <xenctrl.h>
+#include <xs.h>
+#include "internal.h"
+#include "hash.h"
+
+
+/*
+ * 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 VIR_CONNECT_MAGIC 0x4F23DEAD
+
+/*
+ * Flags for Xen connections
+ */
+#define VIR_CONNECT_RO 1
+
+/**
+ * _virConnect:
+ *
+ * Internal structure associated to a connection
+ */
+struct _virConnect {
+    unsigned int magic;                /* specific value to check */
+    int                 handle;        /* internal handle used for hypercall */
+    struct xs_handle *xshandle;        /* handle to talk to the xenstore */
+    virHashTablePtr   domains; /* hash table for known domains */
+    int          flags;                /* a set of connection flags */
+};
+
+#define VIR_DOMAIN_MAGIC 0xDEAD4321
+
+/**
+ * _virDomain:
+ *
+ * Internal structure associated to a domain
+ */
+struct _virDomain {
+    unsigned int magic;                /* specific value to check */
+    virConnectPtr conn;                /* pointer back to the connection */
+    char        *name;         /* the domain external name */
+    char        *path;         /* the domain internal path */
+    int                 handle;        /* internal handle for the dmonain ID */
+};
+
+/**
+ * virConnectOpen:
+ * @name: optional argument currently unused, pass NULL
+ *
+ * This function should be called first to get a connection to the 
+ * Hypervisor and xen store
+ *
+ * Returns a pointer to the hypervisor connection or NULL in case of error
+ */
+virConnectPtr
+virConnectOpen(const char *name) {
+    virConnectPtr ret = NULL;
+    int handle = -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 == NULL)
+        goto failed;
+
+    ret = (virConnectPtr) malloc(sizeof(virConnect));
+    if (ret == NULL)
+        goto failed;
+    ret->magic = VIR_CONNECT_MAGIC;
+    ret->handle = handle;
+    ret->xshandle = xshandle;
+    ret->domains = virHashCreate(20);
+    ret->flags = 0;
+    if (ret->domains == NULL)
+        goto failed;
+
+    return(ret);
+failed:
+    if (handle >= 0)
+        xc_interface_close(handle);
+    if (xshandle != NULL)
+        xs_daemon_close(xshandle);
+    if (ret != NULL)
+        free(ret);
+    return(NULL);
+}
+
+/**
+ * virConnectOpenReadOnly:
+ * @name: optional argument currently unused, pass NULL
+ *
+ * This function should be called first to get a read-only connection to the 
+ * xen store. The set of APIs usable are then restricted.
+ *
+ * Returns a pointer to the hypervisor connection or NULL in case of error
+ */
+virConnectPtr
+virConnectOpenReadOnly(const char *name) {
+    virConnectPtr ret = NULL;
+    struct xs_handle *xshandle = NULL;
+
+    /* we can only talk to the local Xen supervisor ATM */
+    if (name != NULL) 
+        return(NULL);
+
+    xshandle = xs_daemon_open_readonly();
+    if (xshandle == NULL)
+        goto failed;
+
+    ret = (virConnectPtr) malloc(sizeof(virConnect));
+    if (ret == NULL)
+        goto failed;
+    ret->magic = VIR_CONNECT_MAGIC;
+    ret->handle = -1;
+    ret->xshandle = xshandle;
+    ret->domains = virHashCreate(20);
+    ret->flags = VIR_CONNECT_RO;
+    if (ret->domains == NULL)
+        goto failed;
+
+    return(ret);
+failed:
+    if (xshandle != NULL)
+        xs_daemon_close(xshandle);
+    if (ret != NULL)
+        free(ret);
+    return(NULL);
+}
+
+/**
+ * virDomainDestroyName:
+ * @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
+virDomainDestroyName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
+    return(virDomainDestroy(domain));
+}
+
+/**
+ * virConnectClose:
+ * @conn: pointer to the hypervisor connection
+ *
+ * This function closes the connection to the Hypervisor. This should
+ * not be called if further interaction with the Hypervisor are needed
+ * especially if there is running domain which need further monitoring by
+ * the application.
+ *
+ * Returns 0 in case of success or -1 in case of error.
+ */
+int
+virConnectClose(virConnectPtr conn) {
+    if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC))
+        return(-1);
+
+    virHashFree(conn->domains, (virHashDeallocator) virDomainDestroyName);
+    conn->magic = -1;
+    xs_daemon_close(conn->xshandle);
+    conn->xshandle = NULL;
+    if (conn->handle != -1)
+       xc_interface_close(conn->handle);
+    conn->handle = -1;
+    free(conn);
+    return(0);
+}
+
+/**
+ * virConnectGetVersion:
+ * @conn: pointer to the hypervisor connection
+ *
+ * Get the version level of the Hypervisor running.
+ *
+ * Returns -1 in case of error or major * 10,000 + minor * 100 + rev otherwise
+ */
+unsigned long
+virConnectGetVersion(virConnectPtr conn) {
+    if (conn == NULL)
+        return(-1);
+    TODO
+    return(-1);
+}
+
+/**
+ * virConnectListDomains:
+ * @conn: pointer to the hypervisor connection
+ * @ids: array to collect the list of IDs of active domains
+ * @maxids: size of @ids
+ *
+ * Collect the list of active domains, and store their ID in @maxids
+ *
+ * Returns the number of domain found or -1 in case of error
+ */
+int
+virConnectListDomains(virConnectPtr conn, int *ids, int maxids) {
+    struct xs_transaction_handle* t;
+    int ret = -1;
+    unsigned int num, i;
+    long id;
+    char **idlist = NULL, *endptr;
+
+    if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) ||
+        (ids == NULL) || (maxids <= 0))
+        return(-1);
+    
+    t = xs_transaction_start(conn->xshandle);
+    if (t == NULL)
+        goto done;
+
+    idlist = xs_directory(conn->xshandle, t, "/local/domain", &num);
+    if (idlist == NULL)
+        goto done;
+
+    for (ret = 0,i = 0;(i < num) && (ret < maxids);i++) {
+        id = strtol(idlist[i], &endptr, 10);
+       if ((endptr == idlist[i]) || (*endptr != 0)) {
+           ret = -1;
+           goto done;
+       }
+       ids[ret++] = (int) id;
+    }
+
+done:
+    if (t != NULL)
+       xs_transaction_end(conn->xshandle, t, 0);
+    if (idlist != NULL)
+        free(idlist);
+
+    return(ret);
+}
+
+/**
+ * virDomainCreateLinux:
+ * @conn: pointer to the hypervisor connection
+ * @kernel_path: the file path to the kernel image
+ * @initrd_path: an optional file path to an initrd
+ * @cmdline: optional command line parameters for the kernel
+ * @memory: the memory size in kilobytes
+ * @flags: an optional set of virDomainFlags
+ *
+ * Launch a new Linux guest domain 
+ * 
+ * Returns a new domain object or NULL in case of failure
+ */
+virDomainPtr
+virDomainCreateLinux(virConnectPtr conn, const char *kernel_path,
+                    const char *initrd_path, const char *cmdline,
+                    unsigned long memory, unsigned int flags) {
+    if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) ||
+        (kernel_path == NULL) || (memory < 4096))
+        return(NULL);
+    TODO
+    return(NULL);
+}
+
+/**
+ * virDomainLookupByName:
+ * @conn: pointer to the hypervisor connection
+ * @name: name for the domain
+ *
+ * Try to lookup a domain on the given hypervisor
+ *
+ * Returns a new domain object or NULL in case of failure
+ */
+virDomainPtr
+virDomainLookupByName(virConnectPtr conn, const char *name) {
+    if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) || (name == NULL))
+        return(NULL);
+    TODO
+    return(NULL);
+}
+
+/**
+ * virConnectDoStoreQuery:
+ * @conn: pointer to the hypervisor connection
+ * @path: the absolute path of the data in the store to retrieve
+ *
+ * Internal API querying the Xenstore for a string value.
+ *
+ * Returns a string which must be freed by the caller or NULL in case of error
+ */
+static char *
+virConnectDoStoreQuery(virConnectPtr conn, const char *path) {
+    struct xs_transaction_handle* t;
+    char *ret = NULL;
+    unsigned int len = 0;
+
+    t = xs_transaction_start(conn->xshandle);
+    if (t == NULL)
+        goto done;
+
+    ret = xs_read(conn->xshandle, t, path, &len);
+
+done:
+    if (t != NULL)
+       xs_transaction_end(conn->xshandle, t, 0);
+    return(ret);
+}
+
+/**
+ * virDomainDoStoreQuery:
+ * @domain: a domain object
+ * @path: the relative path of the data in the store to retrieve
+ *
+ * Internal API querying the Xenstore for a string value.
+ *
+ * Returns a string which must be freed by the caller or NULL in case of error
+ */
+static char *
+virDomainDoStoreQuery(virDomainPtr domain, const char *path) {
+    struct xs_transaction_handle* t;
+    char s[256];
+    char *ret = NULL;
+    unsigned int len = 0;
+
+    snprintf(s, 255, "/local/domain/%d/%s", domain->handle, path);
+    s[255] = 0;
+
+    t = xs_transaction_start(domain->conn->xshandle);
+    if (t == NULL)
+        goto done;
+
+    ret = xs_read(domain->conn->xshandle, t, &s[0], &len);
+
+done:
+    if (t != NULL)
+       xs_transaction_end(domain->conn->xshandle, t, 0);
+    return(ret);
+}
+
+/**
+ * virDomainLookupByID:
+ * @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
+ */
+virDomainPtr
+virDomainLookupByID(virConnectPtr conn, int id) {
+    char *path;
+    virDomainPtr ret;
+    xc_dominfo_t info;
+    int res;
+
+    if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) || (id < 0))
+        return(NULL);
+
+    if ((conn->flags & VIR_CONNECT_RO) == 0) {
+       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 = (virDomainPtr) malloc(sizeof(virDomain));
+    if (ret == NULL) {
+        free(path);
+       return(NULL);
+    }
+    ret->magic = VIR_DOMAIN_MAGIC;
+    ret->conn = conn;
+    ret->handle = id;
+    ret->path = path;
+    ret->name = virDomainDoStoreQuery(ret, "name");
+
+    return(ret);
+}
+
+/**
+ * virDomainDestroy:
+ * @domain: a domain object
+ *
+ * Destroy the domain object. The running instance is shutdown if not down
+ * already and all resources used by it are given back to the hypervisor.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainDestroy(virDomainPtr domain) {
+    if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
+        return(-1);
+    TODO
+    return(-1);
+}
+
+/**
+ * virDomainSuspend:
+ * @domain: a domain object
+ *
+ * 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 
+ * hypervisor level will stay allocated. Use virDomainResume() to reactivate
+ * the domain.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainSuspend(virDomainPtr domain) {
+    if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
+        return(-1);
+    TODO
+    return(-1);
+}
+
+/**
+ * virDomainResume:
+ * @domain: a domain object
+ *
+ * Resume an suspended domain, the process is restarted from the state where
+ * it was frozen by calling virSuspendDomain().
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainResume(virDomainPtr domain) {
+    if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
+        return(-1);
+    TODO
+    return(-1);
+}
+
+/**
+ * virDomainGetName:
+ * @domain: a domain object
+ *
+ * Get the public name for that domain
+ *
+ * Returns a pointer to the name or NULL, the string need not be deallocated
+ * its lifetime will be the same as the domain object.
+ */
+const char *
+virDomainGetName(virDomainPtr domain) {
+    if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
+        return(NULL);
+    return(domain->name);
+}
+
+/**
+ * virDomainGetID:
+ * @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
+virDomainGetID(virDomainPtr domain) {
+    if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
+        return((unsigned int) -1);
+    return(domain->handle);
+}
+
+/**
+ * virDomainGetMaxMemory:
+ * @domain: a domain object or NULL
+ * 
+ * Retrieve the maximum amount of physical memory allocated to a
+ * domain. If domain is NULL, then this get the amount of memory reserved
+ * to Domain0 i.e. the domain where the application runs.
+ *
+ * Returns the memory size in kilobytes or 0 in case of error.
+ */
+unsigned long
+virDomainGetMaxMemory(virDomainPtr domain) {
+    if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
+        return(0);
+    TODO
+    return(0);
+}
+
+/**
+ * virDomainSetMaxMemory:
+ * @domain: a domain object or NULL
+ * @memory: the memory size in kilobytes
+ * 
+ * Dynamically change the maximum amount of physical memory allocated to a
+ * domain. If domain is NULL, then this change the amount of memory reserved
+ * to Domain0 i.e. the domain where the application runs.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
+    if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC) ||
+        (memory < 4096))
+        return(-1);
+    TODO
+    return(-1);
+}
+
diff --git a/src/libvir_sym.version b/src/libvir_sym.version
new file mode 100644 (file)
index 0000000..5771ba5
--- /dev/null
@@ -0,0 +1,19 @@
+{
+    global:
+        virConnectOpen;
+        virConnectOpenReadOnly;
+       virConnectClose;
+       virConnectGetVersion;
+       virDomainCreateLinux;
+       virConnectListDomains;
+       virDomainLookupByName;
+       virDomainLookupByID;
+       virDomainDestroy;
+       virDomainSuspend;
+       virDomainResume;
+       virDomainGetName;
+       virDomainGetID;
+       virDomainGetMaxMemory;
+       virDomainSetMaxMemory;
+    local: *;
+};
diff --git a/src/libxen.c b/src/libxen.c
deleted file mode 100644 (file)
index bd1eaca..0000000
+++ /dev/null
@@ -1,523 +0,0 @@
-/*
- * libxen.h: Main interfaces for the libxen library to handle virtualization
- *           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>
- */
-
-#include "libxen.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <xenctrl.h>
-#include <xs.h>
-#include "internal.h"
-#include "hash.h"
-
-
-/*
- * 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
-
-/*
- * Flags for Xen connections
- */
-#define XEN_CONNECT_RO 1
-
-/**
- * _xenConnect:
- *
- * Internal structure associated to a connection
- */
-struct _xenConnect {
-    unsigned int magic;                /* specific value to check */
-    int                 handle;        /* internal handle used for hypercall */
-    struct xs_handle *xshandle;        /* handle to talk to the xenstore */
-    xenHashTablePtr   domains; /* hash table for known domains */
-    int          flags;                /* a set of connection flags */
-};
-
-#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 */
-    char        *path;         /* the domain internal path */
-    int                 handle;        /* internal handle for the dmonain ID */
-};
-
-/**
- * xenConnectOpen:
- * @name: optional argument currently unused, pass NULL
- *
- * This function should be called first to get a connection to the 
- * Hypervisor and xen store
- *
- * Returns a pointer to the hypervisor connection or NULL in case of error
- */
-xenConnectPtr
-xenConnectOpen(const char *name) {
-    xenConnectPtr ret = NULL;
-    int handle = -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 == NULL)
-        goto failed;
-
-    ret = (xenConnectPtr) malloc(sizeof(xenConnect));
-    if (ret == NULL)
-        goto failed;
-    ret->magic = XEN_CONNECT_MAGIC;
-    ret->handle = handle;
-    ret->xshandle = xshandle;
-    ret->domains = xenHashCreate(20);
-    ret->flags = 0;
-    if (ret->domains == NULL)
-        goto failed;
-
-    return(ret);
-failed:
-    if (handle >= 0)
-        xc_interface_close(handle);
-    if (xshandle != NULL)
-        xs_daemon_close(xshandle);
-    if (ret != NULL)
-        free(ret);
-    return(NULL);
-}
-
-/**
- * xenConnectOpenReadOnly:
- * @name: optional argument currently unused, pass NULL
- *
- * This function should be called first to get a read-only connection to the 
- * xen store. The set of APIs usable are then restricted.
- *
- * Returns a pointer to the hypervisor connection or NULL in case of error
- */
-xenConnectPtr
-xenConnectOpenReadOnly(const char *name) {
-    xenConnectPtr ret = NULL;
-    struct xs_handle *xshandle = NULL;
-
-    /* we can only talk to the local Xen supervisor ATM */
-    if (name != NULL) 
-        return(NULL);
-
-    xshandle = xs_daemon_open_readonly();
-    if (xshandle == NULL)
-        goto failed;
-
-    ret = (xenConnectPtr) malloc(sizeof(xenConnect));
-    if (ret == NULL)
-        goto failed;
-    ret->magic = XEN_CONNECT_MAGIC;
-    ret->handle = -1;
-    ret->xshandle = xshandle;
-    ret->domains = xenHashCreate(20);
-    ret->flags = XEN_CONNECT_RO;
-    if (ret->domains == NULL)
-        goto failed;
-
-    return(ret);
-failed:
-    if (xshandle != NULL)
-        xs_daemon_close(xshandle);
-    if (ret != NULL)
-        free(ret);
-    return(NULL);
-}
-
-/**
- * xenDomainDestroyName:
- * @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
-xenDomainDestroyName(xenDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
-    return(xenDomainDestroy(domain));
-}
-
-/**
- * xenConnectClose:
- * @conn: pointer to the hypervisor connection
- *
- * This function closes the connection to the Hypervisor. This should
- * not be called if further interaction with the Hypervisor are needed
- * especially if there is running domain which need further monitoring by
- * the application.
- *
- * Returns 0 in case of success or -1 in case of error.
- */
-int
-xenConnectClose(xenConnectPtr conn) {
-    if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC))
-        return(-1);
-
-    xenHashFree(conn->domains, (xenHashDeallocator) xenDomainDestroyName);
-    conn->magic = -1;
-    xs_daemon_close(conn->xshandle);
-    conn->xshandle = NULL;
-    if (conn->handle != -1)
-       xc_interface_close(conn->handle);
-    conn->handle = -1;
-    free(conn);
-    return(0);
-}
-
-/**
- * xenConnectGetVersion:
- * @conn: pointer to the hypervisor connection
- *
- * Get the version level of the Hypervisor running.
- *
- * Returns -1 in case of error or major * 10,000 + minor * 100 + rev otherwise
- */
-unsigned long
-xenConnectGetVersion(xenConnectPtr conn) {
-    if (conn == NULL)
-        return(-1);
-    TODO
-    return(-1);
-}
-
-/**
- * xenConnectListDomains:
- * @conn: pointer to the hypervisor connection
- * @ids: array to collect the list of IDs of active domains
- * @maxids: size of @ids
- *
- * Collect the list of active domains, and store their ID in @maxids
- *
- * Returns the number of domain found or -1 in case of error
- */
-int
-xenConnectListDomains(xenConnectPtr conn, int *ids, int maxids) {
-    struct xs_transaction_handle* t;
-    int ret = -1;
-    unsigned int num, i;
-    long id;
-    char **idlist = NULL, *endptr;
-
-    if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) ||
-        (ids == NULL) || (maxids <= 0))
-        return(-1);
-    
-    t = xs_transaction_start(conn->xshandle);
-    if (t == NULL)
-        goto done;
-
-    idlist = xs_directory(conn->xshandle, t, "/local/domain", &num);
-    if (idlist == NULL)
-        goto done;
-
-    for (ret = 0,i = 0;(i < num) && (ret < maxids);i++) {
-        id = strtol(idlist[i], &endptr, 10);
-       if ((endptr == idlist[i]) || (*endptr != 0)) {
-           ret = -1;
-           goto done;
-       }
-       ids[ret++] = (int) id;
-    }
-
-done:
-    if (t != NULL)
-       xs_transaction_end(conn->xshandle, t, 0);
-    if (idlist != NULL)
-        free(idlist);
-
-    return(ret);
-}
-
-/**
- * xenDomainCreateLinux:
- * @conn: pointer to the hypervisor connection
- * @kernel_path: the file path to the kernel image
- * @initrd_path: an optional file path to an initrd
- * @cmdline: optional command line parameters for the kernel
- * @memory: the memory size in kilobytes
- * @flags: an optional set of xenDomainFlags
- *
- * Launch a new Linux guest domain 
- * 
- * Returns a new domain object or NULL in case of failure
- */
-xenDomainPtr
-xenDomainCreateLinux(xenConnectPtr conn, const char *kernel_path,
-                    const char *initrd_path, const char *cmdline,
-                    unsigned long memory, unsigned int flags) {
-    if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) ||
-        (kernel_path == NULL) || (memory < 4096))
-        return(NULL);
-    TODO
-    return(NULL);
-}
-
-/**
- * xenDomainLookupByName:
- * @conn: pointer to the hypervisor connection
- * @name: name for the domain
- *
- * Try to lookup a domain on the given hypervisor
- *
- * Returns a new domain object or NULL in case of failure
- */
-xenDomainPtr
-xenDomainLookupByName(xenConnectPtr conn, const char *name) {
-    if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) || (name == NULL))
-        return(NULL);
-    TODO
-    return(NULL);
-}
-
-/**
- * xenConnectDoStoreQuery:
- * @conn: pointer to the hypervisor connection
- * @path: the absolute path of the data in the store to retrieve
- *
- * Internal API querying the Xenstore for a string value.
- *
- * Returns a string which must be freed by the caller or NULL in case of error
- */
-static char *
-xenConnectDoStoreQuery(xenConnectPtr conn, const char *path) {
-    struct xs_transaction_handle* t;
-    char *ret = NULL;
-    unsigned int len = 0;
-
-    t = xs_transaction_start(conn->xshandle);
-    if (t == NULL)
-        goto done;
-
-    ret = xs_read(conn->xshandle, t, path, &len);
-
-done:
-    if (t != NULL)
-       xs_transaction_end(conn->xshandle, t, 0);
-    return(ret);
-}
-
-/**
- * xenDomainDoStoreQuery:
- * @domain: a domain object
- * @path: the relative path of the data in the store to retrieve
- *
- * Internal API querying the Xenstore for a string value.
- *
- * Returns a string which must be freed by the caller or NULL in case of error
- */
-static char *
-xenDomainDoStoreQuery(xenDomainPtr domain, const char *path) {
-    struct xs_transaction_handle* t;
-    char s[256];
-    char *ret = NULL;
-    unsigned int len = 0;
-
-    snprintf(s, 255, "/local/domain/%d/%s", domain->handle, path);
-    s[255] = 0;
-
-    t = xs_transaction_start(domain->conn->xshandle);
-    if (t == NULL)
-        goto done;
-
-    ret = xs_read(domain->conn->xshandle, t, &s[0], &len);
-
-done:
-    if (t != NULL)
-       xs_transaction_end(domain->conn->xshandle, t, 0);
-    return(ret);
-}
-
-/**
- * xenDomainLookupByID:
- * @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
-xenDomainLookupByID(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);
-
-    if ((conn->flags & XEN_CONNECT_RO) == 0) {
-       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->path = path;
-    ret->name = xenDomainDoStoreQuery(ret, "name");
-
-    return(ret);
-}
-
-/**
- * xenDomainDestroy:
- * @domain: a domain object
- *
- * Destroy the domain object. The running instance is shutdown if not down
- * already and all resources used by it are given back to the hypervisor.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-int
-xenDomainDestroy(xenDomainPtr domain) {
-    if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
-        return(-1);
-    TODO
-    return(-1);
-}
-
-/**
- * xenDomainSuspend:
- * @domain: a domain object
- *
- * 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 
- * hypervisor level will stay allocated. Use xenDomainResume() to reactivate
- * the domain.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-int
-xenDomainSuspend(xenDomainPtr domain) {
-    if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
-        return(-1);
-    TODO
-    return(-1);
-}
-
-/**
- * xenDomainResume:
- * @domain: a domain object
- *
- * Resume an suspended domain, the process is restarted from the state where
- * it was frozen by calling xenSuspendDomain().
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-int
-xenDomainResume(xenDomainPtr domain) {
-    if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
-        return(-1);
-    TODO
-    return(-1);
-}
-
-/**
- * xenDomainGetName:
- * @domain: a domain object
- *
- * Get the public name for that domain
- *
- * Returns a pointer to the name or NULL, the string need not be deallocated
- * its lifetime will be the same as the domain object.
- */
-const char *
-xenDomainGetName(xenDomainPtr domain) {
-    if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
-        return(NULL);
-    return(domain->name);
-}
-
-/**
- * xenDomainGetID:
- * @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
-xenDomainGetID(xenDomainPtr domain) {
-    if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
-        return((unsigned int) -1);
-    return(domain->handle);
-}
-
-/**
- * xenDomainGetMaxMemory:
- * @domain: a domain object or NULL
- * 
- * Retrieve the maximum amount of physical memory allocated to a
- * domain. If domain is NULL, then this get the amount of memory reserved
- * to Domain0 i.e. the domain where the application runs.
- *
- * Returns the memory size in kilobytes or 0 in case of error.
- */
-unsigned long
-xenDomainGetMaxMemory(xenDomainPtr domain) {
-    if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC))
-        return(0);
-    TODO
-    return(0);
-}
-
-/**
- * xenDomainSetMaxMemory:
- * @domain: a domain object or NULL
- * @memory: the memory size in kilobytes
- * 
- * Dynamically change the maximum amount of physical memory allocated to a
- * domain. If domain is NULL, then this change the amount of memory reserved
- * to Domain0 i.e. the domain where the application runs.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-int
-xenDomainSetMaxMemory(xenDomainPtr domain, unsigned long memory) {
-    if ((domain == NULL) || (domain->magic != XEN_DOMAIN_MAGIC) ||
-        (memory < 4096))
-        return(-1);
-    TODO
-    return(-1);
-}
-
diff --git a/src/libxen_sym.version b/src/libxen_sym.version
deleted file mode 100644 (file)
index 7d36508..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-{
-    global:
-        xenConnectOpen;
-        xenConnectOpenReadOnly;
-       xenConnectClose;
-       xenConnectGetVersion;
-       xenDomainCreateLinux;
-       xenConnectListDomains;
-       xenDomainLookupByName;
-       xenDomainLookupByID;
-       xenDomainDestroy;
-       xenDomainSuspend;
-       xenDomainResume;
-       xenDomainGetName;
-       xenDomainGetID;
-       xenDomainGetMaxMemory;
-       xenDomainSetMaxMemory;
-    local: *;
-};
diff --git a/src/virsh.c b/src/virsh.c
new file mode 100644 (file)
index 0000000..aa547f3
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * virsh.c: a Xen shell used to exercise the libvir API
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ *
+ * See COPYING.LIB for the License of this software
+ *
+ * Daniel Veillard <veillard@redhat.com>
+ */
+
+#include "libvir.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#define MAX_DOM 100
+int errcode = 0;
+virConnectPtr conn;
+virDomainPtr dom0;
+int ids[MAX_DOM];
+
+static void printDomain(virDomainPtr dom) {
+    printf("id %d: name %s\n", virDomainGetID(dom), virDomainGetName(dom));
+}
+
+int main(int argc, char **argv) {
+    int ret, i;
+    virDomainPtr dom;
+    
+    if (getuid() == 0) {
+       conn = virConnectOpen(NULL);
+    } else {
+       conn = virConnectOpenReadOnly(NULL);
+    }
+    if (conn == NULL) {
+        fprintf(stderr, "Failed to connect to the hypervisor\n");
+        errcode = 1;
+       goto done;
+    }
+    dom0 = virDomainLookupByID(conn, 0);
+    if (dom0 == NULL) {
+        fprintf(stderr, "Failed to get domain 0 informations\n");
+       errcode = 2;
+       goto done;
+    }
+
+    printf("Dom0: ");
+    printDomain(dom0);
+
+    ret = virConnectListDomains(conn, &ids[0], MAX_DOM);
+    if (ret < 0) {
+        fprintf(stderr, "Failed to list active domains\n");
+       errcode = 3;
+       goto done;
+    }
+    printf("Found %d more active domains\n", ret - 1);
+    for (i = 0;i < ret;i++) {
+        if (ids[i] == 0)
+           continue;
+        printf("  ");
+       dom = virDomainLookupByID(conn, ids[i]);
+       if (dom == NULL) {
+           printf("domain %d disapeared\n", ids[i]);
+       } else {
+           printDomain(dom);
+       }
+    }
+    
+done:
+    if (conn != NULL) {
+        ret = virConnectClose(conn);
+       if (ret != 0) {
+           fprintf(stderr, "Failed to connect to the hypervisor\n");
+           if (errcode == 0)
+               errcode = 1;
+       }
+    }
+    return(errcode);
+}
diff --git a/src/xensh.c b/src/xensh.c
deleted file mode 100644 (file)
index c671266..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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 <veillard@redhat.com>
- */
-
-#include "libxen.h"
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#define MAX_DOM 100
-int errcode = 0;
-xenConnectPtr conn;
-xenDomainPtr dom0;
-int ids[MAX_DOM];
-
-static void printDomain(xenDomainPtr dom) {
-    printf("id %d: name %s\n", xenDomainGetID(dom), xenDomainGetName(dom));
-}
-
-int main(int argc, char **argv) {
-    int ret, i;
-    xenDomainPtr dom;
-    
-    if (getuid() == 0) {
-       conn = xenConnectOpen(NULL);
-    } else {
-       conn = xenConnectOpenReadOnly(NULL);
-    }
-    if (conn == NULL) {
-        fprintf(stderr, "Failed to connect to the hypervisor\n");
-        errcode = 1;
-       goto done;
-    }
-    dom0 = xenDomainLookupByID(conn, 0);
-    if (dom0 == NULL) {
-        fprintf(stderr, "Failed to get domain 0 informations\n");
-       errcode = 2;
-       goto done;
-    }
-
-    printf("Dom0: ");
-    printDomain(dom0);
-
-    ret = xenConnectListDomains(conn, &ids[0], MAX_DOM);
-    if (ret < 0) {
-        fprintf(stderr, "Failed to list active domains\n");
-       errcode = 3;
-       goto done;
-    }
-    printf("Found %d more active domains\n", ret - 1);
-    for (i = 0;i < ret;i++) {
-        if (ids[i] == 0)
-           continue;
-        printf("  ");
-       dom = xenDomainLookupByID(conn, ids[i]);
-       if (dom == NULL) {
-           printf("domain %d disapeared\n", ids[i]);
-       } else {
-           printDomain(dom);
-       }
-    }
-    
-done:
-    if (conn != NULL) {
-        ret = xenConnectClose(conn);
-       if (ret != 0) {
-           fprintf(stderr, "Failed to connect to the hypervisor\n");
-           if (errcode == 0)
-               errcode = 1;
-       }
-    }
-    return(errcode);
-}