@@ -119,7 +119,12 @@ func (d *driverMgr) Build(ctx context.Context) error {
119119
120120// Load is the default implementation of the driver.Interface.
121121func (d * driverMgr ) Load (ctx context.Context ) (bool , error ) {
122- // TODO: Implement
122+ if err := d .generateOfedModulesBlacklist (ctx ); err != nil {
123+ return false , err
124+ }
125+ if err := d .removeOfedModulesBlacklist (ctx ); err != nil {
126+ return false , err
127+ }
123128 return true , nil
124129}
125130
@@ -323,3 +328,64 @@ func (d *driverMgr) extractMajorVersion(version string) (int, error) {
323328
324329 return major , nil
325330}
331+
332+ // generateOfedModulesBlacklist creates a blacklist file for OFED modules to prevent
333+ // inbox or host OFED driver loading. This function writes module blacklist entries
334+ // to the configured blacklist file.
335+ func (d * driverMgr ) generateOfedModulesBlacklist (ctx context.Context ) error {
336+ log := logr .FromContextOrDiscard (ctx )
337+ log .V (1 ).Info ("Generating OFED modules blacklist" )
338+
339+ // Create the blacklist file
340+ file , err := d .os .Create (d .cfg .OfedBlacklistModulesFile )
341+ if err != nil {
342+ log .Error (err , "Failed to create blacklist file" , "file" , d .cfg .OfedBlacklistModulesFile )
343+ return fmt .Errorf ("failed to create blacklist file %s: %w" , d .cfg .OfedBlacklistModulesFile , err )
344+ }
345+ defer file .Close ()
346+
347+ // Build the entire content first
348+ var content strings.Builder
349+ content .WriteString ("# blacklist ofed-related modules on host to prevent inbox or host OFED driver loading\n \n " )
350+
351+ // Add blacklist entries for each module
352+ for _ , module := range d .cfg .OfedBlacklistModules {
353+ module = strings .TrimSpace (module )
354+ if module == "" {
355+ continue
356+ }
357+ content .WriteString (fmt .Sprintf ("blacklist %s\n " , module ))
358+ log .V (2 ).Info ("Added module to blacklist" , "module" , module )
359+ }
360+
361+ // Write all content at once
362+ if _ , err := file .WriteString (content .String ()); err != nil {
363+ log .Error (err , "Failed to write blacklist content to file" )
364+ return fmt .Errorf ("failed to write blacklist content to file: %w" , err )
365+ }
366+
367+ log .Info ("Successfully generated OFED modules blacklist" , "file" , d .cfg .OfedBlacklistModulesFile , "modules" , d .cfg .OfedBlacklistModules )
368+ return nil
369+ }
370+
371+ // removeOfedModulesBlacklist removes the OFED modules blacklist file from the host.
372+ // This function is typically called during cleanup or when the blacklist is no longer needed.
373+ func (d * driverMgr ) removeOfedModulesBlacklist (ctx context.Context ) error {
374+ log := logr .FromContextOrDiscard (ctx )
375+ log .V (1 ).Info ("Removing OFED modules blacklist file" )
376+
377+ // Check if file exists before attempting to remove
378+ if _ , err := d .os .Stat (d .cfg .OfedBlacklistModulesFile ); os .IsNotExist (err ) {
379+ log .V (1 ).Info ("Blacklist file does not exist, nothing to remove" , "file" , d .cfg .OfedBlacklistModulesFile )
380+ return nil
381+ }
382+
383+ // Remove the blacklist file
384+ if err := d .os .RemoveAll (d .cfg .OfedBlacklistModulesFile ); err != nil {
385+ log .Error (err , "Failed to remove blacklist file" , "file" , d .cfg .OfedBlacklistModulesFile )
386+ return fmt .Errorf ("failed to remove blacklist file %s: %w" , d .cfg .OfedBlacklistModulesFile , err )
387+ }
388+
389+ log .Info ("Successfully removed OFED modules blacklist file" , "file" , d .cfg .OfedBlacklistModulesFile )
390+ return nil
391+ }
0 commit comments