Skip to content

Commit

Permalink
Move metadata path to /run
Browse files Browse the repository at this point in the history
In order to make it trivial to read the config.json for a given mount,
move the metadata path to /run/atomfs/meta/$munged-mountpt-name/

Signed-off-by: Michael McCracken <[email protected]>
  • Loading branch information
mikemccracken committed Oct 1, 2024
1 parent 7fadf7d commit 98626ba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
25 changes: 21 additions & 4 deletions cmd/atomfs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ func doMount(ctx *cli.Context) error {
os.Exit(1)
}
target := ctx.Args()[1]
metadir := filepath.Join(target, "meta")
absTarget, err := filepath.Abs(target)
if err != nil {
return err
}

metadir := filepath.Join("/run", "atomfs", "meta", ReplacePathSeparators(absTarget))

complete := false

Expand All @@ -92,12 +97,24 @@ func doMount(ctx *cli.Context) error {
if err = EnsureDir(rodest); err != nil {
return err
}
absOCIDir, err := filepath.Abs(ocidir)
if err != nil {
return err
}
absMetadir, err := filepath.Abs(metadir)
if err != nil {
return err
}
absRODest, err := filepath.Abs(rodest)
if err != nil {
return err
}

opts := atomfs.MountOCIOpts{
OCIDir: ocidir,
MetadataPath: metadir,
OCIDir: absOCIDir,
MetadataPath: absMetadir,
Tag: tag,
Target: rodest,
Target: absRODest,
}

mol, err := atomfs.BuildMoleculeFromOCI(opts)
Expand Down
13 changes: 7 additions & 6 deletions cmd/atomfs/umount.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ func doUmount(ctx *cli.Context) error {
errs = append(errs, fmt.Errorf("Failed unmounting %s: %v", mountpoint, err))
}

// Now that we've unmounted the mountpoint, we expect the following
// under there:
// $mountpoint/meta/ro - the original readonly overlay mountpoint
// $mountpoint/meta/mounts/* - the original squashfs mounts
metadir := filepath.Join(mountpoint, "meta")
// We expect the following in the metadir
//
// $metadir/ro - the original readonly overlay mountpoint
// $metadir/meta/mounts/* - the original squashfs mounts
// $metadir/meta/config.json
metadir := filepath.Join("/run/atomfs/meta", ReplacePathSeparators(mountpoint))
p := filepath.Join(metadir, "ro")
err = syscall.Unmount(p, 0)
if err != nil {
Expand All @@ -65,7 +66,7 @@ func doUmount(ctx *cli.Context) error {
mounts, err := os.ReadDir(mountsdir)
if err != nil {
errs = append(errs, fmt.Errorf("Failed reading list of mounts: %v", err))
return fmt.Errorf("Encountered errors: %#v", errs)
return fmt.Errorf("Encountered errors: %v", errs)
}

for _, m := range mounts {
Expand Down
10 changes: 10 additions & 0 deletions cmd/atomfs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strings"
)

func EnsureDir(dir string) error {
Expand All @@ -20,3 +21,12 @@ func PathExists(d string) bool {
}
return true
}

// remove dir separators to make one dir name. It is OK that this can't be
// cleanly backed out, we don't need it to
func ReplacePathSeparators(p string) string {
if p[0] == '/' {
p = p[1:]
}
return strings.ReplaceAll(p, "/", "-")
}

0 comments on commit 98626ba

Please sign in to comment.