]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: agent: skip outdated sync replies
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Fri, 16 Sep 2016 10:35:34 +0000 (13:35 +0300)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 20 Sep 2016 14:27:58 +0000 (16:27 +0200)
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 ...

src/qemu/qemu_agent.c

index 16aa629e553c3c72751926855aeaed9bb1271fc7..a8560124508eac25dd681869cd383da9bb28ef38 100644 (file)
@@ -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: