udev: net_id: introduce predictable names for netdevsim

In order to properly and predictably name netdevsim netdevices,
introduce a separate implementation, as the netdevices reside on a
specific netdevsim bus. Note that this applies only to netdevsim devices
created using sysfs, because those expose phys_port_name attribute.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
This commit is contained in:
Jiri Pirko 2019-04-15 20:34:44 +02:00 committed by Zbigniew Jędrzejewski-Szmek
parent 0fde5a3591
commit eaa9d507d8
3 changed files with 53 additions and 0 deletions

View File

@ -8,6 +8,7 @@ static const NamingScheme naming_schemes[] = {
{ "v238", NAMING_V238 },
{ "v239", NAMING_V239 },
{ "v240", NAMING_V240 },
{ "v243", NAMING_V243 },
/* … add more schemes here, as the logic to name devices is updated … */
};

View File

@ -27,11 +27,13 @@ typedef enum NamingSchemeFlags {
NAMING_INFINIBAND = 1 << 2, /* Use "ib" prefix for infiniband, see 938d30aa98df887797c9e05074a562ddacdcdf5e */
NAMING_ZERO_ACPI_INDEX = 1 << 3, /* Allow zero acpi_index field, see d81186ef4f6a888a70f20a1e73a812d6acb9e22f */
NAMING_ALLOW_RERENAMES = 1 << 4, /* Allow re-renaming of devices, see #9006 */
NAMING_NETDEVSIM = 1 << 5, /* Allow re-renaming of netdevsim devices */
/* And now the masks that combine the features above */
NAMING_V238 = 0,
NAMING_V239 = NAMING_V238 | NAMING_SR_IOV_V | NAMING_NPAR_ARI,
NAMING_V240 = NAMING_V239 | NAMING_INFINIBAND | NAMING_ZERO_ACPI_INDEX | NAMING_ALLOW_RERENAMES,
NAMING_V243 = NAMING_V240 | NAMING_NETDEVSIM,
_NAMING_SCHEME_FLAGS_INVALID = -1,
} NamingSchemeFlags;

View File

@ -31,6 +31,7 @@
* USB port number chain
* v<slot> - VIO slot number (IBM PowerVM)
* a<vendor><model>i<instance> Platform bus ACPI instance id
* i<addr>n<phys_port_name> Netdevsim bus address and port name
*
* All multi-function PCI devices will carry the [f<function>] number in the
* device name, including the function 0 device.
@ -126,6 +127,7 @@ enum netname_type{
NET_CCW,
NET_VIO,
NET_PLATFORM,
NET_NETDEVSIM,
};
struct netnames {
@ -145,6 +147,7 @@ struct netnames {
char ccw_busid[IFNAMSIZ];
char vio_slot[IFNAMSIZ];
char platform_path[IFNAMSIZ];
char netdevsim_path[IFNAMSIZ];
};
struct virtfn_info {
@ -794,6 +797,43 @@ static int names_mac(sd_device *dev, struct netnames *names) {
return 0;
}
static int names_netdevsim(sd_device *dev, struct netnames *names) {
sd_device *netdevsimdev;
const char *sysname;
unsigned addr;
const char *port_name = NULL;
int r;
bool ok;
if (!naming_scheme_has(NAMING_NETDEVSIM))
return 0;
assert(dev);
assert(names);
r = sd_device_get_parent_with_subsystem_devtype(dev, "netdevsim", NULL, &netdevsimdev);
if (r < 0)
return r;
r = sd_device_get_sysname(netdevsimdev, &sysname);
if (r < 0)
return r;
if (sscanf(sysname, "netdevsim%u", &addr) != 1)
return -EINVAL;
r = sd_device_get_sysattr_value(dev, "phys_port_name", &port_name);
if (r < 0)
return r;
ok = snprintf_ok(names->netdevsim_path, sizeof(names->netdevsim_path), "i%un%s", addr, port_name);
if (!ok)
return -ENOBUFS;
names->type = NET_NETDEVSIM;
return 0;
}
/* IEEE Organizationally Unique Identifier vendor string */
static int ieee_oui(sd_device *dev, struct netnames *names, bool test) {
char str[32];
@ -897,6 +937,16 @@ static int builtin_net_id(sd_device *dev, int argc, char *argv[], bool test) {
return 0;
}
/* get netdevsim path names */
if (names_netdevsim(dev, &names) >= 0 && names.type == NET_NETDEVSIM) {
char str[IFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.netdevsim_path))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
return 0;
}
/* get PCI based path names, we compose only PCI based paths */
if (names_pci(dev, &names) < 0)
return 0;