From b447627ec89a5c9173a3fb0b57b06cc3213151a7 Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Sun, 13 Dec 2020 12:15:59 +0200 Subject: [PATCH] snapshot: Check that / is a btrfs subvolume before setup Skip setup the snapshots app if the filesystem type is btrfs but / is not a btrfs subvolume. For example, this may happen in containers where / is a bind mounted btrfs filesystem. Closes #1994 Tests performed: - Install freedombox on a lxc container inside Pioneer-FreedomBox. (In a container, / is a bind mounted btrfs filesystem). The snapshot app setup is skipped. - Install freedombox inside dev container (which uses btrfs filesystem image). The snapshot app setup succeeds. - Install freedombox inside container that uses a host directory as a base and the filesystem is ext4. The snapshot app setup is skipped. Signed-off-by: Veiko Aasa [sunil: Add comment explaining the check, fix a flake8 message] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/snapshot/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plinth/modules/snapshot/__init__.py b/plinth/modules/snapshot/__init__.py index b126ab888..3e0bf44b6 100644 --- a/plinth/modules/snapshot/__init__.py +++ b/plinth/modules/snapshot/__init__.py @@ -4,6 +4,7 @@ FreedomBox app to manage filesystem snapshots. """ import json +import pathlib import augeas from django.utils.translation import ugettext_lazy as _ @@ -64,7 +65,11 @@ class SnapshotApp(app_module.App): def is_supported(): """Return whether snapshots are support on current setup.""" fs_type = storage.get_filesystem_type() - return fs_type in fs_types_supported + # Check that / is not a bind mounted btrfs filesystem similar to how + # snapper does the check: https://github.com/openSUSE/snapper/blob/ + # 77eb6565d3d8df95a06cd52ce31174d98994939c/snapper/BtrfsUtils.cc#L61 + root_inode_number = pathlib.Path('/').stat().st_ino + return fs_type in fs_types_supported and root_inode_number == 256 def setup(helper, old_version=None):