summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2017-06-07 10:27:23 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2017-06-07 10:27:23 +0200
commit3223d92eeaf704f0bed774610f5935b8fcfb1adb (patch)
treeb145962fa6aba5a95e86914528ae77940904971c
parent4649ac1a9c55c1cb89ccf714f8a1dceb77d93c66 (diff)
parentcf9ba271e664ffd93f6ba6294ebc5f7e341a9a78 (diff)
downloadNetworkManager-3223d92eeaf704f0bed774610f5935b8fcfb1adb.tar.gz
core: merge branch 'bg/nm-owned-persist-rh1376199'
https://bugzilla.redhat.com/show_bug.cgi?id=1376199
-rw-r--r--src/devices/nm-device.c27
-rw-r--r--src/devices/nm-device.h2
-rw-r--r--src/nm-config.c28
-rw-r--r--src/nm-config.h7
-rw-r--r--src/nm-manager.c8
5 files changed, 58 insertions, 14 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index de3bc687eb..ee0c64affa 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -263,7 +263,7 @@ typedef struct _NMDevicePrivate {
NMUtilsStableType current_stable_id_type:3;
- bool is_nm_owned:1; /* whether the device is a device owned and created by NM */
+ bool nm_owned:1; /* whether the device is a device owned and created by NM */
GHashTable * available_connections;
char * hw_addr;
@@ -2069,7 +2069,7 @@ nm_device_master_release_one_slave (NMDevice *self, NMDevice *slave, gboolean co
static gboolean
can_unmanaged_external_down (NMDevice *self)
{
- return !NM_DEVICE_GET_PRIVATE (self)->is_nm_owned
+ return !NM_DEVICE_GET_PRIVATE (self)->nm_owned
&& nm_device_is_software (self);
}
@@ -2810,9 +2810,9 @@ nm_device_create_and_realize (NMDevice *self,
const NMPlatformLink *plink = NULL;
/* Must be set before device is realized */
- priv->is_nm_owned = !nm_platform_link_get_by_ifname (nm_device_get_platform (self), priv->iface);
+ priv->nm_owned = !nm_platform_link_get_by_ifname (nm_device_get_platform (self), priv->iface);
- _LOGD (LOGD_DEVICE, "create (is %snm-owned)", priv->is_nm_owned ? "" : "not ");
+ _LOGD (LOGD_DEVICE, "create (is %snm-owned)", priv->nm_owned ? "" : "not ");
/* Create any resources the device needs */
if (NM_DEVICE_GET_CLASS (self)->create_and_realize) {
@@ -3012,6 +3012,19 @@ realize_start_setup (NMDevice *self,
_add_capabilities (self, capabilities);
+ /* Update nm-owned flag according to state file */
+ if ( !priv->nm_owned
+ && priv->ifindex > 0
+ && nm_device_is_software (self)) {
+ gs_free NMConfigDeviceStateData *dev_state = NULL;
+
+ dev_state = nm_config_device_state_load (priv->ifindex);
+ if (dev_state && dev_state->nm_owned == TRUE) {
+ priv->nm_owned = TRUE;
+ _LOGD (LOGD_DEVICE, "set nm-owned from state file");
+ }
+ }
+
if (!priv->udi) {
/* Use a placeholder UDI until we get a real one */
priv->udi = g_strdup_printf ("/virtual/device/placeholder/%d", id++);
@@ -8619,9 +8632,9 @@ _update_ip4_address (NMDevice *self)
}
gboolean
-nm_device_get_is_nm_owned (NMDevice *self)
+nm_device_is_nm_owned (NMDevice *self)
{
- return NM_DEVICE_GET_PRIVATE (self)->is_nm_owned;
+ return NM_DEVICE_GET_PRIVATE (self)->nm_owned;
}
/*
@@ -8682,7 +8695,7 @@ delete_on_deactivate_check_and_schedule (NMDevice *self, int ifindex)
if (ifindex <= 0)
return;
- if (!priv->is_nm_owned)
+ if (!priv->nm_owned)
return;
if (priv->queued_act_request)
return;
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index b5c933c94e..8c099508bf 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -606,7 +606,7 @@ void nm_device_set_unmanaged_by_user_settings (NMDevice *self);
void nm_device_set_unmanaged_by_user_udev (NMDevice *self);
void nm_device_set_unmanaged_by_quitting (NMDevice *device);
-gboolean nm_device_get_is_nm_owned (NMDevice *device);
+gboolean nm_device_is_nm_owned (NMDevice *device);
gboolean nm_device_has_capability (NMDevice *self, NMDeviceCapabilities caps);
diff --git a/src/nm-config.c b/src/nm-config.c
index dc4e18f93c..608ef23e1f 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -1872,6 +1872,7 @@ _nm_config_state_set (NMConfig *self,
#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_MANAGED "managed"
#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_PERM_HW_ADDR_FAKE "perm-hw-addr-fake"
#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_CONNECTION_UUID "connection-uuid"
+#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED "nm-owned"
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_device_state_managed_type_to_str, NMConfigDeviceStateManagedType,
NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT ("unknown"),
@@ -1889,6 +1890,7 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
gs_free char *perm_hw_addr_fake = NULL;
gsize connection_uuid_len;
gsize perm_hw_addr_fake_len;
+ gint nm_owned = -1;
char *p;
nm_assert (ifindex > 0);
@@ -1924,6 +1926,11 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
g_free (perm_hw_addr_fake);
perm_hw_addr_fake = normalized;
}
+
+ nm_owned = nm_config_keyfile_get_boolean (kf,
+ DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
+ DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED,
+ -1);
}
connection_uuid_len = connection_uuid ? strlen (connection_uuid) + 1 : 0;
@@ -1937,6 +1944,7 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
device_state->managed = managed_type;
device_state->connection_uuid = NULL;
device_state->perm_hw_addr_fake = NULL;
+ device_state->nm_owned = nm_owned;
p = (char *) (&device_state[1]);
if (connection_uuid) {
@@ -1966,6 +1974,7 @@ nm_config_device_state_load (int ifindex)
NMConfigDeviceStateData *device_state;
char path[NM_STRLEN (NM_CONFIG_DEVICE_STATE_DIR) + 60];
gs_unref_keyfile GKeyFile *kf = NULL;
+ const char *nm_owned_str;
g_return_val_if_fail (ifindex > 0, NULL);
@@ -1976,13 +1985,18 @@ nm_config_device_state_load (int ifindex)
g_clear_pointer (&kf, g_key_file_unref);
device_state = _config_device_state_data_new (ifindex, kf);
+ nm_owned_str = device_state->nm_owned == TRUE ?
+ ", nm-owned=1" :
+ (device_state->nm_owned == FALSE ? ", nm-owned=0" : "");
+
- _LOGT ("device-state: %s #%d (%s); managed=%s%s%s%s%s%s%s",
+ _LOGT ("device-state: %s #%d (%s); managed=%s%s%s%s%s%s%s%s",
kf ? "read" : "miss",
ifindex, path,
_device_state_managed_type_to_str (device_state->managed),
NM_PRINT_FMT_QUOTED (device_state->connection_uuid, ", connection-uuid=", device_state->connection_uuid, "", ""),
- NM_PRINT_FMT_QUOTED (device_state->perm_hw_addr_fake, ", perm-hw-addr-fake=", device_state->perm_hw_addr_fake, "", ""));
+ NM_PRINT_FMT_QUOTED (device_state->perm_hw_addr_fake, ", perm-hw-addr-fake=", device_state->perm_hw_addr_fake, "", ""),
+ nm_owned_str);
return device_state;
}
@@ -1991,7 +2005,8 @@ gboolean
nm_config_device_state_write (int ifindex,
NMConfigDeviceStateManagedType managed,
const char *perm_hw_addr_fake,
- const char *connection_uuid)
+ const char *connection_uuid,
+ gint nm_owned)
{
char path[NM_STRLEN (NM_CONFIG_DEVICE_STATE_DIR) + 60];
GError *local = NULL;
@@ -2026,6 +2041,13 @@ nm_config_device_state_write (int ifindex,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_CONNECTION_UUID,
connection_uuid);
}
+ if (nm_owned >= 0) {
+ g_key_file_set_boolean (kf,
+ DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
+ DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED,
+ nm_owned);
+ }
+
if (!g_key_file_save_to_file (kf, path, &local)) {
_LOGW ("device-state: write #%d (%s) failed: %s", ifindex, path, local->message);
diff --git a/src/nm-config.h b/src/nm-config.h
index ae695fcbf5..c5ff7c67d6 100644
--- a/src/nm-config.h
+++ b/src/nm-config.h
@@ -205,13 +205,18 @@ struct _NMConfigDeviceStateData {
const char *connection_uuid;
const char *perm_hw_addr_fake;
+
+ /* whether the device was nm-owned (0/1) or -1 for
+ * non-software devices. */
+ gint nm_owned;
};
NMConfigDeviceStateData *nm_config_device_state_load (int ifindex);
gboolean nm_config_device_state_write (int ifindex,
NMConfigDeviceStateManagedType managed,
const char *perm_hw_addr_fake,
- const char *connection_uuid);
+ const char *connection_uuid,
+ gint nm_owned);
void nm_config_device_state_prune_unseen (GHashTable *seen_ifindexes);
/*****************************************************************************/
diff --git a/src/nm-manager.c b/src/nm-manager.c
index e902a3e3dc..8d1bf320f3 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -1841,7 +1841,7 @@ recheck_assume_connection (NMManager *self,
g_return_val_if_fail (NM_IS_MANAGER (self), FALSE);
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
- if (nm_device_get_is_nm_owned (device))
+ if (nm_device_is_nm_owned (device))
return FALSE;
if (!nm_device_get_managed (device, FALSE))
@@ -4987,6 +4987,7 @@ nm_manager_write_device_state (NMManager *self)
const GSList *devices;
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
gs_unref_hashtable GHashTable *seen_ifindexes = NULL;
+ gint nm_owned;
seen_ifindexes = g_hash_table_new (NULL, NULL);
@@ -5026,10 +5027,13 @@ nm_manager_write_device_state (NMManager *self)
if (perm_hw_addr_fake && !perm_hw_addr_is_fake)
perm_hw_addr_fake = NULL;
+ nm_owned = nm_device_is_software (device) ? nm_device_is_nm_owned (device) : -1;
+
if (nm_config_device_state_write (ifindex,
managed_type,
perm_hw_addr_fake,
- uuid))
+ uuid,
+ nm_owned))
g_hash_table_add (seen_ifindexes, GINT_TO_POINTER (ifindex));
}