device: inline check_changed_options() in can_reapply_change()

Code doesn't get simpler by having more functions -- if these functions
are only called once.

What actually is a problem is repeated, redundant code. Like the list of
bond options that can be reapplied. But the function didn't help to
avoid repeating the list.
This commit is contained in:
Thomas Haller 2020-09-09 11:20:10 +02:00
parent 5402943420
commit f807b68376
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -561,35 +561,6 @@ create_and_realize (NMDevice *device,
return TRUE;
}
static gboolean
check_changed_options (NMSettingBond *s_a, NMSettingBond *s_b, GError **error)
{
const char **option_list;
option_list = nm_setting_bond_get_valid_options (NULL);
for (; *option_list; ++option_list) {
const char *name = *option_list;
/* We support changes to these */
if (NM_IN_STRSET (name, OPTIONS_REAPPLY_FULL))
continue;
/* Reject any other changes */
if (!nm_streq0 (nm_setting_bond_get_option_normalized (s_a, name),
nm_setting_bond_get_option_normalized (s_b, name))) {
g_set_error (error,
NM_DEVICE_ERROR,
NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
"Can't reapply '%s' bond option",
name);
return FALSE;
}
}
return TRUE;
}
static gboolean
can_reapply_change (NMDevice *device,
const char *setting_name,
@ -602,13 +573,38 @@ can_reapply_change (NMDevice *device,
/* Only handle bond setting here, delegate other settings to parent class */
if (nm_streq (setting_name, NM_SETTING_BOND_SETTING_NAME)) {
NMSettingBond *s_a = NM_SETTING_BOND (s_old);
NMSettingBond *s_b = NM_SETTING_BOND (s_new);
const char **option_list;
if (!nm_device_hash_check_invalid_keys (diffs,
NM_SETTING_BOND_SETTING_NAME,
error,
NM_SETTING_BOND_OPTIONS))
return FALSE;
return check_changed_options (NM_SETTING_BOND (s_old), NM_SETTING_BOND (s_new), error);
option_list = nm_setting_bond_get_valid_options (NULL);
for (; *option_list; ++option_list) {
const char *name = *option_list;
/* We support changes to these */
if (NM_IN_STRSET (name, OPTIONS_REAPPLY_FULL))
continue;
/* Reject any other changes */
if (!nm_streq0 (nm_setting_bond_get_option_normalized (s_a, name),
nm_setting_bond_get_option_normalized (s_b, name))) {
g_set_error (error,
NM_DEVICE_ERROR,
NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
"Can't reapply '%s' bond option",
name);
return FALSE;
}
}
return TRUE;
}
device_class = NM_DEVICE_CLASS (nm_device_bond_parent_class);