]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: log and enter failed state in link_reconfigure()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Aug 2024 22:07:05 +0000 (07:07 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Aug 2024 22:29:30 +0000 (07:29 +0900)
No functional change, just refactoring.

src/network/networkd-link-bus.c
src/network/networkd-link.c
src/network/networkd-manager.c

index ef2e81125577f010c1eedf81cbc6a281ce2bab34..cb114929faf838b1a637f4eb3fac0c3a1c953aed 100644 (file)
@@ -666,13 +666,10 @@ int bus_link_method_reconfigure(sd_bus_message *message, void *userdata, sd_bus_
                 return 1; /* Polkit will call us back */
 
         r = link_reconfigure(l, /* force = */ true);
+        if (r > 0)
+                r = link_save_and_clean_full(l, /* also_save_manager = */ true);
         if (r < 0)
                 return r;
-        if (r > 0) {
-                r = link_save_and_clean_full(l, /* also_save_manager = */ true);
-                if (r < 0)
-                        return r;
-        }
 
         return sd_bus_reply_method_return(message, NULL);
 }
index 2f7aaec2e5097ea443075fbd7809f97732bd53c5..1c6f20695fd6800c727069e388c4fe2dabf94010 100644 (file)
@@ -427,8 +427,6 @@ int link_stop_engines(Link *link, bool may_keep_dhcp) {
 }
 
 void link_enter_failed(Link *link) {
-        int r;
-
         assert(link);
 
         if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
@@ -444,13 +442,8 @@ void link_enter_failed(Link *link) {
         }
 
         log_link_info(link, "Trying to reconfigure the interface.");
-        r = link_reconfigure(link, /* force = */ true);
-        if (r < 0) {
-                log_link_warning_errno(link, r, "Failed to reconfigure interface: %m");
-                goto stop;
-        }
-
-        return;
+        if (link_reconfigure(link, /* force = */ true) > 0)
+                return;
 
 stop:
         (void) link_stop_engines(link, /* may_keep_dhcp = */ false);
@@ -1451,8 +1444,11 @@ int link_reconfigure(Link *link, bool force) {
                 return 0; /* 0 means no-op. */
 
         r = link_call_getlink(link, force ? link_force_reconfigure_handler : link_reconfigure_handler);
-        if (r < 0)
+        if (r < 0) {
+                log_link_warning_errno(link, r, "Failed to reconfigure interface: %m");
+                link_enter_failed(link);
                 return r;
+        }
 
         if (force || link->state == LINK_STATE_FAILED)
                 link_set_state(link, LINK_STATE_INITIALIZED);
@@ -1517,8 +1513,10 @@ int link_reconfigure_on_bus_method_reload(Link *link, sd_bus_message *message) {
                 return 0;
 
         data = new(ReconfigureData, 1);
-        if (!data)
-                return -ENOMEM;
+        if (!data) {
+                r = -ENOMEM;
+                goto failed;
+        }
 
         *data = (ReconfigureData) {
                 .link = link_ref(link),
@@ -1528,13 +1526,13 @@ int link_reconfigure_on_bus_method_reload(Link *link, sd_bus_message *message) {
 
         r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_GETLINK, link->ifindex);
         if (r < 0)
-                return r;
+                goto failed;
 
         r = netlink_call_async(link->manager->rtnl, NULL, req,
                                reconfigure_handler_on_bus_method_reload,
                                reconfigure_data_destroy_callback, data);
         if (r < 0)
-                return r;
+                goto failed;
 
         TAKE_PTR(data);
         link->manager->reloading++;
@@ -1543,6 +1541,11 @@ int link_reconfigure_on_bus_method_reload(Link *link, sd_bus_message *message) {
                 link_set_state(link, LINK_STATE_INITIALIZED);
 
         return 0;
+
+failed:
+        log_link_warning_errno(link, r, "Failed to reconfigure interface: %m");
+        link_enter_failed(link);
+        return r;
 }
 
 static int link_initialized_and_synced(Link *link) {
index 6893ade66adbd610b91edb833f8fee7765b35002..4ebecaac5969f9d33c070a61200cd6fa6155e76c 100644 (file)
@@ -87,13 +87,8 @@ static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_b
 
         log_debug("Coming back from suspend, reconfiguring all connections...");
 
-        HASHMAP_FOREACH(link, m->links_by_index) {
-                r = link_reconfigure(link, /* force = */ true);
-                if (r < 0) {
-                        log_link_warning_errno(link, r, "Failed to reconfigure interface: %m");
-                        link_enter_failed(link);
-                }
-        }
+        HASHMAP_FOREACH(link, m->links_by_index)
+                (void) link_reconfigure(link, /* force = */ true);
 
         return 0;
 }
@@ -1143,13 +1138,9 @@ int manager_reload(Manager *m, sd_bus_message *message) {
 
         HASHMAP_FOREACH(link, m->links_by_index) {
                 if (message)
-                        r = link_reconfigure_on_bus_method_reload(link, message);
+                        (void) link_reconfigure_on_bus_method_reload(link, message);
                 else
-                        r = link_reconfigure(link, /* force = */ false);
-                if (r < 0) {
-                        log_link_warning_errno(link, r, "Failed to reconfigure the interface: %m");
-                        link_enter_failed(link);
-                }
+                        (void) link_reconfigure(link, /* force = */ false);
         }
 
         r = 0;