File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 17
17
package edits
18
18
19
19
import (
20
+ "os"
21
+
20
22
"tags.cncf.io/container-device-interface/pkg/cdi"
21
23
"tags.cncf.io/container-device-interface/specs-go"
22
24
25
+ "github.com/opencontainers/runc/libcontainer/devices"
26
+
23
27
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
24
28
)
25
29
@@ -49,13 +53,31 @@ func (d device) toSpec() (*specs.DeviceNode, error) {
49
53
// Since the behaviour for HostPath == "" and HostPath == Path are equivalent, we clear HostPath
50
54
// if it is equal to Path to ensure compatibility with the widest range of specs.
51
55
hostPath := d .HostPath
56
+
52
57
if hostPath == d .Path {
53
58
hostPath = ""
54
59
}
55
60
s := specs.DeviceNode {
56
61
HostPath : hostPath ,
57
62
Path : d .Path ,
63
+ FileMode : d .getFileMode (),
58
64
}
59
65
60
66
return & s , nil
61
67
}
68
+
69
+ // getFileMode returns the filemode of the host device node associated with the discovered device.
70
+ // If this fails, a nil filemode is returned.
71
+ func (d device ) getFileMode () * os.FileMode {
72
+ path := d .HostPath
73
+ if path == "" {
74
+ path = d .Path
75
+ }
76
+ dn , err := devices .DeviceFromPath (path , "rwm" )
77
+ if err != nil {
78
+ // return nil, fmt.Errorf("failed to get device information for %q: %w", path, err)
79
+ return nil
80
+ }
81
+
82
+ return & dn .FileMode
83
+ }
You can’t perform that action at this time.
0 commit comments