From 5e00026dc9d1ea442f21fca072ad7cf7d25602da Mon Sep 17 00:00:00 2001 From: Zach Koopmans Date: Mon, 5 Aug 2024 11:01:29 -0700 Subject: [PATCH] Sort drivers for nvproxy list-supported-drivers command. Sort drivers for runsc command so that it is easier to find if a driver is supported or not. PiperOrigin-RevId: 659610598 --- pkg/sentry/devices/nvproxy/version.go | 14 ++++++++++++++ runsc/cmd/nvproxy/list_supported_drivers.go | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/sentry/devices/nvproxy/version.go b/pkg/sentry/devices/nvproxy/version.go index 3a59eb9be..f28e0948b 100644 --- a/pkg/sentry/devices/nvproxy/version.go +++ b/pkg/sentry/devices/nvproxy/version.go @@ -17,6 +17,7 @@ package nvproxy import ( "fmt" "reflect" + "sort" "strconv" "strings" @@ -722,6 +723,19 @@ func LatestDriver() DriverVersion { return ret } +// SupportedDrivers returns a list of all supported drivers. +// Precondition: Init() must have been called. +func SupportedDrivers() []DriverVersion { + var ret []DriverVersion + for version := range abis { + ret = append(ret, version) + } + sort.Slice(ret, func(i, j int) bool { + return !ret[i].isGreaterThan(ret[j]) + }) + return ret +} + // ExpectedDriverChecksum returns the expected checksum for a given version. // Precondition: Init() must have been called. func ExpectedDriverChecksum(version DriverVersion) (string, bool) { diff --git a/runsc/cmd/nvproxy/list_supported_drivers.go b/runsc/cmd/nvproxy/list_supported_drivers.go index 3fc43ae41..903d513fe 100644 --- a/runsc/cmd/nvproxy/list_supported_drivers.go +++ b/runsc/cmd/nvproxy/list_supported_drivers.go @@ -53,9 +53,9 @@ func (*listSupportedDrivers) Execute(ctx context.Context, f *flag.FlagSet, args return subcommands.ExitUsageError } - nvproxy.ForEachSupportDriver(func(version nvproxy.DriverVersion, _ string) { - fmt.Println(version) - }) + for _, d := range nvproxy.SupportedDrivers() { + fmt.Println(d) + } return subcommands.ExitSuccess }