Skip to content

Commit 9c4ab0c

Browse files
roumingeriknordmark
authored andcommitted
pillar/qmp: return a proper error if response on "query-status" can't be parsed
The 'query-status' QMP request is a special one: if status can't be parsed - QEMU is stopped by EVE ('quit' is sent over QMP). There are many customer complains on sudden QEMU stops with only a few lines in the log, e.g.: "domain c54579e8-f67e-43fa-ae44-8e03584606c2.1.2 reported to be in unexpected state " "one of the c54579e8-f67e-43fa-ae44-8e03584606c2 tasks has crashed (domain c54579e8-f67e-43fa-ae44-8e03584606c2.1.2 reported to be in unexpected state )" "qmpEventHandler: Received event: SHUTDOWN event details: map[guest:false reason:host-qmp-quit]. Calling quit on socket: /run/hypervisor/kvm/c54579e8-f67e-43fa-ae44-8e03584606c2.1.2/qmp" Which indicates that `getQemuStatus()` routine returns a "" (empty) string. (according to the code the actual returned state is printed: "domain %s reported to be in unexpected state %s", domainName, res) The `getQemuStatus()` can return a "" (empty string) and no error only in one case: when received JSON does not match the expected structure. This commit disallows unknown JSON fields, so that a returned string should match exactly the structure. This does not fix the error or sudden stop, but rather makes an error explicit, so instead of: "domain c54579e8-f67e-43fa-ae44-8e03584606c2.1.2 reported to be in unexpected state " the following error may appear: "couldn't retrieve status for domain c54579e8-f67e-43fa-ae44-8e03584606c2.1.2: json: unknown field "error"; (the bytes received: '{"error": {"class": "CommandNotFound", "desc": "Expecting capabilities negotiation with 'qmp_capabilities'"}} ')" which explicitly indicates the expecting capabilities negotiations. (the error is made up and does not reflect the real problem!) Again. This does not fix a problem, rather exposes it with a clear error message, so QEMU will be stopped by the domainmgr, but I hope clear error help to fix a real problem. Signed-off-by: Roman Penyaev <[email protected]>
1 parent b5f070b commit 9c4ab0c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/pillar/hypervisor/qmp.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hypervisor
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"fmt"
@@ -91,7 +92,14 @@ func getQemuStatus(socket string) (string, error) {
9192
Status string `json:"status"`
9293
} `json:"return"`
9394
}
94-
err = json.Unmarshal(raw, &result)
95+
dec := json.NewDecoder(bytes.NewReader(raw))
96+
dec.DisallowUnknownFields()
97+
err = dec.Decode(&result)
98+
if err != nil {
99+
err = fmt.Errorf("%v; (JSON received: '%s')", err, raw)
100+
} else if result.Return.Status == "" {
101+
err = fmt.Errorf("'status' is empty; (JSON received: '%s')", raw)
102+
}
95103
return result.Return.Status, err
96104
} else {
97105
return "", err

0 commit comments

Comments
 (0)