Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versioning based on btrfs snapshots #3420

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create bottles as btrfs subvolumes
Borgvall committed Jul 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 236985ff96db2cf2a86b14e3e4a67d5972c78e0a
29 changes: 28 additions & 1 deletion bottles/backend/managers/btrfssubvolume.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,11 @@
import os.path
import btrfsutil

# Internal subvolumes created at initialization time:
_internal_subvolumes = [
"cache",
]

class BtrfsSubvolumeManager:
"""
Manager to handle bottles created as btrfs subvolume.
@@ -11,4 +16,26 @@ def __init__(
self,
manager,
):
self.manager = manager
self._manager = manager

@staticmethod
def create_bottle_as_subvolume(bottle_path) -> bool:
"""Create bottle as btrfs subvolume.
Creates the directory 'bottle_path' as btrfs subvolume and internal
subvolumes inside of it. Returns True on success and False on failure.
In particular it fails, if the filesystem is not btrfs.
"""

os.makedirs(os.path.dirname(bottle_path), exist_ok=True)
try:
btrfsutil.create_subvolume(bottle_path)
for internal_subvolume in _internal_subvolumes:
path = os.path.join(bottle_path, internal_subvolume)
btrfsutil.create_subvolume(path)
except btrfsutil.BtrfsUtilError as error:
if not error.btrfsutilerror == btrfsutil.ERROR_NOT_BTRFS:
raise
return False
else:
return True
10 changes: 6 additions & 4 deletions bottles/backend/managers/manager.py
Original file line number Diff line number Diff line change
@@ -1069,7 +1069,8 @@ def create_bottle_from_config(self, config: BottleConfig) -> bool:
config.Name = f"{config.Name}__{rnd}"
config.Path = f"{config.Path}__{rnd}"

os.makedirs(bottle_path)
if not self.btrfs_subvolume_manager.create_bottle_as_subvolume(bottle_path):
os.makedirs(bottle_path)

# Pre-create drive_c directory and set the case-fold flag
bottle_drive_c = os.path.join(bottle_path, "drive_c")
@@ -1232,14 +1233,15 @@ def components_check():

# create the bottle directory
try:
os.makedirs(bottle_complete_path)
if not self.btrfs_subvolume_manager.create_bottle_as_subvolume(bottle_complete_path):
os.makedirs(bottle_complete_path)
# Pre-create drive_c directory and set the case-fold flag
bottle_drive_c = os.path.join(bottle_complete_path, "drive_c")
os.makedirs(bottle_drive_c)
FileUtils.chattr_f(bottle_drive_c)
except:
except RuntimeError as e:
logging.error(
f"Failed to create bottle directory: {bottle_complete_path}", jn=True
f"Failed to create bottle directory '{bottle_complete_path}' {e}", jn=True
)
log_update(_("Failed to create bottle directory."))
return Result(False)