summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2016-07-06 09:12:51 +0100
committerBryn M. Reeves <bmr@redhat.com>2016-07-06 09:14:43 +0100
commit03e03e9c11f5731c225d6cb99a1f36d4d8b699f6 (patch)
tree75c27570a139199798344578757b3464de24dcfd
parent5d3b136d38db40a6d26b8a09e7a4b504fa2f85d1 (diff)
downloadlvm2-03e03e9c11f5731c225d6cb99a1f36d4d8b699f6.tar.gz
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.
-rw-r--r--libdm/libdm-stats.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
index 057bbcc7b..c0ef38f4c 100644
--- a/libdm/libdm-stats.c
+++ b/libdm/libdm-stats.c
@@ -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
* 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.
+ *
+ * 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,
region_id, area_id);
+ if (!interval_ns) {
+ *util = 0.0;
+ return_0;
+ }
+
io_nsecs = ((io_nsecs < interval_ns) ? io_nsecs : interval_ns);
*util = (double) io_nsecs / (double) interval_ns;