To suppress periodic disk wakeups, only write timestamps to disk
when a device gets activated or deactivated.  Timestamps are
still updated periodically in memory, just not flushed to disk
at that time.  Obviously if NM crashes timestamps won't be
preserved, but that shouldn't happen, right? :)
---
 src/nm-device.c                       |   10 ++++++++++
 src/nm-manager.c                      |   15 +++------------
 src/settings/nm-settings-connection.c |    8 +++++++-
 src/settings/nm-settings-connection.h |    4 +++-
 4 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/nm-device.c b/src/nm-device.c
index 7789054..e959148 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -58,6 +58,7 @@
 #include "nm-rfkill.h"
 #include "nm-firewall-manager.h"
 #include "nm-properties-changed-signal.h"
+#include "nm-settings-connection.h"
 
 static void impl_device_disconnect (NMDevice *device, DBusGMethodInvocation 
*context);
 
@@ -4146,6 +4147,15 @@ nm_device_state_changed (NMDevice *device,
        /* Cache the activation request for the dispatcher */
        req = priv->act_request ? g_object_ref (priv->act_request) : NULL;
 
+       /* Update connection timestamps; do this before possibly deactivating 
the
+        * device since that will clear the activation request and thus the
+        * connection, which we need.
+        */
+       if (state == NM_DEVICE_STATE_ACTIVATED || old_state == 
NM_DEVICE_STATE_ACTIVATED) {
+               nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION 
(nm_act_request_get_connection (req)),
+                                                        (guint64) time (NULL), 
TRUE);
+       }
+
        /* Handle the new state here; but anything that could trigger
         * another state change should be done below.
         */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index a53dab8..7e6102f 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -396,7 +396,7 @@ vpn_manager_connection_activated_cb (NMVPNManager *manager,
 {
        /* Update timestamp for the VPN connection */
        nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION 
(nm_vpn_connection_get_connection (vpn)),
-                                                (guint64) time (NULL));
+                                                (guint64) time (NULL), TRUE);
 }
 
 static void
@@ -517,15 +517,6 @@ manager_device_state_changed (NMDevice *device,
        }
 
        nm_manager_update_state (manager);
-
-       if (new_state == NM_DEVICE_STATE_ACTIVATED) {
-               NMActRequest *req;
-
-               req = nm_device_get_act_request (device);
-               if (req)
-                       nm_settings_connection_update_timestamp 
(NM_SETTINGS_CONNECTION (nm_act_request_get_connection (req)),
-                                                                (guint64) time 
(NULL));
-       }
 }
 
 /* Removes a device from a device list; returns the start of the new device 
list */
@@ -3707,7 +3698,7 @@ periodic_update_active_connection_timestamps (gpointer 
user_data)
                req = nm_manager_get_act_request_by_path (manager, active_path, 
&device);
                if (device && nm_device_get_state (device) == 
NM_DEVICE_STATE_ACTIVATED)
                        nm_settings_connection_update_timestamp 
(NM_SETTINGS_CONNECTION (nm_act_request_get_connection (req)),
-                                                                (guint64) time 
(NULL));
+                                                                (guint64) time 
(NULL), FALSE);
                else {
                        /* The connection is probably VPN */
                        NMVPNConnection *vpn_con;
@@ -3715,7 +3706,7 @@ periodic_update_active_connection_timestamps (gpointer 
user_data)
                        vpn_con = nm_vpn_manager_get_vpn_connection_for_active 
(priv->vpn_manager, active_path);
                        if (vpn_con && nm_vpn_connection_get_vpn_state 
(vpn_con) == NM_VPN_CONNECTION_STATE_ACTIVATED)
                                nm_settings_connection_update_timestamp 
(NM_SETTINGS_CONNECTION (nm_vpn_connection_get_connection (vpn_con)),
-                                                                        
(guint64) time (NULL));
+                                                                        
(guint64) time (NULL), FALSE);
                }
        }
 
diff --git a/src/settings/nm-settings-connection.c 
b/src/settings/nm-settings-connection.c
index 5c4ba64..5d240c7 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -1422,11 +1422,14 @@ nm_settings_connection_get_timestamp 
(NMSettingsConnection *connection)
  * @connection: the #NMSettingsConnection
  * @timestamp: timestamp to set into the connection and to store into
  * the timestamps database
+ * @flush_to_disk: if %TRUE, commit timestamp update to persistent storage
  *
  * Updates the connection and timestamps database with the provided timestamp.
  **/
 void
-nm_settings_connection_update_timestamp (NMSettingsConnection *connection, 
guint64 timestamp)
+nm_settings_connection_update_timestamp (NMSettingsConnection *connection,
+                                         guint64 timestamp,
+                                         gboolean flush_to_disk)
 {
        NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE 
(connection);
        const char *connection_uuid;
@@ -1438,6 +1441,9 @@ nm_settings_connection_update_timestamp 
(NMSettingsConnection *connection, guint
        /* Update timestamp in private storage */
        priv->timestamp = timestamp;
 
+       if (flush_to_disk == FALSE)
+               return;
+
        /* Save timestamp to timestamps database file */
        timestamps_file = g_key_file_new ();
        if (!g_key_file_load_from_file (timestamps_file, 
SETTINGS_TIMESTAMPS_FILE, G_KEY_FILE_KEEP_COMMENTS, &error)) {
diff --git a/src/settings/nm-settings-connection.h 
b/src/settings/nm-settings-connection.h
index bc9e3c4..077a145 100644
--- a/src/settings/nm-settings-connection.h
+++ b/src/settings/nm-settings-connection.h
@@ -124,7 +124,9 @@ void nm_settings_connection_signal_remove 
(NMSettingsConnection *self);
 
 guint64 nm_settings_connection_get_timestamp (NMSettingsConnection 
*connection);
 
-void nm_settings_connection_update_timestamp (NMSettingsConnection 
*connection, guint64 timestamp);
+void nm_settings_connection_update_timestamp (NMSettingsConnection *connection,
+                                              guint64 timestamp,
+                                              gboolean flush_to_disk);
 
 void nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection 
*connection);
 
-- 
1.7.7.6


_______________________________________________
networkmanager-list mailing list
networkmanager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to