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.
---
include/libvirt/libvirt-admin.h | 4 ++++
src/admin/admin_protocol.x | 8 ++++++++
src/datatypes.c | 36 ++++++++++++++++++++++++++++++++++++
src/datatypes.h | 34 ++++++++++++++++++++++++++++++++++
src/libvirt_admin_private.syms | 3 +++
5 files changed, 85 insertions(+)
diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
index ab9df96..23420c7 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -42,6 +42,8 @@ extern "C" {
*/
typedef struct _virAdmConnect virAdmConnect;
+typedef struct _virAdmServer virAdmServer;
+
/**
* virAdmConnectPtr:
*
@@ -51,6 +53,8 @@ typedef struct _virAdmConnect virAdmConnect;
*/
typedef virAdmConnect *virAdmConnectPtr;
+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 878983d..2f1f534 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -30,12 +30,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/datatypes.c b/src/datatypes.c
index c832d80..cfc0d06 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -61,10 +61,14 @@ static void virStoragePoolDispose(void *obj);
virClassPtr virAdmConnectClass;
virClassPtr virAdmConnectCloseCallbackDataClass;
+virClassPtr virAdmServerClass;
static void virAdmConnectDispose(void *obj);
static void virAdmConnectCloseCallbackDataDispose(void *obj);
+static void virAdmConnectDispose(void *obj);
+static void virAdmServerDispose(void *obj);
+
static int
virDataTypesOnceInit(void)
{
@@ -92,6 +96,7 @@ virDataTypesOnceInit(void)
DECLARE_CLASS(virStorageVol);
DECLARE_CLASS(virStoragePool);
+ DECLARE_CLASS(virAdmServer);
DECLARE_CLASS_LOCKABLE(virAdmConnect);
DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData);
@@ -859,3 +864,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 %p %s", srv, srv->name);
+
+ VIR_FREE(srv->name);
+ virObjectUnref(srv->conn);
+}
diff --git a/src/datatypes.h b/src/datatypes.h
index 1b1777d..fc84ac6 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,26 @@ extern virClassPtr virAdmConnectClass;
} \
} while (0)
+# define virCheckAdmServerReturn(obj, retval) \
+ do { \
+ if (!virObjectIsClass(obj, virAdmServerClass)) { \
+ virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+ __FILE__, __FUNCTION__, __LINE__, \
+ __FUNCTION__); \
+ virDispatchError(NULL); \
+ return retval; \
+ } \
+ } while (0)
+# define virCheckAdmServerGoto(obj, label) \
+ do { \
+ if (!virObjectIsClass(obj, virAdmServerClass)) { \
+ virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+ __FILE__, __FUNCTION__, __LINE__, \
+ __FUNCTION__); \
+ goto label; \
+ } \
+ } while (0);
+
/**
* VIR_DOMAIN_DEBUG:
* @dom: domain
@@ -417,6 +438,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 +633,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