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 */ /* Functions */
static int static int
adminDispatchConnectOpen(virNetServerPtr server ATTRIBUTE_UNUSED, adminDispatchDaemonOpen(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client, virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED, virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr, virNetMessageErrorPtr rerr,
struct admin_connect_open_args *args) struct admin_daemon_open_args *args)
{ {
unsigned int flags; unsigned int flags;
struct daemonAdmClientPrivate *priv = struct daemonAdmClientPrivate *priv =
@ -105,7 +105,7 @@ adminDispatchConnectOpen(virNetServerPtr server ATTRIBUTE_UNUSED,
} }
static int static int
adminDispatchConnectClose(virNetServerPtr server ATTRIBUTE_UNUSED, adminDispatchDaemonClose(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client, virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED, virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED) virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED)
@ -115,7 +115,7 @@ adminDispatchConnectClose(virNetServerPtr server ATTRIBUTE_UNUSED,
} }
static int static int
adminConnectGetLibVersion(virNetDaemonPtr dmn ATTRIBUTE_UNUSED, adminDaemonGetVersion(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
unsigned long long *libVer) unsigned long long *libVer)
{ {
if (libVer) if (libVer)

View File

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

View File

@ -37,11 +37,11 @@ typedef string admin_nonnull_string<ADMIN_STRING_MAX>;
typedef admin_nonnull_string *admin_string; typedef admin_nonnull_string *admin_string;
/*----- Protocol. -----*/ /*----- Protocol. -----*/
struct admin_connect_open_args { struct admin_daemon_open_args {
unsigned int flags; unsigned int flags;
}; };
struct admin_connect_get_lib_version_ret { struct admin_daemon_get_version_ret {
unsigned hyper libVer; unsigned hyper libVer;
}; };
@ -70,15 +70,15 @@ enum admin_procedure {
/** /**
* @generate: none * @generate: none
*/ */
ADMIN_PROC_CONNECT_OPEN = 1, ADMIN_PROC_DAEMON_OPEN = 1,
/** /**
* @generate: none * @generate: none
*/ */
ADMIN_PROC_CONNECT_CLOSE = 2, ADMIN_PROC_DAEMON_CLOSE = 2,
/** /**
* @generate: both * @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 static int
callFull(virAdmConnectPtr conn ATTRIBUTE_UNUSED, callFull(virAdmDaemonPtr dmn ATTRIBUTE_UNUSED,
remoteAdminPrivPtr priv, remoteAdminPrivPtr priv,
int *fdin, int *fdin,
size_t fdinlen, size_t fdinlen,
@ -86,7 +86,7 @@ callFull(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
} }
static int static int
call(virAdmConnectPtr conn, call(virAdmDaemonPtr dmn,
unsigned int flags, unsigned int flags,
int proc_nr, int proc_nr,
xdrproc_t args_filter, char *args, xdrproc_t args_filter, char *args,
@ -94,7 +94,7 @@ call(virAdmConnectPtr conn,
{ {
virCheckFlags(0, -1); virCheckFlags(0, -1);
return callFull(conn, conn->privateData, return callFull(dmn, dmn->privateData,
NULL, 0, NULL, NULL, proc_nr, NULL, 0, NULL, NULL, proc_nr,
args_filter, args, ret_filter, ret); args_filter, args, ret_filter, ret);
} }
@ -106,14 +106,14 @@ remoteAdminClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED,
int reason, int reason,
void *opaque) void *opaque)
{ {
virAdmConnectCloseCallbackDataPtr cbdata = opaque; virAdmDaemonCloseCallbackDataPtr cbdata = opaque;
virObjectLock(cbdata); virObjectLock(cbdata);
if (cbdata->callback) { if (cbdata->callback) {
VIR_DEBUG("Triggering connection close callback %p reason=%d, opaque=%p", VIR_DEBUG("Triggering connection close callback %p reason=%d, opaque=%p",
cbdata->callback, reason, cbdata->opaque); cbdata->callback, reason, cbdata->opaque);
cbdata->callback(cbdata->conn, reason, cbdata->opaque); cbdata->callback(cbdata->dmn, reason, cbdata->opaque);
if (cbdata->freeCallback) if (cbdata->freeCallback)
cbdata->freeCallback(cbdata->opaque); cbdata->freeCallback(cbdata->opaque);
@ -124,11 +124,11 @@ remoteAdminClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED,
} }
static int static int
remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags) remoteAdminDaemonOpen(virAdmDaemonPtr dmn, unsigned int flags)
{ {
int rv = -1; int rv = -1;
remoteAdminPrivPtr priv = conn->privateData; remoteAdminPrivPtr priv = dmn->privateData;
admin_connect_open_args args; admin_daemon_open_args args;
virObjectLock(priv); virObjectLock(priv);
@ -140,13 +140,13 @@ remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
virResetLastError(); virResetLastError();
} }
virObjectRef(conn->closeCallback); virObjectRef(dmn->closeCallback);
virNetClientSetCloseCallback(priv->client, remoteAdminClientCloseFunc, virNetClientSetCloseCallback(priv->client, remoteAdminClientCloseFunc,
conn->closeCallback, dmn->closeCallback,
virObjectFreeCallback); virObjectFreeCallback);
if (call(conn, 0, ADMIN_PROC_CONNECT_OPEN, if (call(dmn, 0, ADMIN_PROC_DAEMON_OPEN,
(xdrproc_t)xdr_admin_connect_open_args, (char *)&args, (xdrproc_t)xdr_admin_daemon_open_args, (char *)&args,
(xdrproc_t)xdr_void, (char *)NULL) == -1) { (xdrproc_t)xdr_void, (char *)NULL) == -1) {
goto done; goto done;
} }
@ -159,14 +159,14 @@ remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
} }
static int static int
remoteAdminConnectClose(virAdmConnectPtr conn) remoteAdminDaemonClose(virAdmDaemonPtr dmn)
{ {
int rv = -1; int rv = -1;
remoteAdminPrivPtr priv = conn->privateData; remoteAdminPrivPtr priv = dmn->privateData;
virObjectLock(priv); 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,
(xdrproc_t)xdr_void, (char *)NULL) == -1) { (xdrproc_t)xdr_void, (char *)NULL) == -1) {
goto done; goto done;
@ -184,10 +184,10 @@ remoteAdminConnectClose(virAdmConnectPtr conn)
static void static void
remoteAdminPrivFree(void *opaque) remoteAdminPrivFree(void *opaque)
{ {
virAdmConnectPtr conn = opaque; virAdmDaemonPtr dmn = opaque;
remoteAdminConnectClose(conn); remoteAdminDaemonClose(dmn);
virObjectUnref(conn->privateData); virObjectUnref(dmn->privateData);
} }
static remoteAdminPrivPtr static remoteAdminPrivPtr

View File

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

View File

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

View File

@ -41,7 +41,7 @@ extern virClassPtr virStreamClass;
extern virClassPtr virStorageVolClass; extern virClassPtr virStorageVolClass;
extern virClassPtr virStoragePoolClass; extern virClassPtr virStoragePoolClass;
extern virClassPtr virAdmConnectClass; extern virClassPtr virAdmDaemonClass;
# define virCheckConnectReturn(obj, retval) \ # define virCheckConnectReturn(obj, retval) \
do { \ do { \
@ -297,9 +297,9 @@ extern virClassPtr virAdmConnectClass;
dom, NULLSTR(_domname), _uuidstr, __VA_ARGS__); \ dom, NULLSTR(_domname), _uuidstr, __VA_ARGS__); \
} while (0) } while (0)
# define virCheckAdmConnectReturn(obj, retval) \ # define virCheckAdmDaemonReturn(obj, retval) \
do { \ do { \
if (!virObjectIsClass(obj, virAdmConnectClass)) { \ if (!virObjectIsClass(obj, virAdmDaemonClass)) { \
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \ virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
__FILE__, __FUNCTION__, __LINE__, \ __FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \ __FUNCTION__); \
@ -307,9 +307,9 @@ extern virClassPtr virAdmConnectClass;
return retval; \ return retval; \
} \ } \
} while (0) } while (0)
# define virCheckAdmConnectGoto(obj, label) \ # define virCheckAdmDaemonGoto(obj, label) \
do { \ do { \
if (!virObjectIsClass(obj, virAdmConnectClass)) { \ if (!virObjectIsClass(obj, virAdmDaemonClass)) { \
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \ virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
__FILE__, __FUNCTION__, __LINE__, \ __FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \ __FUNCTION__); \
@ -331,8 +331,8 @@ extern virClassPtr virAdmConnectClass;
typedef struct _virConnectCloseCallbackData virConnectCloseCallbackData; typedef struct _virConnectCloseCallbackData virConnectCloseCallbackData;
typedef virConnectCloseCallbackData *virConnectCloseCallbackDataPtr; typedef virConnectCloseCallbackData *virConnectCloseCallbackDataPtr;
typedef struct _virAdmConnectCloseCallbackData virAdmConnectCloseCallbackData; typedef struct _virAdmDaemonCloseCallbackData virAdmDaemonCloseCallbackData;
typedef virAdmConnectCloseCallbackData *virAdmConnectCloseCallbackDataPtr; typedef virAdmDaemonCloseCallbackData *virAdmDaemonCloseCallbackDataPtr;
/** /**
* Internal structures holding data related to connection close callbacks. * Internal structures holding data related to connection close callbacks.
@ -346,11 +346,11 @@ struct _virConnectCloseCallbackData {
virFreeCallback freeCallback; virFreeCallback freeCallback;
}; };
struct _virAdmConnectCloseCallbackData { struct _virAdmDaemonCloseCallbackData {
virObjectLockable parent; virObjectLockable parent;
virAdmConnectPtr conn; virAdmDaemonPtr dmn;
virAdmConnectCloseFunc callback; virAdmDaemonCloseFunc callback;
void *opaque; void *opaque;
virFreeCallback freeCallback; virFreeCallback freeCallback;
}; };
@ -402,11 +402,11 @@ struct _virConnect {
}; };
/** /**
* _virAdmConnect: * _virAdmDaemon:
* *
* Internal structure associated to an admin connection * Internal structure associated to an admin connection
*/ */
struct _virAdmConnect { struct _virAdmDaemon {
virObjectLockable object; virObjectLockable object;
virURIPtr uri; virURIPtr uri;
@ -414,7 +414,7 @@ struct _virAdmConnect {
virFreeCallback privateDataFreeFunc; virFreeCallback privateDataFreeFunc;
/* Per-connection close callback */ /* Per-connection close callback */
virAdmConnectCloseCallbackDataPtr closeCallback; virAdmDaemonCloseCallbackDataPtr closeCallback;
}; };
@ -599,6 +599,6 @@ virNWFilterPtr virGetNWFilter(virConnectPtr conn,
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain, virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain,
const char *name); const char *name);
virAdmConnectPtr virAdmConnectNew(void); virAdmDaemonPtr virAdmDaemonNew(void);
#endif /* __VIR_DATATYPES_H__ */ #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 /* 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 * 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 * until after initialization is complete, and since this is
* one-shot, we never get here again. */ * one-shot, we never get here again. */
if (virThreadInitialize() < 0 || if (virThreadInitialize() < 0 ||
@ -183,20 +183,20 @@ virAdmGetDefaultURI(virConfPtr conf)
} }
/** /**
* virAdmConnectOpen: * virAdmDaemonOpen:
* @name: uri of the daemon to connect to, NULL for default * @name: uri of the daemon to connect to, NULL for default
* @flags: unused, must be 0 * @flags: unused, must be 0
* *
* Opens connection to admin interface of the daemon. * Opens connection to admin interface of the daemon.
* *
* Returns @virAdmConnectPtr object or NULL on error * Returns @virAdmDaemonPtr object or NULL on error
*/ */
virAdmConnectPtr virAdmDaemonPtr
virAdmConnectOpen(const char *name, unsigned int flags) virAdmDaemonOpen(const char *name, unsigned int flags)
{ {
char *sock_path = NULL; char *sock_path = NULL;
char *alias = NULL; char *alias = NULL;
virAdmConnectPtr conn = NULL; virAdmDaemonPtr dmn = NULL;
virConfPtr conf = NULL; virConfPtr conf = NULL;
if (virAdmInitialize() < 0) if (virAdmInitialize() < 0)
@ -206,7 +206,7 @@ virAdmConnectOpen(const char *name, unsigned int flags)
virResetLastError(); virResetLastError();
virCheckFlags(VIR_CONNECT_NO_ALIASES, NULL); virCheckFlags(VIR_CONNECT_NO_ALIASES, NULL);
if (!(conn = virAdmConnectNew())) if (!(dmn = virAdmDaemonNew()))
goto error; goto error;
if (virConfLoadConfig(&conf, "libvirt-admin.conf") < 0) if (virConfLoadConfig(&conf, "libvirt-admin.conf") < 0)
@ -219,46 +219,46 @@ virAdmConnectOpen(const char *name, unsigned int flags)
virURIResolveAlias(conf, name, &alias) < 0)) virURIResolveAlias(conf, name, &alias) < 0))
goto error; goto error;
if (!(conn->uri = virURIParse(alias ? alias : name))) if (!(dmn->uri = virURIParse(alias ? alias : name)))
goto error; goto error;
if (!(sock_path = getSocketPath(conn->uri))) if (!(sock_path = getSocketPath(dmn->uri)))
goto error; goto error;
if (!(conn->privateData = remoteAdminPrivNew(sock_path))) if (!(dmn->privateData = remoteAdminPrivNew(sock_path)))
goto error; goto error;
conn->privateDataFreeFunc = remoteAdminPrivFree; dmn->privateDataFreeFunc = remoteAdminPrivFree;
if (remoteAdminConnectOpen(conn, flags) < 0) if (remoteAdminDaemonOpen(dmn, flags) < 0)
goto error; goto error;
cleanup: cleanup:
VIR_FREE(sock_path); VIR_FREE(sock_path);
VIR_FREE(alias); VIR_FREE(alias);
virConfFree(conf); virConfFree(conf);
return conn; return dmn;
error: error:
virDispatchError(NULL); virDispatchError(NULL);
virObjectUnref(conn); virObjectUnref(dmn);
conn = NULL; dmn = NULL;
goto cleanup; goto cleanup;
} }
/** /**
* virAdmConnectClose: * virAdmDaemonClose:
* @conn: pointer to admin connection to close * @dmn: pointer to admin connection to close
* *
* This function closes the admin connection to the Hypervisor. This should not * This function closes the admin connection to the Hypervisor. This should not
* be called if further interaction with the Hypervisor are needed especially if * be called if further interaction with the Hypervisor are needed especially if
* there is running domain which need further monitoring by the application. * there is running domain which need further monitoring by the application.
* *
* Connections are reference counted; the count is explicitly increased by the * 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 * increased by other API that depend on the connection remaining alive. The
* open and every virAdmConnectRef call should have a matching * open and every virAdmDaemonRef call should have a matching
* virAdmConnectClose, and all other references will be released after the * virAdmDaemonClose, and all other references will be released after the
* corresponding operation completes. * corresponding operation completes.
* *
* Returns a positive number if at least 1 reference remains on success. The * 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 * return of 0 implies no references remain and the connection is closed and
* memory has been freed. A return of -1 implies a failure. * 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 * some other object still has a temporary reference to the connection, but the
* application should not try to further use a connection after 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 int
virAdmConnectClose(virAdmConnectPtr conn) virAdmDaemonClose(virAdmDaemonPtr dmn)
{ {
VIR_DEBUG("conn=%p", conn); VIR_DEBUG("dmn=%p", dmn);
virResetLastError(); virResetLastError();
if (!conn) if (!dmn)
return 0; return 0;
virCheckAdmConnectReturn(conn, -1); virCheckAdmDaemonReturn(dmn, -1);
if (!virObjectUnref(conn)) if (!virObjectUnref(dmn))
return 0; return 0;
return 1; return 1;
} }
/** /**
* virAdmConnectRef: * virAdmDaemonRef:
* @conn: the connection to hold a reference on * @dmn: the connection to hold a reference on
* *
* Increment the reference count on the connection. For each additional call to * 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 * release the reference count, once the caller no longer needs the reference to
* this object. * this object.
* *
@ -305,15 +305,15 @@ virAdmConnectClose(virAdmConnectPtr conn)
* Returns 0 in case of success, -1 in case of failure * Returns 0 in case of success, -1 in case of failure
*/ */
int int
virAdmConnectRef(virAdmConnectPtr conn) virAdmDaemonRef(virAdmDaemonPtr dmn)
{ {
VIR_DEBUG("conn=%p refs=%d", conn, VIR_DEBUG("dmn=%p refs=%d", dmn,
conn ? conn->object.parent.u.s.refs : 0); dmn ? dmn->object.parent.u.s.refs : 0);
virResetLastError(); virResetLastError();
virCheckAdmConnectReturn(conn, -1); virCheckAdmDaemonReturn(dmn, -1);
virObjectRef(conn); virObjectRef(dmn);
return 0; return 0;
} }
@ -327,8 +327,7 @@ virAdmConnectRef(virAdmConnectPtr conn)
* generic message will be returned. @libVer format is as follows: * generic message will be returned. @libVer format is as follows:
* major * 1,000,000 + minor * 1,000 + release. * major * 1,000,000 + minor * 1,000 + release.
* *
* NOTE: To get the remote side library version use virAdmConnectGetLibVersion * NOTE: To get the remote side version use virAdmDaemonGetVersion instead.
* instead.
* *
* Returns 0 on success, -1 in case of an error. * Returns 0 on success, -1 in case of an error.
*/ */
@ -353,8 +352,8 @@ virAdmGetVersion(unsigned long long *libVer)
} }
/** /**
* virAdmConnectIsAlive: * virAdmDaemonIsAlive:
* @conn: connection to admin server * @dmn: connection to admin server
* *
* Decide whether the connection to the admin server is alive or not. * 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 * 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. * connection at all or the channel has already been closed, or -1 on error.
*/ */
int int
virAdmConnectIsAlive(virAdmConnectPtr conn) virAdmDaemonIsAlive(virAdmDaemonPtr dmn)
{ {
bool ret; bool ret;
remoteAdminPrivPtr priv = NULL; remoteAdminPrivPtr priv = NULL;
VIR_DEBUG("conn=%p", conn); VIR_DEBUG("dmn=%p", dmn);
if (!conn) if (!dmn)
return 0; return 0;
virCheckAdmConnectReturn(conn, -1); virCheckAdmDaemonReturn(dmn, -1);
virResetLastError(); virResetLastError();
priv = conn->privateData; priv = dmn->privateData;
virObjectLock(priv); virObjectLock(priv);
ret = virNetClientIsOpen(priv->client); ret = virNetClientIsOpen(priv->client);
virObjectUnlock(priv); virObjectUnlock(priv);
@ -386,35 +385,35 @@ virAdmConnectIsAlive(virAdmConnectPtr conn)
} }
/** /**
* virAdmConnectGetURI: * virAdmDaemonGetURI:
* @conn: pointer to an admin connection * @dmn: pointer to an admin connection
* *
* String returned by this method is normally the same as the string passed * 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. * this method returns a non-null URI string.
* *
* Returns an URI string related to the connection or NULL in case of an error. * Returns an URI string related to the connection or NULL in case of an error.
* Caller is responsible for freeing the string. * Caller is responsible for freeing the string.
*/ */
char * char *
virAdmConnectGetURI(virAdmConnectPtr conn) virAdmDaemonGetURI(virAdmDaemonPtr dmn)
{ {
char *uri = NULL; char *uri = NULL;
VIR_DEBUG("conn=%p", conn); VIR_DEBUG("dmn=%p", dmn);
virResetLastError(); virResetLastError();
virCheckAdmConnectReturn(conn, NULL); virCheckAdmDaemonReturn(dmn, NULL);
if (!(uri = virURIFormat(conn->uri))) if (!(uri = virURIFormat(dmn->uri)))
virDispatchError(NULL); virDispatchError(NULL);
return uri; return uri;
} }
/** /**
* virAdmConnectRegisterCloseCallback: * virAdmDaemonRegisterCloseCallback:
* @conn: connection to admin server * @dmn: connection to admin server
* @cb: callback to be invoked upon connection close * @cb: callback to be invoked upon connection close
* @opaque: user data to pass to @cb * @opaque: user data to pass to @cb
* @freecb: callback to free @opaque * @freecb: callback to free @opaque
@ -430,103 +429,103 @@ virAdmConnectGetURI(virAdmConnectPtr conn)
* *
* Returns 0 on success, -1 on error * Returns 0 on success, -1 on error
*/ */
int virAdmConnectRegisterCloseCallback(virAdmConnectPtr conn, int virAdmDaemonRegisterCloseCallback(virAdmDaemonPtr dmn,
virAdmConnectCloseFunc cb, virAdmDaemonCloseFunc cb,
void *opaque, void *opaque,
virFreeCallback freecb) virFreeCallback freecb)
{ {
VIR_DEBUG("conn=%p", conn); VIR_DEBUG("dmn=%p", dmn);
virResetLastError(); virResetLastError();
virCheckAdmConnectReturn(conn, -1); virCheckAdmDaemonReturn(dmn, -1);
virObjectRef(conn); virObjectRef(dmn);
virObjectLock(conn); virObjectLock(dmn);
virObjectLock(conn->closeCallback); virObjectLock(dmn->closeCallback);
virCheckNonNullArgGoto(cb, error); virCheckNonNullArgGoto(cb, error);
if (conn->closeCallback->callback) { if (dmn->closeCallback->callback) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A close callback is already registered")); _("A close callback is already registered"));
goto error; goto error;
} }
conn->closeCallback->conn = conn; dmn->closeCallback->dmn = dmn;
conn->closeCallback->callback = cb; dmn->closeCallback->callback = cb;
conn->closeCallback->opaque = opaque; dmn->closeCallback->opaque = opaque;
conn->closeCallback->freeCallback = freecb; dmn->closeCallback->freeCallback = freecb;
virObjectUnlock(conn->closeCallback); virObjectUnlock(dmn->closeCallback);
virObjectUnlock(conn); virObjectUnlock(dmn);
return 0; return 0;
error: error:
virObjectUnlock(conn->closeCallback); virObjectUnlock(dmn->closeCallback);
virObjectUnlock(conn); virObjectUnlock(dmn);
virDispatchError(NULL); virDispatchError(NULL);
virObjectUnref(conn); virObjectUnref(dmn);
return -1; return -1;
} }
/** /**
* virAdmConnectUnregisterCloseCallback: * virAdmDaemonUnregisterCloseCallback:
* @conn: pointer to connection object * @dmn: pointer to connection object
* @cb: pointer to the current registered callback * @cb: pointer to the current registered callback
* *
* Unregisters the callback previously set with the * Unregisters the callback previously set with the
* virAdmConnectRegisterCloseCallback method. The callback * virAdmDaemonRegisterCloseCallback method. The callback
* will no longer receive notifications when the connection * will no longer receive notifications when the connection
* closes. If a virFreeCallback was provided at time of * closes. If a virFreeCallback was provided at time of
* registration, it will be invoked. * registration, it will be invoked.
* *
* Returns 0 on success, -1 on error * Returns 0 on success, -1 on error
*/ */
int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn, int virAdmDaemonUnregisterCloseCallback(virAdmDaemonPtr dmn,
virAdmConnectCloseFunc cb) virAdmDaemonCloseFunc cb)
{ {
VIR_DEBUG("conn=%p", conn); VIR_DEBUG("dmn=%p", dmn);
virResetLastError(); virResetLastError();
virCheckAdmConnectReturn(conn, -1); virCheckAdmDaemonReturn(dmn, -1);
virObjectLock(conn); virObjectLock(dmn);
virObjectLock(conn->closeCallback); virObjectLock(dmn->closeCallback);
virCheckNonNullArgGoto(cb, error); virCheckNonNullArgGoto(cb, error);
if (conn->closeCallback->callback != cb) { if (dmn->closeCallback->callback != cb) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A different callback was requested")); _("A different callback was requested"));
goto error; goto error;
} }
conn->closeCallback->callback = NULL; dmn->closeCallback->callback = NULL;
if (conn->closeCallback->freeCallback) if (dmn->closeCallback->freeCallback)
conn->closeCallback->freeCallback(conn->closeCallback->opaque); dmn->closeCallback->freeCallback(dmn->closeCallback->opaque);
conn->closeCallback->freeCallback = NULL; dmn->closeCallback->freeCallback = NULL;
virObjectUnlock(conn->closeCallback); virObjectUnlock(dmn->closeCallback);
virObjectUnlock(conn); virObjectUnlock(dmn);
virObjectUnref(conn); virObjectUnref(dmn);
return 0; return 0;
error: error:
virObjectUnlock(conn->closeCallback); virObjectUnlock(dmn->closeCallback);
virObjectUnlock(conn); virObjectUnlock(dmn);
virDispatchError(NULL); virDispatchError(NULL);
return -1; return -1;
} }
/** /**
* virAdmConnectGetLibVersion: * virAdmDaemonGetVersion:
* @conn: pointer to an active admin connection * @dmn: pointer to an active admin connection
* @libVer: stores the current remote libvirt version number * @libVer: stores the current remote libvirt version number
* *
* Retrieves the remote side libvirt version used by the daemon. Format * 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: * Returns 0 on success, -1 on failure and @libVer follows this format:
*/ */
int virAdmConnectGetLibVersion(virAdmConnectPtr conn, int virAdmDaemonGetVersion(virAdmDaemonPtr dmn,
unsigned long long *libVer) unsigned long long *libVer)
{ {
VIR_DEBUG("conn=%p, libVir=%p", conn, libVer); VIR_DEBUG("dmn=%p, libVir=%p", dmn, libVer);
virResetLastError(); virResetLastError();
virCheckAdmConnectReturn(conn, -1); virCheckAdmDaemonReturn(dmn, -1);
virCheckNonNullArgReturn(libVer, -1); virCheckNonNullArgReturn(libVer, -1);
if (remoteAdminConnectGetLibVersion(conn, libVer) < 0) if (remoteAdminDaemonGetVersion(dmn, libVer) < 0)
goto error; goto error;
return 0; return 0;

View File

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

View File

@ -12,13 +12,13 @@
# #
LIBVIRT_ADMIN_1.3.0 { LIBVIRT_ADMIN_1.3.0 {
global: global:
virAdmConnectOpen; virAdmDaemonClose;
virAdmConnectClose; virAdmDaemonGetURI;
virAdmConnectRef; virAdmDaemonGetVersion;
virAdmDaemonIsAlive;
virAdmDaemonOpen;
virAdmDaemonRef;
virAdmDaemonRegisterCloseCallback;
virAdmDaemonUnregisterCloseCallback;
virAdmGetVersion; 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 $protocol = shift or die "missing protocol argument";
my @autogen; 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"; my $prefix = ($structprefix eq "admin") ? "admin" : "vir";
sub fixup_name { sub fixup_name {

View File

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

View File

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

View File

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

View File

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

View File

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