Skip to content

Commit

Permalink
mount.snapshot: fix remove of last snapshot
Browse files Browse the repository at this point in the history
After last snapshot removal, remount 'nosnapshot'.

Signed-off-by: Amir Goldstein <[email protected]>
  • Loading branch information
amir73il committed Mar 10, 2017
1 parent 0b30203 commit 6a79134
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 19 additions & 4 deletions scripts/mount.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ mount_internal()
exec mount -i -t snapshot "$dev" "$mnt" -o "$mntopts"
}

freeze_thaw()
{
[ "$REMOUNT" = true ] || return
fsfreeze -f "$mntdir" || exit 1
fsfreeze -u "$mntdir" || exit 1
}

# Verify that overlayfs snapshot feature is enabled
grep -wq 'overlay' /proc/filesystems || modprobe overlay
grep -wq 'snapshot' /proc/filesystems || \
Expand All @@ -64,7 +71,12 @@ shift
mntopts="$1"
shift

REMOUNT=false
if ( echo "$mntopts" | grep -q remount ) ; then
REMOUNT=true
fi

if $REMOUNT; then
# Remount - parse <mnt> from <mnt>/_
mntdir="$mnt"
mnt="${mntdir%/@/_}"
Expand Down Expand Up @@ -102,8 +114,12 @@ snapshots="$snapdir/.snapshots"
[ ! -s "$snapshots" ] || id=$(tail -n 1 "$snapshots")

if [ -z "$id" ]; then
# No current snapshot - mount pass through snapshot mount
exec mount -i -t snapshot "$dev@" "$mntdir" -o"upperdir=$lower,$mntopts"
# No current snapshot - mount nosnapshot and exit
mount -i -t snapshot "$dev@" "$mntdir" \
-o"upperdir=$lower,nosnapshot,$mntopts" || exit 1
# freeze/thaw to deactivate old snapshot
freeze_thaw
exit 0
fi

cd "$lower" || exit 1
Expand Down Expand Up @@ -163,5 +179,4 @@ mount -i -t snapshot "$dev@" "$mntdir" \
mount -o remount,ro "$snapmnt" || exit 1

# freeze/thaw to activate new snapshot
fsfreeze -f "$mntdir" || exit 1
fsfreeze -u "$mntdir" || exit 1
freeze_thaw
4 changes: 1 addition & 3 deletions scripts/ovlsnapshot
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ case "$CMD" in
exit 0
fi
[ -n "$snap" ] || usage
if snapshot_is_mounted; then
error "cannot remove snapshot while snapshots are mounted!"
fi
if ! snapshot_exists $snap ; then
error "snapshot $S doesn't exist!"
fi
Expand All @@ -400,6 +397,7 @@ case "$CMD" in
fi

remove_snapshot $snap
remount_snapshot
echo "snapshot $S was removed"
echo .
;;
Expand Down

0 comments on commit 6a79134

Please sign in to comment.