From c7f1e6bd20868aba05d9b0aeeba8a0e191d9fd91 Mon Sep 17 00:00:00 2001 From: "zhuangbowei.zbw" Date: Wed, 16 Oct 2024 16:40:33 +0800 Subject: [PATCH] support priority order for turbo fs type Signed-off-by: zhuangbowei.zbw --- cmd/overlaybd-snapshotter/main.go | 14 ++++++++++++++ pkg/snapshot/overlay.go | 22 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cmd/overlaybd-snapshotter/main.go b/cmd/overlaybd-snapshotter/main.go index a1d639d6..937517e2 100644 --- a/cmd/overlaybd-snapshotter/main.go +++ b/cmd/overlaybd-snapshotter/main.go @@ -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) diff --git a/pkg/snapshot/overlay.go b/pkg/snapshot/overlay.go index 76d53ac8..5e30f911 100644 --- a/pkg/snapshot/overlay.go +++ b/pkg/snapshot/overlay.go @@ -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 { @@ -115,6 +116,10 @@ func DefaultBootConfig() *BootConfig { DefaultFsType: "ext4", RootfsQuota: "", Tenant: -1, + TurboFsType: []string{ + "ext4", + "erofs", + }, } } @@ -183,6 +188,7 @@ type snapshotter struct { defaultFsType string tenant int locker *locker.Locker + turboFsType []string quotaDriver *diskquota.PrjQuotaDriver quotaSize string @@ -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{ @@ -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" }