]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Introduce virConnectIsAlive API
authorJiri Denemark <jdenemar@redhat.com>
Fri, 23 Sep 2011 06:47:59 +0000 (08:47 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 24 Nov 2011 11:00:10 +0000 (12:00 +0100)
This API can be used to check if the socket associated with
virConnectPtr is still open or it was closed (probably because keepalive
protocol timed out). If there the connection is local (i.e., no socket
is associated with the connection, it is trivially always alive.

include/libvirt/libvirt.h.in
src/driver.h
src/libvirt.c
src/libvirt_public.syms

index 89c42d5ad80ac0d085a18db7e248a42441fa55aa..0787f18249e3ef37230d13886b0cf3298a0e4260 100644 (file)
@@ -2655,6 +2655,7 @@ int virInterfaceIsActive(virInterfacePtr iface);
 
 int virConnectIsEncrypted(virConnectPtr conn);
 int virConnectIsSecure(virConnectPtr conn);
+int virConnectIsAlive(virConnectPtr conn);
 
 /*
  * CPU specification API
index 4797960939d469211d1966f49225755399c6927f..9e78257e362ca492660e2c4433436b2a3e72fb94 100644 (file)
@@ -508,6 +508,8 @@ typedef int
     (*virDrvConnectIsEncrypted)(virConnectPtr conn);
 typedef int
     (*virDrvConnectIsSecure)(virConnectPtr conn);
+typedef int
+    (*virDrvConnectIsAlive)(virConnectPtr conn);
 typedef int
     (*virDrvDomainIsActive)(virDomainPtr dom);
 typedef int
@@ -904,6 +906,7 @@ struct _virDriver {
     virDrvDomainBlockJobSetSpeed domainBlockJobSetSpeed;
     virDrvDomainBlockPull domainBlockPull;
     virDrvSetKeepAlive setKeepAlive;
+    virDrvConnectIsAlive isAlive;
 };
 
 typedef int
index ff14f235cf8938b9ac54db2e37fb084bc492d067..b428fe63ae2814cfea0f1e640170a3eda46f9076 100644 (file)
@@ -17246,3 +17246,39 @@ error:
     virDispatchError(conn);
     return -1;
 }
+
+/**
+ * virConnectIsAlive:
+ * @conn: pointer to the connection object
+ *
+ * Determine if the connection to the hypervisor is still alive
+ *
+ * A connection will be classed as alive if it is either local, or running
+ * over a channel (TCP or UNIX socket) which is not closed.
+ *
+ * Returns 1 if alive, 0 if dead, -1 on error
+ */
+int virConnectIsAlive(virConnectPtr conn)
+{
+    VIR_DEBUG("conn=%p", conn);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    if (conn->driver->isAlive) {
+        int ret;
+        ret = conn->driver->isAlive(conn);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+error:
+    virDispatchError(conn);
+    return -1;
+}
index 2331f762190723b7348a28ed703e140389a62ec4..6ba1526b26d929e3d95d6906685ff6b4c555158e 100644 (file)
@@ -500,6 +500,7 @@ LIBVIRT_0.9.7 {
 
 LIBVIRT_0.9.8 {
     global:
+        virConnectIsAlive;
         virConnectSetKeepAlive;
 } LIBVIRT_0.9.7;