admin: Add virAdmHello function

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>
This commit is contained in:
Martin Kletzander 2015-04-15 16:35:42 +02:00
parent 6bda9f8aa2
commit 5792fabb7b
7 changed files with 74 additions and 1 deletions

View 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"

View 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
}

View File

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

View 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
};

View 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,
};

View 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;
}

View File

@ -15,4 +15,5 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmConnectOpen;
virAdmConnectClose;
virAdmConnectRef;
virAdmHello;
};