Skip to content

Commit

Permalink
Modify generic_plugin to skipVFconfiguration
Browse files Browse the repository at this point in the history
If WithSkipVFConfiguration() option is passed
during the plugin initialization, then
the plugin will configure PFs and create VFs,
but will skip VF configuration phase.

This is required to support pre configuration
phase in systemd mode.

Signed-off-by: Yury Kulazhenkov <[email protected]>
  • Loading branch information
ykulazhenkov committed Feb 9, 2024
1 parent 40bc84c commit 038c296
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions pkg/plugins/generic/generic_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,39 @@ type DriverState struct {
type DriverStateMapType map[uint]*DriverState

type GenericPlugin struct {
PluginName string
SpecVersion string
DesireState *sriovnetworkv1.SriovNetworkNodeState
LastState *sriovnetworkv1.SriovNetworkNodeState
DriverStateMap DriverStateMapType
DesiredKernelArgs map[string]bool
pfsToSkip map[string]bool
helpers helper.HostHelpersInterface
PluginName string
SpecVersion string
DesireState *sriovnetworkv1.SriovNetworkNodeState
LastState *sriovnetworkv1.SriovNetworkNodeState
DriverStateMap DriverStateMapType
DesiredKernelArgs map[string]bool
pfsToSkip map[string]bool
helpers helper.HostHelpersInterface
skipVFConfiguration bool
}

type option = func(c *genericPluginOptions)

// WithSkipVFConfiguration configures generic plugin to skip configuration of the VFs.
// In this case PFs will be configured and VFs are just created, VF configuration phase is skipped.
func WithSkipVFConfiguration() option {
return func(c *genericPluginOptions) {
c.skipVFConfiguration = true
}
}

type genericPluginOptions struct {
skipVFConfiguration bool
}

const scriptsPath = "bindata/scripts/enable-kargs.sh"

// Initialize our plugin and set up initial values
func NewGenericPlugin(helpers helper.HostHelpersInterface) (plugin.VendorPlugin, error) {
func NewGenericPlugin(helpers helper.HostHelpersInterface, options ...option) (plugin.VendorPlugin, error) {
cfg := &genericPluginOptions{}
for _, o := range options {
o(cfg)
}
driverStateMap := make(map[uint]*DriverState)
driverStateMap[Vfio] = &DriverState{
DriverName: vfioPciDriver,
Expand All @@ -88,12 +107,13 @@ func NewGenericPlugin(helpers helper.HostHelpersInterface) (plugin.VendorPlugin,
DriverLoaded: false,
}
return &GenericPlugin{
PluginName: PluginName,
SpecVersion: "1.0",
DriverStateMap: driverStateMap,
DesiredKernelArgs: make(map[string]bool),
pfsToSkip: make(map[string]bool),
helpers: helpers,
PluginName: PluginName,
SpecVersion: "1.0",
DriverStateMap: driverStateMap,
DesiredKernelArgs: make(map[string]bool),
pfsToSkip: make(map[string]bool),
helpers: helpers,
skipVFConfiguration: cfg.skipVFConfiguration,
}, nil
}

Expand Down Expand Up @@ -163,7 +183,8 @@ func (p *GenericPlugin) Apply() error {
defer exit()
}

if err := p.helpers.ConfigSriovInterfaces(p.helpers, p.DesireState.Spec.Interfaces, p.DesireState.Status.Interfaces, p.pfsToSkip, false); err != nil {
if err := p.helpers.ConfigSriovInterfaces(p.helpers, p.DesireState.Spec.Interfaces,
p.DesireState.Status.Interfaces, p.pfsToSkip, p.skipVFConfiguration); err != nil {
// Catch the "cannot allocate memory" error and try to use PCI realloc
if errors.Is(err, syscall.ENOMEM) {
p.addToDesiredKernelArgs(consts.KernelArgPciRealloc)
Expand Down

0 comments on commit 038c296

Please sign in to comment.