Skip to content

Commit

Permalink
mount.snapshot: mount previous snapshot with upperdir
Browse files Browse the repository at this point in the history
Instead of stacking 2 last snapshots as 2 lower layers, use current
snapshot as lower and previous layer as upper layer.
This is needed for previous snapshot to follow merge directory
into current snapshot through rename/delete in snapshot mount.

Old snapshots must be mounted after activation of new snapshot,
because the new "last" snapshot needs to use the "last" upper
and the upper holds the in-use exclusive lock bit until the new
snapshot is activated.

Signed-off-by: Amir Goldstein <[email protected]>
  • Loading branch information
amir73il committed Jan 11, 2018
1 parent ca66f8c commit 0a9ec54
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions scripts/mount.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,23 @@ _cleanup()
mount_old_snapshots()
{
local old_snapshots=$snapmnt
local prev=""

# mount snapshots from newest to oldest
tac "$snapshots" | while read old; do
[ "$old" != "$id" ] || continue
oldsnap="@/$old"
oldmnt="$oldsnap/_"
[ -d "$oldsnap" ] || continue
old_snapshots="$oldsnap/u:$old_snapshots"
[ -d "$oldmnt" ] || continue
mount -i -t overlay "$dev@$old" "$oldmnt" \
[ -n "$prev" ] || \
mount -i -t overlay "$dev@$old" "$oldmnt" \
-o"ro,upperdir=$oldsnap/u,workdir=$oldsnap/w,lowerdir=$old_snapshots,$snapmntopts"
old_snapshots="$oldsnap/u:$old_snapshots"
[ -z "$prev" ] || \
mount -i -t overlay "$dev@$old" "$oldmnt" \
-o"ro,lowerdir=$old_snapshots,$oldsnapmntopts"
prev=$old
done
}

Expand All @@ -177,8 +183,8 @@ mount -i -t snapshot "$dev@" "$mntdir" \
# Remount current snapshot overlay read-only
mount -o remount,ro "$snapmnt" || exit 1

# Mount older snapshot overlays
mount_old_snapshots

# freeze/thaw to activate new snapshot
freeze_thaw

# Mount older snapshot overlays
mount_old_snapshots

0 comments on commit 0a9ec54

Please sign in to comment.