fix: kernel module dependency tree generation
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>
This commit is contained in:
@ -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 {
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user