From bbc172a91976787a0623c8bad7aa8dc8c00f9d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Wed, 5 Mar 2014 10:05:25 +0100 Subject: [PATCH 1/3] team: do not free config got from teamd The config is owned by teamd and will be freed by teamdctl_free(). Also use teamdctl_config_get_raw_direct() instead of teamdctl_config_get_raw() to be sure we have current data. --- src/devices/nm-device-team.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/devices/nm-device-team.c b/src/devices/nm-device-team.c index df37cee308..f9ca440c0e 100644 --- a/src/devices/nm-device-team.c +++ b/src/devices/nm-device-team.c @@ -230,17 +230,19 @@ update_connection (NMDevice *device, NMConnection *connection) nm_connection_add_setting (connection, (NMSetting *) s_team); g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_INTERFACE_NAME, iface, NULL); } + g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_CONFIG, NULL, NULL); #if WITH_TEAMDCTL if (ensure_teamd_connection (device)) { - char *config; + const char *config = NULL; + int err; - config = teamdctl_config_get_raw (NM_DEVICE_TEAM_GET_PRIVATE (device)->tdc); - if (config) + err = teamdctl_config_get_raw_direct (NM_DEVICE_TEAM_GET_PRIVATE (device)->tdc, + (char **)&config); + if (err == 0) g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_CONFIG, config, NULL); else - nm_log_err (LOGD_TEAM, "(%s): failed to read teamd config", iface); - g_free (config); + nm_log_err (LOGD_TEAM, "(%s): failed to read teamd config (err=%d)", iface, err); } #endif } From 94d0d30e95eb7b1ab6ce636b011f0f9081e38ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 27 Feb 2014 16:13:20 +0100 Subject: [PATCH 2/3] team: read team port config in nm_team_update_slave_connection() (rh #1035859) Without reading team port config we would fail to assume team slaves. libteam provides teamdctl_port_config_get_raw_direct() from 1.9 up See https://bugzilla.redhat.com/show_bug.cgi?id=1028138 https://bugzilla.redhat.com/show_bug.cgi?id=1035859 --- configure.ac | 2 +- src/devices/nm-device-team.c | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index a7f60ff616..b20f2dc639 100644 --- a/configure.ac +++ b/configure.ac @@ -396,7 +396,7 @@ fi AM_CONDITIONAL(WITH_WIMAX, test "${enable_wimax}" = "yes") # Teamd control checks -PKG_CHECK_MODULES(LIBTEAMDCTL, [libteamdctl], [have_teamdctl=yes],[have_teamdctl=no]) +PKG_CHECK_MODULES(LIBTEAMDCTL, [libteamdctl >= 1.9], [have_teamdctl=yes],[have_teamdctl=no]) AC_ARG_ENABLE(teamdctl, AS_HELP_STRING([--enable-teamdctl], [enable Teamd control support]), [enable_teamdctl=${enableval}], [enable_teamdctl=${have_teamdctl}]) if (test "${enable_teamdctl}" = "yes"); then diff --git a/src/devices/nm-device-team.c b/src/devices/nm-device-team.c index f9ca440c0e..256d872e02 100644 --- a/src/devices/nm-device-team.c +++ b/src/devices/nm-device-team.c @@ -255,12 +255,13 @@ nm_team_update_slave_connection (NMDevice *slave, NMConnection *connection) NMSettingTeamPort *s_port; const char *iface = nm_device_get_iface (slave); char *port_config = NULL; - gboolean success = FALSE; + gboolean with_teamdctl = FALSE; + int err = 0; #if WITH_TEAMDCTL const char *master_iface; int master_ifindex; struct teamdctl *tdc; - int err; + const char *team_port_config = NULL; #endif g_return_val_if_fail (NM_IS_DEVICE (slave), FALSE); @@ -276,14 +277,15 @@ nm_team_update_slave_connection (NMDevice *slave, NMConnection *connection) g_assert (tdc); err = teamdctl_connect (tdc, master_iface, NULL, NULL); if (err) { - nm_log_err (LOGD_TEAM, "(%s): failed to connect to teamd for master %s", - iface, master_iface); + nm_log_err (LOGD_TEAM, "(%s): failed to connect to teamd for master %s (err=%d)", + iface, master_iface, err); teamdctl_free (tdc); return FALSE; } - /* FIXME: wait for libteamd to implement getting port config */ -/* port_config = teamdctl_port_config_get_raw (tdc, iface); */ + err = teamdctl_port_config_get_raw_direct (tdc, iface, (char **)&team_port_config); + port_config = g_strdup (team_port_config); teamdctl_free (tdc); + with_teamdctl = TRUE; #endif s_port = nm_connection_get_setting_team_port (connection); @@ -292,14 +294,20 @@ nm_team_update_slave_connection (NMDevice *slave, NMConnection *connection) nm_connection_add_setting (connection, NM_SETTING (s_port)); } - if (port_config) { - g_object_set (G_OBJECT (s_port), NM_SETTING_TEAM_PORT_CONFIG, port_config, NULL); - free (port_config); - success = TRUE; - } else - nm_log_err (LOGD_TEAM, "(%s): failed to read teamd port configuration", iface); + g_object_set (G_OBJECT (s_port), NM_SETTING_TEAM_PORT_CONFIG, port_config, NULL); + g_free (port_config); - return success; + if (!with_teamdctl || err != 0) { + if (!with_teamdctl) + nm_log_err (LOGD_TEAM, "(%s): failed to read teamd port configuration " + " (compiled without libteamdctl support)", iface); + else + nm_log_err (LOGD_TEAM, "(%s): failed to read teamd port configuration (err=%d)", + iface, err); + return FALSE; + } + + return TRUE; } /******************************************************************/ From 2b2f8e907ec74147fb7e72ee1c299f9928ae56e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Wed, 5 Mar 2014 11:13:00 +0100 Subject: [PATCH 3/3] team: log error codes from teamd functions on failure --- src/devices/nm-device-team.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/devices/nm-device-team.c b/src/devices/nm-device-team.c index 256d872e02..1cc7641f3c 100644 --- a/src/devices/nm-device-team.c +++ b/src/devices/nm-device-team.c @@ -209,8 +209,9 @@ ensure_teamd_connection (NMDevice *self) priv->tdc = teamdctl_alloc (); g_assert (priv->tdc); err = teamdctl_connect (priv->tdc, nm_device_get_iface (self), NULL, NULL); - if (err) { - nm_log_err (LOGD_TEAM, "(%s): failed to connect to teamd", nm_device_get_iface (self)); + if (err != 0) { + nm_log_err (LOGD_TEAM, "(%s): failed to connect to teamd (err=%d)", + nm_device_get_iface (self), err); teamdctl_free (priv->tdc); priv->tdc = NULL; } @@ -680,8 +681,9 @@ enslave_slave (NMDevice *device, int err; err = teamdctl_port_config_update_raw (priv->tdc, slave_iface, config); - if (err) { - nm_log_err (LOGD_TEAM, "(%s): failed to update config for port %s", iface, slave_iface); + if (err != 0) { + nm_log_err (LOGD_TEAM, "(%s): failed to update config for port %s (err=%d)", + iface, slave_iface, err); return FALSE; } }