mirror of
https://github.com/libvirt/libvirt.git
synced 2026-09-03 20:53:04 -05:00
qemu: agent: Make setting of vcpus more robust
Documentation for the "guest-set-vcpus" command describes a proper algorithm how to set vcpus. This patch makes the following changes: - state of cpus that has not changed is not updated - if the command was partially successful the command is re-tried with the rest of the arguments to get a proper error message - code is more robust against malicious guest agent - fix testsuite to the new semantics
This commit is contained in:
+20
-26
@@ -517,17 +517,15 @@ static const char testQemuAgentCPUResponse[] =
|
||||
"}";
|
||||
|
||||
static const char testQemuAgentCPUArguments1[] =
|
||||
"[{\"logical-id\":0,\"online\":true},"
|
||||
"{\"logical-id\":1,\"online\":false},"
|
||||
"{\"logical-id\":2,\"online\":true},"
|
||||
"{\"logical-id\":3,\"online\":false}]";
|
||||
"[{\"logical-id\":1,\"online\":false}]";
|
||||
|
||||
static const char testQemuAgentCPUArguments2[] =
|
||||
"[{\"logical-id\":0,\"online\":true},"
|
||||
"{\"logical-id\":1,\"online\":true},"
|
||||
"{\"logical-id\":2,\"online\":true},"
|
||||
"[{\"logical-id\":1,\"online\":true},"
|
||||
"{\"logical-id\":3,\"online\":true}]";
|
||||
|
||||
static const char testQemuAgentCPUArguments3[] =
|
||||
"[{\"logical-id\":3,\"online\":true}]";
|
||||
|
||||
static int
|
||||
testQemuAgentCPU(const void *data)
|
||||
{
|
||||
@@ -566,44 +564,40 @@ testQemuAgentCPU(const void *data)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddItemParams(test, "guest-set-vcpus",
|
||||
"{ \"return\" : 4 }",
|
||||
"{ \"return\" : 1 }",
|
||||
"vcpus", testQemuAgentCPUArguments1,
|
||||
NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if ((nvcpus = qemuAgentSetVCPUs(qemuMonitorTestGetAgent(test),
|
||||
cpuinfo, nvcpus)) < 0)
|
||||
if (qemuAgentSetVCPUs(qemuMonitorTestGetAgent(test), cpuinfo, nvcpus) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (nvcpus != 4) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Expected '4' cpus updated , got '%d'", nvcpus);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* try to hotplug two */
|
||||
/* try to hotplug two, second one will fail*/
|
||||
if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddItemParams(test, "guest-set-vcpus",
|
||||
"{ \"return\" : 4 }",
|
||||
"{ \"return\" : 1 }",
|
||||
"vcpus", testQemuAgentCPUArguments2,
|
||||
NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddItemParams(test, "guest-set-vcpus",
|
||||
"{ \"error\" : \"random error\" }",
|
||||
"vcpus", testQemuAgentCPUArguments3,
|
||||
NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuAgentUpdateCPUInfo(4, cpuinfo, nvcpus) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if ((nvcpus = qemuAgentSetVCPUs(qemuMonitorTestGetAgent(test),
|
||||
cpuinfo, nvcpus)) < 0)
|
||||
/* this should fail */
|
||||
if (qemuAgentSetVCPUs(qemuMonitorTestGetAgent(test), cpuinfo, nvcpus) != -1)
|
||||
goto cleanup;
|
||||
|
||||
if (nvcpus != 4) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Expected '4' cpus updated , got '%d'", nvcpus);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
|
||||
Reference in New Issue
Block a user