mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 10:20:14 +01:00
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.
This commit is contained in:
parent
5477847eed
commit
332df7a58e
1 changed files with 19 additions and 1 deletions
|
|
@ -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_stale (NULL, priv->platform);
|
||||
}
|
||||
}
|
||||
|
||||
if (NM_IN_SET (new_state,
|
||||
NM_DEVICE_STATE_UNAVAILABLE,
|
||||
NM_DEVICE_STATE_DISCONNECTED))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue