mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-06 20:00:05 +00:00
admin: Introduce virAdmServer structure
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@redhat.com>
This commit is contained in:
parent
159a37f659
commit
c50a834b80
@ -42,6 +42,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:
|
||||
*
|
||||
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1,4 +1,7 @@
|
||||
/* -*- c -*- */
|
||||
struct admin_nonnull_server {
|
||||
admin_nonnull_string name;
|
||||
};
|
||||
struct admin_connect_open_args {
|
||||
u_int flags;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
@ -9,6 +9,10 @@
|
||||
xdr_admin_connect_get_lib_version_ret;
|
||||
xdr_admin_connect_open_args;
|
||||
|
||||
# datatypes.h
|
||||
virAdmGetServer;
|
||||
virAdmServerClass;
|
||||
|
||||
# Let emacs know we want case-insensitive sorting
|
||||
# Local Variables:
|
||||
# sort-fold-case: t
|
||||
|
Loading…
x
Reference in New Issue
Block a user