diff options
author | Thomas Haller <thaller@redhat.com> | 2020-03-04 15:44:53 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-03-04 16:59:22 +0100 |
commit | d65b5c2e81f69ddc9217159a16f49d23d965da1c (patch) | |
tree | 19119bf2c2e257b936fd6c98c3aa7192914f79f7 /src | |
parent | fb6e14cf3f602a840bee66c27dfcb754872f1525 (diff) |
core: periodically cleanup unused device state files from /run
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.
(cherry picked from commit 332df7a58e86ce08cfd9331897d8b928ae6d267e)
Diffstat (limited to 'src')
-rw-r--r-- | src/nm-manager.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c index 3649c87e0f..d7b2211e60 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; @@ -1514,9 +1518,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_stale (NULL, priv->platform); + } + } + if (NM_IN_SET (new_state, NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_DISCONNECTED)) |