]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
keepalive: Add ability to disable keepalive messages
authorPeter Krempa <pkrempa@redhat.com>
Tue, 24 Apr 2012 14:38:41 +0000 (16:38 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 26 Apr 2012 09:35:34 +0000 (11:35 +0200)
The docs for virConnectSetKeepAlive() advertise that this function
should be able to disable keepalives on negative or zero interval time.

This patch removes the check that prohibited this and adds code to
disable keepalives on negative/zero interval.

* src/libvirt.c: virConnectSetKeepAlive(): - remove check for negative
                                             values
* src/rpc/virnetclient.c
* src/rpc/virnetclient.h: - add virNetClientKeepAliveStop() to disable
                            keepalive messages
* src/remote/remote_driver.c: remoteSetKeepAlive(): -add ability to
                                                     disable keepalives

src/libvirt.c
src/probes.d
src/remote/remote_driver.c
src/rpc/virkeepalive.c
src/rpc/virkeepalive.h
src/rpc/virnetclient.c
src/rpc/virnetclient.h

index af42d3b736438cabbc3d96e464f22cfa0201e488..b01ebbaa7b87be28c33817fb23c03a2347d86237 100644 (file)
@@ -18433,6 +18433,10 @@ error:
  * messages.  Failure to do so may result in connections being closed
  * unexpectedly.
  *
+ * Note: This API function controls only keepalive messages sent by the client.
+ * If the server is configured to use keepalive you still need to run the event
+ * loop to respond to them, even if you disable keepalives by this function.
+ *
  * Returns -1 on error, 0 on success, 1 when remote party doesn't support
  * keepalive messages.
  */
@@ -18452,12 +18456,6 @@ int virConnectSetKeepAlive(virConnectPtr conn,
         return -1;
     }
 
-    if (interval <= 0) {
-        virLibConnError(VIR_ERR_INVALID_ARG,
-                        _("negative or zero interval make no sense"));
-        goto error;
-    }
-
     if (conn->driver->setKeepAlive) {
         ret = conn->driver->setKeepAlive(conn, interval, count);
         if (ret < 0)
index 9d70cc9726892b2ef02895ed777ac4214dcdfc43..e56dc3e2648ffa63c0d5566df495b01b957b961a 100644 (file)
@@ -78,7 +78,7 @@ provider libvirt {
        probe rpc_keepalive_ref(void *ka, void *client, int refs);
        probe rpc_keepalive_free(void *ka, void *client, int refs);
        probe rpc_keepalive_start(void *ka, void *client, int interval, int count);
-       probe rpc_keepalive_stop(void *ka, void *client);
+       probe rpc_keepalive_stop(void *ka, void *client, bool all);
        probe rpc_keepalive_send(void *ka, void *client, int prog, int vers, int proc);
        probe rpc_keepalive_received(void *ka, void *client, int prog, int vers, int proc);
        probe rpc_keepalive_timeout(void *ka, void *client, int coundToDeath, int idle);
index af463844418c06154e562cdef8a5d6ab5482e85e..7863b73e39dc81c486247d66d0f42b9d918032aa 100644 (file)
@@ -4631,7 +4631,12 @@ remoteSetKeepAlive(virConnectPtr conn, int interval, unsigned int count)
         goto cleanup;
     }
 
-    ret = virNetClientKeepAliveStart(priv->client, interval, count);
+    if (interval > 0) {
+        ret = virNetClientKeepAliveStart(priv->client, interval, count);
+    } else {
+        virNetClientKeepAliveStop(priv->client);
+        ret = 0;
+    }
 
 cleanup:
     remoteDriverUnlock(priv);
index 06b8e632cefc4ff84daedd9269c24f05cadd6217..a5c2b1aadaa3cda8969899f0ba47979fa9517cde 100644 (file)
@@ -372,32 +372,48 @@ cleanup:
 }
 
 
-void
-virKeepAliveStop(virKeepAlivePtr ka)
+static void
+virKeepAliveStopInternal(virKeepAlivePtr ka, bool all)
 {
     virKeepAliveLock(ka);
 
     PROBE(RPC_KEEPALIVE_STOP,
-          "ka=%p client=%p",
-          ka, ka->client);
+          "ka=%p client=%p all=%d",
+          ka, ka->client, all);
 
     if (ka->timer > 0) {
         virEventRemoveTimeout(ka->timer);
         ka->timer = -1;
     }
 
-    if (ka->responseTimer > 0) {
-        virEventRemoveTimeout(ka->responseTimer);
-        ka->responseTimer = -1;
-    }
+    if (all) {
+        if (ka->responseTimer > 0) {
+            virEventRemoveTimeout(ka->responseTimer);
+            ka->responseTimer = -1;
+        }
 
-    virNetMessageFree(ka->response);
-    ka->response = NULL;
+        virNetMessageFree(ka->response);
+        ka->response = NULL;
+    }
 
     virKeepAliveUnlock(ka);
 }
 
 
+void
+virKeepAliveStop(virKeepAlivePtr ka)
+{
+    virKeepAliveStopInternal(ka, true);
+}
+
+
+void
+virKeepAliveStopSending(virKeepAlivePtr ka)
+{
+    virKeepAliveStopInternal(ka, false);
+}
+
+
 bool
 virKeepAliveCheckMessage(virKeepAlivePtr ka,
                          virNetMessagePtr msg)
index f1654eb25a7a74ccccbcaedac15925c1036f019d..af9e7222972414e29fa4e9575564097a5e356f78 100644 (file)
@@ -49,6 +49,7 @@ int virKeepAliveStart(virKeepAlivePtr ka,
                       int interval,
                       unsigned int count);
 void virKeepAliveStop(virKeepAlivePtr ka);
+void virKeepAliveStopSending(virKeepAlivePtr ka);
 
 bool virKeepAliveCheckMessage(virKeepAlivePtr ka,
                               virNetMessagePtr msg);
index 33b770146a02ea50181844461880ad28fc630db6..d88288d92012e9f84876af90e43ae082d57a5169 100644 (file)
@@ -248,6 +248,14 @@ virNetClientKeepAliveStart(virNetClientPtr client,
     return ret;
 }
 
+void
+virNetClientKeepAliveStop(virNetClientPtr client)
+{
+    virNetClientLock(client);
+    virKeepAliveStopSending(client->keepalive);
+    virNetClientUnlock(client);
+}
+
 static void
 virNetClientKeepAliveDeadCB(void *opaque)
 {
index 7c30d2bac3b7b59acff829cb2c0a9b3fa1d44582..13b4f96ccdad8a00c1836fec5173a6d77273b5d9 100644 (file)
@@ -104,4 +104,6 @@ int virNetClientKeepAliveStart(virNetClientPtr client,
                                int interval,
                                unsigned int count);
 
+void virNetClientKeepAliveStop(virNetClientPtr client);
+
 #endif /* __VIR_NET_CLIENT_H__ */