* 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
This commit is contained in:
Daniel Veillard
2005-12-08 15:08:46 +00:00
parent 304e52d02d
commit ded06db1e6
9 changed files with 339 additions and 50 deletions

View File

@@ -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 \

View File

@@ -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);
}
/**

View File

@@ -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);