Revert "admin: Rename virAdmConnect to virAdmDaemon"

Commmit df8192aa introduced admin related rename and some minor
(caused by automated approach, aka sed) and some more severe isues along with
it. First reason to revert is the inconsistency with libvirt library.
Although we deal with the daemon directly rather than with a specific
hypervisor, we still do have a connection. That being said, contributors might
get under the impression that AdmDaemonNew would spawn/start a new daemon
(since it's admin API, why not...), or AdmDaemonClose would do the exact
opposite or they might expect DaemonIsAlive report overall status of the daemon
which definitely isn't the case.
The second reason to revert this patch is renaming virt-admin client. The
client tool does not necessarily have to reflect the names of the API's it's
using in his internals. An example would be 's/vshAdmConnect/vshAdmDaemon'
where noone can be certain of what the latter function really does. The former
is quite expressive about some connection magic it performs, but the latter does
not say anything, especially when vshAdmReconnect and vshAdmDisconnect were
left untouched.
This commit is contained in:
Erik Skultety 2015-12-10 13:46:45 +01:00
parent 5b74103b0b
commit 3245e1783c
16 changed files with 249 additions and 248 deletions

View File

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

View File

@ -35,51 +35,53 @@ extern "C" {
# undef __VIR_ADMIN_H_INCLUDES__
/**
* virAdmDaemon:
* virAdmConnect:
*
* a virAdmDaemon is a private structure representing a remote daemon.
* a virAdmConnect is a private structure representing a connection to
* libvirt daemon.
*/
typedef struct _virAdmDaemon virAdmDaemon;
typedef struct _virAdmConnect virAdmConnect;
/**
* virAdmDaemonPtr:
* virAdmConnectPtr:
*
* a virAdmDaemonPtr is pointer to a virAdmDaemon private structure,
* this is the type used to reference a daemon in the API.
* a virAdmConnectPtr is pointer to a virAdmConnect private structure,
* this is the type used to reference a connection to the daemon
* in the API.
*/
typedef virAdmDaemon *virAdmDaemonPtr;
typedef virAdmConnect *virAdmConnectPtr;
virAdmDaemonPtr virAdmDaemonOpen(const char *name, unsigned int flags);
int virAdmDaemonClose(virAdmDaemonPtr dmn);
virAdmConnectPtr virAdmConnectOpen(const char *name, unsigned int flags);
int virAdmConnectClose(virAdmConnectPtr conn);
int virAdmDaemonRef(virAdmDaemonPtr dmn);
int virAdmDaemonIsAlive(virAdmDaemonPtr dmn);
int virAdmConnectRef(virAdmConnectPtr conn);
int virAdmConnectIsAlive(virAdmConnectPtr conn);
int virAdmGetVersion(unsigned long long *libVer);
char *virAdmDaemonGetURI(virAdmDaemonPtr dmn);
char *virAdmConnectGetURI(virAdmConnectPtr conn);
int virAdmDaemonGetVersion(virAdmDaemonPtr dmn,
unsigned long long *libVer);
int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
unsigned long long *libVer);
/**
* virAdmDaemonCloseFunc:
* @dmn: virAdmDaemon connection
* virAdmConnectCloseFunc:
* @conn: virAdmConnect 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 (*virAdmDaemonCloseFunc)(virAdmDaemonPtr dmn,
typedef void (*virAdmConnectCloseFunc)(virAdmConnectPtr conn,
int reason,
void *opaque);
int virAdmDaemonRegisterCloseCallback(virAdmDaemonPtr dmn,
virAdmDaemonCloseFunc cb,
void *opaque,
virFreeCallback freecb);
int virAdmDaemonUnregisterCloseCallback(virAdmDaemonPtr dmn,
virAdmDaemonCloseFunc cb);
int virAdmConnectRegisterCloseCallback(virAdmConnectPtr conn,
virAdmConnectCloseFunc cb,
void *opaque,
virFreeCallback freecb);
int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
virAdmConnectCloseFunc 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_daemon_open_args {
struct admin_connect_open_args {
unsigned int flags;
};
struct admin_daemon_get_version_ret {
struct admin_connect_get_lib_version_ret {
unsigned hyper libVer;
};
@ -70,15 +70,15 @@ enum admin_procedure {
/**
* @generate: none
*/
ADMIN_PROC_DAEMON_OPEN = 1,
ADMIN_PROC_CONNECT_OPEN = 1,
/**
* @generate: none
*/
ADMIN_PROC_DAEMON_CLOSE = 2,
ADMIN_PROC_CONNECT_CLOSE = 2,
/**
* @generate: both
*/
ADMIN_PROC_DAEMON_GET_VERSION = 3
ADMIN_PROC_CONNECT_GET_LIB_VERSION = 3
};

