Skip to content

Commit

Permalink
app: create /var/lib/qubes as file-reflink if supported
Browse files Browse the repository at this point in the history
Use the file-reflink storage driver if /var/lib/qubes is on a filesystem
that supports reflinks, e.g. when the btrfs layout was selected in
Anaconda. If it doesn't support reflinks (or if detection fails, e.g. in
an unprivileged test environment), use 'file' as before.
  • Loading branch information
rustybird committed Sep 11, 2018
1 parent 53ef5ed commit 8d1913a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
12 changes: 11 additions & 1 deletion qubes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import qubes.ext
import qubes.utils
import qubes.storage
import qubes.storage.reflink
import qubes.vm
import qubes.vm.adminvm
import qubes.vm.qubesvm
Expand Down Expand Up @@ -553,7 +554,7 @@ def _default_pool(app):
1. If there is one named 'default', use it.
2. Check if root fs is on LVM thin - use that
3. Look for file-based pool pointing /var/lib/qubes
3. Look for file(-reflink)-based pool pointing to /var/lib/qubes
4. Fail
'''
if 'default' in app.pools:
Expand Down Expand Up @@ -1079,6 +1080,15 @@ def load_initial_values(self):
pool_configs[lvm_config['name']] = lvm_config

for name, config in pool_configs.items():
if 'driver' not in config and 'dir_path' in config:
config['driver'] = 'file'
try:
os.makedirs(config['dir_path'], exist_ok=True)
if qubes.storage.reflink.is_supported(config['dir_path']):
config['driver'] = 'file-reflink'
config['setup_check'] = 'no' # don't check twice
except PermissionError: # looks like a testing environment
pass # stay with 'file'
self.pools[name] = self._get_pool(**config)

self.default_pool_kernel = 'linux-kernel'
Expand Down
3 changes: 1 addition & 2 deletions qubes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@
'root_img_size': 10*1024*1024*1024,

'pool_configs': {
# create file pool even when the default one is LVM
# create file(-reflink) pool even when the default one is LVM
'varlibqubes': {'dir_path': qubes_base_dir,
'driver': 'file',
'name': 'varlibqubes'},
'linux-kernel': {
'dir_path': os.path.join(qubes_base_dir,
Expand Down
6 changes: 4 additions & 2 deletions qubes/tests/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from qubes.exc import QubesException
from qubes.storage import pool_drivers
from qubes.storage.file import FilePool
from qubes.storage.reflink import ReflinkPool
from qubes.tests import SystemTestCase

# :pylint: disable=invalid-name
Expand Down Expand Up @@ -107,10 +108,11 @@ def test_001_all_pool_drivers(self):
pool_drivers())

def test_002_get_pool_klass(self):
""" Expect the default pool to be `FilePool` """
""" Expect the default pool to be `FilePool` or `ReflinkPool` """
# :pylint: disable=protected-access
result = self.app.get_pool('varlibqubes')
self.assertIsInstance(result, FilePool)
self.assertTrue(isinstance(result, FilePool)
or isinstance(result, ReflinkPool))

def test_003_pool_exists_default(self):
""" Expect the default pool to exists """
Expand Down

0 comments on commit 8d1913a

Please sign in to comment.