summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-03-04 15:44:53 +0100
committerThomas Haller <thaller@redhat.com>2020-03-04 16:00:24 +0100
commite74485827c626c8159fc8d59948d152feff11970 (patch)
treeefb174f446fc1a4ec693412a898ae62e5de74875
parent2dd7c3d8c40b4c804d460f2cb2ce168e075a17da (diff)
downloadNetworkManager-th/prune-device-state-files.tar.gz
core: periodically cleanup unused device state files from /runth/prune-device-state-files
Otherwise, we only prune unused files when the service terminates. Usually, NetworkManager service doesn't get restarted before shutdown of the system (nor should it be). That means, if you create (and destroy) a large number of software devices, the state files pile up. From time to time, go through the files on disk and delete those that are no longer relevant. In this case, "from time to time" means after we write/update state files 100 times.
-rw-r--r--src/nm-manager.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c
index e78ff38e7c..dab3e5d498 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -50,6 +50,8 @@
#include "nm-dispatcher.h"
#include "NetworkManagerUtils.h"
+#define DEVICE_STATE_PRUNE_RATELIMIT_MAX 100u
+
/*****************************************************************************/
typedef struct {
@@ -191,6 +193,8 @@ typedef struct {
NMConnectivityState connectivity_state;
+ guint8 device_state_prune_ratelimit_count;
+
bool startup:1;
bool devices_inited:1;
@@ -1515,9 +1519,23 @@ manager_device_state_changed (NMDevice *device,
if (NM_IN_SET (new_state,
NM_DEVICE_STATE_UNMANAGED,
NM_DEVICE_STATE_DISCONNECTED,
- NM_DEVICE_STATE_ACTIVATED))
+ NM_DEVICE_STATE_ACTIVATED)) {
nm_manager_write_device_state (self, device, NULL);
+ G_STATIC_ASSERT_EXPR (DEVICE_STATE_PRUNE_RATELIMIT_MAX < G_MAXUINT8);
+ if (priv->device_state_prune_ratelimit_count++ > DEVICE_STATE_PRUNE_RATELIMIT_MAX) {
+ /* We write the device state to /run. The state files are named after the
+ * ifindex (which is assumed to be unique and not repeat -- in practice
+ * it may repeat). So from time to time, we prune device state files
+ * for interfaces that no longer exist.
+ *
+ * Otherwise, the files might pile up if you create (and destroy) a large
+ * number of software devices. */
+ priv->device_state_prune_ratelimit_count = 0;
+ nm_config_device_state_prune_unseen (NULL, priv->platform);
+ }
+ }
+
if (NM_IN_SET (new_state,
NM_DEVICE_STATE_UNAVAILABLE,
NM_DEVICE_STATE_DISCONNECTED))