]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: make names_xen() self-contained
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 Sep 2022 08:01:23 +0000 (17:01 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 29 Jul 2023 13:14:24 +0000 (22:14 +0900)
It is not necessary to store its partial result into NetNames.

No functional changes, just refactoring.

src/udev/udev-builtin-net_id.c

index b214eb1348a5b7c7e7320fd6e6ad351e8628549e..5e929be5b0a2fc02e8ef0456ccad9230ea23b995 100644 (file)
@@ -48,7 +48,6 @@ typedef enum NetNameType {
         NET_PCI,
         NET_USB,
         NET_BCMA,
-        NET_XENVIF,
 } NetNameType;
 
 typedef struct NetNames {
@@ -62,7 +61,6 @@ typedef struct NetNames {
 
         char usb_ports[ALTIFNAMSIZ];
         char bcma_core[ALTIFNAMSIZ];
-        char xen_slot[ALTIFNAMSIZ];
 } NetNames;
 
 typedef struct LinkInfo {
@@ -1075,14 +1073,16 @@ static int names_netdevsim(sd_device *dev, const char *prefix, bool test) {
         return 0;
 }
 
-static int names_xen(sd_device *dev, NetNames *names) {
+static int names_xen(sd_device *dev, const char *prefix, bool test) {
         sd_device *parent;
         unsigned id;
         const char *syspath, *subsystem, *p, *p2;
         int r;
 
         assert(dev);
-        assert(names);
+        assert(prefix);
+
+        /* get xen vif "slot" based names. */
 
         if (!naming_scheme_has(NAMING_XEN_VIF))
                 return 0;
@@ -1123,8 +1123,12 @@ static int names_xen(sd_device *dev, NetNames *names) {
                            SAFE_ATO_REFUSE_LEADING_WHITESPACE | 10, &id);
         if (r < 0)
                 return r;
-        xsprintf(names->xen_slot, "X%u", id);
-        names->type = NET_XENVIF;
+
+        char str[ALTIFNAMSIZ];
+        if (snprintf_ok(str, sizeof str, "%sX%u", prefix, id))
+                udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
+        log_device_debug(dev, "Xen identifier: id=%u %s %s",
+                         id, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
         return 0;
 }
 
@@ -1229,15 +1233,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
         (void) names_vio(dev, prefix, test);
         (void) names_platform(dev, prefix, test);
         (void) names_netdevsim(dev, prefix, test);
-
-        /* get xen vif "slot" based names. */
-        if (names_xen(dev, &names) >= 0 && names.type == NET_XENVIF) {
-                char str[ALTIFNAMSIZ];
-
-                if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.xen_slot))
-                        udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
-                return 0;
-        }
+        (void) names_xen(dev, prefix, test);
 
         /* get PCI based path names */
         r = names_pci(dev, &info, &names);