Skip to content

Commit 0c2f057

Browse files
authored
Merge pull request #309 from WaberZhuang/main
support priority order for turbo fs type
2 parents d2698f7 + c7f1e6b commit 0c2f057

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

cmd/overlaybd-snapshotter/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ func main() {
7676
go metrics.Init()
7777
logrus.Infof("set Prometheus metrics exporter in http://localhost:%d%s", metrics.Config.Port, metrics.Config.UriPrefix)
7878
}
79+
contain := func(fsType string) bool {
80+
for _, fst := range pconfig.TurboFsType {
81+
if fst == fsType {
82+
return true
83+
}
84+
}
85+
return false
86+
}
87+
if !contain("ext4") {
88+
pconfig.TurboFsType = append(pconfig.TurboFsType, "ext4")
89+
}
90+
if !contain("erofs") {
91+
pconfig.TurboFsType = append(pconfig.TurboFsType, "erofs")
92+
}
7993

8094
if err := setLogLevel(pconfig.LogLevel); err != nil {
8195
logrus.Errorf("failed to set log level: %v", err)

pkg/snapshot/overlay.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type BootConfig struct {
9797
DefaultFsType string `json:"defaultFsType"`
9898
RootfsQuota string `json:"rootfsQuota"` // "20g" rootfs quota, only effective when rwMode is 'overlayfs'
9999
Tenant int `json:"tenant"` // do not set this if only a single snapshotter service in the host
100+
TurboFsType []string `json:"turboFsType"`
100101
}
101102

102103
func DefaultBootConfig() *BootConfig {
@@ -115,6 +116,10 @@ func DefaultBootConfig() *BootConfig {
115116
DefaultFsType: "ext4",
116117
RootfsQuota: "",
117118
Tenant: -1,
119+
TurboFsType: []string{
120+
"ext4",
121+
"erofs",
122+
},
118123
}
119124
}
120125

@@ -183,6 +188,7 @@ type snapshotter struct {
183188
defaultFsType string
184189
tenant int
185190
locker *locker.Locker
191+
turboFsType []string
186192

187193
quotaDriver *diskquota.PrjQuotaDriver
188194
quotaSize string
@@ -244,6 +250,7 @@ func NewSnapshotter(bootConfig *BootConfig, opts ...Opt) (snapshots.Snapshotter,
244250
mirrorRegistry: bootConfig.MirrorRegistry,
245251
defaultFsType: bootConfig.DefaultFsType,
246252
locker: locker.New(),
253+
turboFsType: bootConfig.TurboFsType,
247254
tenant: bootConfig.Tenant,
248255
quotaSize: bootConfig.RootfsQuota,
249256
quotaDriver: &diskquota.PrjQuotaDriver{
@@ -1390,10 +1397,19 @@ func IsErofsSupported() bool {
13901397

13911398
func (o *snapshotter) turboOCIFsMeta(id string) (string, string) {
13921399
// TODO: make the priority order (multi-meta exists) configurable later if needed
1393-
erofsmeta := filepath.Join(o.root, "snapshots", id, "fs", "erofs.fs.meta")
1394-
if _, err := os.Stat(erofsmeta); err == nil && IsErofsSupported() {
1395-
return erofsmeta, "erofs"
1400+
for _, fsType := range o.turboFsType {
1401+
fsmeta := filepath.Join(o.root, "snapshots", id, "fs", fsType+".fs.meta")
1402+
if _, err := os.Stat(fsmeta); err == nil {
1403+
if fsType == "erofs" && !IsErofsSupported() {
1404+
log.L.Warn("erofs is not supported on this system, fallback to other fs type")
1405+
continue
1406+
}
1407+
return fsmeta, fsType
1408+
} else if !errors.Is(err, os.ErrNotExist) {
1409+
log.L.Errorf("error while checking fs meta file: %s", err)
1410+
}
13961411
}
1412+
log.L.Warn("no fs meta file found, fallback to ext4")
13971413
return filepath.Join(o.root, "snapshots", id, "fs", "ext4.fs.meta"), "ext4"
13981414
}
13991415

0 commit comments

Comments
 (0)