summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-05-14 09:16:30 +0200
committerAntonio Cardace <acardace@redhat.com>2020-05-20 10:54:57 +0200
commit12063d6cb657b3e4cf007a5eb3549efe89d83abf (patch)
tree99d7ef6500f06d7fad8e3a19b0e277fe7872430d
parentd71f920f2e5e5f1bbe1760695787d1e998d56c0e (diff)
downloadNetworkManager-12063d6cb657b3e4cf007a5eb3549efe89d83abf.tar.gz
platform: simplify NMEthtoolCoalesceState to only track one state
Only in one moment we need the old and requested settings together: during _ethtool_coalesce_set(). But for that we shouldn't track both states in "NMEthtoolCoalesceState". Simplify "NMEthtoolCoalesceState" to only contain one set of options. By tracking less state, the code becomes simpler, because you don't need to wonder where the old and requested state is used.
-rw-r--r--src/devices/nm-device.c43
-rw-r--r--src/platform/nm-platform-utils.c42
-rw-r--r--src/platform/nm-platform-utils.h13
-rw-r--r--src/platform/nm-platform.c66
-rw-r--r--src/platform/nm-platform.h12
5 files changed, 81 insertions, 95 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 66eea16ce4..c20c078002 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -32,6 +32,7 @@
#include "NetworkManagerUtils.h"
#include "nm-manager.h"
#include "platform/nm-platform.h"
+#include "platform/nm-platform-utils.h"
#include "platform/nmp-object.h"
#include "platform/nmp-rules-manager.h"
#include "ndisc/nm-ndisc.h"
@@ -185,7 +186,7 @@ typedef struct {
int ifindex;
NMEthtoolFeatureStates *features;
NMTernary requested[_NM_ETHTOOL_ID_FEATURE_NUM];
- NMEthtoolCoalesceStates *coalesce;
+ NMEthtoolCoalesceState *coalesce;
} EthtoolState;
/*****************************************************************************/
@@ -868,7 +869,7 @@ static gboolean
_ethtool_init_coalesce (NMDevice *self,
NMPlatform *platform,
NMSettingEthtool *s_ethtool,
- NMEthtoolCoalesceStates *coalesce)
+ NMEthtoolCoalesceState *coalesce)
{
GHashTable *hash;
GHashTableIter iter;
@@ -904,14 +905,12 @@ _ethtool_init_coalesce (NMDevice *self,
return (!!n_coalesce_set);
}
-
-
static void
_ethtool_coalesce_reset (NMDevice *self,
NMPlatform *platform,
EthtoolState *ethtool_state)
{
- gs_free NMEthtoolCoalesceStates *coalesce = NULL;
+ gs_free NMEthtoolCoalesceState *coalesce = NULL;
nm_assert (NM_IS_DEVICE (self));
nm_assert (NM_IS_PLATFORM (platform));
@@ -919,13 +918,17 @@ _ethtool_coalesce_reset (NMDevice *self,
coalesce = g_steal_pointer (&ethtool_state->coalesce);
+ if (!coalesce)
+ return;
+
if (!nm_platform_ethtool_set_coalesce (platform,
ethtool_state->ifindex,
- coalesce,
- FALSE))
+ coalesce)) {
_LOGW (LOGD_DEVICE, "ethtool: failure resetting one or more coalesce settings");
- else
- _LOGD (LOGD_DEVICE, "ethtool: coalesce settings successfully reset");
+ return;
+ }
+
+ _LOGD (LOGD_DEVICE, "ethtool: coalesce settings successfully reset");
}
static void
@@ -934,37 +937,39 @@ _ethtool_coalesce_set (NMDevice *self,
EthtoolState *ethtool_state,
NMSettingEthtool *s_ethtool)
{
- gs_free NMEthtoolCoalesceStates *coalesce = NULL;
+ NMEthtoolCoalesceState coalesce_old;
+ NMEthtoolCoalesceState coalesce_new;
nm_assert (ethtool_state);
nm_assert (NM_IS_DEVICE (self));
nm_assert (NM_IS_PLATFORM (platform));
nm_assert (NM_IS_SETTING_ETHTOOL (s_ethtool));
- coalesce = nm_platform_ethtool_get_link_coalesce (platform,
- ethtool_state->ifindex);
-
- if (!coalesce) {
+ if (!nm_platform_ethtool_get_link_coalesce (platform,
+ ethtool_state->ifindex,
+ &coalesce_old)) {
_LOGW (LOGD_DEVICE, "ethtool: failure getting coalesce settings (cannot read)");
return;
}
+ coalesce_new = coalesce_old;
+
if (!_ethtool_init_coalesce (self,
platform,
s_ethtool,
- coalesce))
+ &coalesce_new))
return;
+ ethtool_state->coalesce = nm_memdup (&coalesce_old, sizeof (coalesce_old));
+
if (!nm_platform_ethtool_set_coalesce (platform,
ethtool_state->ifindex,
- coalesce,
- TRUE)) {
+ &coalesce_new)) {
_LOGW (LOGD_DEVICE, "ethtool: failure setting coalesce settings");
return;
}
- _LOGD (LOGD_DEVICE, "ethtool: coalesce settings successfully set");
- ethtool_state->coalesce = g_steal_pointer (&coalesce);
+ _LOGD (LOGD_DEVICE, "ethtool: coalesce settings successfully set");
}
static void
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index c47d8476fc..b0510c077a 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -845,31 +845,26 @@ ethtool_get_coalesce (SocketHandle *shandle,
return TRUE;
}
-
-NMEthtoolCoalesceStates *
-nmp_utils_ethtool_get_coalesce (int ifindex)
+gboolean
+nmp_utils_ethtool_get_coalesce (int ifindex,
+ NMEthtoolCoalesceState *coalesce)
{
- gs_free NMEthtoolCoalesceStates *coalesce = NULL;
nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT (ifindex);
- g_return_val_if_fail (ifindex > 0, NULL);
-
- coalesce = g_new0 (NMEthtoolCoalesceStates, 1);
+ g_return_val_if_fail (ifindex > 0, FALSE);
+ g_return_val_if_fail (coalesce, FALSE);
- if (!ethtool_get_coalesce (&shandle, &coalesce->old_state)) {
+ if (!ethtool_get_coalesce (&shandle, coalesce)) {
nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: failure getting coalesce settings",
ifindex,
"get-coalesce");
- return NULL;
+ return FALSE;
}
- /* copy into requested as well, so that they're merged when applying */
- coalesce->requested_state = coalesce->old_state;
-
nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: retrieved kernel coalesce settings",
ifindex,
"get-coalesce");
- return g_steal_pointer (&coalesce);
+ return TRUE;
}
static gboolean
@@ -916,32 +911,23 @@ ethtool_set_coalesce (SocketHandle *shandle,
gboolean
nmp_utils_ethtool_set_coalesce (int ifindex,
- const NMEthtoolCoalesceStates *coalesce,
- gboolean do_set)
+ const NMEthtoolCoalesceState *coalesce)
{
- gboolean success;
nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT (ifindex);
g_return_val_if_fail (ifindex > 0, FALSE);
g_return_val_if_fail (coalesce, FALSE);
- if (do_set)
- success = ethtool_set_coalesce (&shandle, &coalesce->requested_state);
- else
- success = ethtool_set_coalesce (&shandle, &coalesce->old_state);
-
- if (!success) {
- nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: failure %s coalesce settings",
+ if (!ethtool_set_coalesce (&shandle, coalesce)) {
+ nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: failure setting coalesce settings",
ifindex,
- "set-coalesce",
- do_set ? "setting" : "resetting");
+ "set-coalesce");
return FALSE;
}
- nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: %s kernel coalesce settings",
+ nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: set kernel coalesce settings",
ifindex,
- "set-coalesce",
- do_set ? "set" : "reset");
+ "set-coalesce");
return TRUE;
}
diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h
index 56fdb5e4d3..b511c12cc6 100644
--- a/src/platform/nm-platform-utils.h
+++ b/src/platform/nm-platform-utils.h
@@ -92,7 +92,7 @@ gboolean nmp_utils_ethtool_set_features (int ifindex,
const NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */,
gboolean do_set /* or reset */);
-typedef struct {
+struct _NMEthtoolCoalesceState {
guint32 rx_coalesce_usecs;
guint32 rx_max_coalesced_frames;
guint32 rx_coalesce_usecs_irq;
@@ -115,18 +115,13 @@ typedef struct {
guint32 tx_coalesce_usecs_high;
guint32 tx_max_coalesced_frames_high;
guint32 rate_sample_interval;
-} NMEthtoolCoalesceState;
-
-struct _NMEthtoolCoalesceStates {
- NMEthtoolCoalesceState old_state;
- NMEthtoolCoalesceState requested_state;
};
-NMEthtoolCoalesceStates * nmp_utils_ethtool_get_coalesce (int ifindex);
+gboolean nmp_utils_ethtool_get_coalesce (int ifindex,
+ NMEthtoolCoalesceState *coalesce);
gboolean nmp_utils_ethtool_set_coalesce (int ifindex,
- const NMEthtoolCoalesceStates *coalesce,
- gboolean do_set);
+ const NMEthtoolCoalesceState *coalesce);
/*****************************************************************************/
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index c17cd305dc..03ca152fa8 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -3214,29 +3214,30 @@ nm_platform_ethtool_set_features (NMPlatform *self,
return nmp_utils_ethtool_set_features (ifindex, features, requested, do_set);
}
-NMEthtoolCoalesceStates *
-nm_platform_ethtool_get_link_coalesce (NMPlatform *self, int ifindex)
+gboolean
+nm_platform_ethtool_get_link_coalesce (NMPlatform *self,
+ int ifindex,
+ NMEthtoolCoalesceState *coalesce)
{
- _CHECK_SELF_NETNS (self, klass, netns, NULL);
+ _CHECK_SELF_NETNS (self, klass, netns, FALSE);
- g_return_val_if_fail (ifindex > 0, NULL);
+ g_return_val_if_fail (ifindex > 0, FALSE);
+ g_return_val_if_fail (coalesce, FALSE);
- return nmp_utils_ethtool_get_coalesce (ifindex);
+ return nmp_utils_ethtool_get_coalesce (ifindex, coalesce);
}
gboolean
nm_platform_ethtool_init_coalesce (NMPlatform *self,
- NMEthtoolCoalesceStates *coalesce,
+ NMEthtoolCoalesceState *coalesce,
const char *option_name,
guint32 value)
{
NMEthtoolID ethtool_id;
- NMEthtoolCoalesceState *state;
g_return_val_if_fail (coalesce, FALSE);
g_return_val_if_fail (option_name, FALSE);
- state = &coalesce->requested_state;
ethtool_id = nm_ethtool_id_get_by_name (option_name);
if (!nm_ethtool_id_is_coalesce (ethtool_id))
@@ -3244,70 +3245,70 @@ nm_platform_ethtool_init_coalesce (NMPlatform *self,
switch (ethtool_id) {
case NM_ETHTOOL_ID_COALESCE_ADAPTIVE_RX:
- state->use_adaptive_rx_coalesce = value;
+ coalesce->use_adaptive_rx_coalesce = value;
break;
case NM_ETHTOOL_ID_COALESCE_ADAPTIVE_TX:
- state->use_adaptive_tx_coalesce = value;
+ coalesce->use_adaptive_tx_coalesce = value;
break;
case NM_ETHTOOL_ID_COALESCE_PKT_RATE_HIGH:
- state->pkt_rate_high = value;
+ coalesce->pkt_rate_high = value;
break;
case NM_ETHTOOL_ID_COALESCE_PKT_RATE_LOW:
- state->pkt_rate_low = value;
+ coalesce->pkt_rate_low = value;
break;
case NM_ETHTOOL_ID_COALESCE_RX_FRAMES:
- state->rx_max_coalesced_frames = value;
+ coalesce->rx_max_coalesced_frames = value;
break;
case NM_ETHTOOL_ID_COALESCE_RX_FRAMES_HIGH:
- state->rx_max_coalesced_frames_high = value;
+ coalesce->rx_max_coalesced_frames_high = value;
break;
case NM_ETHTOOL_ID_COALESCE_RX_FRAMES_IRQ:
- state->rx_max_coalesced_frames_irq = value;
+ coalesce->rx_max_coalesced_frames_irq = value;
break;
case NM_ETHTOOL_ID_COALESCE_RX_FRAMES_LOW:
- state->rx_max_coalesced_frames_low = value;
+ coalesce->rx_max_coalesced_frames_low = value;
break;
case NM_ETHTOOL_ID_COALESCE_RX_USECS:
- state->rx_coalesce_usecs = value;
+ coalesce->rx_coalesce_usecs = value;
break;
case NM_ETHTOOL_ID_COALESCE_RX_USECS_HIGH:
- state->rx_coalesce_usecs_high = value;
+ coalesce->rx_coalesce_usecs_high = value;
break;
case NM_ETHTOOL_ID_COALESCE_RX_USECS_IRQ:
- state->rx_coalesce_usecs_irq = value;
+ coalesce->rx_coalesce_usecs_irq = value;
break;
case NM_ETHTOOL_ID_COALESCE_RX_USECS_LOW:
- state->rx_coalesce_usecs_low = value;
+ coalesce->rx_coalesce_usecs_low = value;
break;
case NM_ETHTOOL_ID_COALESCE_SAMPLE_INTERVAL:
- state->rate_sample_interval = value;
+ coalesce->rate_sample_interval = value;
break;
case NM_ETHTOOL_ID_COALESCE_STATS_BLOCK_USECS:
- state->stats_block_coalesce_usecs = value;
+ coalesce->stats_block_coalesce_usecs = value;
break;
case NM_ETHTOOL_ID_COALESCE_TX_FRAMES:
- state->tx_max_coalesced_frames = value;
+ coalesce->tx_max_coalesced_frames = value;
break;
case NM_ETHTOOL_ID_COALESCE_TX_FRAMES_HIGH:
- state->tx_max_coalesced_frames_high = value;
+ coalesce->tx_max_coalesced_frames_high = value;
break;
case NM_ETHTOOL_ID_COALESCE_TX_FRAMES_IRQ:
- state->tx_max_coalesced_frames_irq = value;
+ coalesce->tx_max_coalesced_frames_irq = value;
break;
case NM_ETHTOOL_ID_COALESCE_TX_FRAMES_LOW:
- state->tx_max_coalesced_frames_low = value;
+ coalesce->tx_max_coalesced_frames_low = value;
break;
case NM_ETHTOOL_ID_COALESCE_TX_USECS:
- state->tx_coalesce_usecs = value;
+ coalesce->tx_coalesce_usecs = value;
break;
case NM_ETHTOOL_ID_COALESCE_TX_USECS_HIGH:
- state->tx_coalesce_usecs_high = value;
+ coalesce->tx_coalesce_usecs_high = value;
break;
case NM_ETHTOOL_ID_COALESCE_TX_USECS_IRQ:
- state->tx_coalesce_usecs_irq = value;
+ coalesce->tx_coalesce_usecs_irq = value;
break;
case NM_ETHTOOL_ID_COALESCE_TX_USECS_LOW:
- state->tx_coalesce_usecs_low = value;
+ coalesce->tx_coalesce_usecs_low = value;
break;
default:
g_return_val_if_reached (FALSE);
@@ -3319,14 +3320,13 @@ nm_platform_ethtool_init_coalesce (NMPlatform *self,
gboolean
nm_platform_ethtool_set_coalesce (NMPlatform *self,
int ifindex,
- const NMEthtoolCoalesceStates *coalesce,
- gboolean do_set)
+ const NMEthtoolCoalesceState *coalesce)
{
_CHECK_SELF_NETNS (self, klass, netns, FALSE);
g_return_val_if_fail (ifindex > 0, FALSE);
- return nmp_utils_ethtool_set_coalesce (ifindex, coalesce, do_set);
+ return nmp_utils_ethtool_set_coalesce (ifindex, coalesce);
}
/*****************************************************************************/
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 260b5356ff..87571dd180 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -1954,20 +1954,20 @@ gboolean nm_platform_ethtool_set_features (NMPlatform *self,
const NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */,
gboolean do_set /* or reset */);
-typedef struct _NMEthtoolCoalesceStates NMEthtoolCoalesceStates;
+typedef struct _NMEthtoolCoalesceState NMEthtoolCoalesceState;
-NMEthtoolCoalesceStates *nm_platform_ethtool_get_link_coalesce (NMPlatform *self,
- int ifindex);
+gboolean nm_platform_ethtool_get_link_coalesce (NMPlatform *self,
+ int ifindex,
+ NMEthtoolCoalesceState *coalesce);
gboolean nm_platform_ethtool_init_coalesce (NMPlatform *self,
- NMEthtoolCoalesceStates *coalesce,
+ NMEthtoolCoalesceState *coalesce,
const char *option_name,
guint32 value);
gboolean nm_platform_ethtool_set_coalesce (NMPlatform *self,
int ifindex,
- const NMEthtoolCoalesceStates *coalesce,
- gboolean do_set);
+ const NMEthtoolCoalesceState *coalesce);
const char * nm_platform_link_duplex_type_to_string (NMPlatformLinkDuplexType duplex);