admin: Introduce virAdmConnectGetLibVersion

Introduce a new API to get libvirt version. It is worth noting, that
libvirt-admin and libvirt share the same version number. Unfortunately,
our existing API isn't generic enough to be used with virAdmConnectPtr
as well. Also this patch wires up this API to the virt-admin client
as a generic cmdVersion command.
This commit is contained in:
Erik Skultety 2015-10-05 17:17:51 +02:00
parent 6dd7e42d89
commit a474371fc6
10 changed files with 135 additions and 4 deletions

View File

@ -114,4 +114,13 @@ adminDispatchConnectClose(virNetServerPtr server ATTRIBUTE_UNUSED,
return 0;
}
static int
adminConnectGetLibVersion(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
unsigned long long *libVer)
{
if (libVer)
*libVer = LIBVIR_VERSION_NUMBER;
return 0;
}
#include "admin_dispatch.h"

View File

@ -61,6 +61,9 @@ int virAdmGetVersion(unsigned long long *libVer);
char *virAdmConnectGetURI(virAdmConnectPtr conn);
int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
unsigned long long *libVer);
/**
* virAdmConnectCloseFunc:
* @conn: virAdmConnect connection

View File

@ -1,3 +1,4 @@
daemon/admin_dispatch.h
daemon/admin_server.c
daemon/libvirtd-config.c
daemon/libvirtd.c

View File

@ -41,6 +41,10 @@ struct admin_connect_open_args {
unsigned int flags;
};
struct admin_connect_get_lib_version_ret {
unsigned hyper libVer;
};
/* Define the program number, protocol version and procedure numbers here. */
const ADMIN_PROGRAM = 0x06900690;
const ADMIN_PROTOCOL_VERSION = 1;
@ -71,5 +75,10 @@ enum admin_procedure {
/**
* @generate: none
*/
ADMIN_PROC_CONNECT_CLOSE = 2
ADMIN_PROC_CONNECT_CLOSE = 2,
/**
* @generate: both
*/
ADMIN_PROC_CONNECT_GET_LIB_VERSION = 3
};

View File

@ -2,7 +2,11 @@
struct admin_connect_open_args {
u_int flags;
};
struct admin_connect_get_lib_version_ret {
uint64_t libVer;
};
enum admin_procedure {
ADMIN_PROC_CONNECT_OPEN = 1,
ADMIN_PROC_CONNECT_CLOSE = 2,
ADMIN_PROC_CONNECT_GET_LIB_VERSION = 3,
};

View File

@ -523,3 +523,34 @@ int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
virDispatchError(NULL);
return -1;
}
/**
* virAdmConnectGetLibVersion:
* @conn: pointer to an active admin connection
* @libVer: stores the current remote libvirt version number
*
* Retrieves the remote side libvirt version used by the daemon. Format
* returned in @libVer is of a following pattern:
* major * 1,000,000 + minor * 1,000 + release.
*
* Returns 0 on success, -1 on failure and @libVer follows this format:
*/
int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
unsigned long long *libVer)
{
VIR_DEBUG("conn=%p, libVir=%p", conn, libVer);
virResetLastError();
virCheckAdmConnectReturn(conn, -1);
virCheckNonNullArgReturn(libVer, -1);
if (remoteAdminConnectGetLibVersion(conn, libVer) < 0)
goto error;
return 0;
error:
virDispatchError(NULL);
return -1;
}

View File

@ -6,6 +6,7 @@
#
# admin/admin_protocol.x
xdr_admin_connect_get_lib_version_ret;
xdr_admin_connect_open_args;
# Let emacs know we want case-insensitive sorting

View File

@ -18,6 +18,7 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmGetVersion;
virAdmConnectIsAlive;
virAdmConnectGetURI;
virAdmConnectGetLibVersion;
virAdmConnectRegisterCloseCallback;
virAdmConnectUnregisterCloseCallback;
};

View File

@ -50,7 +50,7 @@ my $protocol = shift or die "missing protocol argument";
my @autogen;
my $connect_ptr = $structprefix eq "admin" ? "virAdmConnectPtr" : "virConnectPtr";
my $prefix = ($structprefix eq "admin") ? "adm" : "vir";
my $prefix = ($structprefix eq "admin") ? "admin" : "vir";
sub fixup_name {
my $name = shift;
@ -1401,8 +1401,13 @@ elsif ($mode eq "client") {
my $ret_name = $1;
if ($call->{ProcName} =~ m/Get(Lib)?Version/) {
push(@args_list, "unsigned long *$ret_name");
push(@ret_list, "if ($ret_name) HYPER_TO_ULONG(*$ret_name, ret.$ret_name);");
if ($structprefix eq "admin") {
push(@args_list, "unsigned long long *$ret_name");
push(@ret_list, "*$ret_name = ret.$ret_name;");
} else {
push(@args_list, "unsigned long *$ret_name");
push(@ret_list, "if ($ret_name) HYPER_TO_ULONG(*$ret_name, ret.$ret_name);");
}
push(@ret_list, "rv = 0;");
$single_ret_var = "int rv = -1";
$single_ret_type = "int";

View File

@ -197,6 +197,67 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
return true;
}
/*
* "version" command
*/
static const vshCmdInfo info_version[] = {
{.name = "help",
.data = N_("show version")
},
{.name = "desc",
.data = N_("Display the system and also the daemon version information.")
},
{.name = NULL}
};
static bool
cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
unsigned long libVersion;
unsigned long long includeVersion;
unsigned long long daemonVersion;
int ret;
unsigned int major;
unsigned int minor;
unsigned int rel;
vshAdmControlPtr priv = ctl->privData;
includeVersion = LIBVIR_VERSION_NUMBER;
major = includeVersion / 1000000;
includeVersion %= 1000000;
minor = includeVersion / 1000;
rel = includeVersion % 1000;
vshPrint(ctl, _("Compiled against library: libvirt %d.%d.%d\n"),
major, minor, rel);
ret = virGetVersion(&libVersion, NULL, NULL);
if (ret < 0) {
vshError(ctl, "%s", _("failed to get the library version"));
return false;
}
major = libVersion / 1000000;
libVersion %= 1000000;
minor = libVersion / 1000;
rel = libVersion % 1000;
vshPrint(ctl, _("Using library: libvirt %d.%d.%d\n"),
major, minor, rel);
ret = virAdmConnectGetLibVersion(priv->conn, &daemonVersion);
if (ret < 0) {
vshError(ctl, "%s", _("failed to get the daemon version"));
} else {
major = daemonVersion / 1000000;
daemonVersion %= 1000000;
minor = daemonVersion / 1000;
rel = daemonVersion % 1000;
vshPrint(ctl, _("Running against daemon: %d.%d.%d\n"),
major, minor, rel);
}
return true;
}
/* ---------------
* Command Connect
@ -516,6 +577,12 @@ static const vshCmdDef vshAdmCmds[] = {
.info = info_uri,
.flags = 0
},
{.name = "version",
.handler = cmdVersion,
.opts = NULL,
.info = info_version,
.flags = 0
},
{.name = "connect",
.handler = cmdConnect,
.opts = opts_connect,