提交 ded06db1 编写于 作者: D Daniel Veillard

* configure.in include/libvir.h.in include/libvir.h src/Makefile.am

  include/Makefile.am: provide/fix library versionning information
  include/libvir.h is now generated !
* include/libvir.h.in src/libvir.c: revamp APIs and implement
  complete ones.
* src/virsh.c: finish the version command and a bit of cleanup.
Daniel
上级 304e52d0
Thu Dec 8 16:07:07 CET 2005 Daniel Veillard <veillard@redhat.com>
* configure.in include/libvir.h.in include/libvir.h src/Makefile.am
include/Makefile.am: provide/fix library versionning information
include/libvir.h is now generated !
* include/libvir.h.in src/libvir.c: revamp APIs and implement
complete ones.
* src/virsh.c: finish the version command and a bit of cleanup.
Thu Dec 8 15:20:57 CET 2005 Karel Zak <kzak@redhat.com>
* src/virsh.c: code cleanup to prevent gcc warnings
Thu Dec 8 14:25:09 CET 2005 Daniel Veillard <veillard@redhat.com>
......
......@@ -3,33 +3,33 @@ AC_INIT(src/libvir.c)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST
LIBXEN_MAJOR_VERSION=0
LIBXEN_MINOR_VERSION=0
LIBXEN_MICRO_VERSION=1
LIBXEN_MICRO_VERSION_SUFFIX=
LIBXEN_VERSION=$LIBXEN_MAJOR_VERSION.$LIBXEN_MINOR_VERSION.$LIBXEN_MICRO_VERSION$LIBXEN_MICRO_VERSION_SUFFIX
LIBXEN_VERSION_INFO=`expr $LIBXEN_MAJOR_VERSION + $LIBXEN_MINOR_VERSION`:$LIBXEN_MICRO_VERSION:$LIBXEN_MINOR_VERSION
LIBVIR_MAJOR_VERSION=0
LIBVIR_MINOR_VERSION=0
LIBVIR_MICRO_VERSION=1
LIBVIR_MICRO_VERSION_SUFFIX=
LIBVIR_VERSION=$LIBVIR_MAJOR_VERSION.$LIBVIR_MINOR_VERSION.$LIBVIR_MICRO_VERSION$LIBVIR_MICRO_VERSION_SUFFIX
LIBVIR_VERSION_INFO=`expr $LIBVIR_MAJOR_VERSION + $LIBVIR_MINOR_VERSION`:$LIBVIR_MICRO_VERSION:$LIBVIR_MINOR_VERSION
LIBXEN_VERSION_NUMBER=`expr $LIBXEN_MAJOR_VERSION \* 10000 + $LIBXEN_MINOR_VERSION \* 100 + $LIBXEN_MICRO_VERSION`
LIBVIR_VERSION_NUMBER=`expr $LIBVIR_MAJOR_VERSION \* 1000000 + $LIBVIR_MINOR_VERSION \* 1000 + $LIBVIR_MICRO_VERSION`
if test -f CVS/Entries; then
extra=`grep ChangeLog CVS/Entries | grep -v LIBXEN | sed -e s\%/ChangeLog/1\.%% -e s\%/.*$%%`
extra=`grep ChangeLog CVS/Entries | grep -v LIBVIR | sed -e s\%/ChangeLog/1\.%% -e s\%/.*$%%`
echo extra=$extra
if test "$extra" != ""
then
LIBXEN_VERSION_EXTRA="-CVS$extra"
LIBVIR_VERSION_EXTRA="-CVS$extra"
fi
fi
AC_SUBST(LIBXEN_MAJOR_VERSION)
AC_SUBST(LIBXEN_MINOR_VERSION)
AC_SUBST(LIBXEN_MICRO_VERSION)
AC_SUBST(LIBXEN_VERSION)
AC_SUBST(LIBXEN_VERSION_INFO)
AC_SUBST(LIBXEN_VERSION_NUMBER)
AC_SUBST(LIBXEN_VERSION_EXTRA)
AC_SUBST(LIBVIR_MAJOR_VERSION)
AC_SUBST(LIBVIR_MINOR_VERSION)
AC_SUBST(LIBVIR_MICRO_VERSION)
AC_SUBST(LIBVIR_VERSION)
AC_SUBST(LIBVIR_VERSION_INFO)
AC_SUBST(LIBVIR_VERSION_NUMBER)
AC_SUBST(LIBVIR_VERSION_EXTRA)
VERSION=${LIBXEN_VERSION}
VERSION=${LIBVIR_VERSION}
AM_INIT_AUTOMAKE(libvir, $VERSION)
......@@ -78,7 +78,7 @@ dnl
CFLAGS="-g -O -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
dnl search for the low level Xen library
dnl search for the Xen store library
AC_SEARCH_LIBS(xs_read, [xenstore], [], [AC_MSG_ERROR([Xen store library not found])])
dnl virsh libraries
......@@ -92,4 +92,5 @@ AC_CHECK_LIB(readline, main,
[$VIRSH_LIBS])
AC_SUBST(VIRSH_LIBS)
AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile libvir.pc libvir.spec)
AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
libvir.pc libvir.spec include/libvir.h)
......@@ -7,3 +7,4 @@ virinc_HEADERS = libvir.h
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(virincdir)
EXTRA_DIST = libvir.h.in
......@@ -109,6 +109,21 @@ typedef enum {
VIR_DOMAIN_NONE = 0
} virDomainFlags;
/* library versionning */
/**
* LIBVIR_VERSION_NUMBER:
*
* Macro providing the version of the library as
* version * 1,000,000 + minor * 1000 + micro
*/
#define LIBVIR_VERSION_NUMBER 1
int virGetVersion (unsigned long *libVer,
const char *type,
unsigned long *typeVer);
/*
* Connection and disconnections to the Hypervisor
*/
......@@ -116,7 +131,8 @@ virConnectPtr virConnectOpen (const char *name);
virConnectPtr virConnectOpenReadOnly (const char *name);
int virConnectClose (virConnectPtr conn);
const char * virConnectGetType (virConnectPtr conn);
unsigned long virConnectGetVersion (virConnectPtr conn);
int virConnectGetVersion (virConnectPtr conn,
unsigned long *hvVer);
/*
* Gather list of running domains
......
/*
* libvir.h:
* Summary: core interfaces for the libvir library
* Description: Provides the interfaces of the libvir library to handle
* Xen domains from a process running in domain 0
*
* Copy: Copyright (C) 2005 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
* Author: 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;
/**
* virDomainState:
*
* A domain may be in different states at a given point in time
*/
typedef enum {
VIR_DOMAIN_NOSTATE = 0, /* no state */
VIR_DOMAIN_RUNNING = 1, /* the domain is running */
VIR_DOMAIN_BLOCKED = 2, /* the domain is blocked on resource */
VIR_DOMAIN_PAUSED = 3, /* the domain is paused by user */
VIR_DOMAIN_SHUTDOWN= 4, /* the domain is being shut down */
VIR_DOMAIN_SHUTOFF = 5 /* the domain is shut off */
} virDomainState;
/**
* virDomainInfoPtr:
*
* a virDomainInfo is a structure filled by virDomainGetInfo()
*/
typedef struct _virDomainInfo virDomainInfo;
struct _virDomainInfo {
unsigned char state; /* the running state, one of virDomainFlags */
unsigned long maxMem; /* the maximum memory in KBytes allowed */
unsigned long memory; /* the memory in KBytes used by the domain */
unsigned short nrVirtCpu; /* the number of virtual CPUs for the domain */
/*
* Informations below are only available to clients with a connection
* with full access to the hypervisor
*/
unsigned long long cpuTime; /* the CPU time used in nanoseconds */
/*
* TODO:
* - check what can be extracted publicly from xenstore
* and what's private limited to the hypervisor call.
* - add padding to this structure for ABI long term protection
*/
};
/**
* virDomainInfoPtr:
*
* a virDomainInfoPtr is a pointer to a virDomainInfo structure.
*/
typedef virDomainInfo *virDomainInfoPtr;
/**
* virDomainFlags:
*
* Flags OR'ed together to provide specific behaviour when creating a
* Domain.
*/
typedef enum {
VIR_DOMAIN_NONE = 0
} virDomainFlags;
/* library versionning */
/**
* LIBVIR_VERSION_NUMBER:
*
* Macro providing the version of the library as
* version * 1,000,000 + minor * 1000 + micro
*/
#define LIBVIR_VERSION_NUMBER @LIBVIR_VERSION_NUMBER@
int virGetVersion (unsigned long *libVer,
const char *type,
unsigned long *typeVer);
/*
* Connection and disconnections to the Hypervisor
*/
virConnectPtr virConnectOpen (const char *name);
virConnectPtr virConnectOpenReadOnly (const char *name);
int virConnectClose (virConnectPtr conn);
const char * virConnectGetType (virConnectPtr conn);
int virConnectGetVersion (virConnectPtr conn,
unsigned long *hvVer);
/*
* Gather list of running domains
*/
int virConnectListDomains (virConnectPtr conn,
int *ids,
int maxids);
/*
* Number of domains
*/
int virConnectNumOfDomains (virConnectPtr conn);
/*
* 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);
/*
* Domain runtime informations
*/
int virDomainGetInfo (virDomainPtr domain,
virDomainInfoPtr info);
/*
* 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__ */
......@@ -7,3 +7,4 @@ virinc_HEADERS = libvir.h
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(virincdir)
EXTRA_DIST = libvir.h.in
......@@ -10,7 +10,7 @@ EXTRA_DIST = libvir_sym.version
lib_LTLIBRARIES = libvir.la
libvir_la_LIBADD =
libvir_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvir_sym.version \
-version-info @LIBXEN_VERSION_INFO@
-version-info @LIBVIR_VERSION_INFO@
libvir_la_SOURCES = \
libvir.c internal.hi \
hash.c hash.h \
......
......@@ -63,6 +63,47 @@ struct _virDomain {
int handle; /* internal handle for the dmonain ID */
};
/**
* virGetVersion:
* @libVer: return value for the library version (OUT)
* @type: hypervisor type
* @typeVer: return value for the version of the hypervisor (OUT)
*
* Provides two information back, @libVer is the version of the library
* while @typeVer will be the version of the hypervisor type @type against
* which the library was compiled. If @type is NULL, "Xen" is assumed, if
* @type is unknown or not availble, an error code will be returned and
* @typeVer will be 0.
*
* Returns -1 in case of failure, 0 otherwise, and values for @libVer and
* @typeVer have the format major * 1,000,000 + minor * 1,000 + release.
*/
int
virGetVersion(unsigned long *libVer, const char *type, unsigned long *typeVer) {
if (libVer == NULL)
return(-1);
*libVer = LIBVIR_VERSION_NUMBER;
if (typeVer != NULL) {
if ((type == NULL) || (!strcasecmp(type, "Xen"))) {
if ((DOM0_INTERFACE_VERSION & 0xFFFF0000) == (0xAAAA0000)) {
/* one time glitch hopefully ! */
*typeVer = 2 * 1000000 +
((DOM0_INTERFACE_VERSION >> 8) & 0xFF) * 1000 +
(DOM0_INTERFACE_VERSION & 0xFF);
} else {
*typeVer = (DOM0_INTERFACE_VERSION >> 24) * 1000000 +
((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 +
(DOM0_INTERFACE_VERSION & 0xFFFF);
}
} else {
*typeVer = 0;
return(-1);
}
}
return(0);
}
/**
* virConnectOpen:
* @name: optional argument currently unused, pass NULL
......@@ -212,28 +253,32 @@ virConnectGetType(virConnectPtr conn) {
/**
* virConnectGetVersion:
* @conn: pointer to the hypervisor connection
* @hvVer: return value for the version of the running hypervisor (OUT)
*
* Get the version level of the Hypervisor running. This may work only with
* hypervisor call, i.e. with priviledged access to the hypervisor, not
* with a Read-Only connection.
*
* Returns -1 in case of error, 0 if the version can't be extracted by lack
* of capacities otherwise major * 1,000,000 + minor * 1,000 + release
* Returns -1 in case of error, 0 otherwise. if the version can't be
* extracted by lack of capacities returns 0 and @hvVer is 0, otherwise
* @hvVer value is major * 1,000,000 + minor * 1,000 + release
*/
unsigned long
virConnectGetVersion(virConnectPtr conn) {
unsigned long ver, ret;
int
virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) {
unsigned long ver;
if (conn == NULL)
if ((conn == NULL) || (hvVer == NULL) || (conn->magic != VIR_CONNECT_MAGIC))
return(-1);
/* this can't be extracted from the Xenstore */
if (conn->handle < 0)
if (conn->handle < 0) {
*hvVer = 0;
return(0);
}
ver = xenHypervisorGetVersion(conn->handle);
ret = (ver >> 16) * 1000000 + (ver & 0xFFFF) * 1000;
return(ret);
*hvVer = (ver >> 16) * 1000000 + (ver & 0xFFFF) * 1000;
return(0);
}
/**
......
......@@ -28,6 +28,7 @@
#include <readline/history.h>
#include "config.h"
#include "internal.h"
static char *progname;
......@@ -270,11 +271,9 @@ static vshCmdInfo info_list[] = {
static int
cmdList(vshControl *ctl, vshCmd *cmd) {
cmdList(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
int *ids, maxid, i;
(void) cmd; /* happy gcc */
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
......@@ -509,12 +508,17 @@ static vshCmdInfo info_version[] = {
static int
cmdVersion(vshControl *ctl, vshCmd *cmd) {
cmdVersion(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
unsigned long hvVersion;
const char *hvType;
unsigned long libVersion;
unsigned long includeVersion;
unsigned long apiVersion;
int ret;
unsigned int major;
unsigned int minor;
unsigned int rel;
(void)cmd;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
......@@ -524,9 +528,36 @@ cmdVersion(vshControl *ctl, vshCmd *cmd) {
return FALSE;
}
hvVersion = virConnectGetVersion(ctl->conn);
if (hvVersion < 0) {
vshError(ctl, FALSE, "failed get hypervisor version");
includeVersion = LIBVIR_VERSION_NUMBER;
major = includeVersion / 1000000;
includeVersion %= 1000000;
minor = includeVersion / 1000;
rel = includeVersion % 1000;
vshPrint(ctl, VSH_MESG, "Compiled against library: libvir %d.%d.%d\n",
major, minor, rel);
ret = virGetVersion(&libVersion, hvType, &apiVersion);
if (ret < 0) {
vshError(ctl, FALSE, "failed to get the library version");
return FALSE;
}
major = libVersion / 1000000;
libVersion %= 1000000;
minor = libVersion / 1000;
rel = libVersion % 1000;
vshPrint(ctl, VSH_MESG, "Using library: libvir %d.%d.%d\n",
major, minor, rel);
major = apiVersion / 1000000;
apiVersion %= 1000000;
minor = apiVersion / 1000;
rel = apiVersion % 1000;
vshPrint(ctl, VSH_MESG, "Using API: %s %d.%d.%d\n", hvType,
major, minor, rel);
ret = virConnectGetVersion(ctl->conn, &hvVersion);
if (ret < 0) {
vshError(ctl, FALSE, "failed to get the hypervisor version");
return FALSE;
}
if (hvVersion == 0) {
......@@ -534,13 +565,10 @@ cmdVersion(vshControl *ctl, vshCmd *cmd) {
"cannot extract running %s hypervisor version\n",
hvType);
} else {
unsigned int major = hvVersion / 1000000;
unsigned int minor;
unsigned int rel;
major = hvVersion / 1000000;
hvVersion %= 1000000;
minor = hvVersion / 1000000;
rel = hvVersion % 1000000;
minor = hvVersion / 1000;
rel = hvVersion % 1000;
vshPrint(ctl, VSH_MESG, "Running hypervisor: %s %d.%d.%d\n", hvType,
major, minor, rel);
......@@ -558,8 +586,7 @@ static vshCmdInfo info_quit[] = {
};
static int
cmdQuit(vshControl *ctl, vshCmd *cmd) {
(void)cmd;
cmdQuit(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
ctl->imode = FALSE;
return TRUE;
}
......@@ -1207,11 +1234,9 @@ vshReadlineOptionsGenerator(const char *text, int state) {
}
static char **
vshReadlineCompletion(const char *text, int start, int end) {
vshReadlineCompletion(const char *text, int start, int end ATTRIBUTE_UNUSED) {
char **matches = (char **) NULL;
(void) end; /* happy gcc */
if (start==0)
/* command name generator */
matches = rl_completion_matches (text, vshReadlineCommandGenerator);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册