提交 c6f4acc4 编写于 作者: P Peter Krempa

qemu: implement qemuDomainSetBlockThreshold

Add code to call the appropriate monitor command and code to lookup the
given disk backing chain member.
上级 9b93c4c2
...@@ -20312,6 +20312,75 @@ qemuDomainSetVcpu(virDomainPtr dom, ...@@ -20312,6 +20312,75 @@ qemuDomainSetVcpu(virDomainPtr dom,
} }
static int
qemuDomainSetBlockThreshold(virDomainPtr dom,
const char *dev,
unsigned long long threshold,
unsigned int flags)
{
virQEMUDriverPtr driver = dom->conn->privateData;
qemuDomainObjPrivatePtr priv;
virDomainObjPtr vm = NULL;
virStorageSourcePtr src;
char *nodename = NULL;
int rc;
int ret = -1;
virCheckFlags(0, -1);
if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup;
priv = vm->privateData;
if (virDomainSetBlockThresholdEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("domain is not running"));
goto endjob;
}
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCK_WRITE_THRESHOLD)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("this qemu does not support setting device threshold"));
goto endjob;
}
if (!(src = qemuDomainGetStorageSourceByDevstr(dev, vm->def)))
goto endjob;
if (!src->nodebacking) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("threshold currently can't be set for block device '%s'"),
dev);
goto endjob;
}
if (VIR_STRDUP(nodename, src->nodebacking) < 0)
goto endjob;
qemuDomainObjEnterMonitor(driver, vm);
rc = qemuMonitorSetBlockThreshold(priv->mon, nodename, threshold);
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
goto endjob;
ret = 0;
endjob:
qemuDomainObjEndJob(driver, vm);
cleanup:
VIR_FREE(nodename);
virDomainObjEndAPI(&vm);
return ret;
}
static virHypervisorDriver qemuHypervisorDriver = { static virHypervisorDriver qemuHypervisorDriver = {
.name = QEMU_DRIVER_NAME, .name = QEMU_DRIVER_NAME,
.connectOpen = qemuConnectOpen, /* 0.2.0 */ .connectOpen = qemuConnectOpen, /* 0.2.0 */
...@@ -20526,6 +20595,7 @@ static virHypervisorDriver qemuHypervisorDriver = { ...@@ -20526,6 +20595,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
.domainGetGuestVcpus = qemuDomainGetGuestVcpus, /* 2.0.0 */ .domainGetGuestVcpus = qemuDomainGetGuestVcpus, /* 2.0.0 */
.domainSetGuestVcpus = qemuDomainSetGuestVcpus, /* 2.0.0 */ .domainSetGuestVcpus = qemuDomainSetGuestVcpus, /* 2.0.0 */
.domainSetVcpu = qemuDomainSetVcpu, /* 3.1.0 */ .domainSetVcpu = qemuDomainSetVcpu, /* 3.1.0 */
.domainSetBlockThreshold = qemuDomainSetBlockThreshold /* 3.2.0 */
}; };
......
...@@ -4206,3 +4206,16 @@ qemuMonitorQueryQMPSchema(qemuMonitorPtr mon) ...@@ -4206,3 +4206,16 @@ qemuMonitorQueryQMPSchema(qemuMonitorPtr mon)
return qemuMonitorJSONQueryQMPSchema(mon); return qemuMonitorJSONQueryQMPSchema(mon);
} }
int
qemuMonitorSetBlockThreshold(qemuMonitorPtr mon,
const char *nodename,
unsigned long long threshold)
{
VIR_DEBUG("mon=%p, node='%s', threshold=%llu", mon, nodename, threshold);
QEMU_CHECK_MONITOR_JSON(mon);
return qemuMonitorJSONSetBlockThreshold(mon, nodename, threshold);
}
...@@ -1079,4 +1079,9 @@ int qemuMonitorGetRTCTime(qemuMonitorPtr mon, ...@@ -1079,4 +1079,9 @@ int qemuMonitorGetRTCTime(qemuMonitorPtr mon,
virHashTablePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon); virHashTablePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon);
int qemuMonitorSetBlockThreshold(qemuMonitorPtr mon,
const char *nodename,
unsigned long long threshold);
#endif /* QEMU_MONITOR_H */ #endif /* QEMU_MONITOR_H */
...@@ -7526,3 +7526,34 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) ...@@ -7526,3 +7526,34 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
return ret; return ret;
} }
int
qemuMonitorJSONSetBlockThreshold(qemuMonitorPtr mon,
const char *nodename,
unsigned long long threshold)
{
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
int ret = -1;
if (!(cmd = qemuMonitorJSONMakeCommand("block-set-write-threshold",
"s:node-name", nodename,
"U:write-threshold", threshold,
NULL)))
return -1;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
}
...@@ -512,4 +512,10 @@ int qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon, ...@@ -512,4 +512,10 @@ int qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
virHashTablePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) virHashTablePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
int qemuMonitorJSONSetBlockThreshold(qemuMonitorPtr mon,
const char *nodename,
unsigned long long threshold)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
#endif /* QEMU_MONITOR_JSON_H */ #endif /* QEMU_MONITOR_JSON_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册