ethtool: add ring settings

This is the initial support for ring settings and only allows
getting/setting, nothing is yet implemented in nm-device.

Also add unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
This commit is contained in:
Antonio Cardace 2020-05-12 17:27:45 +02:00
parent 3e50221d7e
commit 7109ac667a
No known key found for this signature in database
GPG key ID: 6BF80ABD43E377D3
6 changed files with 258 additions and 7 deletions

View file

@ -58,6 +58,22 @@ nm_ethtool_optname_is_coalesce (const char *optname)
return optname && nm_ethtool_id_is_coalesce (nm_ethtool_id_get_by_name (optname));
}
/**
* nm_ethtool_optname_is_ring:
* @optname: (allow-none): the option name to check
*
* Checks whether @optname is a valid option name for a ring setting.
*
* %Returns: %TRUE, if @optname is valid
*
* Since: 1.26
*/
gboolean
nm_ethtool_optname_is_ring (const char *optname)
{
return optname && nm_ethtool_id_is_ring (nm_ethtool_id_get_by_name (optname));
}
/*****************************************************************************/
/**
@ -340,10 +356,105 @@ nm_setting_ethtool_clear_coalesce_all (NMSettingEthtool *setting)
if (nm_setting_gendata_clear_all (NM_SETTING (setting),
&nm_ethtool_optname_is_coalesce))
_notify_attributes (setting);
}
/**
* nm_setting_ethtool_get_ring:
* @setting: the #NMSettingEthtool
* @optname: option name of the ring setting to get
* @out_value (out) (allow-none): value of the ring setting
*
* Gets the value of ring setting.
*
* Note that @optname must be a valid name for a setting, according to
* nm_ethtool_optname_is_ring().
*
*
* Returns: %TRUE and places the ring setting value in @out_value or %FALSE if unset.
*
* Since: 1.26
*/
gboolean
nm_setting_ethtool_get_ring (NMSettingEthtool *setting,
const char *optname,
guint32 *out_value)
{
g_return_val_if_fail (NM_IS_SETTING_ETHTOOL (setting), FALSE);
g_return_val_if_fail (nm_ethtool_optname_is_ring (optname), FALSE);
return nm_setting_gendata_get_uint32 (NM_SETTING (setting),
optname,
out_value);
}
/**
* nm_setting_ethtool_set_ring:
* @setting: the #NMSettingEthtool
* @optname: option name of the ring setting
* @value: the new value to set.
*
* Sets a ring setting.
*
* Note that @optname must be a valid name for a ring setting, according to
* nm_ethtool_optname_is_ring().
*
* Since: 1.26
*/
void
nm_setting_ethtool_set_ring (NMSettingEthtool *setting,
const char *optname,
guint32 value)
{
NMEthtoolID ethtool_id;
g_return_if_fail (NM_IS_SETTING_ETHTOOL (setting));
ethtool_id = nm_ethtool_id_get_by_name (optname);
g_return_if_fail (nm_ethtool_id_is_ring (ethtool_id));
nm_setting_gendata_set_uint32 (NM_SETTING (setting),
optname,
value);
_notify_attributes (setting);
}
/**
* nm_setting_ethtool_clear_ring:
* @setting: the #NMSettingEthtool
* @optname: option name of the ring setting
*
* Clear a ring setting
*
* Since: 1.26
*/
void
nm_setting_ethtool_clear_ring (NMSettingEthtool *setting,
const char *optname)
{
g_return_if_fail (NM_IS_SETTING_ETHTOOL (setting));
g_return_if_fail (nm_str_not_empty (optname));
if (nm_setting_gendata_clear (NM_SETTING (setting), optname))
_notify_attributes (setting);
}
/**
* nm_setting_ethtool_clear_ring_all:
* @setting: the #NMSettingEthtool
*
* Clears all ring settings
*
* Since: 1.26
*/
void
nm_setting_ethtool_clear_ring_all (NMSettingEthtool *setting)
{
g_return_if_fail (NM_IS_SETTING_ETHTOOL (setting));
if (nm_setting_gendata_clear_all (NM_SETTING (setting),
&nm_ethtool_optname_is_ring))
_notify_attributes (setting);
}
@ -401,12 +512,13 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
g_prefix_error (error, "%s.%s: ", NM_SETTING_ETHTOOL_SETTING_NAME, optname);
return FALSE;
}
} else if (nm_ethtool_optname_is_coalesce (optname)) {
} else if ( nm_ethtool_optname_is_coalesce (optname)
|| nm_ethtool_optname_is_ring (optname)) {
if (!g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32)) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("coalesce setting has invalid variant type"));
_("setting has invalid variant type"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_ETHTOOL_SETTING_NAME, optname);
return FALSE;
}
@ -431,10 +543,13 @@ get_variant_type (const NMSettInfoSetting *sett_info,
const char *name,
GError **error)
{
if (nm_ethtool_optname_is_feature (name))
NMEthtoolID ethtool_id = nm_ethtool_id_get_by_name (name);
if (nm_ethtool_id_is_feature (ethtool_id))
return G_VARIANT_TYPE_BOOLEAN;
if (nm_ethtool_optname_is_coalesce (name))
if ( nm_ethtool_id_is_coalesce (ethtool_id)
|| nm_ethtool_id_is_ring (ethtool_id))
return G_VARIANT_TYPE_UINT32;
g_set_error (error,

View file

@ -92,12 +92,20 @@ G_BEGIN_DECLS
#define NM_ETHTOOL_OPTNAME_COALESCE_TX_USECS_IRQ "coalesce-tx-usecs-irq"
#define NM_ETHTOOL_OPTNAME_COALESCE_TX_USECS_LOW "coalesce-tx-usecs-low"
#define NM_ETHTOOL_OPTNAME_RING_RX "ring-rx"
#define NM_ETHTOOL_OPTNAME_RING_RX_JUMBO "ring-rx-jumbo"
#define NM_ETHTOOL_OPTNAME_RING_RX_MINI "ring-rx-mini"
#define NM_ETHTOOL_OPTNAME_RING_TX "ring-tx"
NM_AVAILABLE_IN_1_20
gboolean nm_ethtool_optname_is_feature (const char *optname);
NM_AVAILABLE_IN_1_26
gboolean nm_ethtool_optname_is_coalesce (const char *optname);
NM_AVAILABLE_IN_1_26
gboolean nm_ethtool_optname_is_ring (const char *optname);
/*****************************************************************************/
#define NM_TYPE_SETTING_ETHTOOL (nm_setting_ethtool_get_type ())
@ -152,6 +160,23 @@ void nm_setting_ethtool_clear_coalesce (NMSettingEthtool *setting,
NM_AVAILABLE_IN_1_26
void nm_setting_ethtool_clear_coalesce_all (NMSettingEthtool *setting);
NM_AVAILABLE_IN_1_26
gboolean nm_setting_ethtool_get_ring (NMSettingEthtool *setting,
const char *optname,
guint32 *out_value);
NM_AVAILABLE_IN_1_26
void nm_setting_ethtool_set_ring (NMSettingEthtool *setting,
const char *optname,
guint32 value);
NM_AVAILABLE_IN_1_26
void nm_setting_ethtool_clear_ring (NMSettingEthtool *setting,
const char *optname);
NM_AVAILABLE_IN_1_26
void nm_setting_ethtool_clear_ring_all (NMSettingEthtool *setting);
G_END_DECLS
#endif /* __NM_SETTING_ETHTOOL_H__ */

View file

@ -1499,7 +1499,7 @@ test_team_setting (void)
/*****************************************************************************/
static void
test_ethtool_1 (void)
test_ethtool_features (void)
{
gs_unref_object NMConnection *con = NULL;
gs_unref_object NMConnection *con2 = NULL;
@ -1655,6 +1655,90 @@ test_ethtool_coalesce (void)
g_assert_false (nm_setting_ethtool_get_coalesce (s_ethtool, NM_ETHTOOL_OPTNAME_COALESCE_TX_USECS, NULL));
}
static void
test_ethtool_ring (void)
{
gs_unref_object NMConnection *con = NULL;
gs_unref_object NMConnection *con2 = NULL;
gs_unref_object NMConnection *con3 = NULL;
gs_unref_variant GVariant *variant = NULL;
gs_free_error GError *error = NULL;
gs_unref_keyfile GKeyFile *keyfile = NULL;
NMSettingConnection *s_con;
NMSettingEthtool *s_ethtool;
NMSettingEthtool *s_ethtool2;
NMSettingEthtool *s_ethtool3;
guint32 out_value;
con = nmtst_create_minimal_connection ("ethtool-ring",
NULL,
NM_SETTING_WIRED_SETTING_NAME,
&s_con);
s_ethtool = NM_SETTING_ETHTOOL (nm_setting_ethtool_new ());
nm_connection_add_setting (con, NM_SETTING (s_ethtool));
nm_setting_ethtool_set_ring (s_ethtool,
NM_ETHTOOL_OPTNAME_RING_RX_JUMBO,
4);
g_assert_true (nm_setting_ethtool_get_ring (s_ethtool, NM_ETHTOOL_OPTNAME_RING_RX_JUMBO, &out_value));
g_assert_cmpuint (out_value, ==, 4);
nmtst_connection_normalize (con);
variant = nm_connection_to_dbus (con, NM_CONNECTION_SERIALIZE_ALL);
con2 = nm_simple_connection_new_from_dbus (variant, &error);
nmtst_assert_success (con2, error);
s_ethtool2 = NM_SETTING_ETHTOOL (nm_connection_get_setting (con2, NM_TYPE_SETTING_ETHTOOL));
g_assert_true (nm_setting_ethtool_get_ring (s_ethtool2, NM_ETHTOOL_OPTNAME_RING_RX_JUMBO, &out_value));
g_assert_cmpuint (out_value, ==, 4);
nmtst_assert_connection_verifies_without_normalization (con2);
nmtst_assert_connection_equals (con, FALSE, con2, FALSE);
keyfile = nm_keyfile_write (con, NULL, NULL, &error);
nmtst_assert_success (keyfile, error);
con3 = nm_keyfile_read (keyfile,
"/ignored/current/working/directory/for/loading/relative/paths",
NULL,
NULL,
&error);
nmtst_assert_success (con3, error);
nm_keyfile_read_ensure_id (con3, "unused-because-already-has-id");
nm_keyfile_read_ensure_uuid (con3, "unused-because-already-has-uuid");
nmtst_connection_normalize (con3);
nmtst_assert_connection_equals (con, FALSE, con3, FALSE);
s_ethtool3 = NM_SETTING_ETHTOOL (nm_connection_get_setting (con3, NM_TYPE_SETTING_ETHTOOL));
g_assert_true (nm_setting_ethtool_get_ring (s_ethtool3, NM_ETHTOOL_OPTNAME_RING_RX_JUMBO, &out_value));
g_assert_cmpuint (out_value, ==, 4);
nm_setting_ethtool_clear_ring (s_ethtool, NM_ETHTOOL_OPTNAME_RING_RX_JUMBO);
g_assert_false (nm_setting_ethtool_get_ring (s_ethtool, NM_ETHTOOL_OPTNAME_RING_RX_JUMBO, NULL));
nm_setting_ethtool_set_ring (s_ethtool,
NM_ETHTOOL_OPTNAME_RING_RX_JUMBO,
8);
g_assert_true (nm_setting_ethtool_get_ring (s_ethtool, NM_ETHTOOL_OPTNAME_RING_RX_JUMBO, &out_value));
g_assert_cmpuint (out_value, ==, 8);
nm_setting_ethtool_clear_ring_all (s_ethtool);
g_assert_false (nm_setting_ethtool_get_ring (s_ethtool, NM_ETHTOOL_OPTNAME_RING_RX_JUMBO, NULL));
g_assert_false (nm_setting_ethtool_get_ring (s_ethtool, NM_ETHTOOL_OPTNAME_RING_RX, NULL));
g_assert_false (nm_setting_ethtool_get_ring (s_ethtool, NM_ETHTOOL_OPTNAME_RING_TX, NULL));
}
/*****************************************************************************/
static void
@ -3854,8 +3938,9 @@ main (int argc, char **argv)
g_test_add_func ("/libnm/settings/dcb/priorities", test_dcb_priorities_valid);
g_test_add_func ("/libnm/settings/dcb/bandwidth-sums", test_dcb_bandwidth_sums);
g_test_add_func ("/libnm/settings/ethtool/1", test_ethtool_1);
g_test_add_func ("/libnm/settings/ethtool/features", test_ethtool_features);
g_test_add_func ("/libnm/settings/ethtool/coalesce", test_ethtool_coalesce);
g_test_add_func ("/libnm/settings/ethtool/ring", test_ethtool_ring);
g_test_add_func ("/libnm/settings/sriov/vf", test_sriov_vf);
g_test_add_func ("/libnm/settings/sriov/vf-dup", test_sriov_vf_dup);

View file

@ -1699,6 +1699,7 @@ global:
libnm_1_26_0 {
global:
nm_ethtool_optname_is_coalesce;
nm_ethtool_optname_is_ring;
nm_setting_bridge_get_multicast_hash_max;
nm_setting_bridge_get_multicast_last_member_count;
nm_setting_bridge_get_multicast_last_member_interval;
@ -1711,8 +1712,12 @@ global:
nm_setting_connection_get_mud_url;
nm_setting_ethtool_clear_coalesce;
nm_setting_ethtool_clear_coalesce_all;
nm_setting_ethtool_clear_ring;
nm_setting_ethtool_clear_ring_all;
nm_setting_ethtool_get_coalesce;
nm_setting_ethtool_get_ring;
nm_setting_ethtool_set_coalesce;
nm_setting_ethtool_set_ring;
nm_setting_match_add_driver;
nm_setting_match_add_kernel_command_line;
nm_setting_match_clear_drivers;

View file

@ -93,6 +93,10 @@ const NMEthtoolData *const nm_ethtool_data[_NM_ETHTOOL_ID_NUM + 1] = {
ETHT_DATA (FEATURE_TX_UDP_TNL_CSUM_SEGMENTATION),
ETHT_DATA (FEATURE_TX_UDP_TNL_SEGMENTATION),
ETHT_DATA (FEATURE_TX_VLAN_STAG_HW_INSERT),
ETHT_DATA (RING_RX),
ETHT_DATA (RING_RX_JUMBO),
ETHT_DATA (RING_RX_MINI),
ETHT_DATA (RING_TX),
[_NM_ETHTOOL_ID_NUM] = NULL,
};
@ -172,6 +176,10 @@ static const guint8 _by_name[_NM_ETHTOOL_ID_NUM] = {
NM_ETHTOOL_ID_FEATURE_TX_UDP_TNL_SEGMENTATION,
NM_ETHTOOL_ID_FEATURE_TX_VLAN_STAG_HW_INSERT,
NM_ETHTOOL_ID_FEATURE_TXVLAN,
NM_ETHTOOL_ID_RING_RX,
NM_ETHTOOL_ID_RING_RX_JUMBO,
NM_ETHTOOL_ID_RING_RX_MINI,
NM_ETHTOOL_ID_RING_TX,
};
/*****************************************************************************/

View file

@ -93,10 +93,18 @@ typedef enum {
NM_ETHTOOL_ID_FEATURE_TX_VLAN_STAG_HW_INSERT,
_NM_ETHTOOL_ID_FEATURE_LAST = NM_ETHTOOL_ID_FEATURE_TX_VLAN_STAG_HW_INSERT,
_NM_ETHTOOL_ID_LAST = _NM_ETHTOOL_ID_FEATURE_LAST,
_NM_ETHTOOL_ID_RING_FIRST = _NM_ETHTOOL_ID_FEATURE_LAST + 1,
NM_ETHTOOL_ID_RING_RX = _NM_ETHTOOL_ID_RING_FIRST,
NM_ETHTOOL_ID_RING_RX_JUMBO,
NM_ETHTOOL_ID_RING_RX_MINI,
NM_ETHTOOL_ID_RING_TX,
_NM_ETHTOOL_ID_RING_LAST = NM_ETHTOOL_ID_RING_TX,
_NM_ETHTOOL_ID_LAST = _NM_ETHTOOL_ID_RING_LAST,
_NM_ETHTOOL_ID_COALESCE_NUM = (_NM_ETHTOOL_ID_COALESCE_LAST - _NM_ETHTOOL_ID_COALESCE_FIRST + 1),
_NM_ETHTOOL_ID_FEATURE_NUM = (_NM_ETHTOOL_ID_FEATURE_LAST - _NM_ETHTOOL_ID_FEATURE_FIRST + 1),
_NM_ETHTOOL_ID_RING_NUM = (_NM_ETHTOOL_ID_RING_LAST - _NM_ETHTOOL_ID_RING_FIRST + 1),
_NM_ETHTOOL_ID_NUM = (_NM_ETHTOOL_ID_LAST - _NM_ETHTOOL_ID_FIRST + 1),
} NMEthtoolID;
@ -132,6 +140,11 @@ nm_ethtool_id_is_coalesce (NMEthtoolID id)
return id >= _NM_ETHTOOL_ID_COALESCE_FIRST && id <= _NM_ETHTOOL_ID_COALESCE_LAST;
}
static inline gboolean
nm_ethtool_id_is_ring (NMEthtoolID id)
{
return id >= _NM_ETHTOOL_ID_RING_FIRST && id <= _NM_ETHTOOL_ID_RING_LAST;
}
/****************************************************************************/
#endif /* __NM_ETHTOOL_UTILS_H__ */