mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
cdi: resolve symlinks
Fix using /etc/cdi entries in rootless mode: > level=warning msg="Refreshing the CDI registry generated errors" > error="failed to monitor for changes: no such file or directory\nfailed to monitor for changes: no such file or directory" Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containerd/log"
|
||||
"github.com/moby/moby/api/types/system"
|
||||
@@ -22,6 +23,14 @@ type cdiHandler struct {
|
||||
// The driver injects CDI devices into an incoming OCI spec and is called for DeviceRequests associated with CDI devices.
|
||||
// If the list of CDI spec directories is empty, the driver is not registered.
|
||||
func RegisterCDIDriver(cdiSpecDirs ...string) *cdi.Cache {
|
||||
for i, dir := range cdiSpecDirs {
|
||||
if _, err := os.Stat(dir); !errors.Is(err, os.ErrNotExist) {
|
||||
cdiSpecDirs[i], err = filepath.EvalSymlinks(dir)
|
||||
if err != nil {
|
||||
log.L.WithField("dir", dir).WithError(err).Warn("Failed to evaluate symlinks for CDI spec directory")
|
||||
}
|
||||
}
|
||||
}
|
||||
driver, cache := newCDIDeviceDriver(cdiSpecDirs...)
|
||||
registerDeviceDriver("cdi", driver)
|
||||
return cache
|
||||
|
||||
Reference in New Issue
Block a user