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
(cherry picked from commit
6446a9e20cc65561ce6061742baf35a3a63d5ba1)
* 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.
*/
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)
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);
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);
}
-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)
int interval,
unsigned int count);
void virKeepAliveStop(virKeepAlivePtr ka);
+void virKeepAliveStopSending(virKeepAlivePtr ka);
bool virKeepAliveCheckMessage(virKeepAlivePtr ka,
virNetMessagePtr msg);
return ret;
}
+void
+virNetClientKeepAliveStop(virNetClientPtr client)
+{
+ virNetClientLock(client);
+ virKeepAliveStopSending(client->keepalive);
+ virNetClientUnlock(client);
+}
+
static void
virNetClientKeepAliveDeadCB(void *opaque)
{
int interval,
unsigned int count);
+void virNetClientKeepAliveStop(virNetClientPtr client);
+
#endif /* __VIR_NET_CLIENT_H__ */