mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-03-09 22:00:31 +00:00
Extract FileMode from host path if possible
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
bc9ec77fdd
commit
eb70273971
@ -17,9 +17,13 @@
|
|||||||
package edits
|
package edits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"tags.cncf.io/container-device-interface/pkg/cdi"
|
"tags.cncf.io/container-device-interface/pkg/cdi"
|
||||||
"tags.cncf.io/container-device-interface/specs-go"
|
"tags.cncf.io/container-device-interface/specs-go"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/libcontainer/devices"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,13 +53,31 @@ func (d device) toSpec() (*specs.DeviceNode, error) {
|
|||||||
// Since the behaviour for HostPath == "" and HostPath == Path are equivalent, we clear HostPath
|
// Since the behaviour for HostPath == "" and HostPath == Path are equivalent, we clear HostPath
|
||||||
// if it is equal to Path to ensure compatibility with the widest range of specs.
|
// if it is equal to Path to ensure compatibility with the widest range of specs.
|
||||||
hostPath := d.HostPath
|
hostPath := d.HostPath
|
||||||
|
|
||||||
if hostPath == d.Path {
|
if hostPath == d.Path {
|
||||||
hostPath = ""
|
hostPath = ""
|
||||||
}
|
}
|
||||||
s := specs.DeviceNode{
|
s := specs.DeviceNode{
|
||||||
HostPath: hostPath,
|
HostPath: hostPath,
|
||||||
Path: d.Path,
|
Path: d.Path,
|
||||||
|
FileMode: d.getFileMode(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getFileMode returns the filemode of the host device node associated with the discovered device.
|
||||||
|
// If this fails, a nil filemode is returned.
|
||||||
|
func (d device) getFileMode() *os.FileMode {
|
||||||
|
path := d.HostPath
|
||||||
|
if path == "" {
|
||||||
|
path = d.Path
|
||||||
|
}
|
||||||
|
dn, err := devices.DeviceFromPath(path, "rwm")
|
||||||
|
if err != nil {
|
||||||
|
// return nil, fmt.Errorf("failed to get device information for %q: %w", path, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &dn.FileMode
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user