/
storage.go
58 lines (44 loc) · 1.46 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package util
import (
"github.com/lxc/lxd/lxd/storage/filesystem"
"github.com/lxc/lxd/shared"
"github.com/lxc/lxd/shared/api"
)
// PoolType represents a type of storage pool (local, remote or any).
type PoolType string
// PoolTypeAny represents any storage pool (local or remote).
const PoolTypeAny PoolType = ""
// PoolTypeLocal represents local storage pools.
const PoolTypeLocal PoolType = "local"
// PoolTypeRemote represents remote storage pools.
const PoolTypeRemote PoolType = "remote"
// AvailableStorageDrivers returns a list of storage drivers that are available.
func AvailableStorageDrivers(supportedDrivers []api.ServerStorageDriverInfo, poolType PoolType) []string {
backingFs, err := filesystem.Detect(shared.VarPath())
if err != nil {
backingFs = "dir"
}
drivers := make([]string, 0, len(supportedDrivers))
// Check available backends.
for _, driver := range supportedDrivers {
if poolType == PoolTypeRemote && !driver.Remote {
continue
}
if poolType == PoolTypeLocal && driver.Remote {
continue
}
if poolType == PoolTypeAny && (driver.Name == "cephfs" || driver.Name == "cephobject") {
continue
}
if driver.Name == "dir" {
drivers = append(drivers, driver.Name)
continue
}
// btrfs can work in user namespaces too. (If source=/some/path/on/btrfs is used.)
if shared.RunningInUserNS() && (backingFs != "btrfs" || driver.Name != "btrfs") {
continue
}
drivers = append(drivers, driver.Name)
}
return drivers
}