mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-06 16:21:50 +00:00
device: add nm_device_get_type_desc_for_log()
When logging, messages include the interface name to specify what device they refer to. In most case the interface name is unique. There are some devices that don't have a kernel link associated, and their interface name is not guaranteed to be unique. This is currently the case for OVS bridges and OVS ports. When reading a log with duplicate interface names, it is difficult to understand what is happening. And this is made worse by the fact that it is common practice to assign the same name to all devices in a OVS hierarchy (bridge, port, interface). To make logs unambiguous, we want to print the device type together with the name; however we don't want to *always* print the type because in most cases it's not useful and it would consume valuable real estate on the screen. Adopt a simple heuristic of showing the type only for OVS devices. This commit adds a helper function to return the device type to show in logs, when it is needed.
This commit is contained in:
parent
adef815219
commit
749ebef0d9
|
@ -5399,6 +5399,24 @@ nm_device_get_type_desc(NMDevice *self)
|
|||
return NM_DEVICE_GET_PRIVATE(self)->type_desc;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_device_get_type_desc_for_log(NMDevice *self)
|
||||
{
|
||||
const char *type;
|
||||
|
||||
type = nm_device_get_type_desc(self);
|
||||
|
||||
/* Some OVS device types (ports and bridges) are not backed by a kernel link, and
|
||||
* they can have the same name of another device of a different type. In fact, it's
|
||||
* quite common to assign the same name to the OVS bridge, the OVS port and the OVS
|
||||
* interface. For this reason, also log the type in case of OVS devices to make the
|
||||
* log message unambiguous. */
|
||||
if (NM_STR_HAS_PREFIX(type, "Open vSwitch"))
|
||||
return type;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_device_get_type_description(NMDevice *self)
|
||||
{
|
||||
|
|
|
@ -463,6 +463,7 @@ int nm_device_get_ip_ifindex(const NMDevice *dev);
|
|||
const char *nm_device_get_driver(NMDevice *dev);
|
||||
const char *nm_device_get_driver_version(NMDevice *dev);
|
||||
const char *nm_device_get_type_desc(NMDevice *dev);
|
||||
const char *nm_device_get_type_desc_for_log(NMDevice *dev);
|
||||
const char *nm_device_get_type_description(NMDevice *dev);
|
||||
NMDeviceType nm_device_get_device_type(NMDevice *dev);
|
||||
NMLinkType nm_device_get_link_type(NMDevice *dev);
|
||||
|
|
Loading…
Reference in a new issue