Skip to content

Commit

Permalink
ovlsnapshot: use path <mnt>@ instead of <mnt>/@ as snapshots dir
Browse files Browse the repository at this point in the history
Avoid "overlapping upper dir" mount error.
Create all snapshot dirs not under lower dir (<mnt>).

Signed-off-by: Amir Goldstein <[email protected]>
  • Loading branch information
amir73il committed Jan 20, 2020
1 parent 73ed9ce commit 9b94278
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
26 changes: 13 additions & 13 deletions scripts/mount.snapshot
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh
# mount.snapshot <dev> <mnt> [-o <opt>]
# mount.snapshot <dev> <mnt>/@/_
# mount.snapshot <dev> <mnt>/@/_ -o remount
# mount.snapshot <dev> <mnt>@/_
# mount.snapshot <dev> <mnt>@/_ -o remount
#
# Overlayfs snapshot mount helper
#
# - Check if snapshots stack exists at <mnt>/@/.snapshots
# - Mount (or remount) snapshot mount at <mnt>/@/_
# - Mount snapshot overlays at <mnt>/@/<id>/_
# - Check if snapshots stack exists at <mnt>@/.snapshots
# - Mount (or remount) snapshot mount at <mnt>@/_
# - Mount snapshot overlays at <mnt>@/<id>/_
#
# * If any mount flags other than -o rw[,remount] are passed to helper,
# it passes the command as is without doing the above
Expand Down Expand Up @@ -77,9 +77,9 @@ if ( echo "$mntopts" | grep -q remount ) ; then
REMOUNT=true
fi

# Try to parse <mnt> from <mnt>/@/_
# Try to parse <mnt> from <mnt>@/_
mntdir="$mnt"
mnt="${mntdir%/@/_}"
mnt="${mntdir%@/_}"
[ "$mnt" != "$mntdir" ] || mount_internal

if $REMOUNT; then
Expand All @@ -88,9 +88,9 @@ if $REMOUNT; then
mntopts="rw,remount"
# snapshot overlays do not support remount -
# they have to be umounted/mounted
umount -i "$mnt"/@/*/_ 2>/dev/null
umount -i "$mnt"@/*/_ 2>/dev/null
else
# Verify snapshot is not already mounted on <mnt>/@/_
# Verify snapshot is not already mounted on <mnt>@/_
mount -t snapshot | while read d on m opt; do
[ "$m" != "$mntdir" -a "$m" != "$mnt" ] || \
error "overlayfs snapshot already mounted at '$m'."
Expand All @@ -106,7 +106,7 @@ snapmntopts="noatime,index=on,nfs_export=on,redirect_dir=origin"
oldsnapmntopts="noatime"

lower="$mnt"
snapdir="$mnt/@"
snapdir="$mnt@"
snapshots="$snapdir/.snapshots"
[ ! -s "$snapshots" ] || id=$(tail -n 1 "$snapshots")

Expand All @@ -119,10 +119,10 @@ if [ -z "$id" ]; then
exit 0
fi

cd "$lower" || exit 1
cd "$snapdir" || exit 1

