summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2023-03-08 11:29:17 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2023-04-04 08:21:22 +0200
commitfc132158267e1b7f6d78684ac61b5bc3db3dbf6d (patch)
tree61c0c9e7004bce1d36c6513d9664bb0a63179575
parent07dc237e5ccb4bbe51a5c1e3fd232446a3b98ade (diff)
downloadNetworkManager-bg/rh2054933.tar.gz
ovs: implement asynchronous detach_port()bg/rh2054933
Make detach_port() return only after ovsdb reports that the operation finished.
-rw-r--r--src/core/devices/ovs/nm-device-ovs-port.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/core/devices/ovs/nm-device-ovs-port.c b/src/core/devices/ovs/nm-device-ovs-port.c
index f9b24ee5ac..5ede46e99f 100644
--- a/src/core/devices/ovs/nm-device-ovs-port.c
+++ b/src/core/devices/ovs/nm-device-ovs-port.c
@@ -78,10 +78,11 @@ typedef struct {
GCancellable *cancellable;
NMDeviceAttachPortCallback callback;
gpointer callback_user_data;
+ gboolean add;
} AttachPortData;
static void
-add_iface_cb(GError *error, gpointer user_data)
+add_del_iface_cb(GError *error, gpointer user_data)
{
AttachPortData *data = user_data;
NMDeviceOvsPort *self;
@@ -93,15 +94,17 @@ add_iface_cb(GError *error, gpointer user_data)
} else if (error && !nm_utils_error_is_cancelled_or_disposing(error)) {
self = NM_DEVICE_OVS_PORT(data->device);
_LOGW(LOGD_DEVICE,
- "device %s could not be added to a ovs port: %s",
+ "device %s could not be %s a ovs port: %s",
nm_device_get_iface(data->port),
+ data->add ? "added to" : "removed from",
error->message);
nm_device_state_changed(data->port,
NM_DEVICE_STATE_FAILED,
NM_DEVICE_STATE_REASON_OVSDB_FAILED);
}
- data->callback(data->device, error, data->callback_user_data);
+ if (data->callback)
+ data->callback(data->device, error, data->callback_user_data);
g_object_unref(data->device);
g_object_unref(data->port);
@@ -178,6 +181,7 @@ attach_port(NMDevice *device,
.cancellable = g_object_ref(cancellable),
.callback = callback,
.callback_user_data = user_data,
+ .add = TRUE,
};
nm_ovsdb_add_interface(nm_ovsdb_get(),
@@ -186,7 +190,7 @@ attach_port(NMDevice *device,
nm_device_get_applied_connection(port),
bridge_device,
port,
- add_iface_cb,
+ add_del_iface_cb,
data);
/* DPDK ports does not have a link after the devbind, so the MTU must be
@@ -205,22 +209,6 @@ attach_port(NMDevice *device,
return NM_TERNARY_DEFAULT;
}
-static void
-del_iface_cb(GError *error, gpointer user_data)
-{
- NMDevice *slave = user_data;
-
- if (error && !g_error_matches(error, NM_UTILS_ERROR, NM_UTILS_ERROR_CANCELLED_DISPOSING)) {
- nm_log_warn(LOGD_DEVICE,
- "device %s could not be removed from a ovs port: %s",
- nm_device_get_iface(slave),
- error->message);
- nm_device_state_changed(slave, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_OVSDB_FAILED);
- }
-
- g_object_unref(slave);
-}
-
static NMTernary
detach_port(NMDevice *device,
NMDevice *port,
@@ -233,6 +221,7 @@ detach_port(NMDevice *device,
bool port_not_managed = !NM_IN_SET(nm_device_sys_iface_state_get(port),
NM_DEVICE_SYS_IFACE_STATE_MANAGED,
NM_DEVICE_SYS_IFACE_STATE_ASSUME);
+ NMTernary ret = TRUE;
_LOGI(LOGD_DEVICE, "detaching ovs interface %s", nm_device_get_ip_iface(port));
@@ -241,10 +230,20 @@ detach_port(NMDevice *device,
* to make sure its OVSDB entry is gone.
*/
if (configure || port_not_managed) {
- nm_ovsdb_del_interface(nm_ovsdb_get(),
- nm_device_get_iface(port),
- del_iface_cb,
- g_object_ref(port));
+ AttachPortData *data;
+
+ data = g_slice_new(AttachPortData);
+ *data = (AttachPortData){
+ .device = g_object_ref(device),
+ .port = g_object_ref(port),
+ .cancellable = nm_g_object_ref(cancellable),
+ .callback = callback,
+ .callback_user_data = user_data,
+ .add = FALSE,
+ };
+
+ nm_ovsdb_del_interface(nm_ovsdb_get(), nm_device_get_iface(port), add_del_iface_cb, data);
+ ret = NM_TERNARY_DEFAULT;
}
if (configure) {
@@ -254,7 +253,7 @@ detach_port(NMDevice *device,
nm_device_update_from_platform_link(port, NULL);
}
- return TRUE;
+ return ret;
}
/*****************************************************************************/