View File

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

View File

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

View File

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

View File

@ -41,7 +41,7 @@ extern virClassPtr virStreamClass;
extern virClassPtr virStorageVolClass;
extern virClassPtr virStoragePoolClass;
extern virClassPtr virAdmDaemonClass;
extern virClassPtr virAdmConnectClass;
# define virCheckConnectReturn(obj, retval) \
do { \
@ -297,9 +297,9 @@ extern virClassPtr virAdmDaemonClass;
dom, NULLSTR(_domname), _uuidstr, __VA_ARGS__); \
} while (0)
# define virCheckAdmDaemonReturn(obj, retval) \
# define virCheckAdmConnectReturn(obj, retval) \
do { \
if (!virObjectIsClass(obj, virAdmDaemonClass)) { \
if (!virObjectIsClass(obj, virAdmConnectClass)) { \
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
__FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \
@ -307,9 +307,9 @@ extern virClassPtr virAdmDaemonClass;
return retval; \
} \
} while (0)
# define virCheckAdmDaemonGoto(obj, label) \
# define virCheckAdmConnectGoto(obj, label) \
do { \
if (!virObjectIsClass(obj, virAdmDaemonClass)) { \
if (!virObjectIsClass(obj, virAdmConnectClass)) { \
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
__FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \
@ -331,8 +331,8 @@ extern virClassPtr virAdmDaemonClass;
typedef struct _virConnectCloseCallbackData virConnectCloseCallbackData;
typedef virConnectCloseCallbackData *virConnectCloseCallbackDataPtr;
typedef struct _virAdmDaemonCloseCallbackData virAdmDaemonCloseCallbackData;
typedef virAdmDaemonCloseCallbackData *virAdmDaemonCloseCallbackDataPtr;
typedef struct _virAdmConnectCloseCallbackData virAdmConnectCloseCallbackData;
typedef virAdmConnectCloseCallbackData *virAdmConnectCloseCallbackDataPtr;
/**
* Internal structures holding data related to connection close callbacks.
@ -346,11 +346,11 @@ struct _virConnectCloseCallbackData {
virFreeCallback freeCallback;
};
struct _virAdmDaemonCloseCallbackData {
struct _virAdmConnectCloseCallbackData {
virObjectLockable parent;
virAdmDaemonPtr dmn;
virAdmDaemonCloseFunc callback;
virAdmConnectPtr conn;
virAdmConnectCloseFunc callback;
void *opaque;
virFreeCallback freeCallback;
};
@ -402,11 +402,11 @@ struct _virConnect {
};
/**
* _virAdmDaemon:
* _virAdmConnect:
*
* Internal structure associated to an admin connection
*/
struct _virAdmDaemon {
struct _virAdmConnect {
virObjectLockable object;
virURIPtr uri;
@ -414,7 +414,7 @@ struct _virAdmDaemon {
virFreeCallback privateDataFreeFunc;
/* Per-connection close callback */
virAdmDaemonCloseCallbackDataPtr closeCallback;
virAdmConnectCloseCallbackDataPtr closeCallback;
};
@ -599,6 +599,6 @@ virNWFilterPtr virGetNWFilter(virConnectPtr conn,
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain,
const char *name);
virAdmDaemonPtr virAdmDaemonNew(void);
virAdmConnectPtr virAdmConnectNew(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
* virAdmDaemonOpen first. But we can't rely on VIR_DEBUG working
* virAdmConnectOpen 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)
}
/**
* virAdmDaemonOpen:
* virAdmConnectOpen:
* @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 @virAdmDaemonPtr object or NULL on error
* Returns @virAdmConnectPtr object or NULL on error
*/
virAdmDaemonPtr
virAdmDaemonOpen(const char *name, unsigned int flags)
virAdmConnectPtr
virAdmConnectOpen(const char *name, unsigned int flags)
{
char *sock_path = NULL;
char *alias = NULL;
virAdmDaemonPtr dmn = NULL;
virAdmConnectPtr conn = NULL;
virConfPtr conf = NULL;
if (virAdmInitialize() < 0)
@ -206,7 +206,7 @@ virAdmDaemonOpen(const char *name, unsigned int flags)
virResetLastError();
virCheckFlags(VIR_CONNECT_NO_ALIASES, NULL);
if (!(dmn = virAdmDaemonNew()))
if (!(conn = virAdmConnectNew()))
goto error;
if (virConfLoadConfig(&conf, "libvirt-admin.conf") < 0)
@ -219,46 +219,46 @@ virAdmDaemonOpen(const char *name, unsigned int flags)
virURIResolveAlias(conf, name, &alias) < 0))
goto error;
if (!(dmn->uri = virURIParse(alias ? alias : name)))
if (!(conn->uri = virURIParse(alias ? alias : name)))
goto error;
if (!(sock_path = getSocketPath(dmn->uri)))
if (!(sock_path = getSocketPath(conn->uri)))
goto error;
if (!(dmn->privateData = remoteAdminPrivNew(sock_path)))
if (!(conn->privateData = remoteAdminPrivNew(sock_path)))
goto error;
dmn->privateDataFreeFunc = remoteAdminPrivFree;
conn->privateDataFreeFunc = remoteAdminPrivFree;
if (remoteAdminDaemonOpen(dmn, flags) < 0)
if (remoteAdminConnectOpen(conn, flags) < 0)
goto error;
cleanup:
VIR_FREE(sock_path);
VIR_FREE(alias);
virConfFree(conf);
return dmn;
return conn;
error:
virDispatchError(NULL);
virObjectUnref(dmn);
dmn = NULL;
virObjectUnref(conn);
conn = NULL;
goto cleanup;
}
/**
* virAdmDaemonClose:
* @dmn: pointer to admin connection to close
* virAdmConnectClose:
* @conn: 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 virAdmDaemonOpen, as well as virAdmDaemonRef; it is also temporarily
* initial virAdmConnectOpen, as well as virAdmConnectRef; it is also temporarily
* increased by other API that depend on the connection remaining alive. The
* open and every virAdmDaemonRef call should have a matching
* virAdmDaemonClose, and all other references will be released after the
* open and every virAdmConnectRef call should have a matching
* virAdmConnectClose, 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 @@ virAdmDaemonOpen(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 virAdmDaemonClose to return a positive value if
* It is possible for the last virAdmConnectClose 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
* virAdmDaemonClose that matches the initial open.
* virAdmConnectClose that matches the initial open.
*/
int
virAdmDaemonClose(virAdmDaemonPtr dmn)
virAdmConnectClose(virAdmConnectPtr conn)
{
VIR_DEBUG("dmn=%p", dmn);
VIR_DEBUG("conn=%p", conn);
virResetLastError();
if (!dmn)
if (!conn)
return 0;
virCheckAdmDaemonReturn(dmn, -1);
virCheckAdmConnectReturn(conn, -1);
if (!virObjectUnref(dmn))
if (!virObjectUnref(conn))
return 0;
return 1;
}
/**
* virAdmDaemonRef:
* @dmn: the connection to hold a reference on
* virAdmConnectRef:
* @conn: 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 virAdmDaemonClose to
* this method, there shall be a corresponding call to virAdmConnectClose to
* release the reference count, once the caller no longer needs the reference to
* this object.
*
@ -305,15 +305,15 @@ virAdmDaemonClose(virAdmDaemonPtr dmn)
* Returns 0 in case of success, -1 in case of failure
*/
int
virAdmDaemonRef(virAdmDaemonPtr dmn)
virAdmConnectRef(virAdmConnectPtr conn)
{
VIR_DEBUG("dmn=%p refs=%d", dmn,
dmn ? dmn->object.parent.u.s.refs : 0);
VIR_DEBUG("conn=%p refs=%d", conn,
conn ? conn->object.parent.u.s.refs : 0);
virResetLastError();
virCheckAdmDaemonReturn(dmn, -1);
virCheckAdmConnectReturn(conn, -1);
virObjectRef(dmn);
virObjectRef(conn);
return 0;
}
@ -327,7 +327,8 @@ virAdmDaemonRef(virAdmDaemonPtr dmn)
* generic message will be returned. @libVer format is as follows:
* major * 1,000,000 + minor * 1,000 + release.
*
* NOTE: To get the remote side version use virAdmDaemonGetVersion instead.
* NOTE: To get the remote side library version use virAdmConnectGetLibVersion
* instead.
*
* Returns 0 on success, -1 in case of an error.
*/
@ -352,8 +353,8 @@ virAdmGetVersion(unsigned long long *libVer)
}
/**
* virAdmDaemonIsAlive:
* @dmn: connection to admin server
* virAdmConnectIsAlive:
* @conn: 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
@ -363,20 +364,20 @@ virAdmGetVersion(unsigned long long *libVer)
* connection at all or the channel has already been closed, or -1 on error.
*/
int
virAdmDaemonIsAlive(virAdmDaemonPtr dmn)
virAdmConnectIsAlive(virAdmConnectPtr conn)
{
bool ret;
remoteAdminPrivPtr priv = NULL;
VIR_DEBUG("dmn=%p", dmn);
VIR_DEBUG("conn=%p", conn);
if (!dmn)
if (!conn)
return 0;
virCheckAdmDaemonReturn(dmn, -1);
virCheckAdmConnectReturn(conn, -1);
virResetLastError();
priv = dmn->privateData;
priv = conn->privateData;
virObjectLock(priv);
ret = virNetClientIsOpen(priv->client);
virObjectUnlock(priv);
@ -385,35 +386,35 @@ virAdmDaemonIsAlive(virAdmDaemonPtr dmn)
}
/**
* virAdmDaemonGetURI:
* @dmn: pointer to an admin connection
* virAdmConnectGetURI:
* @conn: pointer to an admin connection
*
* String returned by this method is normally the same as the string passed
* to the virAdmDaemonOpen. Even if NULL was passed to virAdmDaemonOpen,
* to the virAdmConnectOpen. Even if NULL was passed to virAdmConnectOpen,
* 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 *
virAdmDaemonGetURI(virAdmDaemonPtr dmn)
virAdmConnectGetURI(virAdmConnectPtr conn)
{
char *uri = NULL;
VIR_DEBUG("dmn=%p", dmn);
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckAdmDaemonReturn(dmn, NULL);
virCheckAdmConnectReturn(conn, NULL);
if (!(uri = virURIFormat(dmn->uri)))
if (!(uri = virURIFormat(conn->uri)))
virDispatchError(NULL);
return uri;
}
/**
* virAdmDaemonRegisterCloseCallback:
* @dmn: connection to admin server
* virAdmConnectRegisterCloseCallback:
* @conn: connection to admin server
* @cb: callback to be invoked upon connection close
* @opaque: user data to pass to @cb
* @freecb: callback to free @opaque
@ -429,103 +430,103 @@ virAdmDaemonGetURI(virAdmDaemonPtr dmn)
*
* Returns 0 on success, -1 on error
*/
int virAdmDaemonRegisterCloseCallback(virAdmDaemonPtr dmn,
virAdmDaemonCloseFunc cb,
void *opaque,
virFreeCallback freecb)
int virAdmConnectRegisterCloseCallback(virAdmConnectPtr conn,
virAdmConnectCloseFunc cb,
void *opaque,
virFreeCallback freecb)
{
VIR_DEBUG("dmn=%p", dmn);
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckAdmDaemonReturn(dmn, -1);
virCheckAdmConnectReturn(conn, -1);
virObjectRef(dmn);
virObjectRef(conn);
virObjectLock(dmn);
virObjectLock(dmn->closeCallback);
virObjectLock(conn);
virObjectLock(conn->closeCallback);
virCheckNonNullArgGoto(cb, error);
if (dmn->closeCallback->callback) {
if (conn->closeCallback->callback) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A close callback is already registered"));
goto error;
}
dmn->closeCallback->dmn = dmn;
dmn->closeCallback->callback = cb;
dmn->closeCallback->opaque = opaque;
dmn->closeCallback->freeCallback = freecb;
conn->closeCallback->conn = conn;
conn->closeCallback->callback = cb;
conn->closeCallback->opaque = opaque;
conn->closeCallback->freeCallback = freecb;
virObjectUnlock(dmn->closeCallback);
virObjectUnlock(dmn);
virObjectUnlock(conn->closeCallback);
virObjectUnlock(conn);
return 0;
error:
virObjectUnlock(dmn->closeCallback);
virObjectUnlock(dmn);
virObjectUnlock(conn->closeCallback);
virObjectUnlock(conn);
virDispatchError(NULL);
virObjectUnref(dmn);
virObjectUnref(conn);
return -1;
}
/**
* virAdmDaemonUnregisterCloseCallback:
* @dmn: pointer to connection object
* virAdmConnectUnregisterCloseCallback:
* @conn: pointer to connection object
* @cb: pointer to the current registered callback
*
* Unregisters the callback previously set with the
* virAdmDaemonRegisterCloseCallback method. The callback
* virAdmConnectRegisterCloseCallback 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 virAdmDaemonUnregisterCloseCallback(virAdmDaemonPtr dmn,
virAdmDaemonCloseFunc cb)
int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
virAdmConnectCloseFunc cb)
{
VIR_DEBUG("dmn=%p", dmn);
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckAdmDaemonReturn(dmn, -1);
virCheckAdmConnectReturn(conn, -1);
virObjectLock(dmn);
virObjectLock(dmn->closeCallback);
virObjectLock(conn);
virObjectLock(conn->closeCallback);
virCheckNonNullArgGoto(cb, error);
if (dmn->closeCallback->callback != cb) {
if (conn->closeCallback->callback != cb) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A different callback was requested"));
goto error;
}
dmn->closeCallback->callback = NULL;
if (dmn->closeCallback->freeCallback)
dmn->closeCallback->freeCallback(dmn->closeCallback->opaque);
dmn->closeCallback->freeCallback = NULL;
conn->closeCallback->callback = NULL;
if (conn->closeCallback->freeCallback)
conn->closeCallback->freeCallback(conn->closeCallback->opaque);
conn->closeCallback->freeCallback = NULL;
virObjectUnlock(dmn->closeCallback);
virObjectUnlock(dmn);
virObjectUnref(dmn);
virObjectUnlock(conn->closeCallback);
virObjectUnlock(conn);
virObjectUnref(conn);
return 0;
error:
virObjectUnlock(dmn->closeCallback);
virObjectUnlock(dmn);
virObjectUnlock(conn->closeCallback);
virObjectUnlock(conn);
virDispatchError(NULL);
return -1;
}
/**
* virAdmDaemonGetVersion:
* @dmn: pointer to an active admin connection
* virAdmConnectGetLibVersion:
* @conn: 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
@ -534,17 +535,17 @@ int virAdmDaemonUnregisterCloseCallback(virAdmDaemonPtr dmn,
*
* Returns 0 on success, -1 on failure and @libVer follows this format:
*/
int virAdmDaemonGetVersion(virAdmDaemonPtr dmn,
unsigned long long *libVer)
int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
unsigned long long *libVer)
{
VIR_DEBUG("dmn=%p, libVir=%p", dmn, libVer);
VIR_DEBUG("conn=%p, libVir=%p", conn, libVer);
virResetLastError();
virCheckAdmDaemonReturn(dmn, -1);
virCheckAdmConnectReturn(conn, -1);
virCheckNonNullArgReturn(libVer, -1);
if (remoteAdminDaemonGetVersion(dmn, libVer) < 0)
if (remoteAdminConnectGetLibVersion(conn, libVer) < 0)
goto error;
return 0;

View File

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

View File

@ -12,13 +12,13 @@
#
LIBVIRT_ADMIN_1.3.0 {
global:
virAdmDaemonClose;
virAdmDaemonGetURI;
virAdmDaemonGetVersion;
virAdmDaemonIsAlive;
virAdmDaemonOpen;
virAdmDaemonRef;
virAdmDaemonRegisterCloseCallback;
virAdmDaemonUnregisterCloseCallback;
virAdmConnectOpen;
virAdmConnectClose;
virAdmConnectRef;
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" ? "virAdmDaemonPtr" : "virConnectPtr";
my $connect_ptr = $structprefix eq "admin" ? "virAdmConnectPtr" : "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, priv->connname, priv->readonly);
priv->conn = virshConnect(ctl, ctl->connname, priv->readonly);
if (!priv->conn) {
if (disconnected)
@ -275,18 +275,18 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
priv->conn = NULL;
}
VIR_FREE(priv->connname);
VIR_FREE(ctl->connname);
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
return false;
priv->connname = vshStrdup(ctl, name);
ctl->connname = vshStrdup(ctl, name);
priv->useGetInfo = false;
priv->useSnapshotOld = false;
priv->blockJobNoBytes = false;
priv->readonly = ro;
priv->conn = virshConnect(ctl, priv->connname, priv->readonly);
priv->conn = virshConnect(ctl, ctl->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 (priv->connname) {
if (ctl->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(priv->connname);
VIR_FREE(ctl->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(priv->connname);
priv->connname = vshStrdup(ctl, optarg);
VIR_FREE(ctl->connname);
ctl->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")))
virshCtl.connname = vshStrdup(ctl, defaultConn);
ctl->connname = vshStrdup(ctl, defaultConn);
if (!vshInit(ctl, cmdGroups, NULL))
exit(EXIT_FAILURE);

View File

@ -69,7 +69,6 @@ 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 virAdmDaemonIsAlive to
* the fact that the event was raised, sice there is virAdmConnectIsAlive to
* check if the communication channel has not been closed by remote party.
*/
static void
vshAdmCatchDisconnect(virAdmDaemonPtr dmn ATTRIBUTE_UNUSED,
vshAdmCatchDisconnect(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
int reason,
void *opaque)
{
@ -73,7 +73,7 @@ vshAdmCatchDisconnect(virAdmDaemonPtr dmn ATTRIBUTE_UNUSED,
return;
error = virSaveLastError();
uri = virAdmDaemonGetURI(dmn);
uri = virAdmConnectGetURI(conn);
switch ((virConnectCloseReason) reason) {
case VIR_CONNECT_CLOSE_REASON_ERROR:
@ -100,21 +100,21 @@ vshAdmCatchDisconnect(virAdmDaemonPtr dmn ATTRIBUTE_UNUSED,
}
static int
vshAdmDaemon(vshControl *ctl, unsigned int flags)
vshAdmConnect(vshControl *ctl, unsigned int flags)
{
vshAdmControlPtr priv = ctl->privData;
priv->dmn = virAdmDaemonOpen(priv->name, flags);
priv->conn = virAdmConnectOpen(ctl->connname, flags);
if (!priv->dmn) {
if (!priv->conn) {
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 (virAdmDaemonRegisterCloseCallback(priv->dmn, vshAdmCatchDisconnect,
NULL, NULL) < 0)
if (virAdmConnectRegisterCloseCallback(priv->conn, 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->dmn)
if (!priv->conn)
return ret;
virAdmDaemonUnregisterCloseCallback(priv->dmn, vshAdmCatchDisconnect);
ret = virAdmDaemonClose(priv->dmn);
virAdmConnectUnregisterCloseCallback(priv->conn, vshAdmCatchDisconnect);
ret = virAdmConnectClose(priv->conn);
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->dmn = NULL;
priv->conn = NULL;
return ret;
}
@ -156,11 +156,11 @@ static void
vshAdmReconnect(vshControl *ctl)
{
vshAdmControlPtr priv = ctl->privData;
if (priv->dmn)
if (priv->conn)
priv->wantReconnect = true;
vshAdmDisconnect(ctl);
vshAdmDaemon(ctl, 0);
vshAdmConnect(ctl, 0);
priv->wantReconnect = false;
}
@ -185,7 +185,7 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
char *uri;
vshAdmControlPtr priv = ctl->privData;
uri = virAdmDaemonGetURI(priv->dmn);
uri = virAdmConnectGetURI(priv->conn);
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 = virAdmDaemonGetVersion(priv->dmn, &daemonVersion);
ret = virAdmConnectGetLibVersion(priv->conn, &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(priv->name);
priv->name = vshStrdup(ctl, name);
VIR_FREE(ctl->connname);
ctl->connname = vshStrdup(ctl, name);
vshAdmReconnect(ctl);
return !!priv->dmn;
return !!priv->conn;
}
static void *
vshAdmDaemonionHandler(vshControl *ctl)
vshAdmConnectionHandler(vshControl *ctl)
{
vshAdmControlPtr priv = ctl->privData;
if (!virAdmDaemonIsAlive(priv->dmn))
if (!virAdmConnectIsAlive(priv->conn))
vshAdmReconnect(ctl);
if (!virAdmDaemonIsAlive(priv->dmn)) {
if (!virAdmConnectIsAlive(priv->conn)) {
vshError(ctl, "%s", _("no valid connection"));
return NULL;
}
return priv->dmn;
return priv->conn;
}
/*
@ -329,7 +329,7 @@ vshAdmInit(vshControl *ctl)
* work properly */
vshInitReload(ctl);
if (priv->dmn)
if (priv->conn)
return false;
/* set up the library error handler */
@ -342,7 +342,7 @@ vshAdmInit(vshControl *ctl)
return false;
ctl->eventLoopStarted = true;
if (priv->name) {
if (ctl->connname) {
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->dmn) {
if (!priv->conn) {
vshReportError(ctl);
return false;
}
@ -374,9 +374,9 @@ vshAdmDeinit(vshControl *ctl)
vshAdmControlPtr priv = ctl->privData;
vshDeinit(ctl);
VIR_FREE(priv->name);
VIR_FREE(ctl->connname);
if (priv->dmn)
if (priv->conn)
vshAdmDisconnect(ctl);
virResetLastError();
@ -473,7 +473,6 @@ 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'},
@ -490,8 +489,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(priv->name);
priv->name = vshStrdup(ctl, optarg);
VIR_FREE(ctl->connname);
ctl->connname = vshStrdup(ctl, optarg);
break;
case 'd':
if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
@ -599,7 +598,7 @@ static const vshCmdGrp cmdGroups[] = {
};
static const vshClientHooks hooks = {
.connHandler = vshAdmDaemonionHandler
.connHandler = vshAdmConnectionHandler
};
int
@ -657,7 +656,7 @@ main(int argc, char **argv)
virFileActivateDirOverride(argv[0]);
if ((defaultConn = virGetEnvBlockSUID("LIBVIRT_DEFAULT_ADMIN_URI")))
virtAdminCtl.name = vshStrdup(ctl, defaultConn);
ctl->connname = vshStrdup(ctl, defaultConn);
if (!vshInit(ctl, cmdGroups, NULL))
exit(EXIT_FAILURE);

View File

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

View File

@ -197,6 +197,7 @@ 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 */