From 9ea214d0b30c57ddcd2a30577c187addbe79c7b2 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 30 May 2023 10:58:30 +0200 Subject: [PATCH 1/3] Correct typo in info command Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/info/info.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/nvidia-ctk/info/info.go b/cmd/nvidia-ctk/info/info.go index 4a5c89f0..d2aa50cc 100644 --- a/cmd/nvidia-ctk/info/info.go +++ b/cmd/nvidia-ctk/info/info.go @@ -35,13 +35,13 @@ func NewCommand(logger *logrus.Logger) *cli.Command { // build func (m command) build() *cli.Command { - // Create the 'hook' command - hook := cli.Command{ + // Create the 'info' command + info := cli.Command{ Name: "info", Usage: "Provide information about the system", } - hook.Subcommands = []*cli.Command{} + info.Subcommands = []*cli.Command{} - return &hook + return &info } From 39263ea365aad186c259125e308b59ddf7ab6147 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 30 May 2023 10:59:02 +0200 Subject: [PATCH 2/3] Add command to print ldcache Signed-off-by: Evan Lezar --- .../system/print-ldcache/print-ldcache.go | 101 ++++++++++++++++++ cmd/nvidia-ctk/system/system.go | 2 + 2 files changed, 103 insertions(+) create mode 100644 cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go diff --git a/cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go b/cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go new file mode 100644 index 00000000..a53b813f --- /dev/null +++ b/cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go @@ -0,0 +1,101 @@ +/** +# Copyright (c) NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +**/ + +package createdevicenodes + +import ( + "fmt" + + "github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache" + "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" +) + +type command struct { + logger *logrus.Logger +} + +type options struct { + driverRoot string +} + +// NewCommand constructs a command sub-command with the specified logger +func NewCommand(logger *logrus.Logger) *cli.Command { + c := command{ + logger: logger, + } + return c.build() +} + +// build +func (m command) build() *cli.Command { + opts := options{} + + c := cli.Command{ + Name: "print-ldcache", + Usage: "A utility to print the contents of the ldcache", + Before: func(c *cli.Context) error { + return m.validateFlags(c, &opts) + }, + Action: func(c *cli.Context) error { + return m.run(c, &opts) + }, + } + + c.Flags = []cli.Flag{ + &cli.StringFlag{ + Name: "driver-root", + Usage: "the path to the driver root. Device nodes will be created at `DRIVER_ROOT`/dev", + Value: "/", + Destination: &opts.driverRoot, + EnvVars: []string{"DRIVER_ROOT"}, + }, + } + + return &c +} + +func (m command) validateFlags(r *cli.Context, opts *options) error { + return nil +} + +func (m command) run(c *cli.Context, opts *options) error { + cache, err := ldcache.New(m.logger, opts.driverRoot) + if err != nil { + return fmt.Errorf("failed to create ldcache: %v", err) + } + + lib32, lib64 := cache.List() + + if len(lib32) == 0 { + m.logger.Info("No 32-bit libraries found") + } else { + m.logger.Infof("%d 32-bit libraries found", len(lib32)) + for _, lib := range lib32 { + m.logger.Infof("%v", lib) + } + } + if len(lib64) == 0 { + m.logger.Info("No 64-bit libraries found") + } else { + m.logger.Infof("%d 64-bit libraries found", len(lib64)) + for _, lib := range lib64 { + m.logger.Infof("%v", lib) + } + } + + return nil +} diff --git a/cmd/nvidia-ctk/system/system.go b/cmd/nvidia-ctk/system/system.go index b4d2f049..6683c974 100644 --- a/cmd/nvidia-ctk/system/system.go +++ b/cmd/nvidia-ctk/system/system.go @@ -19,6 +19,7 @@ package system import ( devchar "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/create-dev-char-symlinks" devicenodes "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/create-device-nodes" + ldcache "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/print-ldcache" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -45,6 +46,7 @@ func (m command) build() *cli.Command { system.Subcommands = []*cli.Command{ devchar.NewCommand(m.logger), devicenodes.NewCommand(m.logger), + ldcache.NewCommand(m.logger), } return &system From a6b0f45d2c5a5df6c5a0dc8b82093f0c8b14b924 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 30 May 2023 11:03:36 +0200 Subject: [PATCH 3/3] Fix infinite recursion when resolving ldcache Signed-off-by: Evan Lezar --- internal/ldcache/ldcache.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/ldcache/ldcache.go b/internal/ldcache/ldcache.go index 1fe7d074..96e52675 100644 --- a/internal/ldcache/ldcache.go +++ b/internal/ldcache/ldcache.go @@ -293,6 +293,9 @@ func (c *ldcache) resolve(target string) (string, error) { if err != nil { return "", fmt.Errorf("failed to resolve symlink: %v", err) } + if link == name { + return name, nil + } // We return absolute paths for all targets if !filepath.IsAbs(link) || strings.HasPrefix(link, ".") {