From 209f328a9cfad4b3bbf62d6af7515817e4e6207f Mon Sep 17 00:00:00 2001 From: Hongzhen Luo Date: Tue, 8 Oct 2024 11:49:59 +0800 Subject: [PATCH] [EROFS] Add a check for erofs Add an additional check to verify whether the host machine truly supports the EROFS file system, and only mount it as the EROFS file system if it is supported. Signed-off-by: Hongzhen Luo --- pkg/snapshot/overlay.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/snapshot/overlay.go b/pkg/snapshot/overlay.go index e0f66680..76d53ac8 100644 --- a/pkg/snapshot/overlay.go +++ b/pkg/snapshot/overlay.go @@ -17,6 +17,7 @@ package snapshot import ( + "bytes" "context" "fmt" "os" @@ -1379,10 +1380,18 @@ func (o *snapshotter) blockPath(id string) string { return filepath.Join(o.root, "snapshots", id, "block") } +func IsErofsSupported() bool { + fs, err := os.ReadFile("/proc/filesystems") + if err != nil || !bytes.Contains(fs, []byte("\terofs\n")) { + return false + } + return true +} + 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 { + if _, err := os.Stat(erofsmeta); err == nil && IsErofsSupported() { return erofsmeta, "erofs" } return filepath.Join(o.root, "snapshots", id, "fs", "ext4.fs.meta"), "ext4"