提交 5e5019bf 编写于 作者: N Nikolay Shirokovskiy 提交者: Michal Privoznik

qemu: agent: skip outdated sync replies

When we wait for sync reply we can receive delayed
reply to syncs or commands that were sent erlier. We can
safely skip them until we receive sync reply with correct id.
There is no much sense report this situation to client.
Actually with a bit of "luck" if we involve client into
this the play can go on forever: send sync 0, receive
sync reply -1, send sync 1, receive reply 0 ...
上级 832d48d7
......@@ -83,6 +83,8 @@ struct _qemuAgentMessage {
bool finished;
/* true for sync command */
bool sync;
/* id of the issued sync comand */
unsigned long long id;
};
......@@ -337,6 +339,24 @@ qemuAgentIOProcessLine(qemuAgentPtr mon,
} else if (virJSONValueObjectHasKey(obj, "error") == 1 ||
virJSONValueObjectHasKey(obj, "return") == 1) {
if (msg) {
if (msg->sync) {
unsigned long long id;
if (virJSONValueObjectGetNumberUlong(obj, "return", &id) < 0) {
VIR_DEBUG("Ignoring delayed reply on sync");
ret = 0;
goto cleanup;
}
VIR_DEBUG("Guest returned ID: %llu", id);
if (msg->id != id) {
VIR_DEBUG("Guest agent returned ID: %llu instead of %llu",
id, msg->id);
ret = 0;
goto cleanup;
}
}
msg->rxObject = obj;
msg->finished = 1;
obj = NULL;
......@@ -935,7 +955,7 @@ qemuAgentGuestSync(qemuAgentPtr mon)
{
int ret = -1;
int send_ret;
unsigned long long id, id_ret;
unsigned long long id;
qemuAgentMessage sync_msg;
memset(&sync_msg, 0, sizeof(sync_msg));
......@@ -950,6 +970,7 @@ qemuAgentGuestSync(qemuAgentPtr mon)
sync_msg.txLength = strlen(sync_msg.txBuffer);
sync_msg.sync = true;
sync_msg.id = id;
VIR_DEBUG("Sending guest-sync command with ID: %llu", id);
......@@ -967,20 +988,6 @@ qemuAgentGuestSync(qemuAgentPtr mon)
goto cleanup;
}
if (virJSONValueObjectGetNumberUlong(sync_msg.rxObject,
"return", &id_ret) < 0) {
virReportError(VIR_ERR_AGENT_UNSYNCED, "%s",
_("Malformed return value"));
goto cleanup;
}
VIR_DEBUG("Guest returned ID: %llu", id_ret);
if (id_ret != id) {
virReportError(VIR_ERR_AGENT_UNSYNCED,
_("Guest agent returned ID: %llu instead of %llu"),
id_ret, id);
goto cleanup;
}
ret = 0;
cleanup:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册