mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
migration/dirtyrate: Implement qemuMonitorQueryDirtyRate
Implement qemuMonitorQueryDirtyRate which query domain's memory dirty rate calling qmp "query-dirty-rate". Signed-off-by: Hao Wang <wanghao232@huawei.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
a0c7f61f37
commit
4ae60b1caf
@ -4754,3 +4754,15 @@ qemuMonitorStartDirtyRateCalc(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
return qemuMonitorJSONStartDirtyRateCalc(mon, seconds);
|
return qemuMonitorJSONStartDirtyRateCalc(mon, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
qemuMonitorQueryDirtyRate(qemuMonitorPtr mon,
|
||||||
|
qemuMonitorDirtyRateInfoPtr info)
|
||||||
|
{
|
||||||
|
VIR_DEBUG("info=%p", info);
|
||||||
|
|
||||||
|
QEMU_CHECK_MONITOR(mon);
|
||||||
|
|
||||||
|
return qemuMonitorJSONQueryDirtyRate(mon, info);
|
||||||
|
}
|
||||||
|
@ -1530,3 +1530,18 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions,
|
|||||||
int
|
int
|
||||||
qemuMonitorStartDirtyRateCalc(qemuMonitorPtr mon,
|
qemuMonitorStartDirtyRateCalc(qemuMonitorPtr mon,
|
||||||
int seconds);
|
int seconds);
|
||||||
|
|
||||||
|
typedef struct _qemuMonitorDirtyRateInfo qemuMonitorDirtyRateInfo;
|
||||||
|
typedef qemuMonitorDirtyRateInfo *qemuMonitorDirtyRateInfoPtr;
|
||||||
|
|
||||||
|
struct _qemuMonitorDirtyRateInfo {
|
||||||
|
int status; /* the status of last dirtyrate calculation,
|
||||||
|
one of virDomainDirtyRateStatus */
|
||||||
|
int calcTime; /* the period of dirtyrate calculation */
|
||||||
|
long long startTime; /* the start time of dirtyrate calculation */
|
||||||
|
long long dirtyRate; /* the dirtyrate in MiB/s */
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
qemuMonitorQueryDirtyRate(qemuMonitorPtr mon,
|
||||||
|
qemuMonitorDirtyRateInfoPtr info);
|
||||||
|
@ -9502,3 +9502,82 @@ qemuMonitorJSONStartDirtyRateCalc(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VIR_ENUM_DECL(qemuMonitorDirtyRateStatus);
|
||||||
|
VIR_ENUM_IMPL(qemuMonitorDirtyRateStatus,
|
||||||
|
VIR_DOMAIN_DIRTYRATE_LAST,
|
||||||
|
"unstarted",
|
||||||
|
"measuring",
|
||||||
|
"measured");
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuMonitorJSONExtractDirtyRateInfo(virJSONValuePtr data,
|
||||||
|
qemuMonitorDirtyRateInfoPtr info)
|
||||||
|
{
|
||||||
|
const char *statusstr;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if (!(statusstr = virJSONValueObjectGetString(data, "status"))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("query-dirty-rate reply was missing 'status' data"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status = qemuMonitorDirtyRateStatusTypeFromString(statusstr)) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Unknown dirty rate status: %s"), statusstr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
info->status = status;
|
||||||
|
|
||||||
|
/* `query-dirty-rate` replies `dirty-rate` data only if the status of the latest
|
||||||
|
* calculation is `measured`.
|
||||||
|
*/
|
||||||
|
if ((info->status == VIR_DOMAIN_DIRTYRATE_MEASURED) &&
|
||||||
|
(virJSONValueObjectGetNumberLong(data, "dirty-rate", &info->dirtyRate) < 0)) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("query-dirty-rate reply was missing 'dirty-rate' data"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virJSONValueObjectGetNumberLong(data, "start-time", &info->startTime) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("query-dirty-rate reply was missing 'start-time' data"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virJSONValueObjectGetNumberInt(data, "calc-time", &info->calcTime) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("query-dirty-rate reply was missing 'calc-time' data"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
qemuMonitorJSONQueryDirtyRate(qemuMonitorPtr mon,
|
||||||
|
qemuMonitorDirtyRateInfoPtr info)
|
||||||
|
{
|
||||||
|
g_autoptr(virJSONValue) cmd = NULL;
|
||||||
|
g_autoptr(virJSONValue) reply = NULL;
|
||||||
|
virJSONValuePtr data = NULL;
|
||||||
|
|
||||||
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-dirty-rate", NULL)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("query-dirty-rate reply was missing 'return' data"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return qemuMonitorJSONExtractDirtyRateInfo(data, info);
|
||||||
|
}
|
||||||
|
@ -715,3 +715,7 @@ qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon,
|
|||||||
int
|
int
|
||||||
qemuMonitorJSONStartDirtyRateCalc(qemuMonitorPtr mon,
|
qemuMonitorJSONStartDirtyRateCalc(qemuMonitorPtr mon,
|
||||||
int seconds);
|
int seconds);
|
||||||
|
|
||||||
|
int
|
||||||
|
qemuMonitorJSONQueryDirtyRate(qemuMonitorPtr mon,
|
||||||
|
qemuMonitorDirtyRateInfoPtr info);
|
||||||
|
Loading…
Reference in New Issue
Block a user