admin: Rename virAdmConnect to virAdmDaemon

virAdmConnect was named after virConnect, but after some discussions,
most of the APIs called will be working with remote daemon and starting
them virAdmDaemon will make more sense.  Only possibly controversal name
is CloseCallback (de)registration, and connecting to the daemon (which
will still be Open/Close), but even this makes sense if one thinks about
the daemon being opened and closed, e.g. as file, etc.

This way all the APIs working with the daemon will start with
virAdmDaemon prefix, they will accept virAdmDaemonPtr as first parameter
and that will better suit with other namings as well (virDomain*,
virAdmServer*, etc.).

Because in virt-admin, the connection name does not refer to a struct
that would have a connect in its name, also adjust 'connname' in
clients.  And because it is not used anywhere in the vsh code, move it
from there into each client.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2015-11-25 16:59:30 +01:00
parent 15b0a6d641
commit df8192aaf4
16 changed files with 248 additions and 249 deletions

View File

@ -79,11 +79,11 @@ remoteAdmClientInitHook(virNetServerClientPtr client ATTRIBUTE_UNUSED,
/* Functions */
static int
adminDispatchConnectOpen(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr,
struct admin_connect_open_args *args)
adminDispatchDaemonOpen(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr,
struct admin_daemon_open_args *args)
{
unsigned int flags;
struct daemonAdmClientPrivate *priv =
@ -105,18 +105,18 @@ adminDispatchConnectOpen(virNetServerPtr server ATTRIBUTE_UNUSED,
}
static int
adminDispatchConnectClose(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED)
adminDispatchDaemonClose(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED)
{
virNetServerClientDelayedClose(client);
return 0;
}
static int
adminConnectGetLibVersion(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
unsigned long long *libVer)
adminDaemonGetVersion(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
unsigned long long *libVer)
{
if (libVer)
*libVer = LIBVIR_VERSION_NUMBER;

View File

@ -35,53 +35,51 @@ extern "C" {
# undef __VIR_ADMIN_H_INCLUDES__
/**
* virAdmConnect:
* virAdmDaemon:
*
* a virAdmConnect is a private structure representing a connection to
* libvirt daemon.
* a virAdmDaemon is a private structure representing a remote daemon.
*/
typedef struct _virAdmConnect virAdmConnect;
typedef struct _virAdmDaemon virAdmDaemon;
/**
* virAdmConnectPtr:
* virAdmDaemonPtr:
*
* a virAdmConnectPtr is pointer to a virAdmConnect private structure,
* this is the type used to reference a connection to the daemon
* in the API.
* a virAdmDaemonPtr is pointer to a virAdmDaemon private structure,
* this is the type used to reference a daemon in the API.
*/
typedef virAdmConnect *virAdmConnectPtr;
typedef virAdmDaemon *virAdmDaemonPtr;
virAdmConnectPtr virAdmConnectOpen(const char *name, unsigned int flags);
int virAdmConnectClose(virAdmConnectPtr conn);
virAdmDaemonPtr virAdmDaemonOpen(const char *name, unsigned int flags);
int virAdmDaemonClose(virAdmDaemonPtr dmn);
int virAdmConnectRef(virAdmConnectPtr conn);
int virAdmConnectIsAlive(virAdmConnectPtr conn);
int virAdmDaemonRef(virAdmDaemonPtr dmn);
int virAdmDaemonIsAlive(virAdmDaemonPtr dmn);
int virAdmGetVersion(unsigned long long *libVer);
char *virAdmConnectGetURI(virAdmConnectPtr conn);
char *virAdmDaemonGetURI(virAdmDaemonPtr dmn);
int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
unsigned long long *libVer);
int virAdmDaemonGetVersion(virAdmDaemonPtr dmn,
unsigned long long *libVer);
/**
* virAdmConnectCloseFunc:
* @conn: virAdmConnect connection
* virAdmDaemonCloseFunc:
* @dmn: virAdmDaemon connection
* @reason: reason why the connection was closed (see virConnectCloseReason)
* @opaque: opaque client data
*
* A callback to be registered, in case a connection was closed.
*/
typedef void (*virAdmConnectCloseFunc)(virAdmConnectPtr conn,
typedef void (*virAdmDaemonCloseFunc)(virAdmDaemonPtr dmn,
int reason,
void *opaque);
int virAdmConnectRegisterCloseCallback(virAdmConnectPtr conn,
virAdmConnectCloseFunc cb,
void *opaque,
virFreeCallback freecb);
int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
virAdmConnectCloseFunc cb);
int virAdmDaemonRegisterCloseCallback(virAdmDaemonPtr dmn,
virAdmDaemonCloseFunc cb,
void *opaque,
virFreeCallback freecb);
int virAdmDaemonUnregisterCloseCallback(virAdmDaemonPtr dmn,
virAdmDaemonCloseFunc cb);
# ifdef __cplusplus
}

View File

@ -37,11 +37,11 @@ typedef string admin_nonnull_string<ADMIN_STRING_MAX>;
typedef admin_nonnull_string *admin_string;
/*----- Protocol. -----*/
struct admin_connect_open_args {
struct admin_daemon_open_args {
unsigned int flags;
};
struct admin_connect_get_lib_version_ret {
struct admin_daemon_get_version_ret {
unsigned hyper libVer;
};
@ -70,15 +70,15 @@ enum admin_procedure {
/**
* @generate: none
*/
ADMIN_PROC_CONNECT_OPEN = 1,
ADMIN_PROC_DAEMON_OPEN = 1,
/**
* @generate: none
*/
ADMIN_PROC_CONNECT_CLOSE = 2,
ADMIN_PROC_DAEMON_CLOSE = 2,
/**
* @generate: both
*/
ADMIN_PROC_CONNECT_GET_LIB_VERSION = 3
ADMIN_PROC_DAEMON_GET_VERSION = 3
};

View File

@ -48,7 +48,7 @@ remoteAdminPrivDispose(void *opaque)
static int
callFull(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
callFull(virAdmDaemonPtr dmn ATTRIBUTE_UNUSED,
remoteAdminPrivPtr priv,
int *fdin,
size_t fdinlen,
@ -86,7 +86,7 @@ callFull(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
}
static int
call(virAdmConnectPtr conn,
call(virAdmDaemonPtr dmn,
unsigned int flags,
int proc_nr,
xdrproc_t args_filter, char *args,
@ -94,7 +94,7 @@ call(virAdmConnectPtr conn,
{
virCheckFlags(0, -1);
return callFull(conn, conn->privateData,
return callFull(dmn, dmn->privateData,
NULL, 0, NULL, NULL, proc_nr,
args_filter, args, ret_filter, ret);
}
@ -106,14 +106,14 @@ remoteAdminClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED,
int reason,
void *opaque)
{
virAdmConnectCloseCallbackDataPtr cbdata = opaque;
virAdmDaemonCloseCallbackDataPtr cbdata = opaque;
virObjectLock(cbdata);
if (cbdata->callback) {
VIR_DEBUG("Triggering connection close callback %p reason=%d, opaque=%p",
cbdata->callback, reason, cbdata->opaque);
cbdata->callback(cbdata->conn, reason, cbdata->opaque);
cbdata->callback(cbdata->dmn, reason, cbdata->opaque);
if (cbdata->freeCallback)
cbdata->freeCallback(cbdata->opaque);
@ -124,11 +124,11 @@ remoteAdminClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED,
}
static int
remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
remoteAdminDaemonOpen(virAdmDaemonPtr dmn, unsigned int flags)
{
int rv = -1;
remoteAdminPrivPtr priv = conn->privateData;
admin_connect_open_args args;
remoteAdminPrivPtr priv = dmn->privateData;
admin_daemon_open_args args;
virObjectLock(priv);
@ -140,13 +140,13 @@ remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
virResetLastError();
}
virObjectRef(conn->closeCallback);
virObjectRef(dmn->closeCallback);
virNetClientSetCloseCallback(priv->client, remoteAdminClientCloseFunc,
conn->closeCallback,
dmn->closeCallback,
virObjectFreeCallback);
if (call(conn, 0, ADMIN_PROC_CONNECT_OPEN,
(xdrproc_t)xdr_admin_connect_open_args, (char *)&args,
if (call(dmn, 0, ADMIN_PROC_DAEMON_OPEN,
(xdrproc_t)xdr_admin_daemon_open_args, (char *)&args,
(xdrproc_t)xdr_void, (char *)NULL) == -1) {
goto done;
}
@ -159,14 +159,14 @@ remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
}
static int
remoteAdminConnectClose(virAdmConnectPtr conn)
remoteAdminDaemonClose(virAdmDaemonPtr dmn)
{
int rv = -1;
remoteAdminPrivPtr priv = conn->privateData;
remoteAdminPrivPtr priv = dmn->privateData;
virObjectLock(priv);
if (call(conn, 0, ADMIN_PROC_CONNECT_CLOSE,
if (call(dmn, 0, ADMIN_PROC_DAEMON_CLOSE,
(xdrproc_t)xdr_void, (char *)NULL,
(xdrproc_t)xdr_void, (char *)NULL) == -1) {
goto done;
@ -184,10 +184,10 @@ remoteAdminConnectClose(virAdmConnectPtr conn)
static void
remoteAdminPrivFree(void *opaque)
{
virAdmConnectPtr conn = opaque;
virAdmDaemonPtr dmn = opaque;
remoteAdminConnectClose(conn);
virObjectUnref(conn->privateData);
remoteAdminDaemonClose(dmn);
virObjectUnref(dmn->privateData);
}
static remoteAdminPrivPtr

View File

@ -1,12 +1,12 @@
/* -*- c -*- */
struct admin_connect_open_args {
struct admin_daemon_open_args {
u_int flags;
};
struct admin_connect_get_lib_version_ret {
struct admin_daemon_get_version_ret {
uint64_t libVer;
};
enum admin_procedure {
ADMIN_PROC_CONNECT_OPEN = 1,
ADMIN_PROC_CONNECT_CLOSE = 2,
ADMIN_PROC_CONNECT_GET_LIB_VERSION = 3,
ADMIN_PROC_DAEMON_OPEN = 1,
ADMIN_PROC_DAEMON_CLOSE = 2,
ADMIN_PROC_DAEMON_GET_VERSION = 3,
};

View File

@ -59,11 +59,11 @@ static void virStreamDispose(void *obj);
static void virStorageVolDispose(void *obj);
static void virStoragePoolDispose(void *obj);
virClassPtr virAdmConnectClass;
virClassPtr virAdmConnectCloseCallbackDataClass;
virClassPtr virAdmDaemonClass;
virClassPtr virAdmDaemonCloseCallbackDataClass;
static void virAdmConnectDispose(void *obj);
static void virAdmConnectCloseCallbackDataDispose(void *obj);
static void virAdmDaemonDispose(void *obj);
static void virAdmDaemonCloseCallbackDataDispose(void *obj);
static int
virDataTypesOnceInit(void)
@ -92,8 +92,8 @@ virDataTypesOnceInit(void)
DECLARE_CLASS(virStorageVol);
DECLARE_CLASS(virStoragePool);
DECLARE_CLASS_LOCKABLE(virAdmConnect);
DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData);
DECLARE_CLASS_LOCKABLE(virAdmDaemon);
DECLARE_CLASS_LOCKABLE(virAdmDaemonCloseCallbackData);
#undef DECLARE_CLASS_COMMON
#undef DECLARE_CLASS_LOCKABLE
@ -814,18 +814,18 @@ virDomainSnapshotDispose(void *obj)
}
virAdmConnectPtr
virAdmConnectNew(void)
virAdmDaemonPtr
virAdmDaemonNew(void)
{
virAdmConnectPtr ret;
virAdmDaemonPtr ret;
if (virDataTypesInitialize() < 0)
return NULL;
if (!(ret = virObjectLockableNew(virAdmConnectClass)))
if (!(ret = virObjectLockableNew(virAdmDaemonClass)))
return NULL;
if (!(ret->closeCallback = virObjectLockableNew(virAdmConnectCloseCallbackDataClass)))
if (!(ret->closeCallback = virObjectLockableNew(virAdmDaemonCloseCallbackDataClass)))
goto error;
return ret;
@ -836,21 +836,21 @@ virAdmConnectNew(void)
}
static void
virAdmConnectDispose(void *obj)
virAdmDaemonDispose(void *obj)
{
virAdmConnectPtr conn = obj;
virAdmDaemonPtr dmn = obj;
if (conn->privateDataFreeFunc)
conn->privateDataFreeFunc(conn);
if (dmn->privateDataFreeFunc)
dmn->privateDataFreeFunc(dmn);
virURIFree(conn->uri);
virObjectUnref(conn->closeCallback);
virURIFree(dmn->uri);
virObjectUnref(dmn->closeCallback);
}
static void
virAdmConnectCloseCallbackDataDispose(void *obj)
virAdmDaemonCloseCallbackDataDispose(void *obj)
{
virAdmConnectCloseCallbackDataPtr cb_data = obj;
virAdmDaemonCloseCallbackDataPtr cb_data = obj;
virObjectLock(cb_data);

View File

@ -41,7 +41,7 @@ extern virClassPtr virStreamClass;
extern virClassPtr virStorageVolClass;
extern virClassPtr virStoragePoolClass;
extern virClassPtr virAdmConnectClass;
extern virClassPtr virAdmDaemonClass;
# define virCheckConnectReturn(obj, retval) \
do { \
@ -297,9 +297,9 @@ extern virClassPtr virAdmConnectClass;
dom, NULLSTR(_domname), _uuidstr, __VA_ARGS__); \
} while (0)
# define virCheckAdmConnectReturn(obj, retval) \
# define virCheckAdmDaemonReturn(obj, retval) \
do { \
if (!virObjectIsClass(obj, virAdmConnectClass)) { \
if (!virObjectIsClass(obj, virAdmDaemonClass)) { \
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
__FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \
@ -307,9 +307,9 @@ extern virClassPtr virAdmConnectClass;
return retval; \
} \
} while (0)
# define virCheckAdmConnectGoto(obj, label) \
# define virCheckAdmDaemonGoto(obj, label) \
do { \
if (!virObjectIsClass(obj, virAdmConnectClass)) { \
if (!virObjectIsClass(obj, virAdmDaemonClass)) { \
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
__FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \
@ -331,8 +331,8 @@ extern virClassPtr virAdmConnectClass;
typedef struct _virConnectCloseCallbackData virConnectCloseCallbackData;
typedef virConnectCloseCallbackData *virConnectCloseCallbackDataPtr;
typedef struct _virAdmConnectCloseCallbackData virAdmConnectCloseCallbackData;
typedef virAdmConnectCloseCallbackData *virAdmConnectCloseCallbackDataPtr;
typedef struct _virAdmDaemonCloseCallbackData virAdmDaemonCloseCallbackData;
typedef virAdmDaemonCloseCallbackData *virAdmDaemonCloseCallbackDataPtr;
/**
* Internal structures holding data related to connection close callbacks.
@ -346,11 +346,11 @@ struct _virConnectCloseCallbackData {
virFreeCallback freeCallback;
};
struct _virAdmConnectCloseCallbackData {
struct _virAdmDaemonCloseCallbackData {
virObjectLockable parent;
virAdmConnectPtr conn;
virAdmConnectCloseFunc callback;
virAdmDaemonPtr dmn;
virAdmDaemonCloseFunc callback;
void *opaque;
virFreeCallback freeCallback;
};
@ -402,11 +402,11 @@ struct _virConnect {
};
/**
* _virAdmConnect:
* _virAdmDaemon:
*
* Internal structure associated to an admin connection
*/
struct _virAdmConnect {
struct _virAdmDaemon {
virObjectLockable object;
virURIPtr uri;
@ -414,7 +414,7 @@ struct _virAdmConnect {
virFreeCallback privateDataFreeFunc;
/* Per-connection close callback */
virAdmConnectCloseCallbackDataPtr closeCallback;
virAdmDaemonCloseCallbackDataPtr closeCallback;
};
@ -599,6 +599,6 @@ virNWFilterPtr virGetNWFilter(virConnectPtr conn,
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain,
const char *name);
virAdmConnectPtr virAdmConnectNew(void);
virAdmDaemonPtr virAdmDaemonNew(void);
#endif /* __VIR_DATATYPES_H__ */

View File

@ -53,7 +53,7 @@ virAdmGlobalInit(void)
{
/* It would be nice if we could trace the use of this call, to
* help diagnose in log files if a user calls something other than
* virAdmConnectOpen first. But we can't rely on VIR_DEBUG working
* virAdmDaemonOpen first. But we can't rely on VIR_DEBUG working
* until after initialization is complete, and since this is
* one-shot, we never get here again. */
if (virThreadInitialize() < 0 ||
@ -183,20 +183,20 @@ virAdmGetDefaultURI(virConfPtr conf)
}
/**
* virAdmConnectOpen:
* virAdmDaemonOpen:
* @name: uri of the daemon to connect to, NULL for default
* @flags: unused, must be 0
*
* Opens connection to admin interface of the daemon.
*
* Returns @virAdmConnectPtr object or NULL on error
* Returns @virAdmDaemonPtr object or NULL on error
*/
virAdmConnectPtr
virAdmConnectOpen(const char *name, unsigned int flags)
virAdmDaemonPtr
virAdmDaemonOpen(const char *name, unsigned int flags)
{
char *sock_path = NULL;
char *alias = NULL;
virAdmConnectPtr conn = NULL;
virAdmDaemonPtr dmn = NULL;
virConfPtr conf = NULL;
if (virAdmInitialize() < 0)
@ -206,7 +206,7 @@ virAdmConnectOpen(const char *name, unsigned int flags)
virResetLastError();
virCheckFlags(VIR_CONNECT_NO_ALIASES, NULL);
if (!(conn = virAdmConnectNew()))
if (!(dmn = virAdmDaemonNew()))
goto error;
if (virConfLoadConfig(&conf, "libvirt-admin.conf") < 0)
@ -219,46 +219,46 @@ virAdmConnectOpen(const char *name, unsigned int flags)
virURIResolveAlias(conf, name, &alias) < 0))
goto error;
if (!(conn->uri = virURIParse(alias ? alias : name)))
if (!(dmn->uri = virURIParse(alias ? alias : name)))
goto error;
if (!(sock_path = getSocketPath(conn->uri)))
if (!(sock_path = getSocketPath(dmn->uri)))
goto error;
if (!(conn->privateData = remoteAdminPrivNew(sock_path)))
if (!(dmn->privateData = remoteAdminPrivNew(sock_path)))
goto error;
conn->privateDataFreeFunc = remoteAdminPrivFree;
dmn->privateDataFreeFunc = remoteAdminPrivFree;
if (remoteAdminConnectOpen(conn, flags) < 0)
if (remoteAdminDaemonOpen(dmn, flags) < 0)
goto error;
cleanup:
VIR_FREE(sock_path);
VIR_FREE(alias);
virConfFree(conf);
return conn;
return dmn;
error:
virDispatchError(NULL);
virObjectUnref(conn);
conn = NULL;
virObjectUnref(dmn);
dmn = NULL;
goto cleanup;
}
/**
* virAdmConnectClose:
* @conn: pointer to admin connection to close
* virAdmDaemonClose:
* @dmn: pointer to admin connection to close
*
* This function closes the admin connection to the Hypervisor. This should not
* be called if further interaction with the Hypervisor are needed especially if
* there is running domain which need further monitoring by the application.
*
* Connections are reference counted; the count is explicitly increased by the
* initial virAdmConnectOpen, as well as virAdmConnectRef; it is also temporarily
* initial virAdmDaemonOpen, as well as virAdmDaemonRef; it is also temporarily
* increased by other API that depend on the connection remaining alive. The
* open and every virAdmConnectRef call should have a matching
* virAdmConnectClose, and all other references will be released after the
* open and every virAdmDaemonRef call should have a matching
* virAdmDaemonClose, and all other references will be released after the
* corresponding operation completes.
*
* Returns a positive number if at least 1 reference remains on success. The
@ -266,34 +266,34 @@ virAdmConnectOpen(const char *name, unsigned int flags)
* return of 0 implies no references remain and the connection is closed and
* memory has been freed. A return of -1 implies a failure.
*
* It is possible for the last virAdmConnectClose to return a positive value if
* It is possible for the last virAdmDaemonClose to return a positive value if
* some other object still has a temporary reference to the connection, but the
* application should not try to further use a connection after the
* virAdmConnectClose that matches the initial open.
* virAdmDaemonClose that matches the initial open.
*/
int
virAdmConnectClose(virAdmConnectPtr conn)
virAdmDaemonClose(virAdmDaemonPtr dmn)
{
VIR_DEBUG("conn=%p", conn);
VIR_DEBUG("dmn=%p", dmn);
virResetLastError();
if (!conn)
if (!dmn)
return 0;
virCheckAdmConnectReturn(conn, -1);
virCheckAdmDaemonReturn(dmn, -1);
if (!virObjectUnref(conn))
if (!virObjectUnref(dmn))
return 0;
return 1;
}
/**
* virAdmConnectRef:
* @conn: the connection to hold a reference on
* virAdmDaemonRef:
* @dmn: the connection to hold a reference on
*
* Increment the reference count on the connection. For each additional call to
* this method, there shall be a corresponding call to virAdmConnectClose to
* this method, there shall be a corresponding call to virAdmDaemonClose to
* release the reference count, once the caller no longer needs the reference to
* this object.
*
@ -305,15 +305,15 @@ virAdmConnectClose(virAdmConnectPtr conn)
* Returns 0 in case of success, -1 in case of failure
*/
int
virAdmConnectRef(virAdmConnectPtr conn)
virAdmDaemonRef(virAdmDaemonPtr dmn)
{
VIR_DEBUG("conn=%p refs=%d", conn,
conn ? conn->object.parent.u.s.refs : 0);
VIR_DEBUG("dmn=%p refs=%d", dmn,
dmn ? dmn->object.parent.u.s.refs : 0);
virResetLastError();
virCheckAdmConnectReturn(conn, -1);
virCheckAdmDaemonReturn(dmn, -1);
virObjectRef(conn);
virObjectRef(dmn);
return 0;
}
@ -327,8 +327,7 @@ virAdmConnectRef(virAdmConnectPtr conn)
* generic message will be returned. @libVer format is as follows:
* major * 1,000,000 + minor * 1,000 + release.
*
* NOTE: To get the remote side library version use virAdmConnectGetLibVersion
* instead.
* NOTE: To get the remote side version use virAdmDaemonGetVersion instead.
*
* Returns 0 on success, -1 in case of an error.
*/
@ -353,8 +352,8 @@ virAdmGetVersion(unsigned long long *libVer)
}
/**
* virAdmConnectIsAlive:
* @conn: connection to admin server
* virAdmDaemonIsAlive:
* @dmn: connection to admin server
*
* Decide whether the connection to the admin server is alive or not.
* Connection is considered alive if the channel it is running over is not
@ -364,20 +363,20 @@ virAdmGetVersion(unsigned long long *libVer)
* connection at all or the channel has already been closed, or -1 on error.
*/
int
virAdmConnectIsAlive(virAdmConnectPtr conn)
virAdmDaemonIsAlive(virAdmDaemonPtr dmn)
{
bool ret;
remoteAdminPrivPtr priv = NULL;
VIR_DEBUG("conn=%p", conn);
VIR_DEBUG("dmn=%p", dmn);
if (!conn)
if (!dmn)
return 0;
virCheckAdmConnectReturn(conn, -1);
virCheckAdmDaemonReturn(dmn, -1);
virResetLastError();
priv = conn->privateData;
priv = dmn->privateData;
virObjectLock(priv);
ret = virNetClientIsOpen(priv->client);
virObjectUnlock(priv);
@ -386,35 +385,35 @@ virAdmConnectIsAlive(virAdmConnectPtr conn)
}
/**
* virAdmConnectGetURI:
* @conn: pointer to an admin connection
* virAdmDaemonGetURI:
* @dmn: pointer to an admin connection
*
* String returned by this method is normally the same as the string passed
* to the virAdmConnectOpen. Even if NULL was passed to virAdmConnectOpen,
* to the virAdmDaemonOpen. Even if NULL was passed to virAdmDaemonOpen,
* this method returns a non-null URI string.
*
* Returns an URI string related to the connection or NULL in case of an error.
* Caller is responsible for freeing the string.
*/
char *
virAdmConnectGetURI(virAdmConnectPtr conn)
virAdmDaemonGetURI(virAdmDaemonPtr dmn)
{
char *uri = NULL;
VIR_DEBUG("conn=%p", conn);
VIR_DEBUG("dmn=%p", dmn);
virResetLastError();
virCheckAdmConnectReturn(conn, NULL);
virCheckAdmDaemonReturn(dmn, NULL);
if (!(uri = virURIFormat(conn->uri)))
if (!(uri = virURIFormat(dmn->uri)))
virDispatchError(NULL);
return uri;
}
/**
* virAdmConnectRegisterCloseCallback:
* @conn: connection to admin server
* virAdmDaemonRegisterCloseCallback:
* @dmn: connection to admin server
* @cb: callback to be invoked upon connection close
* @opaque: user data to pass to @cb
* @freecb: callback to free @opaque
@ -430,103 +429,103 @@ virAdmConnectGetURI(virAdmConnectPtr conn)
*
* Returns 0 on success, -1 on error
*/
int virAdmConnectRegisterCloseCallback(virAdmConnectPtr conn,
virAdmConnectCloseFunc cb,
void *opaque,
virFreeCallback freecb)
int virAdmDaemonRegisterCloseCallback(virAdmDaemonPtr dmn,
virAdmDaemonCloseFunc cb,
void *opaque,
virFreeCallback freecb)
{
VIR_DEBUG("conn=%p", conn);
VIR_DEBUG("dmn=%p", dmn);
virResetLastError();
virCheckAdmConnectReturn(conn, -1);
virCheckAdmDaemonReturn(dmn, -1);
virObjectRef(conn);
virObjectRef(dmn);
virObjectLock(conn);
virObjectLock(conn->closeCallback);
virObjectLock(dmn);
virObjectLock(dmn->closeCallback);
virCheckNonNullArgGoto(cb, error);
if (conn->closeCallback->callback) {
if (dmn->closeCallback->callback) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A close callback is already registered"));
goto error;
}
conn->closeCallback->conn = conn;
conn->closeCallback->callback = cb;
conn->closeCallback->opaque = opaque;
conn->closeCallback->freeCallback = freecb;
dmn->closeCallback->dmn = dmn;
dmn->closeCallback->callback = cb;
dmn->closeCallback->opaque = opaque;
dmn->closeCallback->freeCallback = freecb;
virObjectUnlock(conn->closeCallback);
virObjectUnlock(conn);
virObjectUnlock(dmn->closeCallback);
virObjectUnlock(dmn);
return 0;
error:
virObjectUnlock(conn->closeCallback);
virObjectUnlock(conn);
virObjectUnlock(dmn->closeCallback);
virObjectUnlock(dmn);
virDispatchError(NULL);
virObjectUnref(conn);
virObjectUnref(dmn);
return -1;
}
/**
* virAdmConnectUnregisterCloseCallback:
* @conn: pointer to connection object
* virAdmDaemonUnregisterCloseCallback:
* @dmn: pointer to connection object
* @cb: pointer to the current registered callback
*
* Unregisters the callback previously set with the
* virAdmConnectRegisterCloseCallback method. The callback
* virAdmDaemonRegisterCloseCallback method. The callback
* will no longer receive notifications when the connection
* closes. If a virFreeCallback was provided at time of
* registration, it will be invoked.
*
* Returns 0 on success, -1 on error
*/
int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
virAdmConnectCloseFunc cb)
int virAdmDaemonUnregisterCloseCallback(virAdmDaemonPtr dmn,
virAdmDaemonCloseFunc cb)
{
VIR_DEBUG("conn=%p", conn);
VIR_DEBUG("dmn=%p", dmn);
virResetLastError();
virCheckAdmConnectReturn(conn, -1);
virCheckAdmDaemonReturn(dmn, -1);
virObjectLock(conn);
virObjectLock(conn->closeCallback);
virObjectLock(dmn);
virObjectLock(dmn->closeCallback);
virCheckNonNullArgGoto(cb, error);
if (conn->closeCallback->callback != cb) {
if (dmn->closeCallback->callback != cb) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A different callback was requested"));
goto error;
}
conn->closeCallback->callback = NULL;
if (conn->closeCallback->freeCallback)
conn->closeCallback->freeCallback(conn->closeCallback->opaque);
conn->closeCallback->freeCallback = NULL;
dmn->closeCallback->callback = NULL;
if (dmn->closeCallback->freeCallback)
dmn->closeCallback->freeCallback(dmn->closeCallback->opaque);
dmn->closeCallback->freeCallback = NULL;
virObjectUnlock(conn->closeCallback);
virObjectUnlock(conn);
virObjectUnref(conn);
virObjectUnlock(dmn->closeCallback);
virObjectUnlock(dmn);
virObjectUnref(dmn);
return 0;
error:
virObjectUnlock(conn->closeCallback);
virObjectUnlock(conn);
virObjectUnlock(dmn->closeCallback);
virObjectUnlock(dmn);
virDispatchError(NULL);
return -1;
}
/**
* virAdmConnectGetLibVersion:
* @conn: pointer to an active admin connection
* virAdmDaemonGetVersion:
* @dmn: pointer to an active admin connection
* @libVer: stores the current remote libvirt version number
*
* Retrieves the remote side libvirt version used by the daemon. Format
@ -535,17 +534,17 @@ int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
*
* Returns 0 on success, -1 on failure and @libVer follows this format:
*/
int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
unsigned long long *libVer)
int virAdmDaemonGetVersion(virAdmDaemonPtr dmn,
unsigned long long *libVer)
{
VIR_DEBUG("conn=%p, libVir=%p", conn, libVer);
VIR_DEBUG("dmn=%p, libVir=%p", dmn, libVer);
virResetLastError();
virCheckAdmConnectReturn(conn, -1);
virCheckAdmDaemonReturn(dmn, -1);
virCheckNonNullArgReturn(libVer, -1);
if (remoteAdminConnectGetLibVersion(conn, libVer) < 0)
if (remoteAdminDaemonGetVersion(dmn, libVer) < 0)
goto error;
return 0;

View File

@ -6,8 +6,8 @@
#
# admin/admin_protocol.x
xdr_admin_connect_get_lib_version_ret;
xdr_admin_connect_open_args;
xdr_admin_daemon_get_version_ret;
xdr_admin_daemon_open_args;
# Let emacs know we want case-insensitive sorting
# Local Variables:

View File

@ -12,13 +12,13 @@
#
LIBVIRT_ADMIN_1.3.0 {
global:
virAdmConnectOpen;
virAdmConnectClose;
virAdmConnectRef;
virAdmDaemonClose;
virAdmDaemonGetURI;
virAdmDaemonGetVersion;
virAdmDaemonIsAlive;
virAdmDaemonOpen;
virAdmDaemonRef;
virAdmDaemonRegisterCloseCallback;
virAdmDaemonUnregisterCloseCallback;
virAdmGetVersion;
virAdmConnectIsAlive;
virAdmConnectGetURI;
virAdmConnectGetLibVersion;
virAdmConnectRegisterCloseCallback;
virAdmConnectUnregisterCloseCallback;
};

View File

@ -49,7 +49,7 @@ my $procprefix = shift or die "missing procedure prefix argument";
my $protocol = shift or die "missing protocol argument";
my @autogen;
my $connect_ptr = $structprefix eq "admin" ? "virAdmConnectPtr" : "virConnectPtr";
my $connect_ptr = $structprefix eq "admin" ? "virAdmDaemonPtr" : "virConnectPtr";
my $prefix = ($structprefix eq "admin") ? "admin" : "vir";
sub fixup_name {

View File

@ -198,7 +198,7 @@ virshReconnect(vshControl *ctl)
"disconnect from the hypervisor"));
}
priv->conn = virshConnect(ctl, ctl->connname, priv->readonly);
priv->conn = virshConnect(ctl, priv->connname, priv->readonly);
if (!priv->conn) {
if (disconnected)
@ -275,18 +275,18 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
priv->conn = NULL;
}
VIR_FREE(ctl->connname);
VIR_FREE(priv->connname);
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
return false;
ctl->connname = vshStrdup(ctl, name);
priv->connname = vshStrdup(ctl, name);
priv->useGetInfo = false;
priv->useSnapshotOld = false;
priv->blockJobNoBytes = false;
priv->readonly = ro;
priv->conn = virshConnect(ctl, ctl->connname, priv->readonly);
priv->conn = virshConnect(ctl, priv->connname, priv->readonly);
if (!priv->conn) {
vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
@ -398,7 +398,7 @@ virshInit(vshControl *ctl)
NULL)) < 0)
return false;
if (ctl->connname) {
if (priv->connname) {
virshReconnect(ctl);
/* Connecting to a named connection must succeed, but we delay
* connecting to the default connection until we need it
@ -430,7 +430,7 @@ virshDeinit(vshControl *ctl)
virshControlPtr priv = ctl->privData;
vshDeinit(ctl);
VIR_FREE(ctl->connname);
VIR_FREE(priv->connname);
if (priv->conn) {
int ret;
virConnectUnregisterCloseCallback(priv->conn, virshCatchDisconnect);
@ -706,8 +706,8 @@ virshParseArgv(vshControl *ctl, int argc, char **argv)
while ((arg = getopt_long(argc, argv, "+:c:d:e:hk:K:l:qrtvV", opt, &longindex)) != -1) {
switch (arg) {
case 'c':
VIR_FREE(ctl->connname);
ctl->connname = vshStrdup(ctl, optarg);
VIR_FREE(priv->connname);
priv->connname = vshStrdup(ctl, optarg);
break;
case 'd':
if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
@ -934,7 +934,7 @@ main(int argc, char **argv)
virFileActivateDirOverride(argv[0]);
if ((defaultConn = virGetEnvBlockSUID("VIRSH_DEFAULT_CONNECT_URI")))
ctl->connname = vshStrdup(ctl, defaultConn);
virshCtl.connname = vshStrdup(ctl, defaultConn);
if (!vshInit(ctl, cmdGroups, NULL))
exit(EXIT_FAILURE);

View File

@ -69,6 +69,7 @@ typedef struct _virshCtrlData virshCtrlData;
*/
struct _virshControl {
virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */
char *connname; /* connection name */
bool readonly; /* connect readonly (first time only, not
* during explicit connect command)
*/

View File

@ -56,11 +56,11 @@ static const vshClientHooks hooks;
* vshAdmCatchDisconnect:
*
* We get here when the connection was closed. Unlike virsh, we do not save
* the fact that the event was raised, sice there is virAdmConnectIsAlive to
* the fact that the event was raised, sice there is virAdmDaemonIsAlive to
* check if the communication channel has not been closed by remote party.
*/
static void
vshAdmCatchDisconnect(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
vshAdmCatchDisconnect(virAdmDaemonPtr dmn ATTRIBUTE_UNUSED,
int reason,
void *opaque)
{
@ -73,7 +73,7 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
return;
error = virSaveLastError();
uri = virAdmConnectGetURI(conn);
uri = virAdmDaemonGetURI(dmn);
switch ((virConnectCloseReason) reason) {
case VIR_CONNECT_CLOSE_REASON_ERROR:
@ -100,21 +100,21 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
}
static int
vshAdmConnect(vshControl *ctl, unsigned int flags)
vshAdmDaemon(vshControl *ctl, unsigned int flags)
{
vshAdmControlPtr priv = ctl->privData;
priv->conn = virAdmConnectOpen(ctl->connname, flags);
priv->dmn = virAdmDaemonOpen(priv->name, flags);
if (!priv->conn) {
if (!priv->dmn) {
if (priv->wantReconnect)
vshError(ctl, "%s", _("Failed to reconnect to the admin server"));
else
vshError(ctl, "%s", _("Failed to connect to the admin server"));
return -1;
} else {
if (virAdmConnectRegisterCloseCallback(priv->conn, vshAdmCatchDisconnect,
NULL, NULL) < 0)
if (virAdmDaemonRegisterCloseCallback(priv->dmn, vshAdmCatchDisconnect,
NULL, NULL) < 0)
vshError(ctl, "%s", _("Unable to register disconnect callback"));
if (priv->wantReconnect)
@ -132,17 +132,17 @@ vshAdmDisconnect(vshControl *ctl)
int ret = 0;
vshAdmControlPtr priv = ctl->privData;
if (!priv->conn)
if (!priv->dmn)
return ret;
virAdmConnectUnregisterCloseCallback(priv->conn, vshAdmCatchDisconnect);
ret = virAdmConnectClose(priv->conn);
virAdmDaemonUnregisterCloseCallback(priv->dmn, vshAdmCatchDisconnect);
ret = virAdmDaemonClose(priv->dmn);
if (ret < 0)
vshError(ctl, "%s", _("Failed to disconnect from the admin server"));
else if (ret > 0)
vshError(ctl, "%s", _("One or more references were leaked after "
"disconnect from the hypervisor"));
priv->conn = NULL;
priv->dmn = NULL;
return ret;
}
@ -156,11 +156,11 @@ static void
vshAdmReconnect(vshControl *ctl)
{
vshAdmControlPtr priv = ctl->privData;
if (priv->conn)
if (priv->dmn)
priv->wantReconnect = true;
vshAdmDisconnect(ctl);
vshAdmConnect(ctl, 0);
vshAdmDaemon(ctl, 0);
priv->wantReconnect = false;
}
@ -185,7 +185,7 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
char *uri;
vshAdmControlPtr priv = ctl->privData;
uri = virAdmConnectGetURI(priv->conn);
uri = virAdmDaemonGetURI(priv->dmn);
if (!uri) {
vshError(ctl, "%s", _("failed to get URI"));
return false;
@ -243,7 +243,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
vshPrint(ctl, _("Using library: libvirt %d.%d.%d\n"),
major, minor, rel);
ret = virAdmConnectGetLibVersion(priv->conn, &daemonVersion);
ret = virAdmDaemonGetVersion(priv->dmn, &daemonVersion);
if (ret < 0) {
vshError(ctl, "%s", _("failed to get the daemon version"));
} else {
@ -292,28 +292,28 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
return false;
VIR_FREE(ctl->connname);
ctl->connname = vshStrdup(ctl, name);
VIR_FREE(priv->name);
priv->name = vshStrdup(ctl, name);
vshAdmReconnect(ctl);
return !!priv->conn;
return !!priv->dmn;
}
static void *
vshAdmConnectionHandler(vshControl *ctl)
vshAdmDaemonionHandler(vshControl *ctl)
{
vshAdmControlPtr priv = ctl->privData;
if (!virAdmConnectIsAlive(priv->conn))
if (!virAdmDaemonIsAlive(priv->dmn))
vshAdmReconnect(ctl);
if (!virAdmConnectIsAlive(priv->conn)) {
if (!virAdmDaemonIsAlive(priv->dmn)) {
vshError(ctl, "%s", _("no valid connection"));
return NULL;
}
return priv->conn;
return priv->dmn;
}
/*
@ -329,7 +329,7 @@ vshAdmInit(vshControl *ctl)
* work properly */
vshInitReload(ctl);
if (priv->conn)
if (priv->dmn)
return false;
/* set up the library error handler */
@ -342,7 +342,7 @@ vshAdmInit(vshControl *ctl)
return false;
ctl->eventLoopStarted = true;
if (ctl->connname) {
if (priv->name) {
vshAdmReconnect(ctl);
/* Connecting to a named connection must succeed, but we delay
* connecting to the default connection until we need it
@ -350,7 +350,7 @@ vshAdmInit(vshControl *ctl)
* non-default connection, or might be 'help' which needs no
* connection).
*/
if (!priv->conn) {
if (!priv->dmn) {
vshReportError(ctl);
return false;
}
@ -374,9 +374,9 @@ vshAdmDeinit(vshControl *ctl)
vshAdmControlPtr priv = ctl->privData;
vshDeinit(ctl);
VIR_FREE(ctl->connname);
VIR_FREE(priv->name);
if (priv->conn)
if (priv->dmn)
vshAdmDisconnect(ctl);
virResetLastError();
@ -473,6 +473,7 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **argv)
int arg, debug;
size_t i;
int longindex = -1;
vshAdmControlPtr priv = ctl->privData;
struct option opt[] = {
{"connect", required_argument, NULL, 'c'},
{"debug", required_argument, NULL, 'd'},
@ -489,8 +490,8 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **argv)
while ((arg = getopt_long(argc, argv, "+:c:d:hl:qvV", opt, &longindex)) != -1) {
switch (arg) {
case 'c':
VIR_FREE(ctl->connname);
ctl->connname = vshStrdup(ctl, optarg);
VIR_FREE(priv->name);
priv->name = vshStrdup(ctl, optarg);
break;
case 'd':
if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
@ -598,7 +599,7 @@ static const vshCmdGrp cmdGroups[] = {
};
static const vshClientHooks hooks = {
.connHandler = vshAdmConnectionHandler
.connHandler = vshAdmDaemonionHandler
};
int
@ -656,7 +657,7 @@ main(int argc, char **argv)
virFileActivateDirOverride(argv[0]);
if ((defaultConn = virGetEnvBlockSUID("LIBVIRT_DEFAULT_ADMIN_URI")))
ctl->connname = vshStrdup(ctl, defaultConn);
virtAdminCtl.name = vshStrdup(ctl, defaultConn);
if (!vshInit(ctl, cmdGroups, NULL))
exit(EXIT_FAILURE);

View File

@ -39,7 +39,8 @@ typedef vshAdmControl *vshAdmControlPtr;
* adminControl
*/
struct _vshAdmControl {
virAdmConnectPtr conn; /* connection to a daemon's admin server */
virAdmDaemonPtr dmn; /* remote daemon */
char *name;
bool wantReconnect;
};

View File

@ -197,7 +197,6 @@ struct _vshControl {
const char *name; /* hardcoded name of the binary that cannot
* be changed without recompilation compared
* to program name */
char *connname; /* connection name */
char *progname; /* program name */
vshCmd *cmd; /* the current command */
char *cmdstr; /* string with command */