Skip to content

Commit 6e4b063

Browse files
authored
Merge pull request #861 from elezar/remove-fsnotify
Remove watch option from create-dev-char-symlinks
2 parents e4be26f + 8e6b57b commit 6e4b063

File tree

2 files changed

+3
-88
lines changed

2 files changed

+3
-88
lines changed

cmd/nvidia-ctk/system/create-dev-char-symlinks/create-dev-char-symlinks.go

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ package devchar
1919
import (
2020
"fmt"
2121
"os"
22-
"os/signal"
2322
"path/filepath"
24-
"strings"
25-
"syscall"
2623

27-
"github.com/fsnotify/fsnotify"
2824
"github.com/urfave/cli/v2"
2925

3026
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
@@ -44,7 +40,6 @@ type config struct {
4440
devCharPath string
4541
driverRoot string
4642
dryRun bool
47-
watch bool
4843
createAll bool
4944
createDeviceNodes bool
5045
loadKernelModules bool
@@ -89,13 +84,6 @@ func (m command) build() *cli.Command {
8984
Destination: &cfg.driverRoot,
9085
EnvVars: []string{"NVIDIA_DRIVER_ROOT", "DRIVER_ROOT"},
9186
},
92-
&cli.BoolFlag{
93-
Name: "watch",
94-
Usage: "If set, the command will watch for changes to the driver root and recreate the symlinks when changes are detected.",
95-
Value: false,
96-
Destination: &cfg.watch,
97-
EnvVars: []string{"WATCH"},
98-
},
9987
&cli.BoolFlag{
10088
Name: "create-all",
10189
Usage: "Create all possible /dev/char symlinks instead of limiting these to existing device nodes.",
@@ -127,7 +115,7 @@ func (m command) build() *cli.Command {
127115
}
128116

129117
func (m command) validateFlags(r *cli.Context, cfg *config) error {
130-
if cfg.createAll && cfg.watch {
118+
if cfg.createAll {
131119
return fmt.Errorf("create-all and watch are mutually exclusive")
132120
}
133121

@@ -145,19 +133,6 @@ func (m command) validateFlags(r *cli.Context, cfg *config) error {
145133
}
146134

147135
func (m command) run(c *cli.Context, cfg *config) error {
148-
var watcher *fsnotify.Watcher
149-
var sigs chan os.Signal
150-
151-
if cfg.watch {
152-
watcher, err := newFSWatcher(filepath.Join(cfg.driverRoot, "dev"))
153-
if err != nil {
154-
return fmt.Errorf("failed to create FS watcher: %v", err)
155-
}
156-
defer watcher.Close()
157-
158-
sigs = newOSWatcher(syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
159-
}
160-
161136
l, err := NewSymlinkCreator(
162137
WithLogger(m.logger),
163138
WithDevCharPath(cfg.devCharPath),
@@ -171,47 +146,11 @@ func (m command) run(c *cli.Context, cfg *config) error {
171146
return fmt.Errorf("failed to create symlink creator: %v", err)
172147
}
173148

174-
create:
175149
err = l.CreateLinks()
176150
if err != nil {
177151
return fmt.Errorf("failed to create links: %v", err)
178152
}
179-
if !cfg.watch {
180-
return nil
181-
}
182-
for {
183-
select {
184-
185-
case event := <-watcher.Events:
186-
deviceNode := filepath.Base(event.Name)
187-
if !strings.HasPrefix(deviceNode, "nvidia") {
188-
continue
189-
}
190-
if event.Has(fsnotify.Create) {
191-
m.logger.Infof("%s created, restarting.", event.Name)
192-
goto create
193-
}
194-
if event.Has(fsnotify.Remove) {
195-
m.logger.Infof("%s removed. Ignoring", event.Name)
196-
197-
}
198-
199-
// Watch for any other fs errors and log them.
200-
case err := <-watcher.Errors:
201-
m.logger.Errorf("inotify: %s", err)
202-
203-
// React to signals
204-
case s := <-sigs:
205-
switch s {
206-
case syscall.SIGHUP:
207-
m.logger.Infof("Received SIGHUP, recreating symlinks.")
208-
goto create
209-
default:
210-
m.logger.Infof("Received signal %q, shutting down.", s)
211-
return nil
212-
}
213-
}
214-
}
153+
return nil
215154
}
216155

217156
type linkCreator struct {
@@ -399,27 +338,3 @@ type deviceNode struct {
399338
func (d deviceNode) devCharName() string {
400339
return fmt.Sprintf("%d:%d", d.major, d.minor)
401340
}
402-
403-
func newFSWatcher(files ...string) (*fsnotify.Watcher, error) {
404-
watcher, err := fsnotify.NewWatcher()
405-
if err != nil {
406-
return nil, err
407-
}
408-
409-
for _, f := range files {
410-
err = watcher.Add(f)
411-
if err != nil {
412-
watcher.Close()
413-
return nil, err
414-
}
415-
}
416-
417-
return watcher, nil
418-
}
419-
420-
func newOSWatcher(sigs ...os.Signal) chan os.Signal {
421-
sigChan := make(chan os.Signal, 1)
422-
signal.Notify(sigChan, sigs...)
423-
424-
return sigChan
425-
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.22.0
55
require (
66
github.com/NVIDIA/go-nvlib v0.6.1
77
github.com/NVIDIA/go-nvml v0.12.4-1
8-
github.com/fsnotify/fsnotify v1.7.0
98
github.com/moby/sys/symlink v0.3.0
109
github.com/opencontainers/runtime-spec v1.2.0
1110
github.com/pelletier/go-toml v1.9.5
@@ -21,6 +20,7 @@ require (
2120
require (
2221
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
2322
github.com/davecgh/go-spew v1.1.1 // indirect
23+
github.com/fsnotify/fsnotify v1.7.0 // indirect
2424
github.com/google/uuid v1.6.0 // indirect
2525
github.com/hashicorp/errwrap v1.1.0 // indirect
2626
github.com/kr/pretty v0.3.1 // indirect

0 commit comments

Comments
 (0)