# Relative to $lower to keep overlay mount options shorter
current="@/$id"
current="$id"
upper="$current/u"
work="$current/w"
snapmnt="$current/_"
Expand All @@ -144,7 +144,7 @@ mount_old_snapshots()
# mount snapshots from newest to oldest
tac "$snapshots" | while read old; do
[ "$old" != "$id" ] || continue
oldsnap="@/$old"
oldsnap="$old"
oldmnt="$oldsnap/_"
[ -d "$oldsnap" ] || continue
[ -d "$oldmnt" ] || continue
Expand Down
20 changes: 10 additions & 10 deletions scripts/ovlsnapshot
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ usage()
echo "$FSTYPE snapshot commands:"
echo "usage: $SCRIPT_NAME {status|list} [<path>|-a]"
echo "usage: $SCRIPT_NAME {umount|mount} [<path>|-a]"
echo "usage: $SCRIPT_NAME {create|take} <path>[[/]@[/]<snapshot-name>] (default-name=<date.time>)"
echo "usage: $SCRIPT_NAME {delete|remove} <path>[/]@[/]<snapshot-name>"
echo "usage: $SCRIPT_NAME {create|take} <path>[@[/]<snapshot-name>] (default-name=<date.time>)"
echo "usage: $SCRIPT_NAME {delete|remove} <path>@[/]<snapshot-name>"
echo "usage: $SCRIPT_NAME {clean} <path>"
echo
echo "snapshot command parameter may be given in ZFS style <path>@<snapshot-name>"
echo "and it may be given as the snapshot directory path <path>/@/<snapshot-name>."
echo "and it may be given as the snapshot directory path <path>@/<snapshot-name>."
echo "If <snapshot-name> part is omitted, command may apply to all snapshots (e.g. umount)."
echo
echo "$FSTYPE snapshot test commands:"
echo "usage: $SCRIPT_NAME {test|tests} <path> [test-number] [file-size-mb]"
echo "usage: $SCRIPT_NAME {check} <path>[[/]@[/]<snapshot-name>]"
echo "usage: $SCRIPT_NAME {check} <path>[@[/]<snapshot-name>]"
echo
exit $1
}
Expand All @@ -117,10 +117,10 @@ parse_path_snapshot_arg()
MNT=${1%/}
snap=${2#/}
# directory inside <path> to store snapshot related files
SNAPDIR=$MNT/@
SNAPDIR=$MNT@
# directory prefix for snapshot mount points
# snaphot mount points will be created as $SNAPROOT/<snapshot-name>/_
SNAPROOT=$MNT/@
SNAPROOT=$MNT@
SNAPMNT=$SNAPROOT/_
# file to store snapshots stack
SNAPSHOTS="$SNAPDIR/.snapshots"
Expand Down Expand Up @@ -484,7 +484,7 @@ case "$CMD" in
create|take)
if [ "$2" = help ]; then
echo "$CMD: create a new snapshot."
echo "usage: $SCRIPT_NAME {create|take} <path>[[/]@[/]<snapshot-name>] (default-name=<date.time>)"
echo "usage: $SCRIPT_NAME {create|take} <path>[@[/]<snapshot-name>] (default-name=<date.time>)"
exit 0
fi
if [ -z "$snap" ] ; then
Expand All @@ -507,7 +507,7 @@ case "$CMD" in
echo "delete: umount a snapshot and mark it for deletion."
echo "any non-mounted snapshot can be marked for deletion"
echo "but some snapshot deletion is deferred to later time."
echo "usage: $SCRIPT_NAME delete <path>[/]@[/]<snapshot-name>"
echo "usage: $SCRIPT_NAME delete <path>@[/]<snapshot-name>"
exit 0
fi
[ -n "$snap" ] || usage 1
Expand All @@ -530,7 +530,7 @@ case "$CMD" in
echo "remove: delete a snapshot permanently."
echo "this command will fail for active snapshot and snapshots"
echo "in use by older snapshots. try using the delete command."
echo "usage: $SCRIPT_NAME remove <path>[/]@[/]<snapshot-name>"
echo "usage: $SCRIPT_NAME remove <path>@[/]<snapshot-name>"
exit 0
fi
[ -n "$snap" ] || usage 1
Expand Down Expand Up @@ -727,7 +727,7 @@ case "$CMD" in
check)
if [ "$2" = help ]; then
echo "check: verify content of test snapshot."
echo "usage: $SCRIPT_NAME check <path>[[/]@[/]<snapshot-name>]"
echo "usage: $SCRIPT_NAME check <path>[@[/]<snapshot-name>]"
exit 0
fi
lstest $snap
Expand Down
16 changes: 8 additions & 8 deletions scripts/umount.snapshot
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh
# umount.snapshot <mnt>
# umount.snapshot <mnt>/@/_
# umount.snapshot <mnt>@/_
#
# Overlayfs snapshot umount helper
#
# - Unmount snapshot overlays <mnt>/@/*/_
# - Unmount snapshot mount at <mnt>/@/_
# - Unmount snapshot overlays <mnt>@/*/_
# - Unmount snapshot mount at <mnt>@/_
#
# * If mount point does not end with /@/_, pass the command as is
# * If mount point does not end with @/_, pass the command as is
# without doing the above
#
#-----------------------------------------------------------------------
Expand All @@ -34,17 +34,17 @@ mnt="${1%/}"

[ -d "$mnt" ] || exit 1

# Try to parse <mnt> from <mnt>/@/_
# Try to parse <mnt> from <mnt>@/_
mntdir="$mnt"
mnt="${mntdir%/@/_}"
mnt="${mntdir%@/_}"

# If mount point doesn't end with /@/_ bypass helper.
# If mount point doesn't end with @/_ bypass helper.
if [ "$mnt" = "$mntdir" ]; then
echo "$*" > /tmp/umount.snapshot.in
exec umount -i $*
fi

snapdir="$mnt/@"
snapdir="$mnt@"
snapshots="$snapdir/.snapshots"

umount_snapshots()
Expand Down

0 comments on commit 9b94278

Please sign in to comment.