diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index afdd2f2fc1..bda7f89d14 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -360,7 +360,7 @@ gboolean _nm_setting_option_clear(NMSetting *setting, const char *optname); guint nm_setting_ethtool_init_features( NMSettingEthtool *setting, - NMTernary * requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */); + NMOptionBool * requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */); /*****************************************************************************/ diff --git a/libnm-core/nm-setting-ethtool.c b/libnm-core/nm-setting-ethtool.c index 4a7fb21cd3..7d3f4d96f9 100644 --- a/libnm-core/nm-setting-ethtool.c +++ b/libnm-core/nm-setting-ethtool.c @@ -195,7 +195,7 @@ nm_setting_ethtool_clear_features(NMSettingEthtool *setting) guint nm_setting_ethtool_init_features( NMSettingEthtool *setting, - NMTernary * requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */) + NMOptionBool * requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */) { GHashTable * hash; GHashTableIter iter; @@ -208,7 +208,7 @@ nm_setting_ethtool_init_features( nm_assert(requested); for (i = 0; i < _NM_ETHTOOL_ID_FEATURE_NUM; i++) - requested[i] = NM_TERNARY_DEFAULT; + requested[i] = NM_OPTION_BOOL_DEFAULT; hash = _nm_setting_option_hash(NM_SETTING(setting), FALSE); if (!hash) @@ -224,7 +224,7 @@ nm_setting_ethtool_init_features( continue; requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(ethtool_id)] = - g_variant_get_boolean(variant) ? NM_TERNARY_TRUE : NM_TERNARY_FALSE; + g_variant_get_boolean(variant) ? NM_OPTION_BOOL_TRUE : NM_OPTION_BOOL_FALSE; n_req++; } diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index a6bf0a37a5..53c42dbedf 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -134,7 +134,7 @@ typedef struct { NMPlatformAsyncCallback callback; gpointer callback_data; guint num_vfs; - NMTernary autoprobe; + NMOptionBool autoprobe; } SriovOp; typedef void (*AcdCallback)(NMDevice *, NMIP4Config **, gboolean); @@ -205,7 +205,7 @@ struct _NMDeviceConnectivityHandle { typedef struct { int ifindex; NMEthtoolFeatureStates *features; - NMTernary requested[_NM_ETHTOOL_ID_FEATURE_NUM]; + NMOptionBool requested[_NM_ETHTOOL_ID_FEATURE_NUM]; NMEthtoolCoalesceState *coalesce; NMEthtoolRingState * ring; } EthtoolState; @@ -5829,7 +5829,7 @@ sriov_op_queue_op(NMDevice *self, SriovOp *op) static void sriov_op_queue(NMDevice * self, guint num_vfs, - NMTernary autoprobe, + NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer callback_data) { @@ -5878,7 +5878,7 @@ device_init_static_sriov_num_vfs(NMDevice *self) NULL); num_vfs = _nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXINT32, -1); if (num_vfs >= 0) - sriov_op_queue(self, num_vfs, NM_TERNARY_DEFAULT, NULL, NULL); + sriov_op_queue(self, num_vfs, NM_OPTION_BOOL_DEFAULT, NULL, NULL); } } @@ -8055,7 +8055,8 @@ activate_stage1_device_prepare(NMDevice *self) gs_free_error GError *error = NULL; NMSriovVF * vf; NMTernary autoprobe; - guint i, num; + guint num; + guint i; autoprobe = nm_setting_sriov_get_autoprobe_drivers(s_sriov); if (autoprobe == NM_TERNARY_DEFAULT) { @@ -8063,9 +8064,9 @@ activate_stage1_device_prepare(NMDevice *self) NM_CONFIG_GET_DATA, NM_CON_DEFAULT("sriov.autoprobe-drivers"), self, - NM_TERNARY_FALSE, - NM_TERNARY_TRUE, - NM_TERNARY_TRUE); + NM_OPTION_BOOL_FALSE, + NM_OPTION_BOOL_TRUE, + NM_OPTION_BOOL_TRUE); } num = nm_setting_sriov_get_num_vfs(s_sriov); @@ -8092,7 +8093,7 @@ activate_stage1_device_prepare(NMDevice *self) */ sriov_op_queue(self, nm_setting_sriov_get_total_vfs(s_sriov), - autoprobe, + NM_TERNARY_TO_OPTION_BOOL(autoprobe), sriov_params_cb, nm_utils_user_data_pack(self, g_steal_pointer(&plat_vfs))); priv->stage1_sriov_state = NM_DEVICE_STAGE_STATE_PENDING; @@ -16521,7 +16522,7 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, priv->sriov_reset_pending++; sriov_op_queue(self, 0, - NM_TERNARY_TRUE, + NM_OPTION_BOOL_TRUE, sriov_reset_on_deactivate_cb, nm_utils_user_data_pack(self, GINT_TO_POINTER(reason))); } @@ -16573,7 +16574,7 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, if (priv->ifindex > 0 && (s_sriov = nm_device_get_applied_setting(self, NM_TYPE_SETTING_SRIOV))) { priv->sriov_reset_pending++; - sriov_op_queue(self, 0, NM_TERNARY_TRUE, sriov_reset_on_failure_cb, self); + sriov_op_queue(self, 0, NM_OPTION_BOOL_TRUE, sriov_reset_on_failure_cb, self); break; } /* Schedule the transition to DISCONNECTED. The device can't transition diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 6c04f6c121..e21c31e0a6 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -7653,7 +7653,7 @@ static void link_set_sriov_params_async(NMPlatform * platform, int ifindex, guint num_vfs, - NMTernary autoprobe, + NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer data, GCancellable * cancellable) @@ -7726,10 +7726,11 @@ link_set_sriov_params_async(NMPlatform * platform, } if (current_num == num_vfs - && (autoprobe == NM_TERNARY_DEFAULT || current_autoprobe == autoprobe)) + && (autoprobe == NM_OPTION_BOOL_DEFAULT || current_autoprobe == autoprobe)) goto out_idle; - if (NM_IN_SET(autoprobe, NM_TERNARY_TRUE, NM_TERNARY_FALSE) && current_autoprobe != autoprobe + if (NM_IN_SET(autoprobe, NM_OPTION_BOOL_TRUE, NM_OPTION_BOOL_FALSE) + && current_autoprobe != autoprobe && !nm_platform_sysctl_set( NM_PLATFORM_GET, NMP_SYSCTL_PATHID_NETDIR(dirfd, ifname, "device/sriov_drivers_autoprobe"), diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 4f0ae089a4..0947ef4c81 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -693,8 +693,8 @@ gboolean nmp_utils_ethtool_set_features( int ifindex, const NMEthtoolFeatureStates *features, - const NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, - gboolean do_set /* or reset */) + const NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, + gboolean do_set /* or reset */) { nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT(ifindex); gs_free struct ethtool_sfeatures * sfeatures_free = NULL; @@ -704,7 +704,7 @@ nmp_utils_ethtool_set_features( guint i, j; struct { const NMEthtoolFeatureState *f_state; - NMTernary requested; + NMOptionBool requested; } set_states[N_ETHTOOL_KERNEL_FEATURES]; guint set_states_n = 0; gboolean success = TRUE; @@ -718,7 +718,7 @@ nmp_utils_ethtool_set_features( for (i = 0; i < _NM_ETHTOOL_ID_FEATURE_NUM; i++) { const NMEthtoolFeatureState *const *states_indexed; - if (requested[i] == NM_TERNARY_DEFAULT) + if (requested[i] == NM_OPTION_BOOL_DEFAULT) continue; if (!(states_indexed = features->states_indexed[i])) { @@ -749,7 +749,7 @@ nmp_utils_ethtool_set_features( do_set ? "set" : "reset", nm_ethtool_data[i + _NM_ETHTOOL_ID_FEATURE_FIRST]->optname, s->info->kernel_names[s->idx_kernel_name], - ONOFF(do_set ? requested[i] == NM_TERNARY_TRUE : s->active), + ONOFF(do_set ? requested[i] == NM_OPTION_BOOL_TRUE : s->active), _ethtool_feature_state_to_string(sbuf, sizeof(sbuf), s, @@ -764,14 +764,14 @@ nmp_utils_ethtool_set_features( do_set ? "set" : "reset", nm_ethtool_data[i + _NM_ETHTOOL_ID_FEATURE_FIRST]->optname, s->info->kernel_names[s->idx_kernel_name], - ONOFF(do_set ? requested[i] == NM_TERNARY_TRUE : s->active), + ONOFF(do_set ? requested[i] == NM_OPTION_BOOL_TRUE : s->active), _ethtool_feature_state_to_string(sbuf, sizeof(sbuf), s, do_set ? " currently:" : " before:")); if (do_set && (!s->available || s->never_changed) - && (s->active != (requested[i] == NM_TERNARY_TRUE))) { + && (s->active != (requested[i] == NM_OPTION_BOOL_TRUE))) { /* we request to change a flag which kernel reported as fixed. * While the ethtool operation will silently succeed, mark the request * as failure. */ @@ -811,7 +811,7 @@ nmp_utils_ethtool_set_features( sfeatures->features[i_block].valid |= i_flag; if (do_set) - is_requested = (set_states[i].requested == NM_TERNARY_TRUE); + is_requested = (set_states[i].requested == NM_OPTION_BOOL_TRUE); else is_requested = s->active; diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h index 38f8a00729..d74723eb9f 100644 --- a/src/platform/nm-platform-utils.h +++ b/src/platform/nm-platform-utils.h @@ -40,8 +40,8 @@ NMEthtoolFeatureStates *nmp_utils_ethtool_get_features(int ifindex); gboolean nmp_utils_ethtool_set_features( int ifindex, const NMEthtoolFeatureStates *features, - const NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, - gboolean do_set /* or reset */); + const NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, + gboolean do_set /* or reset */); gboolean nmp_utils_ethtool_get_coalesce(int ifindex, NMEthtoolCoalesceState *coalesce); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 44c6ee4797..bf2ee5d19c 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1842,7 +1842,7 @@ nm_platform_link_supports_sriov(NMPlatform *self, int ifindex) * @ifindex: the index of the interface to change * @num_vfs: the number of VFs to create * @autoprobe: the new autoprobe-drivers value (pass - * %NM_TERNARY_DEFAULT to keep current value) + * %NM_OPTION_BOOL_DEFAULT to keep current value) * @callback: called when the operation finishes * @callback_data: data passed to @callback * @cancellable: cancellable to abort the operation @@ -1855,7 +1855,7 @@ void nm_platform_link_set_sriov_params_async(NMPlatform * self, int ifindex, guint num_vfs, - NMTernary autoprobe, + NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer callback_data, GCancellable * cancellable) @@ -3339,8 +3339,8 @@ nm_platform_ethtool_set_features( NMPlatform * self, int ifindex, const NMEthtoolFeatureStates *features, - const NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, - gboolean do_set /* or reset */) + const NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, + gboolean do_set /* or reset */) { _CHECK_SELF_NETNS(self, klass, netns, FALSE); diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index a785144155..d400c5680a 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -1035,7 +1035,7 @@ _nm_platform_kernel_support_detected(NMPlatformKernelSupportType type) return G_LIKELY(g_atomic_int_get(&_nm_platform_kernel_support_state[type]) != 0); } -static inline NMTernary +static inline NMOptionBool nm_platform_kernel_support_get_full(NMPlatformKernelSupportType type, gboolean init_if_not_set) { int v; @@ -1045,7 +1045,7 @@ nm_platform_kernel_support_get_full(NMPlatformKernelSupportType type, gboolean i v = g_atomic_int_get(&_nm_platform_kernel_support_state[type]); if (G_UNLIKELY(v == 0)) { if (!init_if_not_set) - return NM_TERNARY_DEFAULT; + return NM_OPTION_BOOL_DEFAULT; v = _nm_platform_kernel_support_init(type, 0); } return (v >= 0); @@ -1054,7 +1054,7 @@ nm_platform_kernel_support_get_full(NMPlatformKernelSupportType type, gboolean i static inline gboolean nm_platform_kernel_support_get(NMPlatformKernelSupportType type) { - return nm_platform_kernel_support_get_full(type, TRUE) != NM_TERNARY_FALSE; + return nm_platform_kernel_support_get_full(type, TRUE) != NM_OPTION_BOOL_FALSE; } /*****************************************************************************/ @@ -1118,7 +1118,7 @@ typedef struct { void (*link_set_sriov_params_async)(NMPlatform * self, int ifindex, guint num_vfs, - int autoprobe, + NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer callback_data, GCancellable * cancellable); @@ -1853,7 +1853,7 @@ gboolean nm_platform_link_set_name(NMPlatform *self, int ifindex, const char *na void nm_platform_link_set_sriov_params_async(NMPlatform * self, int ifindex, guint num_vfs, - int autoprobe, + NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer callback_data, GCancellable * cancellable); @@ -2342,8 +2342,8 @@ gboolean nm_platform_ethtool_set_features( NMPlatform * self, int ifindex, const NMEthtoolFeatureStates *features, - const NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, - gboolean do_set /* or reset */); + const NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, + gboolean do_set /* or reset */); gboolean nm_platform_ethtool_get_link_coalesce(NMPlatform * self, int ifindex, diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index 4e08b282b0..529100b9f2 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -2274,18 +2274,18 @@ gboolean nmtstp_kernel_support_get(NMPlatformKernelSupportType type) { const NMPlatformLink *pllink; - NMTernary v; + NMOptionBool v; v = nm_platform_kernel_support_get_full(type, FALSE); - if (v != NM_TERNARY_DEFAULT) - return v != NM_TERNARY_FALSE; + if (v != NM_OPTION_BOOL_DEFAULT) + return v != NM_OPTION_BOOL_FALSE; switch (type) { case NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_BR_VLAN_STATS_ENABLED: pllink = nmtstp_link_bridge_add(NULL, -1, "br-test-11", &nm_platform_lnk_bridge_default); nmtstp_link_delete(NULL, -1, pllink->ifindex, NULL, TRUE); v = nm_platform_kernel_support_get_full(type, FALSE); - g_assert(v != NM_TERNARY_DEFAULT); + g_assert(v != NM_OPTION_BOOL_DEFAULT); return v; default: g_assert_not_reached(); diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 4970b5a475..6dc9f3e453 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -3677,25 +3677,28 @@ test_ethtool_features_get(void) for (i_run = 0; i_run < 5; i_run++) { NMEthtoolFeatureStates *features; - NMTernary * requested; + NMOptionBool * requested; gboolean do_set = TRUE; - requested = g_new(NMTernary, _NM_ETHTOOL_ID_FEATURE_NUM); + requested = g_new(NMOptionBool, _NM_ETHTOOL_ID_FEATURE_NUM); for (i = 0; i < _NM_ETHTOOL_ID_FEATURE_NUM; i++) - requested[i] = NM_TERNARY_DEFAULT; + requested[i] = NM_OPTION_BOOL_DEFAULT; g_ptr_array_add(gfree_keeper, requested); if (i_run == 0) { - requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(NM_ETHTOOL_ID_FEATURE_RX)] = NM_TERNARY_FALSE; - requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(NM_ETHTOOL_ID_FEATURE_TSO)] = NM_TERNARY_FALSE; + requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(NM_ETHTOOL_ID_FEATURE_RX)] = + NM_OPTION_BOOL_FALSE; + requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(NM_ETHTOOL_ID_FEATURE_TSO)] = + NM_OPTION_BOOL_FALSE; requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(NM_ETHTOOL_ID_FEATURE_TX_TCP6_SEGMENTATION)] = - NM_TERNARY_FALSE; + NM_OPTION_BOOL_FALSE; } else if (i_run == 1) do_set = FALSE; else if (i_run == 2) { - requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(NM_ETHTOOL_ID_FEATURE_TSO)] = NM_TERNARY_FALSE; + requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(NM_ETHTOOL_ID_FEATURE_TSO)] = + NM_OPTION_BOOL_FALSE; requested[_NM_ETHTOOL_ID_FEATURE_AS_IDX(NM_ETHTOOL_ID_FEATURE_TX_TCP6_SEGMENTATION)] = - NM_TERNARY_TRUE; + NM_OPTION_BOOL_TRUE; } else if (i_run == 3) do_set = FALSE;