Skip to content

Commit c5dd4fa

Browse files
authored
Merge pull request #316 from hsiangkao/turbooci_erofs
EROFS TurboOCI enhancement
2 parents 8f3673c + ba88b6f commit c5dd4fa

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

pkg/snapshot/overlay.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import (
2121
"context"
2222
"fmt"
2323
"os"
24+
"os/exec"
2425
"path/filepath"
2526
"strings"
27+
"sync"
2628
"syscall"
2729
"time"
2830
"unsafe"
@@ -119,8 +121,8 @@ func DefaultBootConfig() *BootConfig {
119121
RootfsQuota: "",
120122
Tenant: -1,
121123
TurboFsType: []string{
122-
"ext4",
123124
"erofs",
125+
"ext4",
124126
},
125127
}
126128
}
@@ -606,9 +608,9 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
606608
if isTurboOCI, _, _ := o.checkTurboOCI(obdInfo.Labels); isTurboOCI {
607609
_, fsType = o.turboOCIFsMeta(obdID)
608610
} else {
611+
log.G(ctx).Warnf("cannot get fs type from label, %v, using %s", obdInfo.Labels, fsType)
609612
fsType = o.defaultFsType
610613
}
611-
log.G(ctx).Warnf("cannot get fs type from label, %v, using %s", obdInfo.Labels, fsType)
612614
}
613615
log.G(ctx).Debugf("attachAndMountBlockDevice (obdID: %s, writeType: %s, fsType %s, targetPath: %s)",
614616
obdID, writeType, fsType, o.overlaybdTargetPath(obdID))
@@ -1471,16 +1473,31 @@ func (o *snapshotter) blockPath(id string) string {
14711473
return filepath.Join(o.root, "snapshots", id, "block")
14721474
}
14731475

1476+
var erofsSupported = false
1477+
var erofsSupportedOnce sync.Once
1478+
1479+
// If EROFS fsmeta exists and is prioritized, check and modprobe erofs
14741480
func IsErofsSupported() bool {
1475-
fs, err := os.ReadFile("/proc/filesystems")
1476-
if err != nil || !bytes.Contains(fs, []byte("\terofs\n")) {
1477-
return false
1478-
}
1479-
return true
1481+
erofsSupportedOnce.Do(func() {
1482+
fs, err := os.ReadFile("/proc/filesystems")
1483+
if err != nil || !bytes.Contains(fs, []byte("\terofs\n")) {
1484+
// Try to `modprobe erofs` again
1485+
cmd := exec.Command("modprobe", "erofs")
1486+
_, err = cmd.CombinedOutput()
1487+
if err != nil {
1488+
return
1489+
}
1490+
fs, err = os.ReadFile("/proc/filesystems")
1491+
if err != nil || !bytes.Contains(fs, []byte("\terofs\n")) {
1492+
return
1493+
}
1494+
}
1495+
erofsSupported = true
1496+
})
1497+
return erofsSupported
14801498
}
14811499

14821500
func (o *snapshotter) turboOCIFsMeta(id string) (string, string) {
1483-
// TODO: make the priority order (multi-meta exists) configurable later if needed
14841501
for _, fsType := range o.turboFsType {
14851502
fsmeta := filepath.Join(o.root, "snapshots", id, "fs", fsType+".fs.meta")
14861503
if _, err := os.Stat(fsmeta); err == nil {

pkg/snapshot/storage.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ const (
6666
// param used to restrict tcmu data area size
6767
// it is worked by setting max_data_area_mb for devices in configfs.
6868
obdMaxDataAreaMB = 4
69+
70+
// Just in case someone really needs to force to ext4
71+
ext4FSFallbackFile = ".TurboOCI_ext4"
6972
)
7073

7174
type mountMatcherFunc func(fields []string, separatorIndex int) bool
@@ -542,7 +545,15 @@ func (o *snapshotter) constructOverlayBDSpec(ctx context.Context, key string, wr
542545

543546
configJSON.RepoBlobURL = blobPrefixURL
544547
if isTurboOCI, dataDgst, compType := o.checkTurboOCI(info.Labels); isTurboOCI {
545-
fsmeta, _ := o.turboOCIFsMeta(id)
548+
var fsmeta string
549+
550+
// If parent layers exist, follow the meta choice from the bottom layer
551+
if info.Parent != "" {
552+
_, fsmeta = filepath.Split(configJSON.Lowers[0].File)
553+
fsmeta = filepath.Join(o.root, "snapshots", id, "fs", fsmeta)
554+
} else {
555+
fsmeta, _ = o.turboOCIFsMeta(id)
556+
}
546557
lower := sn.OverlayBDBSConfigLower{
547558
Dir: o.upperPath(id),
548559
// keep this to support ondemand turboOCI loading.
@@ -651,6 +662,22 @@ func (o *snapshotter) constructOverlayBDSpec(ctx context.Context, key string, wr
651662
Data: o.overlaybdWritableDataPath(id),
652663
}
653664
}
665+
666+
if isTurboOCI, _, _ := o.checkTurboOCI(info.Labels); isTurboOCI {
667+
// If the fallback file exists, enforce TurboOCI fstype to EXT4
668+
ext4FSFallbackPath := filepath.Join(o.root, ext4FSFallbackFile)
669+
_, err = os.Stat(ext4FSFallbackPath)
670+
if err == nil && configJSON.Lowers[0].File != "" {
671+
var newLowers []sn.OverlayBDBSConfigLower
672+
log.G(ctx).Infof("fallback to EXT4 since %s exists", ext4FSFallbackPath)
673+
for _, l := range configJSON.Lowers {
674+
s, _ := filepath.Split(l.File)
675+
l.File = filepath.Join(s, "ext4.fs.meta")
676+
newLowers = append(newLowers, l)
677+
}
678+
configJSON.Lowers = newLowers
679+
}
680+
}
654681
configBuffer, _ := json.MarshalIndent(configJSON, "", " ")
655682
log.G(ctx).Infoln(string(configBuffer))
656683
return o.atomicWriteOverlaybdTargetConfig(id, &configJSON)

0 commit comments

Comments
 (0)