Skip to content

Commit

Permalink
automatically exclude btrfs snapshot subvolumes from 'btrfsmountedsub…
Browse files Browse the repository at this point in the history
…vol'

Related: #3175 (comment)
  • Loading branch information
lzaoral committed May 14, 2024
1 parent 6389691 commit 4742906
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ fi
# Output header only once:
btrfsmountedsubvol_entry_exists="yes"
echo "# All mounted btrfs subvolumes (including mounted btrfs default subvolumes and mounted btrfs snapshot subvolumes)."
echo "Mounted btrfs snapshot subvolumes are autoexcluded.

This comment has been minimized.

Copy link
@jsmeix

jsmeix May 14, 2024

Member

Here you must use

echo "# ..."

because here STDOUT gets written into disklayout.conf
because that code is within the

# Begin of group command that appends its stdout to DISKLAYOUT_FILE:
{

...

} 1>>$DISKLAYOUT_FILE
# End of group command that appends its stdout to DISKLAYOUT_FILE

Yes - I know - that is horrible coding style
which needs to be cleaned up - at some time -
as time permits - i.e. "never in practice" :-(

This comment has been minimized.

Copy link
@lzaoral

lzaoral May 14, 2024

Author Contributor

Yes, my bad. I have immediately pushed a fixup which fixes the quoting.

This comment has been minimized.

Copy link
@lzaoral

lzaoral May 14, 2024

Author Contributor

Oh, right, I forgot to push the # as well. This morning will be hard... 😄

This comment has been minimized.

Copy link
@jsmeix

jsmeix May 14, 2024

Member

Ah - I didn't notice the missing closing ".
Thanks for the fixes!

This comment has been minimized.

Copy link
@lzaoral

lzaoral May 14, 2024

Author Contributor

All problems with that line should be resolved in 018c528.

This comment has been minimized.

Copy link
@jsmeix

jsmeix May 14, 2024

Member

Now it looks good.

if test "$findmnt_FSROOT_works" ; then
echo "# Determined by the findmnt command that shows the mounted btrfs_subvolume_path."
echo "# Format: btrfsmountedsubvol <device> <subvolume_mountpoint> <mount_options> <btrfs_subvolume_path>"
Expand Down Expand Up @@ -469,7 +470,10 @@ fi
# Finally, test whether the btrfs subvolume listed as mounted actually exists. A running docker
# daemon apparently can convince the system to list a non-existing btrfs volume as mounted.
# See https://github.com/rear/rear/issues/1496
if btrfs_subvolume_exists "$subvolume_mountpoint" "$btrfs_subvolume_path"; then
if btrfs_snapshot_subvolume_exists "$subvolume_mountpoint" "$btrfs_subvolume_path"; then
# Exclude mounted snapshot subvolumes
echo "#btrfsmountedsubvol $device $subvolume_mountpoint $mount_options $btrfs_subvolume_path"
elif btrfs_subvolume_exists "$subvolume_mountpoint" "$btrfs_subvolume_path"; then
echo "btrfsmountedsubvol $device $subvolume_mountpoint $mount_options $btrfs_subvolume_path"
else
LogPrintError "Ignoring non-existing btrfs subvolume listed as mounted: $subvolume_mountpoint"
Expand Down
13 changes: 12 additions & 1 deletion usr/share/rear/lib/filesystems-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
#
# File system support functions

function btrfs_snapshot_subvolume_exists() {
# returns true if the btrfs snapshot subvolume ($2) exists in the Btrfs
# file system at the mount point ($1).

# Use -s so that btrfs subvolume list considers snapshots only
btrfs_subvolume_exists "$1" "$2" "-s"
}

function btrfs_subvolume_exists() {
# returns true if the btrfs subvolume ($2) exists in the Btrfs file system at the mount point ($1).
local subvolume_mountpoint="$1" btrfs_subvolume_path="$2"

# extra options for the btrfs subvolume list command ($3)
local btrfs_extra_opts="$3"

# A root subvolume can be assumed to always exist
[ "$btrfs_subvolume_path" == "/" ] && return 0

# A non-root subvolume exists if the btrfs subvolume list contains its complete path at the end of one line.
# This code deliberately uses a plain string comparison rather than a regexp.
btrfs subvolume list -a "$subvolume_mountpoint" | sed -e 's; path <FS_TREE>/; path ;' |
btrfs subvolume list -a $btrfs_extra_opts "$subvolume_mountpoint" | sed -e 's; path <FS_TREE>/; path ;' |
awk -v path="$btrfs_subvolume_path" '
BEGIN {
match_string = " path " path;
Expand Down

0 comments on commit 4742906

Please sign in to comment.