sriov: only valid sriov capacity when enabled

NetworkManager current code will refuse to activate a connection if its
interface has no SRIOV capacity but holding a empty SRIOV settings.

This patch only valid SRIOV capacity when it is enabled(total_vfs > 0).

Resolves: https://issues.redhat.com/browse/RHEL-58397

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit 421ccf8b4c)
(cherry picked from commit c9e31e70cb)
(cherry picked from commit 90a3b01468)
(cherry picked from commit 296fc53ea8)
(cherry picked from commit 2ad9fa82f4)
This commit is contained in:
Gris Ge 2024-10-21 21:13:29 +08:00 committed by Fernando Fernandez Mancera
parent 0663f56cbe
commit 485529ca6f

View file

@ -8806,6 +8806,7 @@ check_connection_compatible(NMDevice *self, NMConnection *connection, GError **e
NMSettingMatch *s_match; NMSettingMatch *s_match;
const GSList *specs; const GSList *specs;
gboolean has_match = FALSE; gboolean has_match = FALSE;
NMSettingSriov *s_sriov = NULL;
klass = NM_DEVICE_GET_CLASS(self); klass = NM_DEVICE_GET_CLASS(self);
if (klass->connection_type_check_compatible) { if (klass->connection_type_check_compatible) {
@ -8823,12 +8824,14 @@ check_connection_compatible(NMDevice *self, NMConnection *connection, GError **e
return FALSE; return FALSE;
} }
if (!nm_device_has_capability(self, NM_DEVICE_CAP_SRIOV) if (!nm_device_has_capability(self, NM_DEVICE_CAP_SRIOV)) {
&& nm_connection_get_setting(connection, NM_TYPE_SETTING_SRIOV)) { s_sriov = (NMSettingSriov *) nm_connection_get_setting(connection, NM_TYPE_SETTING_SRIOV);
nm_utils_error_set_literal(error, if (s_sriov && nm_setting_sriov_get_total_vfs(s_sriov)) {
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, nm_utils_error_set_literal(error,
"device does not support SR-IOV"); NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
return FALSE; "device does not support SR-IOV");
return FALSE;
}
} }
conn_iface = nm_manager_get_connection_iface(NM_MANAGER_GET, connection, NULL, NULL, &local); conn_iface = nm_manager_get_connection_iface(NM_MANAGER_GET, connection, NULL, NULL, &local);
@ -9435,7 +9438,7 @@ activate_stage1_device_prepare(NMDevice *self)
s_sriov = nm_device_get_applied_setting(self, NM_TYPE_SETTING_SRIOV); s_sriov = nm_device_get_applied_setting(self, NM_TYPE_SETTING_SRIOV);
} }
if (s_sriov) { if (s_sriov && nm_device_has_capability(self, NM_DEVICE_CAP_SRIOV)) {
nm_auto_freev NMPlatformVF **plat_vfs = NULL; nm_auto_freev NMPlatformVF **plat_vfs = NULL;
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
NMSriovVF *vf; NMSriovVF *vf;
@ -9443,8 +9446,6 @@ activate_stage1_device_prepare(NMDevice *self)
guint num; guint num;
guint i; guint i;
nm_assert(nm_device_has_capability(self, NM_DEVICE_CAP_SRIOV));
autoprobe = nm_setting_sriov_get_autoprobe_drivers(s_sriov); autoprobe = nm_setting_sriov_get_autoprobe_drivers(s_sriov);
if (autoprobe == NM_TERNARY_DEFAULT) { if (autoprobe == NM_TERNARY_DEFAULT) {
autoprobe = nm_config_data_get_connection_default_int64( autoprobe = nm_config_data_get_connection_default_int64(