From f5a4b23041cbd916387cfb83fec1d81e3e698cfd Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 4 Jun 2024 10:07:19 +0200 Subject: [PATCH] Add dev-root option to create-device-nodes This allows for dev nodes to be created in cases where the driver root and the dev root do not match. Signed-off-by: Evan Lezar --- .../create-device-nodes/create-device-nodes.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/nvidia-ctk/system/create-device-nodes/create-device-nodes.go b/cmd/nvidia-ctk/system/create-device-nodes/create-device-nodes.go index b9c58a39..6b3cf1f5 100644 --- a/cmd/nvidia-ctk/system/create-device-nodes/create-device-nodes.go +++ b/cmd/nvidia-ctk/system/create-device-nodes/create-device-nodes.go @@ -32,6 +32,7 @@ type command struct { type options struct { driverRoot string + devRoot string dryRun bool @@ -71,6 +72,12 @@ func (m command) build() *cli.Command { Destination: &opts.driverRoot, EnvVars: []string{"NVIDIA_DRIVER_ROOT", "DRIVER_ROOT"}, }, + &cli.StringFlag{ + Name: "dev-root", + Usage: "specify the root where `/dev` is located. If this is not specified, the root is assumed.", + Destination: &opts.devRoot, + EnvVars: []string{"NVIDIA_DEV_ROOT", "DEV_ROOT"}, + }, &cli.BoolFlag{ Name: "control-devices", Usage: "create all control device nodes: nvidiactl, nvidia-modeset, nvidia-uvm, nvidia-uvm-tools", @@ -83,7 +90,7 @@ func (m command) build() *cli.Command { }, &cli.BoolFlag{ Name: "dry-run", - Usage: "if set, the command will not create any symlinks.", + Usage: "if set, the command will not perform any operations", Value: false, Destination: &opts.dryRun, EnvVars: []string{"DRY_RUN"}, @@ -94,6 +101,10 @@ func (m command) build() *cli.Command { } func (m command) validateFlags(r *cli.Context, opts *options) error { + if opts.devRoot == "" && opts.driverRoot != "" { + m.logger.Infof("Using dev-root %q", opts.driverRoot) + opts.devRoot = opts.driverRoot + } return nil } @@ -113,12 +124,12 @@ func (m command) run(c *cli.Context, opts *options) error { devices, err := nvdevices.New( nvdevices.WithLogger(m.logger), nvdevices.WithDryRun(opts.dryRun), - nvdevices.WithDevRoot(opts.driverRoot), + nvdevices.WithDevRoot(opts.devRoot), ) if err != nil { return err } - m.logger.Infof("Creating control device nodes at %s", opts.driverRoot) + m.logger.Infof("Creating control device nodes at %s", opts.devRoot) if err := devices.CreateNVIDIAControlDevices(); err != nil { return fmt.Errorf("failed to create NVIDIA control device nodes: %v", err) }