Skip to content

Commit c34dc69

Browse files
committed
geat: Go implement blacklist
Signed-off-by: Fred Rolland <[email protected]>
1 parent fab58e0 commit c34dc69

File tree

3 files changed

+601
-1
lines changed

3 files changed

+601
-1
lines changed

entrypoint/internal/driver/driver.go

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"os"
23+
"strings"
2324

2425
"github.com/go-logr/logr"
2526

@@ -116,7 +117,12 @@ func (d *driverMgr) Build(ctx context.Context) error {
116117

117118
// Load is the default implementation of the driver.Interface.
118119
func (d *driverMgr) Load(ctx context.Context) (bool, error) {
119-
// TODO: Implement
120+
if err := d.generateOfedModulesBlacklist(ctx); err != nil {
121+
return false, err
122+
}
123+
if err := d.removeOfedModulesBlacklist(ctx); err != nil {
124+
return false, err
125+
}
120126
return true, nil
121127
}
122128

@@ -143,3 +149,64 @@ func (d *driverMgr) prepareGCC(ctx context.Context) error {
143149
}
144150
return nil
145151
}
152+
153+
// generateOfedModulesBlacklist creates a blacklist file for OFED modules to prevent
154+
// inbox or host OFED driver loading. This function writes module blacklist entries
155+
// to the configured blacklist file.
156+
func (d *driverMgr) generateOfedModulesBlacklist(ctx context.Context) error {
157+
log := logr.FromContextOrDiscard(ctx)
158+
log.V(1).Info("Generating OFED modules blacklist")
159+
160+
// Create the blacklist file
161+
file, err := d.os.Create(d.cfg.OfedBlacklistModulesFile)
162+
if err != nil {
163+
log.Error(err, "Failed to create blacklist file", "file", d.cfg.OfedBlacklistModulesFile)
164+
return fmt.Errorf("failed to create blacklist file %s: %w", d.cfg.OfedBlacklistModulesFile, err)
165+
}
166+
defer file.Close()
167+
168+
// Build the entire content first
169+
var content strings.Builder
170+
content.WriteString("# blacklist ofed-related modules on host to prevent inbox or host OFED driver loading\n\n")
171+
172+
// Add blacklist entries for each module
173+
for _, module := range d.cfg.OfedBlacklistModules {
174+
module = strings.TrimSpace(module)
175+
if module == "" {
176+
continue
177+
}
178+
content.WriteString(fmt.Sprintf("blacklist %s\n", module))
179+
log.V(2).Info("Added module to blacklist", "module", module)
180+
}
181+
182+
// Write all content at once
183+
if _, err := file.WriteString(content.String()); err != nil {
184+
log.Error(err, "Failed to write blacklist content to file")
185+
return fmt.Errorf("failed to write blacklist content to file: %w", err)
186+
}
187+
188+
log.Info("Successfully generated OFED modules blacklist", "file", d.cfg.OfedBlacklistModulesFile, "modules", d.cfg.OfedBlacklistModules)
189+
return nil
190+
}
191+
192+
// removeOfedModulesBlacklist removes the OFED modules blacklist file from the host.
193+
// This function is typically called during cleanup or when the blacklist is no longer needed.
194+
func (d *driverMgr) removeOfedModulesBlacklist(ctx context.Context) error {
195+
log := logr.FromContextOrDiscard(ctx)
196+
log.V(1).Info("Removing OFED modules blacklist file")
197+
198+
// Check if file exists before attempting to remove
199+
if _, err := d.os.Stat(d.cfg.OfedBlacklistModulesFile); os.IsNotExist(err) {
200+
log.V(1).Info("Blacklist file does not exist, nothing to remove", "file", d.cfg.OfedBlacklistModulesFile)
201+
return nil
202+
}
203+
204+
// Remove the blacklist file
205+
if err := d.os.RemoveAll(d.cfg.OfedBlacklistModulesFile); err != nil {
206+
log.Error(err, "Failed to remove blacklist file", "file", d.cfg.OfedBlacklistModulesFile)
207+
return fmt.Errorf("failed to remove blacklist file %s: %w", d.cfg.OfedBlacklistModulesFile, err)
208+
}
209+
210+
log.Info("Successfully removed OFED modules blacklist file", "file", d.cfg.OfedBlacklistModulesFile)
211+
return nil
212+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2025, NVIDIA CORPORATION & AFFILIATES
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package driver
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
)
25+
26+
func TestDriver(t *testing.T) {
27+
RegisterFailHandler(Fail)
28+
RunSpecs(t, "Driver Suite")
29+
}

0 commit comments

Comments
 (0)