mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
admin: Introduce virAdmConnectIsAlive
Since most of our APIs rely on an acive functional connection to a daemon and we have such a mechanism in libvirt already, there's need to have such a way in libvirt-admin as well. By introducing a new public API, this patch provides support to check for an active connection.
This commit is contained in:
parent
6409578790
commit
47a089f06c
@ -55,6 +55,7 @@ virAdmConnectPtr virAdmConnectOpen(const char *name, unsigned int flags);
|
||||
int virAdmConnectClose(virAdmConnectPtr conn);
|
||||
|
||||
int virAdmConnectRef(virAdmConnectPtr conn);
|
||||
int virAdmConnectIsAlive(virAdmConnectPtr conn);
|
||||
|
||||
int virAdmGetVersion(unsigned long long *libVer);
|
||||
|
||||
|
@ -420,3 +420,36 @@ virAdmGetVersion(unsigned long long *libVer)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* closed.
|
||||
*
|
||||
* Returns 1, if the connection is alive, 0 if there isn't an existing
|
||||
* connection at all or the channel has already been closed, or -1 on error.
|
||||
*/
|
||||
int
|
||||
virAdmConnectIsAlive(virAdmConnectPtr conn)
|
||||
{
|
||||
bool ret;
|
||||
remoteAdminPrivPtr priv = NULL;
|
||||
|
||||
VIR_DEBUG("conn=%p", conn);
|
||||
|
||||
if (!conn)
|
||||
return 0;
|
||||
|
||||
virCheckAdmConnectReturn(conn, -1);
|
||||
virResetLastError();
|
||||
|
||||
priv = conn->privateData;
|
||||
virObjectLock(priv);
|
||||
ret = virNetClientIsOpen(priv->client);
|
||||
virObjectUnlock(priv);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -16,4 +16,5 @@ LIBVIRT_ADMIN_1.3.0 {
|
||||
virAdmConnectClose;
|
||||
virAdmConnectRef;
|
||||
virAdmGetVersion;
|
||||
virAdmConnectIsAlive;
|
||||
};
|
||||
|
@ -159,10 +159,10 @@ vshAdmConnectionHandler(vshControl *ctl)
|
||||
{
|
||||
vshAdmControlPtr priv = ctl->privData;
|
||||
|
||||
if (!priv->conn)
|
||||
if (!virAdmConnectIsAlive(priv->conn))
|
||||
vshAdmReconnect(ctl);
|
||||
|
||||
if (!priv->conn) {
|
||||
if (!virAdmConnectIsAlive(priv->conn)) {
|
||||
vshError(ctl, "%s", _("no valid connection"));
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user