All the setters are the same code except for parameter name and variable, so they can be converted to a macro to save a ton of duplicated code. --- src/qemu/qemu_driver.c | 78 +++++++++++--------------------------------------- 1 file changed, 16 insertions(+), 62 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ceceafa..e94275f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10575,7 +10575,6 @@ qemuDomainBlockStatsFlags(virDomainPtr dom, qemuDomainObjPrivatePtr priv; long long rd_req, rd_bytes, wr_req, wr_bytes, rd_total_times; long long wr_total_times, flush_req, flush_total_times, errs; - virTypedParameterPtr param; char *diskAlias = NULL; virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1); @@ -10656,73 +10655,28 @@ qemuDomainBlockStatsFlags(virDomainPtr dom, tmp = 0; ret = -1; - if (tmp < *nparams && wr_bytes != -1) { - param = ¶ms[tmp]; - if (virTypedParameterAssign(param, VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES, - VIR_TYPED_PARAM_LLONG, wr_bytes) < 0) - goto endjob; - tmp++; +/* the following macro shall not be used with side effects statements */ +#define QEMU_BLOCK_STAT(VAR, NAME) \ + if (tmp < *nparams && (VAR) != -1) { \ + if (virTypedParameterAssign(params + tmp, NAME, VIR_TYPED_PARAM_LLONG,\ + (VAR)) < 0) \ + goto endjob; \ + tmp++; \ } - if (tmp < *nparams && wr_req != -1) { - param = ¶ms[tmp]; - if (virTypedParameterAssign(param, VIR_DOMAIN_BLOCK_STATS_WRITE_REQ, - VIR_TYPED_PARAM_LLONG, wr_req) < 0) - goto endjob; - tmp++; - } + QEMU_BLOCK_STAT(wr_bytes, VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES); + QEMU_BLOCK_STAT(wr_req, VIR_DOMAIN_BLOCK_STATS_WRITE_REQ); - if (tmp < *nparams && rd_bytes != -1) { - param = ¶ms[tmp]; - if (virTypedParameterAssign(param, VIR_DOMAIN_BLOCK_STATS_READ_BYTES, - VIR_TYPED_PARAM_LLONG, rd_bytes) < 0) - goto endjob; - tmp++; - } + QEMU_BLOCK_STAT(rd_bytes, VIR_DOMAIN_BLOCK_STATS_READ_BYTES); + QEMU_BLOCK_STAT(rd_req, VIR_DOMAIN_BLOCK_STATS_READ_REQ); - if (tmp < *nparams && rd_req != -1) { - param = ¶ms[tmp]; - if (virTypedParameterAssign(param, VIR_DOMAIN_BLOCK_STATS_READ_REQ, - VIR_TYPED_PARAM_LLONG, rd_req) < 0) - goto endjob; - tmp++; - } + QEMU_BLOCK_STAT(flush_req, VIR_DOMAIN_BLOCK_STATS_FLUSH_REQ); - if (tmp < *nparams && flush_req != -1) { - param = ¶ms[tmp]; - if (virTypedParameterAssign(param, VIR_DOMAIN_BLOCK_STATS_FLUSH_REQ, - VIR_TYPED_PARAM_LLONG, flush_req) < 0) - goto endjob; - tmp++; - } + QEMU_BLOCK_STAT(wr_total_times, VIR_DOMAIN_BLOCK_STATS_WRITE_TOTAL_TIMES); + QEMU_BLOCK_STAT(rd_total_times, VIR_DOMAIN_BLOCK_STATS_READ_TOTAL_TIMES); + QEMU_BLOCK_STAT(flush_total_times, VIR_DOMAIN_BLOCK_STATS_FLUSH_TOTAL_TIMES); - if (tmp < *nparams && wr_total_times != -1) { - param = ¶ms[tmp]; - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLOCK_STATS_WRITE_TOTAL_TIMES, - VIR_TYPED_PARAM_LLONG, wr_total_times) < 0) - goto endjob; - tmp++; - } - - if (tmp < *nparams && rd_total_times != -1) { - param = ¶ms[tmp]; - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLOCK_STATS_READ_TOTAL_TIMES, - VIR_TYPED_PARAM_LLONG, rd_total_times) < 0) - goto endjob; - tmp++; - } - - if (tmp < *nparams && flush_total_times != -1) { - param = ¶ms[tmp]; - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLOCK_STATS_FLUSH_TOTAL_TIMES, - VIR_TYPED_PARAM_LLONG, - flush_total_times) < 0) - goto endjob; - tmp++; - } +#undef QEMU_BLOCK_STAT /* Field 'errs' is meaningless for QEMU, won't set it. */ -- 2.2.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list