[libvirt] [PATCHv3 3/4] Simplify linuxNodeGetCPUStats
Eric Blake
eblake at redhat.com
Mon Jan 27 16:16:21 UTC 2014
On 01/22/2014 06:37 AM, Ján Tomko wrote:
> Split out the repetitive code.
> ---
> src/nodeinfo.c | 77 +++++++++++++++++++++++-----------------------------------
> 1 file changed, 30 insertions(+), 47 deletions(-)
>
ACK.
> @@ -722,51 +734,22 @@ linuxNodeGetCPUStats(FILE *procstat,
> continue;
> }
>
> - for (i = 0; i < *nparams; i++) {
> - virNodeCPUStatsPtr param = ¶ms[i];
The old loop terminates early if *nparams < 4.
> + if (virNodeCPUStatsAssign(¶ms[0], VIR_NODE_CPU_STATS_KERNEL,
> + (sys + irq + softirq) * TICK_TO_NSEC) < 0)
> + goto cleanup;
> +
> + if (virNodeCPUStatsAssign(¶ms[1], VIR_NODE_CPU_STATS_USER,
> + (usr + ni) * TICK_TO_NSEC) < 0)
> + goto cleanup;
> +
> + if (virNodeCPUStatsAssign(¶ms[2], VIR_NODE_CPU_STATS_IDLE,
> + idle * TICK_TO_NSEC) < 0)
> + goto cleanup;
> +
> + if (virNodeCPUStatsAssign(¶ms[3], VIR_NODE_CPU_STATS_IOWAIT,
> + iowait * TICK_TO_NSEC) < 0)
> + goto cleanup;
whereas the new code blindly dereferences past the end of the array.
Needs another spin that avoids that issue.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140127/f9280ca3/attachment-0001.sig>
More information about the libvir-list
mailing list