[libvirt] [PATCH] keepalive: Add ability to disable keepalive messages

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 | 6 ------ src/remote/remote_driver.c | 7 ++++++- src/rpc/virnetclient.c | 8 ++++++++ src/rpc/virnetclient.h | 2 ++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index af42d3b..3f043e1 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -18452,12 +18452,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) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index af46384..7863b73 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -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); diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 33b7701..2629c14 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -248,6 +248,14 @@ virNetClientKeepAliveStart(virNetClientPtr client, return ret; } +void +virNetClientKeepAliveStop(virNetClientPtr client) +{ + virNetClientLock(client); + virKeepAliveStop(client->keepalive); + virNetClientUnlock(client); +} + static void virNetClientKeepAliveDeadCB(void *opaque) { diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h index 7c30d2b..13b4f96 100644 --- a/src/rpc/virnetclient.h +++ b/src/rpc/virnetclient.h @@ -104,4 +104,6 @@ int virNetClientKeepAliveStart(virNetClientPtr client, int interval, unsigned int count); +void virNetClientKeepAliveStop(virNetClientPtr client); + #endif /* __VIR_NET_CLIENT_H__ */ -- 1.7.3.4

On Tue, Apr 24, 2012 at 16:56:37 +0200, Peter Krempa wrote:
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.
OK, makes sense, if the client wants to change keepalive settings in runtime. That is, it can dynamically start/stop sending keepalive requests to the server.
* 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 | 6 ------ src/remote/remote_driver.c | 7 ++++++- src/rpc/virnetclient.c | 8 ++++++++ src/rpc/virnetclient.h | 2 ++ 4 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c index af42d3b..3f043e1 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -18452,12 +18452,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) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index af46384..7863b73 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -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; + }
This is not exactly what you want to do here. virKeepAliveStop (which is what virNetClientKeepAliveStop ends up calling) was meant to be called only when a connection is getting closed and thus it does more than we need. In addition to disabling the timer which sends keepalive requests to the server, virKeepAliveStop disables even the response timer, which means no keepalive response will be sent anymore. As a result of it, the server will just automatically close the connection sooner or later. Jirka
participants (2)
-
Jiri Denemark
-
Peter Krempa