From e3924a3ab6fa0e0d9d1369ce9a4d4d8a7c31e6bd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 26 Aug 2021 17:33:22 +0200 Subject: [PATCH] ifcfg-rh: refactor write_bond_port_setting() and always write queue-id - the writer/reader should be lossless. There is a difference on whether a NMConnection has/hasn't a NMSettingBondPort instance. If we thus have a NMSettingBondPort, we must always encode that in the ifcfg file, by writing BOND_PORT_QUEUE_ID=0. Otherwise, the reader will not create the setting. - it's really not the task of the writer to validate what it writes. All these write_bridge_port_setting() really should not fail. They should serialize the setting as good as they can. And if they cannot, it's probably a bug in the writer (by not being lossless). write_bond_port_setting() did not ever fail. It should not ever fail. So don't let the function return a potential failure, and don't handle a failure that should never happen. --- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 9c5676f872..b648d5be6a 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -1889,24 +1889,14 @@ write_bridge_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **e return TRUE; } -static gboolean -write_bond_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) +static void +write_bond_port_setting(NMConnection *connection, shvarFile *ifcfg) { - NMSettingBondPort *s_port = NULL; - guint16 queue_id = NM_BOND_PORT_QUEUE_ID_DEF; + NMSettingBondPort *s_port; s_port = _nm_connection_get_setting_bond_port(connection); - if (!s_port) - return TRUE; - - queue_id = nm_setting_bond_port_get_queue_id(s_port); - if (queue_id - != get_setting_default_checked_uint(NM_BOND_PORT_QUEUE_ID_DEF, - s_port, - NM_SETTING_BOND_PORT_QUEUE_ID)) - svSetValueInt64(ifcfg, "BOND_PORT_QUEUE_ID", queue_id); - - return TRUE; + if (s_port) + svSetValueInt64(ifcfg, "BOND_PORT_QUEUE_ID", nm_setting_bond_port_get_queue_id(s_port)); } static gboolean @@ -3391,8 +3381,7 @@ do_write_construct(NMConnection * connection, if (!write_bridge_port_setting(connection, ifcfg, error)) return FALSE; - if (!write_bond_port_setting(connection, ifcfg, error)) - return FALSE; + write_bond_port_setting(connection, ifcfg); if (!write_team_port_setting(connection, ifcfg, error)) return FALSE;