Skip to content

Commit

Permalink
ensure workdir and upperdir are on same fs
Browse files Browse the repository at this point in the history
This redefines the --persist argument to point to a directory where
atomfs will create or use both the workdir and the upperdir.

So if you run `atomfs mount --persist=foo/` then the persistent writes
will end up at foo/persist/.

Signed-off-by: Michael McCracken <[email protected]>
  • Loading branch information
mikemccracken committed Oct 31, 2024
1 parent a256377 commit 075ad2b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cmd/atomfs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var mountCmd = cli.Command{
Action: doMount,
Flags: []cli.Flag{
cli.StringFlag{
Name: "persist, upper, upperdir",
Usage: "Specify a directory to use as writeable overlay (implies --writeable)",
Name: "persist",
Usage: "Specify a directory to use for the workdir and upperdir of a writeable overlay (implies --writeable)",
},
cli.BoolFlag{
Name: "writeable, writable",
Expand Down
16 changes: 9 additions & 7 deletions molecule.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,20 @@ func (m Molecule) Mount(dest string) error {
return err
}

workdir := filepath.Join(metadir, "work")
if err := EnsureDir(workdir); err != nil {
return errors.Wrapf(err, "failed to ensure workdir")
persistMetaPath := m.config.WriteableOverlayPath
if persistMetaPath == "" {
// no configured path, use metadir
persistMetaPath = metadir
}

upperdir := m.config.WriteableOverlayPath
if upperdir == "" {
upperdir = filepath.Join(metadir, "persist")
workdir := filepath.Join(persistMetaPath, "work")
if err := EnsureDir(workdir); err != nil {
return errors.Wrapf(err, "failed to ensure workdir %q", workdir)
}

upperdir := filepath.Join(persistMetaPath, "persist")
if err := EnsureDir(upperdir); err != nil {
return errors.Wrapf(err, "failed to ensure upperdir")
return errors.Wrapf(err, "failed to ensure upperdir %q", upperdir)
}

defer func() {
Expand Down
12 changes: 6 additions & 6 deletions test/priv-mount.bats
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function setup() {
}

@test "mount with writeable overlay in separate dir" {
export PERSIST_DIR=${BATS_TEST_TMPDIR}/upperdir
export PERSIST_DIR=${BATS_TEST_TMPDIR}/persist-dir
mkdir -p $PERSIST_DIR
run atomfs --debug mount --persist=${PERSIST_DIR} ${BATS_SUITE_TMPDIR}/oci:test-squashfs $MP
assert_success
Expand All @@ -104,9 +104,9 @@ function setup() {
run cp $MP/1.README.md $MP/3.README.md
assert_success

assert_file_exists $PERSIST_DIR/this-time-let-me
assert_file_exists $PERSIST_DIR/3.README.md
assert_file_not_exists $PERSIST_DIR/1.README.md
assert_file_exists $PERSIST_DIR/persist/this-time-let-me
assert_file_exists $PERSIST_DIR/persist/3.README.md
assert_file_not_exists $PERSIST_DIR/persist/1.README.md

run atomfs --debug umount $MP
assert_success
Expand All @@ -117,6 +117,6 @@ function setup() {
assert [ -z $( ls -A $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/) ]

# but persist dir should still be there:
assert_file_exists $PERSIST_DIR/this-time-let-me
assert_file_exists $PERSIST_DIR/3.README.md
assert_file_exists $PERSIST_DIR/persist/this-time-let-me
assert_file_exists $PERSIST_DIR/persist/3.README.md
}
8 changes: 4 additions & 4 deletions test/unpriv-guestmount.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function setup() {
lxc-usernsexec -s <<EOF
set -x
export ATOMFS_TEST_RUN_DIR=$ATOMFS_TEST_RUN_DIR
export PERSIST_DIR=${BATS_TEST_TMPDIR}/upperdir
export PERSIST_DIR=${BATS_TEST_TMPDIR}/persist-dir
mkdir -p \$PERSIST_DIR
export INNER_MNTNSNAME=\$(readlink /proc/self/ns/mnt | cut -c 6-15)
Expand Down Expand Up @@ -50,7 +50,7 @@ function setup() {
find $ATOMFS_TEST_RUN_DIR/meta/\$INNER_MNTNSNAME/
atomfs --debug umount $MP
[ -f \$PERSIST_DIR/let-me-write ]
[ -f \$PERSIST_DIR/persist/let-me-write ]
# mount point and meta dir should be empty
[ -d $MP ]
Expand All @@ -69,7 +69,7 @@ EOF
lxc-usernsexec -s <<EOF
set -x
export ATOMFS_TEST_RUN_DIR=$ATOMFS_TEST_RUN_DIR
export PERSIST_DIR=${BATS_TEST_TMPDIR}/upperdir
export PERSIST_DIR=${BATS_TEST_TMPDIR}/persist-dir
mkdir -p \$PERSIST_DIR
export INNER_MNTNSNAME=\$(readlink /proc/self/ns/mnt | cut -c 6-15)
Expand All @@ -88,7 +88,7 @@ EOF
set -e
atomfs --debug umount $MP
[ -f \$PERSIST_DIR/let-me-write ]
[ -f \$PERSIST_DIR/persist/let-me-write ]
[ -d $MP ]
[ -z \$( ls -A $MP) ]
Expand Down

0 comments on commit 075ad2b

Please sign in to comment.