summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2023-05-22 17:53:47 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2023-06-12 11:17:09 +0200
commit749ebef0d9d05935bf373999c1e5bbdc5f291f7d (patch)
tree7756d8bc97364cf93104523acb45e43d427f847a
parentadef815219fa96d3cae410819852e2895f2f7158 (diff)
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.
-rw-r--r--src/core/devices/nm-device.c18
-rw-r--r--src/core/devices/nm-device.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c
index edd8ef5f13..6c9f93808c 100644
--- a/src/core/devices/nm-device.c
+++ b/src/core/devices/nm-device.c
@@ -5400,6 +5400,24 @@ nm_device_get_type_desc(NMDevice *self)
}
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)
{
g_return_val_if_fail(self != NULL, NULL);
diff --git a/src/core/devices/nm-device.h b/src/core/devices/nm-device.h
index e22dbd07a9..35a8d1cd49 100644
--- a/src/core/devices/nm-device.h
+++ b/src/core/devices/nm-device.h
@@ -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);