]> xenbits.xensource.com Git - libvirt.git/commitdiff
admin: Add virAdmHello function
authorMartin Kletzander <mkletzan@redhat.com>
Wed, 15 Apr 2015 14:35:42 +0000 (16:35 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 16 Jun 2015 11:46:21 +0000 (13:46 +0200)
Just one of the simplest functions that returns string "Clients: X"
where X is the number of connected clients to daemon's first
subserver (the original one), so it can be tested using virsh, ipython,
etc.

The subserver is gathered by incrementing its reference
counter (similarly to getting qemu capabilities), so there is no
deadlock with admin subserver in this API.

Here you can see how functions should be named in the client (virAdm*)
and server (adm*).

There is also a parameter @flags that must be 0, which helps testing
proper error propagation into the client.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
daemon/admin_server.c
include/libvirt/libvirt-admin.h
po/POTFILES.in
src/admin/admin_protocol.x
src/admin_protocol-structs
src/libvirt-admin.c
src/libvirt_admin.syms

index 712a44beca106b51d0f753b443e1b5d7ee90c845..76d0b28d74495192b971c214fd9d00359e12dadc 100644 (file)
@@ -114,4 +114,27 @@ adminDispatchConnectClose(virNetServerPtr server ATTRIBUTE_UNUSED,
     return 0;
 }
 
+
+static char *
+admHello(virNetDaemonPtr dmn,
+         unsigned int flags)
+{
+    char *ret = NULL;
+    virNetServerPtr srv = NULL;
+    size_t nclients;
+
+    virCheckFlags(0, NULL);
+
+    if (!(srv = virNetDaemonGetServer(dmn, 0)))
+        return NULL;
+
+    nclients = virNetServerGetNClients(srv);
+    if (virAsprintf(&ret, "Clients: %zu", nclients) < 0)
+        goto cleanup;
+
+ cleanup:
+    virObjectUnref(srv);
+    return ret;
+}
+
 #include "admin_dispatch.h"
index b3cfc93fcb7da4ed91a001e7394f9c2f78d0cb54..27178b45efe76a9bdfcd677a059c59b3ec3d581f 100644 (file)
@@ -54,6 +54,7 @@ virAdmConnectPtr virAdmConnectOpen(const char *name, unsigned int flags);
 int virAdmConnectClose(virAdmConnectPtr conn);
 
 int virAdmConnectRef(virAdmConnectPtr conn);
+char *virAdmHello(virAdmConnectPtr conn, unsigned int flags);
 
 # ifdef __cplusplus
 }
index 189e2cc2f4d9d4667adc83d2ccd61cce84fff04e..31f03d9e449d15c266ed9c96c3bdd9931239c286 100644 (file)
@@ -1,3 +1,4 @@
+daemon/admin_dispatch.h
 daemon/admin_server.c
 daemon/libvirtd-config.c
 daemon/libvirtd.c
index 1a2e94ee86e7f07c46236c537cba4bc89f72a0cc..70954ccb87c26465ac60e47fd77a342e0fc54c23 100644 (file)
@@ -43,6 +43,15 @@ struct admin_connect_open_args {
     unsigned int flags;
 };
 
+struct admin_hello_args {
+    unsigned int flags;
+};
+
+struct admin_hello_ret {
+    admin_string greeting;
+};
+
+
 /* Define the program number, protocol version and procedure numbers here. */
 const ADMIN_PROGRAM = 0x06900690;
 const ADMIN_PROTOCOL_VERSION = 1;
@@ -73,5 +82,10 @@ enum admin_procedure {
     /**
      * @generate: client
      */
-    ADMIN_PROC_CONNECT_CLOSE = 2
+    ADMIN_PROC_CONNECT_CLOSE = 2,
+
+    /**
+     * @generate: both
+     */
+    ADMIN_PROC_HELLO = 3
 };
index 3ac31fa2532a399fcb55fe1e283fff86c247fc07..f91f7013ad9b5480d0319fe899eb63f6cec41148 100644 (file)
@@ -2,7 +2,14 @@
 struct admin_connect_open_args {
         u_int                      flags;
 };
+struct admin_hello_args {
+        u_int                      flags;
+};
+struct admin_hello_ret {
+        admin_string               greeting;
+};
 enum admin_procedure {
         ADMIN_PROC_CONNECT_OPEN = 1,
         ADMIN_PROC_CONNECT_CLOSE = 2,
+        ADMIN_PROC_HELLO = 3,
 };
index 11b6fe3238b8537c97c75ef2f0fa7a0b441ba4a5..107e27e4307c981496a19e4fa7e851b4db24f7a3 100644 (file)
@@ -384,3 +384,29 @@ virAdmConnectRef(virAdmConnectPtr conn)
 
     return 0;
 }
+
+
+/**
+ * virAdmHello:
+ * @conn: a connection object
+ * @flags: unused, 0 for now
+ *
+ * Testing function.
+ *
+ * Returns the number of connected clients as a string.  Yes, as a
+ * string.  Because it's just for testing.
+ */
+char *
+virAdmHello(virAdmConnectPtr conn,
+            unsigned int flags)
+{
+    char *ret = NULL;
+
+    virResetLastError();
+
+    ret = remoteAdminHello(conn, flags);
+    if (!ret)
+        virDispatchError(NULL);
+
+    return ret;
+}
index d9e3c0b1b988b1134e59e30b5b0cfc96e6993827..a3c9e5fc3ef110c07bf723b3a17c8c48267abeed 100644 (file)
@@ -15,4 +15,5 @@ LIBVIRT_ADMIN_1.3.0 {
         virAdmConnectOpen;
         virAdmConnectClose;
         virAdmConnectRef;
+        virAdmHello;
 };