Skip to content

Commit

Permalink
support priority order for turbo fs type
Browse files Browse the repository at this point in the history
Signed-off-by: zhuangbowei.zbw <[email protected]>
  • Loading branch information
WaberZhuang committed Oct 16, 2024
1 parent d2698f7 commit c7f1e6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
14 changes: 14 additions & 0 deletions cmd/overlaybd-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ func main() {
go metrics.Init()
logrus.Infof("set Prometheus metrics exporter in http://localhost:%d%s", metrics.Config.Port, metrics.Config.UriPrefix)
}
contain := func(fsType string) bool {
for _, fst := range pconfig.TurboFsType {
if fst == fsType {
return true
}
}
return false
}
if !contain("ext4") {
pconfig.TurboFsType = append(pconfig.TurboFsType, "ext4")
}
if !contain("erofs") {
pconfig.TurboFsType = append(pconfig.TurboFsType, "erofs")
}

if err := setLogLevel(pconfig.LogLevel); err != nil {
logrus.Errorf("failed to set log level: %v", err)
Expand Down
22 changes: 19 additions & 3 deletions pkg/snapshot/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type BootConfig struct {
DefaultFsType string `json:"defaultFsType"`
RootfsQuota string `json:"rootfsQuota"` // "20g" rootfs quota, only effective when rwMode is 'overlayfs'
Tenant int `json:"tenant"` // do not set this if only a single snapshotter service in the host
TurboFsType []string `json:"turboFsType"`
}

func DefaultBootConfig() *BootConfig {
Expand All @@ -115,6 +116,10 @@ func DefaultBootConfig() *BootConfig {
DefaultFsType: "ext4",
RootfsQuota: "",
Tenant: -1,
TurboFsType: []string{
"ext4",
"erofs",
},
}
}

Expand Down Expand Up @@ -183,6 +188,7 @@ type snapshotter struct {
defaultFsType string
tenant int
locker *locker.Locker
turboFsType []string

quotaDriver *diskquota.PrjQuotaDriver
quotaSize string
Expand Down Expand Up @@ -244,6 +250,7 @@ func NewSnapshotter(bootConfig *BootConfig, opts ...Opt) (snapshots.Snapshotter,
mirrorRegistry: bootConfig.MirrorRegistry,
defaultFsType: bootConfig.DefaultFsType,
locker: locker.New(),
turboFsType: bootConfig.TurboFsType,
tenant: bootConfig.Tenant,
quotaSize: bootConfig.RootfsQuota,
quotaDriver: &diskquota.PrjQuotaDriver{
Expand Down Expand Up @@ -1390,10 +1397,19 @@ func IsErofsSupported() bool {

func (o *snapshotter) turboOCIFsMeta(id string) (string, string) {
// TODO: make the priority order (multi-meta exists) configurable later if needed
erofsmeta := filepath.Join(o.root, "snapshots", id, "fs", "erofs.fs.meta")
if _, err := os.Stat(erofsmeta); err == nil && IsErofsSupported() {
return erofsmeta, "erofs"
for _, fsType := range o.turboFsType {
fsmeta := filepath.Join(o.root, "snapshots", id, "fs", fsType+".fs.meta")
if _, err := os.Stat(fsmeta); err == nil {
if fsType == "erofs" && !IsErofsSupported() {
log.L.Warn("erofs is not supported on this system, fallback to other fs type")
continue
}
return fsmeta, fsType
} else if !errors.Is(err, os.ErrNotExist) {
log.L.Errorf("error while checking fs meta file: %s", err)
}
}
log.L.Warn("no fs meta file found, fallback to ext4")
return filepath.Join(o.root, "snapshots", id, "fs", "ext4.fs.meta"), "ext4"
}

Expand Down

0 comments on commit c7f1e6b

Please sign in to comment.