Skip to content

Commit 14b3d6f

Browse files
committed
fix: detect a filesystem type in cross-platform builds (#268)
1 parent 4ec1858 commit 14b3d6f

File tree

5 files changed

+89
-26
lines changed

5 files changed

+89
-26
lines changed

pkg/services/provision/pool/block_devices.go

-10
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@ package pool
88
import (
99
"encoding/json"
1010
"os/exec"
11-
"strconv"
1211

1312
"github.com/pkg/errors"
1413
)
1514

16-
var fsTypeToString = map[string]string{
17-
"ef53": ext4,
18-
"2fc12fc1": ZFS,
19-
}
2015

2116
type blockDeviceList struct {
2217
BlockDevices []blockDevice `json:"blockdevices"`
@@ -27,11 +22,6 @@ type blockDevice struct {
2722
MountPoint string `json:"mountpoint"`
2823
}
2924

30-
// detectFSType detects the filesystem type of the underlying mounted filesystem.
31-
func detectFSType(fsType int64) string {
32-
return fsTypeToString[strconv.FormatInt(fsType, 16)]
33-
}
34-
3525
// getBlockDeviceTypes returns a filesystem type list of mounted block devices.
3626
func getBlockDeviceTypes() (map[string]string, error) {
3727
output, err := exec.Command("lsblk", "--json", "--output", "type,mountpoint").Output()
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// +build darwin freebsd dragonfly openbsd solaris
2+
3+
/*
4+
2020 © Postgres.ai
5+
*/
6+
7+
// Package pool provides components to work with storage pools.
8+
package pool
9+
10+
import (
11+
"syscall"
12+
)
13+
14+
func (pm *Manager) getFSInfo(path string) (string, error) {
15+
fs := syscall.Statfs_t{}
16+
if err := syscall.Statfs(path, &fs); err != nil {
17+
return "", err
18+
}
19+
20+
fsType := detectFSType(fs.Fstypename[:])
21+
if fsType == ext4 {
22+
// cannot detect LVM checking the blockDeviceTypes map.
23+
return LVM, nil
24+
}
25+
26+
return fsType, nil
27+
}
28+
29+
// detectFSType detects the filesystem type of the underlying mounted filesystem.
30+
func detectFSType(fsType []int8) string {
31+
fsTypeBytes := make([]byte, 0, len(fsType))
32+
33+
for _, v := range fsType {
34+
fsTypeBytes = append(fsTypeBytes, byte(v))
35+
}
36+
37+
return string(fsTypeBytes)
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// +build linux,!s390x,!arm,!386
2+
3+
/*
4+
2020 © Postgres.ai
5+
*/
6+
7+
// Package pool provides components to work with storage pools.
8+
package pool
9+
10+
import (
11+
"strconv"
12+
"syscall"
13+
)
14+
15+
var fsTypeToString = map[string]string{
16+
"ef53": ext4,
17+
"2fc12fc1": ZFS,
18+
}
19+
20+
func (pm *Manager) getFSInfo(path string) (string, error) {
21+
fs := syscall.Statfs_t{}
22+
if err := syscall.Statfs(path, &fs); err != nil {
23+
return "", err
24+
}
25+
26+
fsType := detectFSType(fs.Type)
27+
if fsType == ext4 {
28+
// cannot detect LVM checking the blockDeviceTypes map.
29+
return LVM, nil
30+
}
31+
32+
return fsType, nil
33+
}
34+
35+
// detectFSType detects the filesystem type of the underlying mounted filesystem.
36+
func detectFSType(fsType int64) string {
37+
return fsTypeToString[strconv.FormatInt(fsType, 16)]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// +build windows
2+
3+
/*
4+
2020 © Postgres.ai
5+
*/
6+
7+
// Package pool provides components to work with storage pools.
8+
package pool
9+
10+
func (pm *Manager) getFSInfo(path string) (string, error) {
11+
// Not supported for windows.
12+
return "", nil
13+
}

pkg/services/provision/pool/pool_manager.go

-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"os"
1111
"path"
1212
"sync"
13-
"syscall"
1413
"time"
1514

1615
"github.com/pkg/errors"
@@ -284,21 +283,6 @@ func extractDataStateAt(dataPath string) (*time.Time, error) {
284283
return &dsa, nil
285284
}
286285

287-
func (pm *Manager) getFSInfo(path string) (string, error) {
288-
fs := syscall.Statfs_t{}
289-
if err := syscall.Statfs(path, &fs); err != nil {
290-
return "", err
291-
}
292-
293-
fsType := detectFSType(fs.Type)
294-
if fsType == ext4 {
295-
// cannot detect LVM checking the blockDeviceTypes map.
296-
return LVM, nil
297-
}
298-
299-
return fsType, nil
300-
}
301-
302286
func (pm *Manager) describeAvailablePools() []string {
303287
availablePools := []string{}
304288

0 commit comments

Comments
 (0)