Introduce virNetDevBandwidthUpdateFilter

This is a simple wrapper around virNetDevBandwidthManipulateFilter() that
will update the desired filter on an interface (usually a network bridge)
with a new MAC address. Although, the MAC address in question usually
refers to some other interface - the one that the filter is constructed
for. Yeah, hard to parse. Thing is, our NATed network has a bridge where
some part of QoS takes place. And vNICs from guests are plugged into
the bridge. However, if a guest decides to change the MAC of its vNIC,
the corresponding qemu process emits an event which we can use to
update the QoS configuration based on the new MAC address.. However,
our QoS hierarchy is currently not notified, therefore it falls apart.
This function (when called in response to the aforementioned event)
will update our QoS hierarchy and duct tape it together again.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2015-04-14 18:04:30 +02:00
parent c6f0be2fcf
commit 176a95fd50
3 changed files with 45 additions and 0 deletions

View File

@ -1758,6 +1758,7 @@ virNetDevBandwidthFree;
virNetDevBandwidthPlug;
virNetDevBandwidthSet;
virNetDevBandwidthUnplug;
virNetDevBandwidthUpdateFilter;
virNetDevBandwidthUpdateRate;

View File

@ -681,3 +681,41 @@ virNetDevBandwidthUpdateRate(const char *ifname,
VIR_FREE(ceil);
return ret;
}
/**
* virNetDevBandwidthUpdateFilter:
* @ifname: interface to operate on
* @ifmac_ptr: new MAC to update the filter with
* @id: filter ID
*
* Sometimes the host environment is so dynamic, that even a
* guest's MAC addresses change on the fly. When that happens we
* must update our QoS hierarchy so that the guest's traffic is
* placed into the correct QDiscs. This function updates the
* filter for the interface @ifname with the unique identifier
* @id so that it uses the new MAC address of the guest interface
* @ifmac_ptr.
*
* Returns: 0 on success,
* -1 on failure (with error reported).
*/
int
virNetDevBandwidthUpdateFilter(const char *ifname,
const virMacAddr *ifmac_ptr,
unsigned int id)
{
int ret = -1;
char *class_id = NULL;
if (virAsprintf(&class_id, "1:%x", id) < 0)
goto cleanup;
if (virNetDevBandwidthManipulateFilter(ifname, ifmac_ptr, id,
class_id, true, true) < 0)
goto cleanup;
ret = 0;
cleanup:
VIR_FREE(class_id);
return ret;
}

View File

@ -73,4 +73,10 @@ int virNetDevBandwidthUpdateRate(const char *ifname,
unsigned long long new_rate)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
ATTRIBUTE_RETURN_CHECK;
int virNetDevBandwidthUpdateFilter(const char *ifname,
const virMacAddr *ifmac_ptr,
unsigned int id)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
ATTRIBUTE_RETURN_CHECK;
#endif /* __VIR_NETDEV_BANDWIDTH_H__ */