createDevCharSymlinks creates symlinks in /host-dev-char that point to all possible NVIDIA devices nodes.
(driverInfo driverInfo, disableDevCharSymlinkCreation bool)
| 941 | |
| 942 | // createDevCharSymlinks creates symlinks in /host-dev-char that point to all possible NVIDIA devices nodes. |
| 943 | func createDevCharSymlinks(driverInfo driverInfo, disableDevCharSymlinkCreation bool) error { |
| 944 | if disableDevCharSymlinkCreation { |
| 945 | log.WithField("disableDevCharSymlinkCreation", true). |
| 946 | Info("skipping the creation of symlinks under /dev/char that correspond to NVIDIA character devices") |
| 947 | return nil |
| 948 | } |
| 949 | |
| 950 | log.Info("creating symlinks under /dev/char that correspond to NVIDIA character devices") |
| 951 | |
| 952 | // Check if NVIDIA module is already loaded in kernel memory. |
| 953 | // If it is, we don't need to run modprobe (which would fail if modules aren't in /lib/modules/). |
| 954 | // This handles the case where the driver container performed a userspace-only install |
| 955 | // after detecting that module was already loaded from a previous boot. |
| 956 | moduleAlreadyLoaded := isNvidiaModuleLoaded() |
| 957 | |
| 958 | // Only attempt to load NVIDIA kernel modules when: |
| 959 | // 1. Module is not already loaded in kernel memory, AND |
| 960 | // 2. We can chroot into driverRoot to run modprobe |
| 961 | loadKernelModules := !moduleAlreadyLoaded && (driverInfo.isHostDriver || (driverInfo.devRoot == driverInfo.driverRoot)) |
| 962 | |
| 963 | // driverRootCtrPath is the path of the driver install dir in the container. This will either be |
| 964 | // driverInstallDirCtrPathFlag or '/host'. |
| 965 | // Note, if we always mounted the driver install dir to '/driver-root' in the validation container |
| 966 | // instead, then we could simplify to always use driverInfo.driverRootCtrPath -- which would be |
| 967 | // either '/host' or '/driver-root', both paths would exist in the validation container. |
| 968 | driverRootCtrPath := driverInstallDirCtrPathFlag |
| 969 | if driverInfo.isHostDriver { |
| 970 | driverRootCtrPath = "/host" |
| 971 | } |
| 972 | |
| 973 | // We now create the symlinks in /dev/char. |
| 974 | creator, err := devchar.NewSymlinkCreator( |
| 975 | devchar.WithDriverRoot(driverRootCtrPath), |
| 976 | devchar.WithDevRoot(driverInfo.devRoot), |
| 977 | devchar.WithDevCharPath(hostDevCharPath), |
| 978 | devchar.WithCreateAll(true), |
| 979 | devchar.WithCreateDeviceNodes(true), |
| 980 | devchar.WithLoadKernelModules(loadKernelModules), |
| 981 | ) |
| 982 | if err != nil { |
| 983 | return fmt.Errorf("error creating symlink creator: %w", err) |
| 984 | } |
| 985 | |
| 986 | err = creator.CreateLinks() |
| 987 | if err != nil { |
| 988 | return fmt.Errorf("error creating symlinks: %w", err) |
| 989 | } |
| 990 | |
| 991 | return nil |
| 992 | } |
| 993 | |
| 994 | func createStatusFile(statusFile string) error { |
| 995 | _, err := os.Create(statusFile) |
no test coverage detected