Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support priority order for turbo fs type #309

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading