core: various minor code cleanups around find_master()

This commit is contained in:
Thomas Haller 2023-06-13 09:31:35 +02:00
parent 2b09512481
commit 44076802a9
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -2575,9 +2575,10 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
guint i; guint i;
gs_free char *iface = NULL; gs_free char *iface = NULL;
const char *parent_spec; const char *parent_spec;
NMDevice *device = NULL, *parent = NULL; NMDevice *device = NULL;
NMDevice *parent = NULL;
NMDevice *dev_candidate; NMDevice *dev_candidate;
GError *error = NULL; gs_free_error GError *error = NULL;
NMLogLevel log_level; NMLogLevel log_level;
g_return_val_if_fail(NM_IS_MANAGER(self), NULL); g_return_val_if_fail(NM_IS_MANAGER(self), NULL);
@ -2586,7 +2587,6 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
iface = nm_manager_get_connection_iface(self, connection, &parent, &parent_spec, &error); iface = nm_manager_get_connection_iface(self, connection, &parent, &parent_spec, &error);
if (!iface) { if (!iface) {
_LOG3D(LOGD_DEVICE, connection, "can't get a name of a virtual device: %s", error->message); _LOG3D(LOGD_DEVICE, connection, "can't get a name of a virtual device: %s", error->message);
g_error_free(error);
return NULL; return NULL;
} }
@ -2624,7 +2624,6 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
device = nm_device_factory_create_device(factory, iface, NULL, connection, NULL, &error); device = nm_device_factory_create_device(factory, iface, NULL, connection, NULL, &error);
if (!device) { if (!device) {
_LOG3W(LOGD_DEVICE, connection, "factory can't create the device: %s", error->message); _LOG3W(LOGD_DEVICE, connection, "factory can't create the device: %s", error->message);
g_error_free(error);
return NULL; return NULL;
} }
@ -2635,7 +2634,6 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
connection, connection,
"can't register the device with manager: %s", "can't register the device with manager: %s",
error->message); error->message);
g_error_free(error);
g_object_unref(device); g_object_unref(device);
return NULL; return NULL;
} }
@ -2656,7 +2654,6 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
if (!find_master(self, connection, device, NULL, NULL, NULL, &error)) { if (!find_master(self, connection, device, NULL, NULL, NULL, &error)) {
_LOG3D(LOGD_DEVICE, connection, "skip activation: %s", error->message); _LOG3D(LOGD_DEVICE, connection, "skip activation: %s", error->message);
g_error_free(error);
return device; return device;
} }
@ -2670,7 +2667,6 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
continue; continue;
s_con = nm_connection_get_setting_connection(candidate); s_con = nm_connection_get_setting_connection(candidate);
g_assert(s_con);
if (!nm_setting_connection_get_autoconnect(s_con) if (!nm_setting_connection_get_autoconnect(s_con)
|| nm_settings_connection_autoconnect_is_blocked(connections[i])) || nm_settings_connection_autoconnect_is_blocked(connections[i]))
continue; continue;
@ -2686,7 +2682,6 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
connection, connection,
"couldn't create the device: %s", "couldn't create the device: %s",
error->message); error->message);
g_error_free(error);
return NULL; return NULL;
} }
@ -4898,8 +4893,11 @@ find_master(NMManager *self,
NMSettingsConnection *const *connections; NMSettingsConnection *const *connections;
guint i; guint i;
s_con = nm_connection_get_setting_connection(connection); nm_assert(!out_master_connection || !*out_master_connection);
g_assert(s_con); nm_assert(!out_master_device || !*out_master_device);
nm_assert(!out_master_ac || !*out_master_ac);
s_con = nm_connection_get_setting_connection(connection);
master = nm_setting_connection_get_master(s_con); master = nm_setting_connection_get_master(s_con);
if (master == NULL) if (master == NULL)
@ -5007,10 +5005,8 @@ find_master(NMManager *self,
nm_device_get_iface(master_device)); nm_device_get_iface(master_device));
} }
if (out_master_connection) NM_SET_OUT(out_master_connection, master_connection);
*out_master_connection = master_connection; NM_SET_OUT(out_master_device, master_device);
if (out_master_device)
*out_master_device = master_device;
if (out_master_ac && master_connection) { if (out_master_ac && master_connection) {
*out_master_ac = active_connection_find(self, *out_master_ac = active_connection_find(self,
master_connection, master_connection,
@ -5020,15 +5016,15 @@ find_master(NMManager *self,
NULL); NULL);
} }
if (master_device || master_connection) if (!master_device && !master_connection) {
return TRUE;
else {
g_set_error_literal(error, g_set_error_literal(error,
NM_MANAGER_ERROR, NM_MANAGER_ERROR,
NM_MANAGER_ERROR_UNKNOWN_DEVICE, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
"Master connection not found or invalid"); "Master connection not found or invalid");
return FALSE; return FALSE;
} }
return TRUE;
} }
/** /**
@ -5273,8 +5269,9 @@ find_slaves(NMManager *manager,
&n_all_connections); &n_all_connections);
for (i = 0; i < n_all_connections; i++) { for (i = 0; i < n_all_connections; i++) {
NMSettingsConnection *master_connection = NULL; NMSettingsConnection *master_connection = NULL;
NMDevice *master_device = NULL, *slave_device; NMDevice *master_device = NULL;
NMSettingsConnection *candidate = all_connections[i]; NMDevice *slave_device;
NMSettingsConnection *candidate = all_connections[i];
find_master(manager, find_master(manager,
nm_settings_connection_get_connection(candidate), nm_settings_connection_get_connection(candidate),
@ -5607,7 +5604,8 @@ active_connection_parent_active(NMActiveConnection *active,
static gboolean static gboolean
_internal_activate_device(NMManager *self, NMActiveConnection *active, GError **error) _internal_activate_device(NMManager *self, NMActiveConnection *active, GError **error)
{ {
NMDevice *device, *master_device = NULL; NMDevice *device;
NMDevice *master_device = NULL;
NMConnection *applied; NMConnection *applied;
NMSettingsConnection *sett_conn; NMSettingsConnection *sett_conn;
NMSettingsConnection *master_connection = NULL; NMSettingsConnection *master_connection = NULL;