@@ -31,6 +31,7 @@ import (
3131 "github.com/NVIDIA/go-nvlib/pkg/nvmdev"
3232 "github.com/NVIDIA/go-nvlib/pkg/nvpci"
3333 devchar "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/create-dev-char-symlinks"
34+ "github.com/moby/sys/symlink"
3435 log "github.com/sirupsen/logrus"
3536 "github.com/stretchr/testify/assert/yaml"
3637 cli "github.com/urfave/cli/v3"
@@ -135,6 +136,7 @@ var (
135136 hostRootFlag string
136137 driverInstallDirFlag string
137138 driverInstallDirCtrPathFlag string
139+ hostRootCtrPath = "/host"
138140)
139141
140142// defaultGPUWorkloadConfig is "vm-passthrough" unless
@@ -645,7 +647,7 @@ func validateComponent(ctx context.Context, componentFlag string) error {
645647 }
646648}
647649
648- func runCommand (command string , args []string , silent bool ) error {
650+ var runCommand = func (command string , args []string , silent bool ) error {
649651 cmd := exec .Command (command , args ... )
650652 if ! silent {
651653 cmd .Stdout = os .Stdout
@@ -744,20 +746,26 @@ func isDriverManagedByOperator(ctx context.Context) (bool, error) {
744746
745747func validateHostDriver (silent bool ) error {
746748 log .Info ("Attempting to validate a pre-installed driver on the host" )
747- if fileInfo , err := os .Lstat (filepath .Join ("/host" , wslNvidiaSMIPath )); err == nil && fileInfo .Size () != 0 {
749+ if fileInfo , err := os .Lstat (filepath .Join (hostRootCtrPath , wslNvidiaSMIPath )); err == nil && fileInfo .Size () != 0 {
748750 log .Infof ("WSL2 system detected, assuming driver is pre-installed" )
749751 disableDevCharSymlinkCreation = true
750752 return nil
751753 }
752- fileInfo , err := os .Lstat ("/host/usr/bin/nvidia-smi" )
754+
755+ nvidiaSMIPath , err := symlink .FollowSymlinkInScope (filepath .Join (hostRootCtrPath , "usr/bin/nvidia-smi" ), hostRootCtrPath )
756+ if err != nil {
757+ return fmt .Errorf ("failed to resolve 'nvidia-smi' path on the host: %w" , err )
758+ }
759+
760+ fileInfo , err := os .Lstat (nvidiaSMIPath )
753761 if err != nil {
754762 return fmt .Errorf ("no 'nvidia-smi' file present on the host: %w" , err )
755763 }
756764 if fileInfo .Size () == 0 {
757765 return fmt .Errorf ("empty 'nvidia-smi' file found on the host" )
758766 }
759767 command := "chroot"
760- args := []string {"/host" , "nvidia-smi" }
768+ args := []string {hostRootCtrPath , "nvidia-smi" }
761769
762770 return runCommand (command , args , silent )
763771}
@@ -1753,9 +1761,12 @@ func (v *VGPUManager) runValidation(silent bool) (hostDriver bool, err error) {
17531761 args := []string {"/run/nvidia/driver" , "nvidia-smi" }
17541762
17551763 // check if driver is pre-installed on the host and use host path for validation
1756- if _ , err := os .Lstat ("/host/usr/bin/nvidia-smi" ); err == nil {
1757- args = []string {"/host" , "nvidia-smi" }
1758- hostDriver = true
1764+ nvidiaSMIPath , resolveErr := symlink .FollowSymlinkInScope (filepath .Join (hostRootCtrPath , "usr/bin/nvidia-smi" ), hostRootCtrPath )
1765+ if resolveErr == nil {
1766+ if _ , err := os .Lstat (nvidiaSMIPath ); err == nil {
1767+ args = []string {hostRootCtrPath , "nvidia-smi" }
1768+ hostDriver = true
1769+ }
17591770 }
17601771
17611772 if withWaitFlag {
0 commit comments