1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

libdm: test for zero interval_ns in _utilization() (Coverity)

It's possible for interval_ns to be zero if the interval is not
set or the clock is misconfigured. Test for this before using the
value as the divisor in the utilisation calculation.
This commit is contained in:
Bryn M. Reeves 2016-07-06 09:12:51 +01:00
parent 5d3b136d38
commit 03e03e9c11

View File

@ -2656,10 +2656,19 @@ static int _utilization(const struct dm_stats *dms, double *util,
* for the last interval; do not allow a value > 100% utilization * for the last interval; do not allow a value > 100% utilization
* to be passed to a dm_make_percent() call. We expect to see these * to be passed to a dm_make_percent() call. We expect to see these
* at startup if counters have not been cleared before the first read. * at startup if counters have not been cleared before the first read.
*
* A zero interval_ns is also an error since metrics cannot be
* calculated without a defined interval - return zero and emit a
* backtrace in this case.
*/ */
io_nsecs = dm_stats_get_counter(dms, DM_STATS_IO_NSECS, io_nsecs = dm_stats_get_counter(dms, DM_STATS_IO_NSECS,
region_id, area_id); region_id, area_id);
if (!interval_ns) {
*util = 0.0;
return_0;
}
io_nsecs = ((io_nsecs < interval_ns) ? io_nsecs : interval_ns); io_nsecs = ((io_nsecs < interval_ns) ? io_nsecs : interval_ns);
*util = (double) io_nsecs / (double) interval_ns; *util = (double) io_nsecs / (double) interval_ns;