From: Yu Watanabe Date: Tue, 27 Sep 2022 07:55:09 +0000 (+0900) Subject: udev-builtin-net_id: make names_netdevsim() self-contained X-Git-Tag: v255-rc1~877^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f7abd9ede8ecd1ae70ffdc5de97b0015b53b54f9;p=thirdparty%2Fsystemd.git udev-builtin-net_id: make names_netdevsim() self-contained It is not necessary to store its partial result into NetNames. No functional changes, just refactoring. --- diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 8a53323077b..31202567a2e 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -49,7 +49,6 @@ typedef enum NetNameType { NET_USB, NET_BCMA, NET_XENVIF, - NET_NETDEVSIM, } NetNameType; typedef struct NetNames { @@ -64,7 +63,6 @@ typedef struct NetNames { char usb_ports[ALTIFNAMSIZ]; char bcma_core[ALTIFNAMSIZ]; char xen_slot[ALTIFNAMSIZ]; - char netdevsim_path[ALTIFNAMSIZ]; } NetNames; typedef struct LinkInfo { @@ -1037,21 +1035,19 @@ static int names_mac(sd_device *dev, const char *prefix, bool test) { return 0; } -static int names_netdevsim(sd_device *dev, const LinkInfo *info, NetNames *names) { +static int names_netdevsim(sd_device *dev, const char *prefix, bool test) { sd_device *netdevsimdev; - const char *sysname; + const char *sysname, *phys_port_name; unsigned addr; int r; - if (!naming_scheme_has(NAMING_NETDEVSIM)) - return 0; - assert(dev); - assert(info); - assert(names); + assert(prefix); - if (isempty(info->phys_port_name)) - return -EINVAL; + /* get netdevsim path names */ + + if (!naming_scheme_has(NAMING_NETDEVSIM)) + return 0; r = sd_device_get_parent_with_subsystem_devtype(dev, "netdevsim", NULL, &netdevsimdev); if (r < 0) @@ -1063,11 +1059,17 @@ static int names_netdevsim(sd_device *dev, const LinkInfo *info, NetNames *names if (sscanf(sysname, "netdevsim%u", &addr) != 1) return -EINVAL; - if (!snprintf_ok(names->netdevsim_path, sizeof(names->netdevsim_path), "i%un%s", addr, info->phys_port_name)) - return -ENOBUFS; - - names->type = NET_NETDEVSIM; + r = sd_device_get_sysattr_value(dev, "phys_port_name", &phys_port_name); + if (r < 0) + return r; + if (isempty(phys_port_name)) + return -EOPNOTSUPP; + char str[ALTIFNAMSIZ]; + if (snprintf_ok(str, sizeof str, "%si%un%s", prefix, addr, phys_port_name)) + udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str); + log_device_debug(dev, "Netdevsim identifier: address=%u, port_name=%s %s %s", + addr, phys_port_name, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix)); return 0; } @@ -1224,16 +1226,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) { (void) names_ccw(dev, prefix, test); (void) names_vio(dev, prefix, test); (void) names_platform(dev, prefix, test); - - /* get netdevsim path names */ - if (names_netdevsim(dev, &info, &names) >= 0 && names.type == NET_NETDEVSIM) { - char str[ALTIFNAMSIZ]; - - 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; - } + (void) names_netdevsim(dev, prefix, test); /* get xen vif "slot" based names. */ if (names_xen(dev, &names) >= 0 && names.type == NET_XENVIF) {