Skip to content

Commit 415ade0

Browse files
committed
udev-builtin-net_id: split out names_pci_onboard_label() from dev_pci_onboard()
Then call it only when it is necessary. The label is used only when the interface is directly connected to the PCI bus, and it does not have the SR-IOV feature (or the naming based on SR-IOV is disabled).
1 parent f831aef commit 415ade0

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/udev/udev-builtin-net_id.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ typedef struct NetNames {
5555
char pci_slot[ALTIFNAMSIZ];
5656
char pci_path[ALTIFNAMSIZ];
5757
char pci_onboard[ALTIFNAMSIZ];
58-
const char *pci_onboard_label;
5958
} NetNames;
6059

6160
/* skip intermediate virtio devices */
@@ -263,7 +262,7 @@ static int dev_pci_onboard(sd_device *dev, NetNames *names) {
263262
assert(dev);
264263
assert(names);
265264

266-
/* retrieve on-board index number and label from firmware */
265+
/* retrieve on-board index number from firmware */
267266
r = pci_get_onboard_index(names->pcidev, &idx);
268267
if (r < 0)
269268
return r;
@@ -279,11 +278,28 @@ static int dev_pci_onboard(sd_device *dev, NetNames *names) {
279278
idx, strna(port),
280279
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), empty_to_na(names->pci_onboard));
281280

282-
if (sd_device_get_sysattr_value(names->pcidev, "label", &names->pci_onboard_label) >= 0)
283-
log_device_debug(dev, "Onboard label from PCI device: %s", names->pci_onboard_label);
284-
else
285-
names->pci_onboard_label = NULL;
281+
return 0;
282+
}
283+
284+
static int names_pci_onboard_label(sd_device *dev, sd_device *pci_dev, const char *prefix, bool test) {
285+
const char *label;
286+
int r;
287+
288+
assert(dev);
289+
assert(prefix);
290+
291+
/* retrieve on-board label from firmware */
292+
r = sd_device_get_sysattr_value(pci_dev, "label", &label);
293+
if (r < 0)
294+
return r;
295+
296+
char str[ALTIFNAMSIZ];
297+
if (snprintf_ok(str, sizeof str, "%s%s",
298+
naming_scheme_has(NAMING_LABEL_NOPREFIX) ? "" : prefix,
299+
label))
300+
udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", str);
286301

302+
log_device_debug(dev, "Onboard label from PCI device: %s", label);
287303
return 0;
288304
}
289305

@@ -835,14 +851,15 @@ static int names_devicetree(sd_device *dev, const char *prefix, bool test) {
835851
return -ENOENT;
836852
}
837853

838-
static int names_pci(sd_device *dev, NetNames *names) {
854+
static int names_pci(sd_device *dev, const char *prefix, NetNames *names, bool test) {
839855
_cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL;
840856
_cleanup_free_ char *virtfn_suffix = NULL;
841857
sd_device *parent;
842858
const char *subsystem;
843859
int r;
844860

845861
assert(dev);
862+
assert(prefix);
846863
assert(names);
847864

848865
r = sd_device_get_parent(dev, &parent);
@@ -886,11 +903,15 @@ static int names_pci(sd_device *dev, NetNames *names) {
886903
if (strlen(vf_names.pci_path) + strlen(virtfn_suffix) < sizeof(names->pci_path))
887904
strscpyl(names->pci_path, sizeof(names->pci_path),
888905
vf_names.pci_path, virtfn_suffix, NULL);
889-
} else {
890-
dev_pci_onboard(dev, names);
891-
dev_pci_slot(dev, names);
906+
907+
return 0;
892908
}
893909

910+
if (names->type == NET_PCI)
911+
(void) names_pci_onboard_label(dev, names->pcidev, prefix, test);
912+
913+
dev_pci_onboard(dev, names);
914+
dev_pci_slot(dev, names);
894915
return 0;
895916
}
896917

@@ -1386,7 +1407,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
13861407
(void) names_xen(dev, prefix, test);
13871408

13881409
/* get PCI based path names */
1389-
r = names_pci(dev, &names);
1410+
r = names_pci(dev, prefix, &names, test);
13901411
if (r == -ENOENT)
13911412
(void) names_usb(dev, prefix, NULL, test);
13921413
if (r < 0)
@@ -1400,12 +1421,6 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
14001421
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_onboard))
14011422
udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
14021423

1403-
if (names.pci_onboard_label &&
1404-
snprintf_ok(str, sizeof str, "%s%s",
1405-
naming_scheme_has(NAMING_LABEL_NOPREFIX) ? "" : prefix,
1406-
names.pci_onboard_label))
1407-
udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", str);
1408-
14091424
if (names.pci_path[0] &&
14101425
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_path))
14111426
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);

0 commit comments

Comments
 (0)