mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
conf: Introduce virNetDevBandwidthValidate()
This function validates whether parsed limits are within range as defined by 'tc' sources (since we use tc to set QoS; or OVS which then uses tc too). The 'tc' program stores speeds in 64bit integers (unit is bytes per second) and sizes in uints (unit is bytes). We use different units: kilobytes per second and kibibytes and therefore we can parse values larger than 'tc' can handle and thus need a function to check if values still fit. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
f644cba8ae
commit
ab489ea318
@ -200,6 +200,48 @@ virNetDevBandwidthFormat(const virNetDevBandwidth *def,
|
||||
}
|
||||
|
||||
|
||||
#define CHECK_LIMIT(val, limit, name) \
|
||||
do { \
|
||||
if ((val) > (limit)) { \
|
||||
virReportError(VIR_ERR_OVERFLOW, \
|
||||
_("value '%1$llu' is too big for '%2$s' parameter, maximum is '%3$llu'"), \
|
||||
val, name, (unsigned long long) limit); \
|
||||
return false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static bool
|
||||
virNetDevBandwidthRateValidate(const virNetDevBandwidthRate *rate)
|
||||
{
|
||||
const unsigned long long speedLimit = 1ULL << 54;
|
||||
const unsigned int sizeLimit = UINT_MAX >> 10;
|
||||
|
||||
/* These limits are taken straight from 'tc' sources. */
|
||||
|
||||
if (!rate)
|
||||
return true;
|
||||
|
||||
CHECK_LIMIT(rate->average, speedLimit, "average");
|
||||
CHECK_LIMIT(rate->peak, speedLimit, "peak");
|
||||
CHECK_LIMIT(rate->burst, sizeLimit, "burst");
|
||||
CHECK_LIMIT(rate->floor, speedLimit, "floor");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef CHECK_LIMIT
|
||||
|
||||
bool
|
||||
virNetDevBandwidthValidate(const virNetDevBandwidth *def)
|
||||
{
|
||||
if (!def)
|
||||
return true;
|
||||
|
||||
return virNetDevBandwidthRateValidate(def->in) &&
|
||||
virNetDevBandwidthRateValidate(def->out);
|
||||
}
|
||||
|
||||
|
||||
bool virNetDevSupportsBandwidth(virDomainNetType type)
|
||||
{
|
||||
switch ((virDomainNetType) type) {
|
||||
|
@ -34,6 +34,8 @@ int virNetDevBandwidthFormat(const virNetDevBandwidth *def,
|
||||
unsigned int class_id,
|
||||
virBuffer *buf);
|
||||
|
||||
bool virNetDevBandwidthValidate(const virNetDevBandwidth *def);
|
||||
|
||||
bool virNetDevSupportsBandwidth(virDomainNetType type);
|
||||
bool virNetDevBandwidthHasFloor(const virNetDevBandwidth *b);
|
||||
bool virNetDevBandwidthSupportsFloor(virNetworkForwardType type);
|
||||
|
@ -825,6 +825,7 @@ virNetDevBandwidthFormat;
|
||||
virNetDevBandwidthHasFloor;
|
||||
virNetDevBandwidthParse;
|
||||
virNetDevBandwidthSupportsFloor;
|
||||
virNetDevBandwidthValidate;
|
||||
virNetDevSupportsBandwidth;
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user