Commit ddc502df authored by zhangliping's avatar zhangliping Committed by David S. Miller

openvswitch: meter: fix the incorrect calculation of max delta_t

Max delat_t should be the full_bucket/rate instead of the full_bucket.
Also report EINVAL if the rate is zero.

Fixes: 96fbc13d ("openvswitch: Add meter infrastructure")
Cc: Andy Zhou <azhou@ovn.org>
Signed-off-by: default avatarzhangliping <zhangliping02@baidu.com>
Acked-by: default avatarPravin B Shelar <pshelar@ovn.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 13fbcc8d
...@@ -242,14 +242,20 @@ static struct dp_meter *dp_meter_create(struct nlattr **a) ...@@ -242,14 +242,20 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
band->type = nla_get_u32(attr[OVS_BAND_ATTR_TYPE]); band->type = nla_get_u32(attr[OVS_BAND_ATTR_TYPE]);
band->rate = nla_get_u32(attr[OVS_BAND_ATTR_RATE]); band->rate = nla_get_u32(attr[OVS_BAND_ATTR_RATE]);
if (band->rate == 0) {
err = -EINVAL;
goto exit_free_meter;
}
band->burst_size = nla_get_u32(attr[OVS_BAND_ATTR_BURST]); band->burst_size = nla_get_u32(attr[OVS_BAND_ATTR_BURST]);
/* Figure out max delta_t that is enough to fill any bucket. /* Figure out max delta_t that is enough to fill any bucket.
* Keep max_delta_t size to the bucket units: * Keep max_delta_t size to the bucket units:
* pkts => 1/1000 packets, kilobits => bits. * pkts => 1/1000 packets, kilobits => bits.
*
* Start with a full bucket.
*/ */
band_max_delta_t = (band->burst_size + band->rate) * 1000; band->bucket = (band->burst_size + band->rate) * 1000;
/* Start with a full bucket. */ band_max_delta_t = band->bucket / band->rate;
band->bucket = band_max_delta_t;
if (band_max_delta_t > meter->max_delta_t) if (band_max_delta_t > meter->max_delta_t)
meter->max_delta_t = band_max_delta_t; meter->max_delta_t = band_max_delta_t;
band++; band++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment