udev-builtin-net_id: make names_vio() self-contained

It is not necessary to store its partial result in NetNames.

No functional changes, just refactoring.
This commit is contained in:
Yu Watanabe
2023-07-29 22:14:24 +09:00
parent 80cd180807
commit 07e1841eb9
+11 -15
View File
@@ -48,7 +48,6 @@ typedef enum NetNameType {
NET_PCI,
NET_USB,
NET_BCMA,
NET_VIO,
NET_XENVIF,
NET_PLATFORM,
NET_NETDEVSIM,
@@ -65,7 +64,6 @@ typedef struct NetNames {
char usb_ports[ALTIFNAMSIZ];
char bcma_core[ALTIFNAMSIZ];
char vio_slot[ALTIFNAMSIZ];
char xen_slot[ALTIFNAMSIZ];
char platform_path[ALTIFNAMSIZ];
char netdevsim_path[ALTIFNAMSIZ];
@@ -502,12 +500,17 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) {
return 0;
}
static int names_vio(sd_device *dev, NetNames *names) {
static int names_vio(sd_device *dev, const char *prefix, bool test) {
sd_device *parent;
unsigned busid, slotid, ethid;
const char *syspath, *subsystem;
int r;
assert(dev);
assert(prefix);
/* get ibmveth/ibmvnic slot-based names. */
/* check if our direct parent is a VIO device with no other bus in-between */
r = sd_device_get_parent(dev, &parent);
if (r < 0)
@@ -534,10 +537,11 @@ static int names_vio(sd_device *dev, NetNames *names) {
if (r != 3)
return -EINVAL;
xsprintf(names->vio_slot, "v%u", slotid);
names->type = NET_VIO;
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%sv%u", prefix, slotid))
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
log_device_debug(dev, "Vio slot identifier: slotid=%u %s %s",
slotid, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), names->vio_slot);
slotid, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
return 0;
}
@@ -1192,15 +1196,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
(void) names_mac(dev, prefix, test);
(void) names_devicetree(dev, prefix, test);
(void) names_ccw(dev, prefix, test);
/* get ibmveth/ibmvnic slot-based names. */
if (names_vio(dev, &names) >= 0 && names.type == NET_VIO) {
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.vio_slot))
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
return 0;
}
(void) names_vio(dev, prefix, test);
/* get ACPI path names for ARM64 platform devices */
if (names_platform(dev, &names, test) >= 0 && names.type == NET_PLATFORM) {