Skip to content

Commit

Permalink
Removed support for btrfs filesystems on a file. refs: #41
Browse files Browse the repository at this point in the history
  • Loading branch information
spanezz committed Jun 29, 2022
1 parent 5937068 commit 7fe4c4b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 122 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version UNRELEASED

* Removed support for a btrfs filesystem in a file (#41)

# Version 0.6

* Fixed network issues with systemd-resolved based images (Fedora 36)
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,8 @@ For running the test suite of local code on a different OS, see [Testing on anot
## Technology

Moncic-CI uses [systemd-nspawn](https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html)
as a backend, and a [btrfs](https://btrfs.wiki.kernel.org/index.php/Main_Page)
filesystem for storage and fast snapshotting.

The btrfs storage can be just a normal directory for systems that already use
btrfs or can easily setup a btrfs partition. Otherwise, with a small
performance penalty, Moncic-CI can [store OS images in a
file](doc/btrfs-on-file.md) by managing a btrfs filesystem inside it.
as a backend. When using a [btrfs](https://btrfs.wiki.kernel.org/index.php/Main_Page)
filesystem it can optionally use its features to reduce disk usage.


## Distributions supported
Expand Down Expand Up @@ -112,7 +107,6 @@ ubuntu:jammy jammy, ubuntu:22.04

* [Security considerations](doc/security.md)
* [Image bootstrapping and maintenance](doc/image-maintenance.md)
* [OS images in a file](doc/btrfs-on-file.md)

## Reference documentation

Expand Down
52 changes: 0 additions & 52 deletions doc/btrfs-on-file.md

This file was deleted.

4 changes: 0 additions & 4 deletions doc/moncic-ci-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ The only keyword currently supported is:
* `compression`: [btrfs compression attribute](https://btrfs.wiki.kernel.org/index.php/Compression)
to set on OS image subvolumes when they are created. The value is the same as
can be set by `btrfs property set compression`. By default, nothing is set.
* `trim_image_file`: if set to True, automatically run fstrim on the image file
after regular maintenance. If set to False, do not do that. By default,
Moncic-CI will run fstrim if it can detect that the image file is on a SSD.
This is only relevant when [using a file to store OS images](btrfs-on-file.md).
* `auto_sudo`: Automatically reexec with sudo if permissions are needed.
Default: true
* `tmpfs`: Use a tmpfs overlay for ephemeral containers instead of btrfs
Expand Down
55 changes: 1 addition & 54 deletions moncic/imagestorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import shutil
import stat
import subprocess
import tempfile
from collections import defaultdict
from typing import TYPE_CHECKING, ContextManager, Generator, List, Optional

from .btrfs import Subvolume, do_dedupe, is_btrfs
from .distro import DistroFamily
from .system import MaintenanceSystem, System, SystemConfig
from .utils import is_on_rotational, pause_automounting
from .runner import LocalRunner

if TYPE_CHECKING:
Expand Down Expand Up @@ -311,22 +309,6 @@ def deduplicate(self):
log.info("%d total bytes are currently deduplicated", total_saved)


class ImagesInFile(BtrfsImages):
"""
Images stored in a file
"""
def __init__(self, storage: "FileImageStorage", imagedir: str):
super().__init__(storage.moncic, imagedir)
self.storage = storage

def deduplicate(self):
super().deduplicate()

if self.storage.should_trim():
log.info("%s: trimming unused storage", self.storage.imagefile)
subprocess.run(["fstrim", self.imagedir], check=True)


class ImageStorage:
"""
Interface for handling image storage
Expand Down Expand Up @@ -358,7 +340,7 @@ def create(cls, moncic: Moncic, path: str) -> "ImageStorage":
else:
return PlainImageStorage(moncic, path)
else:
return FileImageStorage(moncic, path)
raise RuntimeError(f"images path {path!r} does not point to a directory")

@classmethod
def create_default(cls, moncic: Moncic) -> "ImageStorage":
Expand Down Expand Up @@ -394,41 +376,6 @@ def images(self) -> Generator[Images, None, None]:
yield BtrfsImages(self.moncic, self.imagedir)


class FileImageStorage(ImageStorage):
"""
Store images in a btrfs filesystem on a file
"""
def __init__(self, moncic: Moncic, imagefile: str):
super().__init__(moncic)
self.imagefile = imagefile

@contextlib.contextmanager
def images(self) -> Generator[Images, None, None]:
with tempfile.TemporaryDirectory() as imagedir:
with pause_automounting(self.imagefile):
subprocess.run(["mount", self.imagefile, imagedir], check=True)

try:
yield ImagesInFile(self, imagedir)
finally:
subprocess.run(["umount", imagedir], check=True)

def should_trim(self):
"""
Run fstrim on the image file if requested by config or if we can see
that the image file is on a SSD
"""
do_trim = self.moncic.config.trim_image_file
if do_trim is None:
rot = is_on_rotational(self.imagefile)
if rot or rot is None:
return False
elif not do_trim:
return False

return True


class PlainMachineImageStorage(PlainImageStorage):
"""
Store images in /var/lib/machines in a way that is compatibile with
Expand Down
4 changes: 0 additions & 4 deletions moncic/moncic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class MoncicConfig:
# created. The value is the same as can be set by `btrfs property set
# compression`. Default: nothing is set
compression: Optional[str] = None
# If set to True, automatically run fstrim on the image file after regular
# maintenance. If set to False, do not do that. By default, Moncic-CI will
# run fstrim if it can detect that the image file is on a SSD
trim_image_file: Optional[bool] = None
# Automatically reexec with sudo if permissions are needed
auto_sudo: bool = True
# Use a tmpfs overlay for ephemeral containers instead of btrfs snapshots
Expand Down

0 comments on commit 7fe4c4b

Please sign in to comment.