-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces support for ComposeFS using the EROFS filesystem to mount the file system metadata. The current implementation allows each layer to be mounted individually. Only images that are using the zstd:chunked and eStargz format can be used in this way since the metadata is stored in the image itself. In future support for arbitrary images can be added. Signed-off-by: Giuseppe Scrivano <[email protected]>
- Loading branch information
Showing
3 changed files
with
214 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build !linux || !composefs || !cgo | ||
// +build !linux !composefs !cgo | ||
|
||
package overlay | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func composeFsSupported() bool { | ||
return false | ||
} | ||
|
||
func generateComposeFsBlob(toc []byte, destFile string) error { | ||
return fmt.Errorf("composefs is not supported") | ||
} | ||
|
||
func mountErofsBlob(blobFile, mountPoint string) error { | ||
return fmt.Errorf("composefs is not supported") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//go:build linux && composefs && cgo | ||
// +build linux,composefs,cgo | ||
|
||
package overlay | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"sync" | ||
|
||
"github.com/containers/storage/pkg/loopback" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var ( | ||
composeFsHelperOnce sync.Once | ||
composeFsHelperPath string | ||
composeFsHelperErr error | ||
) | ||
|
||
func getComposeFsHelper() (string, error) { | ||
composeFsHelperOnce.Do(func() { | ||
composeFsHelperPath, composeFsHelperErr = exec.LookPath("composefs-from-json") | ||
}) | ||
return composeFsHelperPath, composeFsHelperErr | ||
} | ||
|
||
func composeFsSupported() bool { | ||
_, err := getComposeFsHelper() | ||
return err == nil | ||
} | ||
|
||
func generateComposeFsBlob(toc []byte, destFile string) error { | ||
writerJson, err := getComposeFsHelper() | ||
if err != nil { | ||
return fmt.Errorf("failed to find composefs-from-json: %w", err) | ||
} | ||
|
||
fd, err := unix.Openat(unix.AT_FDCWD, destFile, unix.O_WRONLY|unix.O_CREAT|unix.O_TRUNC|unix.O_EXCL|unix.O_CLOEXEC, 0o644) | ||
if err != nil { | ||
return fmt.Errorf("failed to open output file: %w", err) | ||
} | ||
outFd := os.NewFile(uintptr(fd), "outFd") | ||
|
||
defer outFd.Close() | ||
cmd := exec.Command(writerJson, "--format=erofs", "--out=/proc/self/fd/3", "/proc/self/fd/0") | ||
cmd.ExtraFiles = []*os.File{outFd} | ||
cmd.Stdin = bytes.NewReader(toc) | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("failed to convert json to erofs: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func mountErofsBlob(blobFile, mountPoint string) error { | ||
loop, err := loopback.AttachLoopDevice(blobFile) | ||
if err != nil { | ||
return err | ||
} | ||
defer loop.Close() | ||
|
||
return unix.Mount(loop.Name(), mountPoint, "erofs", unix.MS_RDONLY, "ro,noacl") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters