Skip to content

Commit

Permalink
fix: kernel module dependency tree generation
Browse files Browse the repository at this point in the history
This fixes the issue when the overlay mount target directory was used as
lowerdir for the mount, creating extra folders in the extension.

Fix the issue by adding support for normal overlay mounts to use a
source directory when specified.

Also fixes a small issue where messages was logged when error is nil.

Signed-off-by: Noel Georgi <git@frezbo.dev>
  • Loading branch information
frezbo committed Feb 13, 2023
1 parent 65d02e5 commit 7b75cd8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions internal/pkg/extensions/kernel_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ func GenerateKernelModuleDependencyTreeExtension(extensionsPathWithKernelModules
// writable overlayfs mount inside a container required a tmpfs mount
overlays.Set("overlays-tmpfs", mount.NewMountPoint("tmpfs", constants.VarSystemOverlaysPath, "tmpfs", unix.MS_I_VERSION, ""))

rootfsKernelModulesPath := filepath.Join(rootfsMountPath, constants.DefaultKernelModulesPath)

// append the rootfs mount point
extensionsPathWithKernelModules = append(extensionsPathWithKernelModules, filepath.Join(rootfsMountPath, constants.DefaultKernelModulesPath))
extensionsPathWithKernelModules = append(extensionsPathWithKernelModules, rootfsKernelModulesPath)

// create the overlayfs mount point as read write
mp := mount.NewMountPoint("", strings.Join(extensionsPathWithKernelModules, ":"), "", unix.MS_I_VERSION, "", mount.WithFlags(mount.Overlay|mount.Shared))
mp := mount.NewMountPoint(strings.Join(extensionsPathWithKernelModules, ":"), rootfsKernelModulesPath, "", unix.MS_I_VERSION, "", mount.WithFlags(mount.Overlay|mount.Shared))
overlays.Set("overlays-mnt", mp)

if err = mount.Mount(overlays); err != nil {
Expand Down Expand Up @@ -168,7 +170,7 @@ func GenerateKernelModuleDependencyTreeExtension(extensionsPathWithKernelModules

func logErr(f func() error) {
// if file is already closed, ignore the error
if err := f(); !errors.Is(err, os.ErrClosed) {
if err := f(); err != nil && !errors.Is(err, os.ErrClosed) {
log.Println(err)
}
}
Expand Down
7 changes: 6 additions & 1 deletion internal/pkg/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,12 @@ func overlay(p *Point) error {
}
}

opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", p.target, diff, workdir)
lowerDir := p.target
if p.source != "" {
lowerDir = p.source
}

opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lowerDir, diff, workdir)
if err := unix.Mount("overlay", p.target, "overlay", 0, opts); err != nil {
return fmt.Errorf("error creating overlay mount to %s: %w", p.target, err)
}
Expand Down

0 comments on commit 7b75cd8

Please sign in to comment.