Skip to content

Commit

Permalink
sriov: accept setting the eswitch mode without VFs
Browse files Browse the repository at this point in the history
The embedded switch mode can be set even if the interface doesn't have
any virtual functions. This is a requisite to use the PF with only
scalable functions for example.

With this change, the presence of the 'embedded-switch-mode' will be
enough to identify the interface as a PF and emit the systemd services
required to apply the configuration.

The changes required by the CLI will be done is the next commit.
  • Loading branch information
daniloegea committed Apr 15, 2024
1 parent dca7227 commit ef34695
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/sriov.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,18 @@ netplan_state_finish_sriov_write(const NetplanState* np_state, const char* rootd
GHashTable* rebind_pfs = g_hash_table_new(g_str_hash, g_str_equal);
GHashTable* apply_pfs = g_hash_table_new(g_str_hash, g_str_equal);

/* Find netdev interface names for SR-IOV PFs*/
/* Find netdev interface names for SR-IOV PFs
* We consider an interface to be a PF if at least of the conditions below is true:
* 1) the user explicitly set a desired number of VFs
* 2) there is at least one interface with a link to it (meaning the interface is a VF of this PF)
* 3) the user set the embedded-switch-mode (which can be applied regardless if the interface has VFs)
* */
for (GList* iterator = np_state->netdefs_ordered; iterator; iterator = iterator->next) {
def = (NetplanNetDefinition*) iterator->data;
pf = NULL;
if (def->sriov_explicit_vf_count < G_MAXUINT || def->sriov_link) {
if (def->sriov_explicit_vf_count < G_MAXUINT || def->sriov_link || def->embedded_switch_mode) {
any_sriov = TRUE;
if (def->sriov_explicit_vf_count < G_MAXUINT)
if (def->sriov_explicit_vf_count < G_MAXUINT || def->embedded_switch_mode)
pf = def;
else if (def->sriov_link)
pf = def->sriov_link;
Expand Down
7 changes: 4 additions & 3 deletions src/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,10 @@ validate_sriov_rules(const NetplanParser* npp, NetplanNetDefinition* nd, GError*
}
}
}
gboolean eswitch_mode = (nd->embedded_switch_mode ||
nd->sriov_delay_virtual_functions_rebind);
if (eswitch_mode && !is_sriov_pf) {
/* Does it set the eswitch mode? It can be set regardless if the interface has VFs */
if (nd->embedded_switch_mode)
is_sriov_pf = TRUE;
if (nd->sriov_delay_virtual_functions_rebind && !is_sriov_pf) {
valid = yaml_error(npp, node, error, "%s: This is not a SR-IOV PF", nd->id);
goto sriov_rules_error;
}
Expand Down
39 changes: 33 additions & 6 deletions tests/test_sriov.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,17 +1112,44 @@ def test_eswitch_mode(self):
Description=(Re-)bind SR-IOV Virtual Functions to their driver
After=network.target
After=netplan-sriov-apply.service
After=sys-subsystem-net-devices-enblue.device
After=sys-subsystem-net-devices-engreen.device
After=sys-subsystem-net-devices-enblue.device
[Service]
Type=oneshot
ExecStart=/usr/sbin/netplan rebind --debug enblue engreen
ExecStart=/usr/sbin/netplan rebind --debug engreen enblue
''', 'apply.service': '''[Unit]
Description=Apply SR-IOV configuration
DefaultDependencies=no
Before=network-pre.target
After=sys-subsystem-net-devices-engreen.device
After=sys-subsystem-net-devices-enblue.device
[Service]
Type=oneshot
ExecStart=/usr/sbin/netplan apply --sriov-only
'''})

def test_eswitch_mode_sets_interface_as_pf(self):
self.generate('''network:
version: 2
ethernets:
engreen:
embedded-switch-mode: switchdev
delay-virtual-functions-rebind: true''')
self.assert_sriov({'rebind.service': '''[Unit]
Description=(Re-)bind SR-IOV Virtual Functions to their driver
After=network.target
After=netplan-sriov-apply.service
After=sys-subsystem-net-devices-engreen.device
[Service]
Type=oneshot
ExecStart=/usr/sbin/netplan rebind --debug engreen
''', 'apply.service': '''[Unit]
Description=Apply SR-IOV configuration
DefaultDependencies=no
Before=network-pre.target
After=sys-subsystem-net-devices-engreen.device
[Service]
Expand Down Expand Up @@ -1159,18 +1186,18 @@ def test_rebind_service_generation(self):
Description=(Re-)bind SR-IOV Virtual Functions to their driver
After=network.target
After=netplan-sriov-apply.service
After=sys-subsystem-net-devices-enblue.device
After=sys-subsystem-net-devices-engreen.device
After=sys-subsystem-net-devices-enblue.device
[Service]
Type=oneshot
ExecStart=/usr/sbin/netplan rebind --debug enblue engreen
ExecStart=/usr/sbin/netplan rebind --debug engreen enblue
''', 'apply.service': '''[Unit]
Description=Apply SR-IOV configuration
DefaultDependencies=no
Before=network-pre.target
After=sys-subsystem-net-devices-enblue.device
After=sys-subsystem-net-devices-engreen.device
After=sys-subsystem-net-devices-enblue.device
[Service]
Type=oneshot
Expand Down Expand Up @@ -1223,7 +1250,7 @@ def test_invalid_not_a_pf(self):
version: 2
ethernets:
engreen:
embedded-switch-mode: legacy''', expect_fail=True)
delay-virtual-functions-rebind: true''', expect_fail=True)
self.assertIn("This is not a SR-IOV PF", err)

def test_invalid_eswitch_mode(self):
Expand Down

0 comments on commit ef34695

Please sign in to comment.