Re: [PATCH 3/3] bonding: Apply bonding settings when setting up bonding device
- From: Dan Williams <dcbw redhat com>
- To: Thomas Graf <tgraf redhat com>
- Cc: networkmanager-list gnome org
- Subject: Re: [PATCH 3/3] bonding: Apply bonding settings when setting up bonding device
- Date: Wed, 09 Nov 2011 12:16:42 -0600
On Wed, 2011-11-09 at 11:22 +0100, Thomas Graf wrote:
> Adds a new function nm_system_apply_bonding_config() which applies
> the parameters specified in the NMSettingBond object via sysfs.
>
> Calls that function after creating/updating the bonding master
> device.
>
> If a parameter is not specified in the ifcfg the parameter will be
> re-initialized to the default value. This may overwrite changes
> which have been done manually via sysfs but it is the only reliable
> way of setting up the bond.
>
> Supported parameters for now:
> - mode (default: balance-rr)
> - miimon (default: 100)
> - updelay (default: 0)
> - downdelay (default: 0)
> - arp_interval (default: 0)
> - arp_ip_target (default: none)
Hmm, is there no way to do this via netlink yet?
Dan
> Thomas Graf <tgraf redhat com>
> ---
> src/nm-system.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> src/nm-system.h | 1 +
> 2 files changed, 71 insertions(+), 0 deletions(-)
>
> diff --git a/src/nm-system.c b/src/nm-system.c
> index 3317eb4..cdfd4da 100644
> --- a/src/nm-system.c
> +++ b/src/nm-system.c
> @@ -1216,6 +1216,74 @@ nm_system_device_set_priority (int ifindex,
> }
> }
>
> +static gboolean
> +set_bond_attr (const char *iface, const char *attr, const char *value)
> +{
> + char file[FILENAME_MAX];
> + gboolean ret;
> +
> + snprintf (file, sizeof(file), "/sys/class/net/%s/bonding/%s",
> + iface, attr);
> +
> + ret = nm_utils_do_sysctl (file, value);
> + if (!ret)
> + nm_log_warn (LOGD_HW, "(%s): failed to set bonding attribute "
> + "'%s' to '%s'", iface, attr, value);
> +
> + return ret;
> +}
> +
> +static gboolean
> +set_bond_attr_int (const char *iface, const char *attr,
> + guint32 value)
> +{
> + char buf[128];
> +
> + snprintf (buf, sizeof(buf), "%u", value);
> +
> + return set_bond_attr (iface, attr, buf);
> +}
> +
> +gboolean
> +nm_system_apply_bonding_config (NMSettingBond *s_bond)
> +{
> + const char *name, *val;
> +
> + name = nm_setting_bond_get_interface_name (s_bond);
> + g_assert (name);
> +
> + if ((val = nm_setting_bond_get_mode (s_bond)))
> + set_bond_attr (name, "mode", val);
> +
> + /*
> + * FIXME:
> + *
> + * ifup-eth contains code to append targets if the value is prefixed
> + * with '+':
> + *
> + * if [ "${key}" = "arp_ip_target" -a "${value:0:1}" != "+" ]; then
> + * OLDIFS=$IFS;
> + * IFS=',';
> + * for arp_ip in $value; do
> + * if ! grep -q $arp_ip /sys/class/net/${DEVICE}/bonding/$key; then
> + * echo +$arp_ip > /sys/class/net/${DEVICE}/bonding/$key
> + * fi
> + * done
> + *
> + * Not sure if this is actually being used and it seems dangerous as
> + * the result is pretty much unforeseeable.
> + */
> + if ((val = nm_setting_bond_get_arp_ip_target (s_bond)))
> + set_bond_attr (name, "arp_ip_target", val);
> +
> + set_bond_attr_int (name, "miimon", nm_setting_bond_get_miimon (s_bond));
> + set_bond_attr_int (name, "downdelay", nm_setting_bond_get_downdelay (s_bond));
> + set_bond_attr_int (name, "updelay", nm_setting_bond_get_updelay (s_bond));
> + set_bond_attr_int (name, "arp_interval", nm_setting_bond_get_arp_interval (s_bond));
> +
> + return TRUE;
> +}
> +
> /**
> * nm_system_add_bonding_master:
> * @setting: bonding setting
> @@ -1244,6 +1312,8 @@ nm_system_add_bonding_master (NMSettingBond *setting)
> return FALSE;
> }
>
> + nm_system_apply_bonding_config (setting);
> +
> return TRUE;
> }
>
> diff --git a/src/nm-system.h b/src/nm-system.h
> index f151e90..aa175a6 100644
> --- a/src/nm-system.h
> +++ b/src/nm-system.h
> @@ -91,6 +91,7 @@ gboolean nm_system_iface_set_mtu (int ifindex, guint32 mtu);
>
> gboolean nm_system_iface_set_mac (int ifindex, const struct ether_addr *mac);
>
> +gboolean nm_system_apply_bonding_config (NMSettingBond *s_bond);
> gboolean nm_system_add_bonding_master (NMSettingBond *setting);
> gboolean nm_system_iface_enslave (NMDevice *slave, NMDevice *master);
> gboolean nm_system_iface_release (NMDevice *slave, NMDevice *master);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]