This is the key structure of all management operations performed on the
daemon/clients. An admin client needs to be able to identify
another client (either admin or non-privileged client) to perform an
action on it. This identification includes a server the client is
connected to, thus a client-side representation of a server is needed.
Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
include/libvirt/libvirt-admin.h | 17 +++++++++++++++++
src/admin/admin_protocol.x | 8 ++++++++
src/admin_protocol-structs | 3 +++
src/datatypes.c | 35 +++++++++++++++++++++++++++++++++++
src/datatypes.h | 38 ++++++++++++++++++++++++++++++++++++++
src/libvirt_admin_private.syms | 3 +++
6 files changed, 104 insertions(+)
diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
index ab9df96..b342510 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -43,6 +43,14 @@ extern "C" {
typedef struct _virAdmConnect virAdmConnect;
/**
+ * virAdmServer:
+ *
+ * a virAdmServer is a private structure and client-side representation of
+ * a remote server object
+ */
+typedef struct _virAdmServer virAdmServer;
+
+/**
* virAdmConnectPtr:
*
* a virAdmConnectPtr is pointer to a virAdmConnect private structure,
@@ -51,6 +59,15 @@ typedef struct _virAdmConnect virAdmConnect;
*/
typedef virAdmConnect *virAdmConnectPtr;
+/**
+ * virAdmServerPtr:
+ *
+ * a virAdmServerPtr is a pointer to a virAdmServer structure,
+ * this is the type used to reference client-side representation of a
+ * remote server object throughout all the APIs.
+ */
+typedef virAdmServer *virAdmServerPtr;
+
virAdmConnectPtr virAdmConnectOpen(const char *name, unsigned int flags);
int virAdmConnectClose(virAdmConnectPtr conn);
diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x
index 711201a..549fdf3 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -32,12 +32,20 @@
*/
const ADMIN_STRING_MAX = 4194304;
+/* Upper limit on list of servers */
+const ADMIN_SERVER_LIST_MAX = 16384;
+
/* A long string, which may NOT be NULL. */
typedef string admin_nonnull_string<ADMIN_STRING_MAX>;
/* A long string, which may be NULL. */
typedef admin_nonnull_string *admin_string;
+/* A server which may NOT be NULL */
+struct admin_nonnull_server {
+ admin_nonnull_string name;
+};
+
/*----- Protocol. -----*/
struct admin_connect_open_args {
unsigned int flags;
diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
index 809379b..95ea4e4 100644
--- a/src/admin_protocol-structs
+++ b/src/admin_protocol-structs
@@ -1,4 +1,7 @@
/* -*- c -*- */
+struct admin_nonnull_server {
+ admin_nonnull_string name;
+};
struct admin_connect_open_args {
u_int flags;
};
diff --git a/src/datatypes.c b/src/datatypes.c
index c832d80..da6ec37 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -65,6 +65,9 @@ virClassPtr virAdmConnectCloseCallbackDataClass;
static void virAdmConnectDispose(void *obj);
static void virAdmConnectCloseCallbackDataDispose(void *obj);
+virClassPtr virAdmServerClass;
+static void virAdmServerDispose(void *obj);
+
static int
virDataTypesOnceInit(void)
{
@@ -94,6 +97,7 @@ virDataTypesOnceInit(void)
DECLARE_CLASS_LOCKABLE(virAdmConnect);
DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData);
+ DECLARE_CLASS(virAdmServer);
#undef DECLARE_CLASS_COMMON
#undef DECLARE_CLASS_LOCKABLE
@@ -859,3 +863,34 @@ virAdmConnectCloseCallbackDataDispose(void *obj)
virObjectUnlock(cb_data);
}
+
+virAdmServerPtr
+virAdmGetServer(virAdmConnectPtr conn, const char *name)
+{
+ virAdmServerPtr ret = NULL;
+
+ if (virDataTypesInitialize() < 0)
+ goto error;
+
+ if (!(ret = virObjectNew(virAdmServerClass)))
+ goto error;
+ if (VIR_STRDUP(ret->name, name) < 0)
+ goto error;
+
+ ret->conn = virObjectRef(conn);
+
+ return ret;
+ error:
+ virObjectUnref(ret);
+ return NULL;
+}
+
+static void
+virAdmServerDispose(void *obj)
+{
+ virAdmServerPtr srv = obj;
+ VIR_DEBUG("release server srv=%p name=%s", srv, srv->name);
+
+ VIR_FREE(srv->name);
+ virObjectUnref(srv->conn);
+}
diff --git a/src/datatypes.h b/src/datatypes.h
index 1b1777d..31c636c 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -42,6 +42,7 @@ extern virClassPtr virStorageVolClass;
extern virClassPtr virStoragePoolClass;
extern virClassPtr virAdmConnectClass;
+extern virClassPtr virAdmServerClass;
# define virCheckConnectReturn(obj, retval) \
do { \
@@ -317,6 +318,30 @@ extern virClassPtr virAdmConnectClass;
} \
} while (0)
+# define virCheckAdmServerReturn(obj, retval) \
+ do { \
+ virAdmServerPtr _srv = (obj); \
+ if (!virObjectIsClass(_srv, virAdmServerClass) || \
+ !virObjectIsClass(_srv->conn, virAdmConnectClass)) { \
+ virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+ __FILE__, __FUNCTION__, __LINE__, \
+ __FUNCTION__); \
+ virDispatchError(NULL); \
+ return retval; \
+ } \
+ } while (0)
+# define virCheckAdmServerGoto(obj, label) \
+ do { \
+ virAdmServerPtr _srv = (obj); \
+ if (!virObjectIsClass(_srv, virAdmServerClass) || \
+ !virObjectIsClass(_srv->conn, virAdmConnectClass)) { \
+ virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+ __FILE__, __FUNCTION__, __LINE__, \
+ __FUNCTION__); \
+ goto label; \
+ } \
+ } while (0);
+
/**
* VIR_DOMAIN_DEBUG:
* @dom: domain
@@ -417,6 +442,17 @@ struct _virAdmConnect {
virAdmConnectCloseCallbackDataPtr closeCallback;
};
+/**
+ * _virAdmServer:
+ *
+ * Internal structure associated to a daemon server
+ */
+struct _virAdmServer {
+ virObject object;
+ virAdmConnectPtr conn; /* pointer back to the admin connection */
+ char *name; /* the server external name */
+};
+
/**
* _virDomain:
@@ -601,4 +637,6 @@ virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain,
virAdmConnectPtr virAdmConnectNew(void);
+virAdmServerPtr virAdmGetServer(virAdmConnectPtr conn,
+ const char *name);
#endif /* __VIR_DATATYPES_H__ */
diff --git a/src/libvirt_admin_private.syms b/src/libvirt_admin_private.syms
index 85380dc..31f1f8d 100644
--- a/src/libvirt_admin_private.syms
+++ b/src/libvirt_admin_private.syms
@@ -9,6 +9,9 @@
xdr_admin_connect_get_lib_version_ret;
xdr_admin_connect_open_args;
+# datatypes.h
+virAdmGetServer;
+
# Let emacs know we want case-insensitive sorting
# Local Variables:
# sort-fold-case: t
--
2.4.3