all: add device.path property

Add a device property to expose its path as reported in the ID_PATH
udev property.
This commit is contained in:
Beniamino Galvani
2020-06-10 15:17:39 +02:00
parent 755e894b91
commit d13ca45ca2
10 changed files with 1272 additions and 880 deletions

View File

@@ -203,6 +203,8 @@ _metagen_device_detail_general_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
get_type));
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_UDI:
return nm_device_get_udi (d);
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PATH:
return nm_device_get_path (d);
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP_IFACE:
return nm_device_get_ip_iface (d);
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IS_SOFTWARE:
@@ -255,6 +257,7 @@ const NmcMetaGenericInfo *const metagen_device_detail_general[_NMC_GENERIC_INFO_
_METAGEN_DEVICE_DETAIL_GENERAL (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP4_CONNECTIVITY, "IP4-CONNECTIVITY"),
_METAGEN_DEVICE_DETAIL_GENERAL (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP6_CONNECTIVITY, "IP6-CONNECTIVITY"),
_METAGEN_DEVICE_DETAIL_GENERAL (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_UDI, "UDI"),
_METAGEN_DEVICE_DETAIL_GENERAL (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PATH, "PATH"),
_METAGEN_DEVICE_DETAIL_GENERAL (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP_IFACE, "IP-IFACE"),
_METAGEN_DEVICE_DETAIL_GENERAL (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IS_SOFTWARE, "IS-SOFTWARE"),
_METAGEN_DEVICE_DETAIL_GENERAL (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_MANAGED, "NM-MANAGED"),

View File

@@ -179,6 +179,7 @@ typedef enum {
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP4_CONNECTIVITY,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP6_CONNECTIVITY,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_UDI,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PATH,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP_IFACE,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IS_SOFTWARE,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_MANAGED,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -27,6 +27,16 @@
-->
<property name="Udi" type="s" access="read"/>
<!--
Path:
The path of the device as exposed by the udev property ID_PATH.
Note that non-UTF-8 characters are backslash escaped. Use g_strcompress()
to obtain the true (non-UTF-8) string.
-->
<property name="Path" type="s" access="read"/>
<!--
Interface:

View File

@@ -1698,6 +1698,7 @@ global:
libnm_1_26_0 {
global:
nm_device_get_path;
nm_ethtool_optname_is_coalesce;
nm_ethtool_optname_is_ring;
nm_setting_bridge_get_multicast_hash_max;

View File

@@ -32,6 +32,7 @@
NM_GOBJECT_PROPERTIES_DEFINE (NMDevice,
PROP_INTERFACE,
PROP_UDI,
PROP_PATH,
PROP_DRIVER,
PROP_DRIVER_VERSION,
PROP_FIRMWARE_VERSION,
@@ -92,6 +93,7 @@ typedef struct _NMDevicePrivate {
char *firmware_version;
char *physical_port_id;
char *udi;
char *path;
guint32 capabilities;
guint32 device_type;
guint32 ip4_connectivity;
@@ -334,6 +336,7 @@ finalize (GObject *object)
g_free (priv->interface);
g_free (priv->ip_interface);
g_free (priv->udi);
g_free (priv->path);
g_free (priv->driver);
g_free (priv->driver_version);
g_free (priv->firmware_version);
@@ -366,6 +369,9 @@ get_property (GObject *object,
case PROP_UDI:
g_value_set_string (value, nm_device_get_udi (device));
break;
case PROP_PATH:
g_value_set_string (value, nm_device_get_path (device));
break;
case PROP_INTERFACE:
g_value_set_string (value, nm_device_get_iface (device));
break;
@@ -523,6 +529,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device = NML_DBUS_META_IFACE_INIT
NML_DBUS_META_PROPERTY_INIT_U ("Metered", PROP_METERED, NMDevicePrivate, metered ),
NML_DBUS_META_PROPERTY_INIT_U ("Mtu", PROP_MTU, NMDevicePrivate, mtu ),
NML_DBUS_META_PROPERTY_INIT_B ("NmPluginMissing", PROP_NM_PLUGIN_MISSING, NMDevicePrivate, nm_plugin_missing ),
NML_DBUS_META_PROPERTY_INIT_S ("Path", PROP_PATH, NMDevicePrivate, path ),
NML_DBUS_META_PROPERTY_INIT_S ("PhysicalPortId", PROP_PHYSICAL_PORT_ID, NMDevicePrivate, physical_port_id ),
NML_DBUS_META_PROPERTY_INIT_B ("Real", PROP_REAL, NMDevicePrivate, real ),
NML_DBUS_META_PROPERTY_INIT_IGNORE ("State", "u" ),
@@ -603,6 +610,23 @@ nm_device_class_init (NMDeviceClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
/**
* NMDevice:path:
*
* The device path as exposed by the udev property ID_PATH.
*
* The string is backslash escaped (C escaping) for invalid
* characters. The escaping can be reverted with g_strcompress(),
* however the result may not be valid UTF-8.
*
* Since: 1.26
**/
obj_properties[PROP_PATH] =
g_param_spec_string (NM_DEVICE_PATH, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
/**
* NMDevice:driver:
*
@@ -1014,6 +1038,27 @@ nm_device_get_udi (NMDevice *device)
return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->udi);
}
/**
* nm_device_get_path:
* @device: a #NMDevice
*
* Gets the path of the #NMDevice as exposed by the udev property ID_PATH.
*
* Returns: the path of the device.
*
* The string is backslash escaped (C escaping) for invalid characters. The escaping
* can be reverted with g_strcompress(), however the result may not be valid UTF-8.
*
* Since: 1.26
**/
const char *
nm_device_get_path (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->path);
}
/**
* nm_device_get_driver:
* @device: a #NMDevice

View File

@@ -24,6 +24,7 @@ G_BEGIN_DECLS
#define NM_DEVICE_DEVICE_TYPE "device-type"
#define NM_DEVICE_UDI "udi"
#define NM_DEVICE_PATH "path"
#define NM_DEVICE_INTERFACE "interface"
#define NM_DEVICE_IP_INTERFACE "ip-interface"
#define NM_DEVICE_DRIVER "driver"
@@ -70,6 +71,8 @@ const char * nm_device_get_iface (NMDevice *device);
const char * nm_device_get_ip_iface (NMDevice *device);
NMDeviceType nm_device_get_device_type (NMDevice *device);
const char * nm_device_get_udi (NMDevice *device);
NM_AVAILABLE_IN_1_26
const char * nm_device_get_path (NMDevice *device);
const char * nm_device_get_driver (NMDevice *device);
const char * nm_device_get_driver_version (NMDevice *device);
const char * nm_device_get_firmware_version (NMDevice *device);

View File

@@ -207,6 +207,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
NM_GOBJECT_PROPERTIES_DEFINE (NMDevice,
PROP_UDI,
PROP_PATH,
PROP_IFACE,
PROP_IP_IFACE,
PROP_DRIVER,
@@ -281,6 +282,7 @@ typedef struct _NMDevicePrivate {
NMDBusTrackObjPath parent_device;
char * udi;
char * path;
char * iface; /* may change, could be renamed by user */
int ifindex;
@@ -4238,6 +4240,13 @@ device_link_changed (NMDevice *self)
_notify (self, PROP_UDI);
}
str = nm_platform_link_get_path (nm_device_get_platform (self), pllink->ifindex);
if (!nm_streq0 (str, priv->path)) {
g_free (priv->path);
priv->path = g_strdup (str);
_notify (self, PROP_PATH);
}
if (!nm_streq0 (pllink->driver, priv->driver)) {
g_free (priv->driver);
priv->driver = g_strdup (pllink->driver);
@@ -4623,6 +4632,13 @@ nm_device_update_from_platform_link (NMDevice *self, const NMPlatformLink *plink
_notify (self, PROP_UDI);
}
str = plink ? nm_platform_link_get_path (nm_device_get_platform (self), plink->ifindex) : NULL;
if (g_strcmp0 (str, priv->path)) {
g_free (priv->path);
priv->path = g_strdup (str);
_notify (self, PROP_PATH);
}
str = plink ? plink->name : NULL;
if (str && g_strcmp0 (str, priv->iface)) {
g_free (priv->iface);
@@ -5153,6 +5169,10 @@ nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error)
nm_clear_g_free (&priv->udi);
_notify (self, PROP_UDI);
}
if (priv->path) {
nm_clear_g_free (&priv->path);
_notify (self, PROP_PATH);
}
if (priv->physical_port_id) {
nm_clear_g_free (&priv->physical_port_id);
_notify (self, PROP_PHYSICAL_PORT_ID);
@@ -17372,6 +17392,11 @@ get_property (GObject *object, guint prop_id,
nm_utils_str_utf8safe_escape_cp (priv->udi,
NM_UTILS_STR_UTF8_SAFE_FLAG_NONE));
break;
case PROP_PATH:
g_value_take_string (value,
nm_utils_str_utf8safe_escape_cp (priv->path,
NM_UTILS_STR_UTF8_SAFE_FLAG_NONE));
break;
case PROP_IFACE:
g_value_take_string (value,
nm_utils_str_utf8safe_escape_cp (priv->iface,
@@ -17889,6 +17914,7 @@ finalize (GObject *object)
g_slist_free_full (priv->dad6_failed_addrs, (GDestroyNotify) nmp_object_unref);
nm_clear_g_free (&priv->physical_port_id);
g_free (priv->udi);
g_free (priv->path);
g_free (priv->iface);
g_free (priv->ip_iface);
g_free (priv->driver);
@@ -17973,6 +17999,7 @@ static const NMDBusInterfaceInfoExtended interface_info_device = {
),
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Udi", "s", NM_DEVICE_UDI),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Path", "s", NM_DEVICE_PATH),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Interface", "s", NM_DEVICE_IFACE),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("IpInterface", "s", NM_DEVICE_IP_IFACE),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Driver", "s", NM_DEVICE_DRIVER),
@@ -18068,6 +18095,11 @@ nm_device_class_init (NMDeviceClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_PATH] =
g_param_spec_string (NM_DEVICE_PATH, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_IFACE] =
g_param_spec_string (NM_DEVICE_IFACE, "", "",
NULL,

View File

@@ -66,6 +66,7 @@ nm_device_state_reason_check (NMDeviceStateReason reason)
/* Properties */
#define NM_DEVICE_UDI "udi"
#define NM_DEVICE_PATH "path"
#define NM_DEVICE_IFACE "interface"
#define NM_DEVICE_IP_IFACE "ip-interface"
#define NM_DEVICE_DRIVER "driver"