network: log and enter failed state in link_reconfigure()

No functional change, just refactoring.
This commit is contained in:
Yu Watanabe
2024-08-21 07:29:30 +09:00
parent 685fd0d729
commit 021d39d3d1
3 changed files with 23 additions and 32 deletions
+2 -5
View 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);
}
+17 -14
View 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) {
+4 -13
View 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;