device: make detach_port() method asynchronous

This changes the signature of detach_port() to be asynchronous,
similarly to attach_port(). The implementation can return TRUE/FALSE
on immediate completion.

Current implementations return immediately and so there is no change
in behavior for now.
This commit is contained in:
Beniamino Galvani 2023-03-06 15:49:43 +01:00
parent de8104c71c
commit 82d0fa2a87
8 changed files with 76 additions and 19 deletions

View file

@ -695,8 +695,13 @@ attach_port(NMDevice *device,
return TRUE;
}
static void
detach_port(NMDevice *device, NMDevice *port, gboolean configure)
static NMTernary
detach_port(NMDevice *device,
NMDevice *port,
gboolean configure,
GCancellable *cancellable,
NMDeviceAttachPortCallback callback,
gpointer user_data)
{
NMDeviceBond *self = NM_DEVICE_BOND(device);
gboolean success;
@ -758,6 +763,8 @@ detach_port(NMDevice *device, NMDevice *port, gboolean configure)
_LOGI(LOGD_BOND, "bond port %s was detached", nm_device_get_ip_iface(port));
}
}
return TRUE;
}
static gboolean

View file

@ -1052,8 +1052,13 @@ attach_port(NMDevice *device,
return TRUE;
}
static void
detach_port(NMDevice *device, NMDevice *port, gboolean configure)
static NMTernary
detach_port(NMDevice *device,
NMDevice *port,
gboolean configure,
GCancellable *cancellable,
NMDeviceAttachPortCallback callback,
gpointer user_data)
{
NMDeviceBridge *self = NM_DEVICE_BRIDGE(device);
gboolean success;
@ -1070,7 +1075,7 @@ detach_port(NMDevice *device, NMDevice *port, gboolean configure)
if (ifindex_slave <= 0) {
_LOGD(LOGD_TEAM, "bridge port %s is already detached", nm_device_get_ip_iface(port));
return;
return TRUE;
}
if (configure) {
@ -1086,6 +1091,8 @@ detach_port(NMDevice *device, NMDevice *port, gboolean configure)
} else {
_LOGI(LOGD_BRIDGE, "bridge port %s was detached", nm_device_get_ip_iface(port));
}
return TRUE;
}
static gboolean

View file

@ -241,8 +241,13 @@ attach_port(NMDevice *device,
return TRUE;
}
static void
detach_port(NMDevice *device, NMDevice *port, gboolean configure)
static NMTernary
detach_port(NMDevice *device,
NMDevice *port,
gboolean configure,
GCancellable *cancellable,
NMDeviceAttachPortCallback callback,
gpointer user_data)
{
NMDeviceVrf *self = NM_DEVICE_VRF(device);
gboolean success;
@ -277,6 +282,8 @@ detach_port(NMDevice *device, NMDevice *port, gboolean configure)
_LOGI(LOGD_DEVICE, "VRF port %s was detached", nm_device_get_ip_iface(port));
}
}
return TRUE;
}
/*****************************************************************************/

View file

@ -6402,10 +6402,17 @@ nm_device_master_release_slave(NMDevice *self,
/* first, let subclasses handle the release ... */
if (info->slave_is_enslaved || nm_device_sys_iface_state_is_external(slave)
|| release_type >= RELEASE_SLAVE_TYPE_CONFIG_FORCE)
NM_DEVICE_GET_CLASS(self)->detach_port(self,
slave,
release_type >= RELEASE_SLAVE_TYPE_CONFIG);
|| release_type >= RELEASE_SLAVE_TYPE_CONFIG_FORCE) {
NMTernary ret;
ret = NM_DEVICE_GET_CLASS(self)->detach_port(self,
slave,
release_type >= RELEASE_SLAVE_TYPE_CONFIG,
NULL,
NULL,
NULL);
nm_assert(NM_IN_SET(ret, TRUE, FALSE));
}
/* raise notifications about the release, including clearing is_enslaved. */
nm_device_slave_notify_release(slave, reason, release_type);

View file

@ -389,7 +389,15 @@ typedef struct _NMDeviceClass {
GCancellable *cancellable,
NMDeviceAttachPortCallback callback,
gpointer user_data);
void (*detach_port)(NMDevice *self, NMDevice *port, gboolean configure);
/* This works similarly to attach_port(). However, current
* implementations don't report errors and so the only possible
* return values are TRUE and DEFAULT. */
NMTernary (*detach_port)(NMDevice *self,
NMDevice *port,
gboolean configure,
GCancellable *cancellable,
NMDeviceAttachPortCallback callback,
gpointer user_data);
void (*parent_changed_notify)(NMDevice *self,
int old_ifindex,

View file

@ -97,9 +97,16 @@ attach_port(NMDevice *device,
return TRUE;
}
static void
detach_port(NMDevice *device, NMDevice *port, gboolean configure)
{}
static NMTernary
detach_port(NMDevice *device,
NMDevice *port,
gboolean configure,
GCancellable *cancellable,
NMDeviceAttachPortCallback callback,
gpointer user_data)
{
return TRUE;
}
void
nm_device_ovs_reapply_connection(NMDevice *self, NMConnection *con_old, NMConnection *con_new)

View file

@ -221,8 +221,13 @@ del_iface_cb(GError *error, gpointer user_data)
g_object_unref(slave);
}
static void
detach_port(NMDevice *device, NMDevice *port, gboolean configure)
static NMTernary
detach_port(NMDevice *device,
NMDevice *port,
gboolean configure,
GCancellable *cancellable,
NMDeviceAttachPortCallback callback,
gpointer user_data)
{
NMDeviceOvsPort *self = NM_DEVICE_OVS_PORT(device);
bool port_not_managed = !NM_IN_SET(nm_device_sys_iface_state_get(port),
@ -248,6 +253,8 @@ detach_port(NMDevice *device, NMDevice *port, gboolean configure)
if (NM_IS_DEVICE_OVS_INTERFACE(port))
nm_device_update_from_platform_link(port, NULL);
}
return TRUE;
}
/*****************************************************************************/

View file

@ -913,8 +913,13 @@ attach_port(NMDevice *device,
return TRUE;
}
static void
detach_port(NMDevice *device, NMDevice *port, gboolean configure)
static NMTernary
detach_port(NMDevice *device,
NMDevice *port,
gboolean configure,
GCancellable *cancellable,
NMDeviceAttachPortCallback callback,
gpointer user_data)
{
NMDeviceTeam *self = NM_DEVICE_TEAM(device);
NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self);
@ -964,6 +969,8 @@ detach_port(NMDevice *device, NMDevice *port, gboolean configure)
_update_port_config(self, port_iface, "{}");
g_hash_table_remove(priv->port_configs, port_iface);
}
return TRUE;
}
static gboolean