[PATCH v4 10/13] Implement virConnectIsAlive in all drivers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
Notes:
    ACKed except for esx driver

    Version 4:
    - fix esx implementation
    
    Version 3:
    - no changes
    
    Version 2:
    - new patch

 src/esx/esx_driver.c       |   18 ++++++++++++++++++
 src/hyperv/hyperv_driver.c |   18 ++++++++++++++++++
 src/libxl/libxl_driver.c   |    8 ++++++++
 src/lxc/lxc_driver.c       |    7 +++++++
 src/openvz/openvz_driver.c |    7 +++++++
 src/phyp/phyp_driver.c     |   18 ++++++++++++++++++
 src/qemu/qemu_driver.c     |    6 ++++++
 src/remote/remote_driver.c |   18 ++++++++++++++++++
 src/rpc/virnetclient.c     |   14 ++++++++++++++
 src/rpc/virnetclient.h     |    1 +
 src/test/test_driver.c     |    6 ++++++
 src/uml/uml_driver.c       |    7 +++++++
 src/vbox/vbox_tmpl.c       |    6 ++++++
 src/vmware/vmware_driver.c |    7 +++++++
 src/xen/xen_driver.c       |    8 ++++++++
 src/xenapi/xenapi_driver.c |   12 ++++++++++++
 16 files changed, 161 insertions(+), 0 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 41086ef..14ab5f5 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -4166,6 +4166,23 @@ esxIsSecure(virConnectPtr conn)
 
 
 static int
+esxIsAlive(virConnectPtr conn)
+{
+    esxPrivate *priv = conn->privateData;
+
+    /* XXX we should be able to do something better than this but this is
+     * simple, safe, and good enough for now. In worst case, the function will
+     * return true even though the connection is not alive.
+     */
+    if (priv->primary)
+        return 1;
+    else
+        return 0;
+}
+
+
+
+static int
 esxDomainIsActive(virDomainPtr domain)
 {
     int result = -1;
@@ -4992,6 +5009,7 @@ static virDriver esxDriver = {
     .domainSnapshotCurrent = esxDomainSnapshotCurrent, /* 0.8.0 */
     .domainRevertToSnapshot = esxDomainRevertToSnapshot, /* 0.8.0 */
     .domainSnapshotDelete = esxDomainSnapshotDelete, /* 0.8.0 */
+    .isAlive = esxIsAlive, /* 0.9.7 */
 };
 
 
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 39b55f8..7665a76 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1119,6 +1119,23 @@ hypervIsSecure(virConnectPtr conn)
 
 
 static int
+hypervIsAlive(virConnectPtr conn)
+{
+    hypervPrivate *priv = conn->privateData;
+
+    /* XXX we should be able to do something better than this is simple, safe,
+     * and good enough for now. In worst case, the function will return true
+     * even though the connection is not alive.
+     */
+    if (priv->client)
+        return 1;
+    else
+        return 0;
+}
+
+
+
+static int
 hypervDomainIsActive(virDomainPtr domain)
 {
     int result = -1;
@@ -1276,6 +1293,7 @@ static virDriver hypervDriver = {
     .domainManagedSave = hypervDomainManagedSave, /* 0.9.5 */
     .domainHasManagedSaveImage = hypervDomainHasManagedSaveImage, /* 0.9.5 */
     .domainManagedSaveRemove = hypervDomainManagedSaveRemove, /* 0.9.5 */
+    .isAlive = hypervIsAlive, /* 0.9.7 */
 };
 
 
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index d324632..42503d6 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3875,6 +3875,13 @@ libxlDomainEventDeregisterAny(virConnectPtr conn, int callbackID)
 }
 
 
+static int
+libxlIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
+
 static virDriver libxlDriver = {
     .no = VIR_DRV_LIBXL,
     .name = "xenlight",
@@ -3948,6 +3955,7 @@ static virDriver libxlDriver = {
     .domainIsUpdated = libxlDomainIsUpdated, /* 0.9.0 */
     .domainEventRegisterAny = libxlDomainEventRegisterAny, /* 0.9.0 */
     .domainEventDeregisterAny = libxlDomainEventDeregisterAny, /* 0.9.0 */
+    .isAlive = libxlIsAlive, /* 0.9.7 */
 };
 
 static virStateDriver libxlStateDriver = {
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 06bfa85..701bd8d 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -200,6 +200,12 @@ static int lxcIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
 }
 
 
+static int lxcIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
+
 static char *lxcGetCapabilities(virConnectPtr conn) {
     lxc_driver_t *driver = conn->privateData;
     char *xml;
@@ -3139,6 +3145,7 @@ static virDriver lxcDriver = {
     .domainEventRegisterAny = lxcDomainEventRegisterAny, /* 0.8.0 */
     .domainEventDeregisterAny = lxcDomainEventDeregisterAny, /* 0.8.0 */
     .domainOpenConsole = lxcDomainOpenConsole, /* 0.8.6 */
+    .isAlive = lxcIsAlive, /* 0.9.7 */
 };
 
 static virStateDriver lxcStateDriver = {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 69ff444..8a4e6cf 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1426,6 +1426,12 @@ static int openvzIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) {
     return 1;
 }
 
+static int
+openvzIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
 static char *openvzGetCapabilities(virConnectPtr conn) {
     struct openvz_driver *driver = conn->privateData;
     char *ret;
@@ -1714,6 +1720,7 @@ static virDriver openvzDriver = {
     .domainIsActive = openvzDomainIsActive, /* 0.7.3 */
     .domainIsPersistent = openvzDomainIsPersistent, /* 0.7.3 */
     .domainIsUpdated = openvzDomainIsUpdated, /* 0.8.6 */
+    .isAlive = openvzIsAlive, /* 0.9.7 */
 };
 
 int openvzRegister(void) {
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index ff16aae..458c9c9 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1284,6 +1284,23 @@ phypIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
     return 1;
 }
 
+
+static int
+phypIsAlive(virConnectPtr conn)
+{
+    ConnectionData *connection_data = conn->networkPrivateData;
+
+    /* XXX we should be able to do something better but this is simple, safe,
+     * and good enough for now. In worst case, the function will return true
+     * even though the connection is not alive.
+     */
+    if (connection_data && connection_data->session)
+        return 1;
+    else
+        return 0;
+}
+
+
 static int
 phypIsUpdated(virDomainPtr conn ATTRIBUTE_UNUSED)
 {
@@ -3786,6 +3803,7 @@ static virDriver phypDriver = {
     .isEncrypted = phypIsEncrypted, /* 0.7.3 */
     .isSecure = phypIsSecure, /* 0.7.3 */
     .domainIsUpdated = phypIsUpdated, /* 0.8.6 */
+    .isAlive = phypIsAlive, /* 0.9.7 */
 };
 
 static virStorageDriver phypStorageDriver = {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e053a97..e375fd2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -942,6 +942,11 @@ static int qemuIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
     return 0;
 }
 
+static int qemuIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
 
 static int kvmGetMaxVCPUs(void) {
     int maxvcpus = 1;
@@ -10802,6 +10807,7 @@ static virDriver qemuDriver = {
     .domainGetBlockJobInfo = qemuDomainGetBlockJobInfo, /* 0.9.4 */
     .domainBlockJobSetSpeed = qemuDomainBlockJobSetSpeed, /* 0.9.4 */
     .domainBlockPull = qemuDomainBlockPull, /* 0.9.4 */
+    .isAlive = qemuIsAlive, /* 0.9.7 */
 };
 
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index f99c32d..09139aa 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -4171,6 +4171,23 @@ cleanup:
 }
 
 
+static int
+remoteIsAlive(virConnectPtr conn)
+{
+    struct private_data *priv = conn->privateData;
+    bool ret;
+
+    remoteDriverLock(priv);
+    ret = virNetClientIsOpen(priv->client);
+    remoteDriverUnlock(priv);
+
+    if (ret)
+        return 1;
+    else
+        return 0;
+}
+
+
 #include "remote_client_bodies.h"
 #include "qemu_client_bodies.h"
 
@@ -4524,6 +4541,7 @@ static virDriver remote_driver = {
     .domainBlockJobSetSpeed = remoteDomainBlockJobSetSpeed, /* 0.9.4 */
     .domainBlockPull = remoteDomainBlockPull, /* 0.9.4 */
     .setKeepAlive = remoteSetKeepAlive, /* 0.9.7 */
+    .isAlive = remoteIsAlive, /* 0.9.7 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 37e9cc8..d546253 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -570,6 +570,20 @@ bool virNetClientIsEncrypted(virNetClientPtr client)
 }
 
 
+bool virNetClientIsOpen(virNetClientPtr client)
+{
+    bool ret;
+
+    if (!client)
+        return false;
+
+    virNetClientLock(client);
+    ret = client->sock && !client->wantClose;
+    virNetClientUnlock(client);
+    return ret;
+}
+
+
 int virNetClientAddProgram(virNetClientPtr client,
                            virNetClientProgramPtr prog)
 {
diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h
index 3227a4e..7d7a8c0 100644
--- a/src/rpc/virnetclient.h
+++ b/src/rpc/virnetclient.h
@@ -78,6 +78,7 @@ int virNetClientSetTLSSession(virNetClientPtr client,
                               virNetTLSContextPtr tls);
 
 bool virNetClientIsEncrypted(virNetClientPtr client);
+bool virNetClientIsOpen(virNetClientPtr client);
 
 const char *virNetClientLocalAddrString(virNetClientPtr client);
 const char *virNetClientRemoteAddrString(virNetClientPtr client);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 326409d..bc76640 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1184,6 +1184,11 @@ static int testIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
     return 0;
 }
 
+static int testIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
 static int testGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED,
                            const char *type ATTRIBUTE_UNUSED)
 {
@@ -5623,6 +5628,7 @@ static virDriver testDriver = {
     .domainIsUpdated = testDomainIsUpdated, /* 0.8.6 */
     .domainEventRegisterAny = testDomainEventRegisterAny, /* 0.8.0 */
     .domainEventDeregisterAny = testDomainEventDeregisterAny, /* 0.8.0 */
+    .isAlive = testIsAlive, /* 0.9.7 */
 };
 
 static virNetworkDriver testNetworkDriver = {
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 16ab73a..c2880fe 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1218,6 +1218,12 @@ static int umlIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
 }
 
 
+static int umlIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
+
 static char *umlGetCapabilities(virConnectPtr conn) {
     struct uml_driver *driver = (struct uml_driver *)conn->privateData;
     char *xml;
@@ -2584,6 +2590,7 @@ static virDriver umlDriver = {
     .domainEventRegisterAny = umlDomainEventRegisterAny, /* 0.9.4 */
     .domainEventDeregisterAny = umlDomainEventDeregisterAny, /* 0.9.4 */
     .domainOpenConsole = umlDomainOpenConsole, /* 0.8.6 */
+    .isAlive = umlIsAlive, /* 0.9.7 */
 };
 
 static int
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index bc19b63..9f54c18 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1070,6 +1070,11 @@ static int vboxIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) {
     return 0;
 }
 
+static int vboxIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
 static int vboxGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED) {
     VBOX_OBJECT_CHECK(conn, int, -1);
     PRUint32 maxCPUCount = 0;
@@ -8976,6 +8981,7 @@ virDriver NAME(Driver) = {
     .domainSnapshotCurrent = vboxDomainSnapshotCurrent, /* 0.8.0 */
     .domainRevertToSnapshot = vboxDomainRevertToSnapshot, /* 0.8.0 */
     .domainSnapshotDelete = vboxDomainSnapshotDelete, /* 0.8.0 */
+    .isAlive = vboxIsAlive, /* 0.9.7 */
 };
 
 virNetworkDriver NAME(NetworkDriver) = {
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index b2cfdce..987a7a8 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -958,6 +958,12 @@ vmwareDomainGetState(virDomainPtr dom,
     return ret;
 }
 
+static int
+vmwareIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
 static virDriver vmwareDriver = {
     .no = VIR_DRV_VMWARE,
     .name = "VMWARE",
@@ -990,6 +996,7 @@ static virDriver vmwareDriver = {
     .domainUndefineFlags = vmwareDomainUndefineFlags, /* 0.9.4 */
     .domainIsActive = vmwareDomainIsActive, /* 0.8.7 */
     .domainIsPersistent = vmwareDomainIsPersistent, /* 0.8.7 */
+    .isAlive = vmwareIsAlive, /* 0.9.7 */
 };
 
 int
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index b3e7782..6f8b981 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -506,6 +506,13 @@ xenUnifiedIsSecure(virConnectPtr conn)
     return ret;
 }
 
+static int
+xenUnifiedIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    /* XenD reconnects for each request */
+    return 1;
+}
+
 int
 xenUnifiedGetMaxVcpus (virConnectPtr conn, const char *type)
 {
@@ -2249,6 +2256,7 @@ static virDriver xenUnifiedDriver = {
     .domainEventRegisterAny = xenUnifiedDomainEventRegisterAny, /* 0.8.0 */
     .domainEventDeregisterAny = xenUnifiedDomainEventDeregisterAny, /* 0.8.0 */
     .domainOpenConsole = xenUnifiedDomainOpenConsole, /* 0.8.6 */
+    .isAlive = xenUnifiedIsAlive, /* 0.9.7 */
 };
 
 /**
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 3946455..b2888d2 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1888,6 +1888,17 @@ xenapiNodeGetCellsFreeMemory (virConnectPtr conn, unsigned long long *freeMems,
     }
 }
 
+static int
+xenapiIsAlive(virConnectPtr conn)
+{
+    struct _xenapiPrivate *priv = conn->privateData;
+
+    if (priv->session && priv->session->ok)
+        return 1;
+    else
+        return 0;
+}
+
 /* The interface which we export upwards to libvirt.c. */
 static virDriver xenapiDriver = {
     .no = VIR_DRV_XENAPI,
@@ -1938,6 +1949,7 @@ static virDriver xenapiDriver = {
     .nodeGetCellsFreeMemory = xenapiNodeGetCellsFreeMemory, /* 0.8.0 */
     .nodeGetFreeMemory = xenapiNodeGetFreeMemory, /* 0.8.0 */
     .domainIsUpdated = xenapiDomainIsUpdated, /* 0.8.6 */
+    .isAlive = xenapiIsAlive, /* 0.9.7 */
 };
 
 /**
-- 
1.7.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]