@@ -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
14741480func IsErofsSupported () bool {
1475- fs , err := os .ReadFile ("/proc/filesystems" )
1476- if err != nil || ! bytes .Contains (fs , []byte ("\t erofs\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 ("\t erofs\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 ("\t erofs\n " )) {
1492+ return
1493+ }
1494+ }
1495+ erofsSupported = true
1496+ })
1497+ return erofsSupported
14801498}
14811499
14821500func (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 {
0 commit comments