Skip to content

Commit

Permalink
types: create simpler ScanPriorDrivers for options
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed Jun 12, 2023
1 parent 083f61b commit 0c6fcf4
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 4 deletions.
29 changes: 29 additions & 0 deletions pkg/fsutils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fsutils

import (
"path/filepath"
"os"
)


var Drivers = []string{
"overlay",
"aufs",
"btrfs",
"zfs",
"vfs",
}

// scanPriorDrivers returns an un-ordered scan of directories of prior storage drivers
func ScanPriorDrivers(root string) map[string]bool {
driversMap := make(map[string]bool)

for _, driver := range Drivers {
p := filepath.Join(root, driver)
if _, err := os.Stat(p); err == nil {
driversMap[driver] = true
}
}
return driversMap
}

13 changes: 13 additions & 0 deletions pkg/fsutils/utils_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build darwin
// +build darwin

package fsutils


var (
// Slice of drivers that should be used in an order
DriverPriority = []string{
"zfs",
"vfs",
}
)
13 changes: 13 additions & 0 deletions pkg/fsutils/utils_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build freebsd
// +build freebsd

package fsutils


var (
// Slice of drivers that should be used in an order
DriverPriority = []string{
"zfs",
"vfs",
}
)
18 changes: 18 additions & 0 deletions pkg/fsutils/utils_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build linux
// +build linux

package fsutils


var (
// Slice of drivers that should be used in an order
DriverPriority = []string{
"overlay",
// We don't support devicemapper without configuration
// "devicemapper",
"aufs",
"btrfs",
"zfs",
"vfs",
}
)
12 changes: 12 additions & 0 deletions pkg/fsutils/utils_solaris.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build solaris && cgo
// +build solaris,cgo

package fsutils


var (
// Slice of drivers that should be used in an order
DriverPriority = []string{
"zfs",
}
)
11 changes: 11 additions & 0 deletions pkg/fsutils/utils_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !linux && !windows && !freebsd && !solaris && !darwin
// +build !linux,!windows,!freebsd,!solaris,!darwin

package fsutils

var (
// Slice of drivers that should be used in an order
DriverPriority = []string{
"unsupported",
}
)
12 changes: 12 additions & 0 deletions pkg/fsutils/utils_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build windows
// +build windows

package fsutils


var (
// Slice of drivers that should be used in an order
DriverPriority = []string{
"windowsfilter",
}
)
7 changes: 3 additions & 4 deletions types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
"time"

"github.com/BurntSushi/toml"
drivers "github.com/containers/storage/drivers"
_ "github.com/containers/storage/drivers/register"
cfg "github.com/containers/storage/pkg/config"
"github.com/containers/storage/pkg/fsutils"
"github.com/containers/storage/pkg/idtools"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -312,9 +311,9 @@ func getRootlessStorageOpts(rootlessUID int, systemOpts StoreOptions) (StoreOpti
}
if opts.GraphDriverName == "" {
if len(systemOpts.GraphDriverPriority) == 0 {
driversMap := drivers.ScanPriorDrivers(opts.GraphRoot)
driversMap := fsutils.ScanPriorDrivers(opts.GraphRoot)

for _, name := range drivers.Priority {
for _, name := range fsutils.DriverPriority {
if _, prior := driversMap[name]; prior {
opts.GraphDriverName = name
break
Expand Down

0 comments on commit 0c6fcf4

Please sign in to comment.