mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 18:58:05 +02:00
core: device: implement storing to disk for Device.SetManaged()
If the NM_DEVICE_MANAGED_FLAGS_PERMANENT flag is used, the value will be stored to disk, to the NetworkManager-intern.conf file, in a [device-*] section. To modify the runtime value, the NM_DEVICE_MANAGED_FLAGS_RUNTIME must be passed. This allows to control independently whether to modify only one or both.
This commit is contained in:
parent
a74d13bf96
commit
0d78e29289
4 changed files with 74 additions and 5 deletions
|
|
@ -397,10 +397,11 @@
|
||||||
<!--
|
<!--
|
||||||
SetManaged:
|
SetManaged:
|
||||||
@managed: Whether the device is managed.
|
@managed: Whether the device is managed.
|
||||||
@flags: Flags which would modify the behavior of the SetManaged call.
|
@flags: (<link linkend="NMDeviceManagedFlags">NMDeviceManagedFlags</link>) flags.
|
||||||
@since: 1.58
|
@since: 1.58
|
||||||
|
|
||||||
Set the managed state of the device.
|
Set the managed state of the device. With the flags argument different
|
||||||
|
behaviors can be achieved, like storing the new managed state to disk.
|
||||||
-->
|
-->
|
||||||
<method name="SetManaged">
|
<method name="SetManaged">
|
||||||
<arg name="managed" type="b" direction="in"/>
|
<arg name="managed" type="b" direction="in"/>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ src/core/NetworkManagerUtils.c
|
||||||
src/core/devices/adsl/nm-device-adsl.c
|
src/core/devices/adsl/nm-device-adsl.c
|
||||||
src/core/devices/bluetooth/nm-bluez-manager.c
|
src/core/devices/bluetooth/nm-bluez-manager.c
|
||||||
src/core/devices/bluetooth/nm-device-bt.c
|
src/core/devices/bluetooth/nm-device-bt.c
|
||||||
|
src/core/devices/nm-device.c
|
||||||
src/core/devices/nm-device-6lowpan.c
|
src/core/devices/nm-device-6lowpan.c
|
||||||
src/core/devices/nm-device-bond.c
|
src/core/devices/nm-device-bond.c
|
||||||
src/core/devices/nm-device-bridge.c
|
src/core/devices/nm-device-bridge.c
|
||||||
|
|
|
||||||
|
|
@ -14943,12 +14943,72 @@ typedef struct {
|
||||||
NMDeviceManagedFlags managed_flags;
|
NMDeviceManagedFlags managed_flags;
|
||||||
} SetManagedData;
|
} SetManagedData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set_managed:
|
||||||
|
* @self: the device
|
||||||
|
* @managed: the new managed state to set.
|
||||||
|
* @flags: flags to select different behaviors like storing to disk.
|
||||||
|
* @error: return location for a #GError, or %NULL
|
||||||
|
*
|
||||||
|
* Sets the managed state of the device. It can affect the runtime managed state
|
||||||
|
* if the %NM_DEVICE_MANAGED_FLAGS_RUNTIME is set, and to the value stored on disk
|
||||||
|
* (persistent across reboots) state if the %NM_DEVICE_MANAGED_FLAGS_PERMANENT is set.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the managed state was set successfully, %FALSE otherwise.
|
||||||
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
set_managed(NMDevice *self, gboolean managed, NMDeviceManagedFlags flags, GError **error)
|
set_managed(NMDevice *self, gboolean managed, NMDeviceManagedFlags flags, GError **error)
|
||||||
{
|
{
|
||||||
|
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||||
|
NMTernary old;
|
||||||
|
|
||||||
nm_assert((flags & ~NM_DEVICE_MANAGED_FLAGS_ALL) == 0);
|
nm_assert((flags & ~NM_DEVICE_MANAGED_FLAGS_ALL) == 0);
|
||||||
|
|
||||||
g_object_set(self, NM_DEVICE_MANAGED, managed, NULL);
|
if (!NM_FLAGS_ANY(flags, NM_DEVICE_MANAGED_FLAGS_PERMANENT | NM_DEVICE_MANAGED_FLAGS_RUNTIME)) {
|
||||||
|
g_set_error_literal(error,
|
||||||
|
NM_DEVICE_ERROR,
|
||||||
|
NM_DEVICE_ERROR_INVALID_ARGUMENT,
|
||||||
|
_("set managed: no permanent or runtime was selected"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & NM_DEVICE_MANAGED_FLAGS_PERMANENT) {
|
||||||
|
if (!nm_config_get_device_managed(nm_manager_get_config(priv->manager), self, &old, error))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (!nm_config_set_device_managed(nm_manager_get_config(priv->manager),
|
||||||
|
self,
|
||||||
|
managed,
|
||||||
|
flags & NM_DEVICE_MANAGED_FLAGS_BY_MAC,
|
||||||
|
error))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Update the unmanaged flags after the change on disk */
|
||||||
|
nm_device_set_unmanaged_by_user_conf(self);
|
||||||
|
|
||||||
|
if (!!nm_device_get_unmanaged_flags(self, NM_UNMANAGED_USER_CONF) != !managed) {
|
||||||
|
/* We failed to make the new state effective on disk. Maybe the new config
|
||||||
|
* collides with other config. Try to revert and return error. Otherwise,
|
||||||
|
* we would set the runtime state correctly, but get an unexpected state
|
||||||
|
* after a reboot. */
|
||||||
|
nm_config_set_device_managed(nm_manager_get_config(priv->manager),
|
||||||
|
self,
|
||||||
|
old,
|
||||||
|
flags & NM_DEVICE_MANAGED_FLAGS_BY_MAC,
|
||||||
|
NULL);
|
||||||
|
g_set_error(error,
|
||||||
|
NM_DEVICE_ERROR,
|
||||||
|
NM_DEVICE_ERROR_FAILED,
|
||||||
|
_("failed to persist 'managed=%d' on disk, other configurations may be "
|
||||||
|
"overriding it"),
|
||||||
|
managed);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & NM_DEVICE_MANAGED_FLAGS_RUNTIME) {
|
||||||
|
g_object_set(self, NM_DEVICE_MANAGED, !!managed, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1251,6 +1251,10 @@ typedef enum /*< flags >*/ {
|
||||||
/**
|
/**
|
||||||
* NMDeviceManagedFlags:
|
* NMDeviceManagedFlags:
|
||||||
* @NM_DEVICE_MANAGED_FLAGS_NONE: no flag set.
|
* @NM_DEVICE_MANAGED_FLAGS_NONE: no flag set.
|
||||||
|
* @NM_DEVICE_MANAGED_FLAGS_RUNTIME: to set the device managed state to the runtime value.
|
||||||
|
* @NM_DEVICE_MANAGED_FLAGS_PERMANENT: to set the device managed state to the permanent (on disk) value.
|
||||||
|
* @NM_DEVICE_MANAGED_FLAGS_BY_MAC: to match the device by MAC address, not by name.
|
||||||
|
* This option only makes sense together with %NM_DEVICE_MANAGED_FLAGS_PERMANENT.
|
||||||
* @NM_DEVICE_MANAGED_FLAGS_ALL: all flags.
|
* @NM_DEVICE_MANAGED_FLAGS_ALL: all flags.
|
||||||
*
|
*
|
||||||
* Flags for the SetManaged() D-Bus call of a device and nm_device_set_managed_async().
|
* Flags for the SetManaged() D-Bus call of a device and nm_device_set_managed_async().
|
||||||
|
|
@ -1258,9 +1262,12 @@ typedef enum /*< flags >*/ {
|
||||||
* Since: 1.58
|
* Since: 1.58
|
||||||
*/
|
*/
|
||||||
typedef enum /*< flags >*/ {
|
typedef enum /*< flags >*/ {
|
||||||
NM_DEVICE_MANAGED_FLAGS_NONE = 0,
|
NM_DEVICE_MANAGED_FLAGS_NONE = 0,
|
||||||
|
NM_DEVICE_MANAGED_FLAGS_RUNTIME = 0x1,
|
||||||
|
NM_DEVICE_MANAGED_FLAGS_PERMANENT = 0x2,
|
||||||
|
NM_DEVICE_MANAGED_FLAGS_BY_MAC = 0x4,
|
||||||
|
|
||||||
NM_DEVICE_MANAGED_FLAGS_ALL = 0, /* <skip> */
|
NM_DEVICE_MANAGED_FLAGS_ALL = 0x7, /* <skip> */
|
||||||
} NMDeviceManagedFlags;
|
} NMDeviceManagedFlags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue