@@ -19,12 +19,8 @@ package devchar
1919import (
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
129117func (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
147135func (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
217156type linkCreator struct {
@@ -399,27 +338,3 @@ type deviceNode struct {
399338func (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- }
0 commit comments