mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-24 04:12:20 +00:00
rpc: Refactor keepalive timer code
The code that needs to be run every keepalive interval of inactivity was only called from a timer and thus from the main event loop. We will need to call the code directly from another place. (cherry picked from commit a2ba8686325c8ba61c95f3f1152ef4420a029c15)
This commit is contained in:
parent
419cb87283
commit
2c5b4c5621
@ -152,51 +152,64 @@ virKeepAliveScheduleResponse(virKeepAlivePtr ka)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
|
virKeepAliveTimerInternal(virKeepAlivePtr ka,
|
||||||
|
virNetMessagePtr *msg)
|
||||||
{
|
{
|
||||||
virKeepAlivePtr ka = opaque;
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
virKeepAliveLock(ka);
|
if (now - ka->lastPacketReceived < ka->interval - 1) {
|
||||||
|
int timeout = ka->interval - (now - ka->lastPacketReceived);
|
||||||
|
virEventUpdateTimeout(ka->timer, timeout * 1000);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
PROBE(RPC_KEEPALIVE_TIMEOUT,
|
PROBE(RPC_KEEPALIVE_TIMEOUT,
|
||||||
"ka=%p client=%p countToDeath=%d idle=%d",
|
"ka=%p client=%p countToDeath=%d idle=%d",
|
||||||
ka, ka->client, ka->countToDeath,
|
ka, ka->client, ka->countToDeath,
|
||||||
(int) (now - ka->lastPacketReceived));
|
(int) (now - ka->lastPacketReceived));
|
||||||
|
|
||||||
if (now - ka->lastPacketReceived < ka->interval - 1) {
|
|
||||||
int timeout = ka->interval - (now - ka->lastPacketReceived);
|
|
||||||
virEventUpdateTimeout(ka->timer, timeout * 1000);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ka->countToDeath == 0) {
|
if (ka->countToDeath == 0) {
|
||||||
virKeepAliveDeadFunc deadCB = ka->deadCB;
|
|
||||||
void *client = ka->client;
|
|
||||||
|
|
||||||
VIR_WARN("No response from client %p after %d keepalive messages in"
|
VIR_WARN("No response from client %p after %d keepalive messages in"
|
||||||
" %d seconds",
|
" %d seconds",
|
||||||
ka->client,
|
ka->client,
|
||||||
ka->count,
|
ka->count,
|
||||||
(int) (now - ka->lastPacketReceived));
|
(int) (now - ka->lastPacketReceived));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
ka->countToDeath--;
|
||||||
|
*msg = virKeepAliveMessage(KEEPALIVE_PROC_PING);
|
||||||
|
virEventUpdateTimeout(ka->timer, ka->interval * 1000);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
|
||||||
|
{
|
||||||
|
virKeepAlivePtr ka = opaque;
|
||||||
|
virNetMessagePtr msg = NULL;
|
||||||
|
bool dead;
|
||||||
|
|
||||||
|
virKeepAliveLock(ka);
|
||||||
|
|
||||||
|
dead = virKeepAliveTimerInternal(ka, &msg);
|
||||||
|
|
||||||
|
if (dead) {
|
||||||
|
virKeepAliveDeadFunc deadCB = ka->deadCB;
|
||||||
|
void *client = ka->client;
|
||||||
|
|
||||||
ka->refs++;
|
ka->refs++;
|
||||||
virKeepAliveUnlock(ka);
|
virKeepAliveUnlock(ka);
|
||||||
deadCB(client);
|
deadCB(client);
|
||||||
virKeepAliveLock(ka);
|
virKeepAliveLock(ka);
|
||||||
ka->refs--;
|
ka->refs--;
|
||||||
} else {
|
} else if (msg) {
|
||||||
virNetMessagePtr msg;
|
virKeepAliveSend(ka, msg);
|
||||||
|
|
||||||
ka->countToDeath--;
|
|
||||||
if (!(msg = virKeepAliveMessage(KEEPALIVE_PROC_PING)))
|
|
||||||
VIR_WARN("Failed to generate keepalive request");
|
|
||||||
else
|
|
||||||
virKeepAliveSend(ka, msg);
|
|
||||||
virEventUpdateTimeout(ka->timer, ka->interval * 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virKeepAliveUnlock(ka);
|
virKeepAliveUnlock(ka);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user