mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu: blockstats: Refactor qemuDomainBlockStatsFlags
Now that qemuDomainBlocksStatsGather provides functions of both qemuMonitorGetBlockStatsParamsNumber and qemuMonitorGetBlockStatsInfo we can reuse it and kill a lot of code. Additionally as a bonus qemuDomainBlockStatsFlags will now support summary statistics so add a statement to the virsh man page about that. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1142636
This commit is contained in:
parent
cf093414c5
commit
e045587dda
@ -10637,22 +10637,15 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virQEMUDriverPtr driver = dom->conn->privateData;
|
virQEMUDriverPtr driver = dom->conn->privateData;
|
||||||
int idx;
|
|
||||||
int tmp, ret = -1;
|
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
qemuDomainObjPrivatePtr priv;
|
qemuBlockStatsPtr blockstats = NULL;
|
||||||
long long rd_req, rd_bytes, wr_req, wr_bytes, rd_total_times;
|
int nstats;
|
||||||
long long wr_total_times, flush_req, flush_total_times;
|
int ret = -1;
|
||||||
char *diskAlias = NULL;
|
|
||||||
|
VIR_DEBUG("params=%p, flags=%x", params, flags);
|
||||||
|
|
||||||
virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1);
|
virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1);
|
||||||
|
|
||||||
if (!*path) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
||||||
_("summary statistics are not supported yet"));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We don't return strings, and thus trivially support this flag. */
|
/* We don't return strings, and thus trivially support this flag. */
|
||||||
flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
|
flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
|
||||||
|
|
||||||
@ -10671,63 +10664,25 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*nparams != 0) {
|
if ((nstats = qemuDomainBlocksStatsGather(driver, vm, path,
|
||||||
virDomainDiskDefPtr disk = NULL;
|
&blockstats)) < 0)
|
||||||
if ((idx = virDomainDiskIndexByName(vm->def, path, false)) < 0) {
|
goto endjob;
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("invalid path: %s"), path);
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
disk = vm->def->disks[idx];
|
|
||||||
|
|
||||||
if (!disk->info.alias) {
|
/* return count of supported stats */
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
if (*nparams == 0) {
|
||||||
_("missing disk device alias name for %s"),
|
*nparams = nstats;
|
||||||
disk->dst);
|
ret = 0;
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
if (VIR_STRDUP(diskAlias, disk->info.alias) < 0)
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv = vm->privateData;
|
|
||||||
VIR_DEBUG("priv=%p, params=%p, flags=%x", priv, params, flags);
|
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
|
||||||
tmp = *nparams;
|
|
||||||
ret = qemuMonitorGetBlockStatsParamsNumber(priv->mon, nparams);
|
|
||||||
|
|
||||||
if (tmp == 0 || ret < 0) {
|
|
||||||
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemuMonitorGetBlockStatsInfo(priv->mon,
|
nstats = 0;
|
||||||
diskAlias,
|
|
||||||
&rd_req,
|
|
||||||
&rd_bytes,
|
|
||||||
&rd_total_times,
|
|
||||||
&wr_req,
|
|
||||||
&wr_bytes,
|
|
||||||
&wr_total_times,
|
|
||||||
&flush_req,
|
|
||||||
&flush_total_times);
|
|
||||||
|
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
|
||||||
ret = -1;
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
tmp = 0;
|
|
||||||
ret = -1;
|
|
||||||
|
|
||||||
#define QEMU_BLOCK_STATS_ASSIGN_PARAM(VAR, NAME) \
|
#define QEMU_BLOCK_STATS_ASSIGN_PARAM(VAR, NAME) \
|
||||||
if (tmp < *nparams && (VAR) != -1) { \
|
if (nstats < *nparams && (blockstats->VAR) != -1) { \
|
||||||
if (virTypedParameterAssign(params + tmp, NAME, VIR_TYPED_PARAM_LLONG,\
|
if (virTypedParameterAssign(params + nstats, NAME, \
|
||||||
(VAR)) < 0) \
|
VIR_TYPED_PARAM_LLONG, (blockstats->VAR)) < 0) \
|
||||||
goto endjob; \
|
goto endjob; \
|
||||||
tmp++; \
|
nstats++; \
|
||||||
}
|
}
|
||||||
|
|
||||||
QEMU_BLOCK_STATS_ASSIGN_PARAM(wr_bytes, VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES);
|
QEMU_BLOCK_STATS_ASSIGN_PARAM(wr_bytes, VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES);
|
||||||
@ -10747,13 +10702,13 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
|
|||||||
#undef QEMU_BLOCK_STATS_ASSIGN_PARAM
|
#undef QEMU_BLOCK_STATS_ASSIGN_PARAM
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
*nparams = tmp;
|
*nparams = nstats;
|
||||||
|
|
||||||
endjob:
|
endjob:
|
||||||
qemuDomainObjEndJob(driver, vm);
|
qemuDomainObjEndJob(driver, vm);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(diskAlias);
|
VIR_FREE(blockstats);
|
||||||
qemuDomObjEndAPI(&vm);
|
qemuDomObjEndAPI(&vm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -709,8 +709,9 @@ return an error instead.
|
|||||||
Get device block stats for a running domain. A I<block-device> corresponds
|
Get device block stats for a running domain. A I<block-device> corresponds
|
||||||
to a unique target name (<target dev='name'/>) or source file (<source
|
to a unique target name (<target dev='name'/>) or source file (<source
|
||||||
file='name'/>) for one of the disk devices attached to I<domain> (see
|
file='name'/>) for one of the disk devices attached to I<domain> (see
|
||||||
also B<domblklist> for listing these names). On a lxc domain, omitting the
|
also B<domblklist> for listing these names). On a lxc or qemu domain,
|
||||||
I<block-device> yields device block stats summarily for the entire domain.
|
omitting the I<block-device> yields device block stats summarily for the
|
||||||
|
entire domain.
|
||||||
|
|
||||||
Use I<--human> for a more human readable output.
|
Use I<--human> for a more human readable output.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user