Re: [PATCH v2 8/9] admin: Introduce virAdmConnectGetLibVersion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 16, 2015 at 08:12:25PM +0200, Erik Skultety wrote:
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.
---
daemon/admin_server.c           |  9 ++++++
include/libvirt/libvirt-admin.h |  3 ++
po/POTFILES.in                  |  1 +
src/admin/admin_protocol.x      | 11 ++++++-
src/admin_protocol-structs      |  4 +++
src/libvirt-admin.c             | 31 +++++++++++++++++++
src/libvirt_admin_private.syms  |  1 +
src/libvirt_admin_public.syms   |  1 +
src/rpc/gendispatch.pl          | 11 +++++--
tools/virt-admin.c              | 67 +++++++++++++++++++++++++++++++++++++++++
10 files changed, 135 insertions(+), 4 deletions(-)

diff --git a/daemon/admin_server.c b/daemon/admin_server.c
index 712a44b..189091e 100644
--- a/daemon/admin_server.c
+++ b/daemon/admin_server.c
@@ -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"
diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
index 1688201..d76b1bd 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -56,6 +56,9 @@ int virAdmConnectIsAlive(virAdmConnectPtr conn);

char * virAdmConnectGetURI(virAdmConnectPtr conn);

+int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
+                               unsigned long long *libVer);
+
/**
 * virAdmConnectCloseFunc:
 * @conn: virAdmConnect connection
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d0840f4..e165a08 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,3 +1,4 @@
+daemon/admin_dispatch.h
daemon/admin_server.c
daemon/libvirtd-config.c
daemon/libvirtd.c
diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x
index d0ca1a3..878983d 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -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
};
diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
index 3ac31fa..809379b 100644
--- a/src/admin_protocol-structs
+++ b/src/admin_protocol-structs
@@ -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,
};
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index 2a38e09..666d39e 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -488,3 +488,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;
+}
diff --git a/src/libvirt_admin_private.syms b/src/libvirt_admin_private.syms
index 401cd4e..85380dc 100644
--- a/src/libvirt_admin_private.syms
+++ b/src/libvirt_admin_private.syms
@@ -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
diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms
index df01837..303b110 100644
--- a/src/libvirt_admin_public.syms
+++ b/src/libvirt_admin_public.syms
@@ -17,6 +17,7 @@ LIBVIRT_ADMIN_1.3.0 {
        virAdmConnectRef;
        virAdmConnectIsAlive;
        virAdmConnectGetURI;
+        virAdmConnectGetLibVersion;
        virAdmConnectRegisterCloseCallback;
        virAdmConnectUnregisterCloseCallback;
};
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index b6d50f3..5cfc512 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -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";


I wanted to differentiate two different calls with admCall and
adminCall, I wish I remembered which were those.

Otherwise looks fine to me.

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]