Skip to content

Commit 7794a2f

Browse files
authored
Merge pull request #2838 from OSInside/fix_root_reference_in_snapshot_root
Fix mount system for root_is_snapper_snapshot
2 parents 1c3e764 + 29bb3d3 commit 7794a2f

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

build-tests/x86/tumbleweed/test-image-MicroOS/appliance.kiwi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@
136136
<package name="coreutils"/>
137137
<package name="grep"/>
138138
<package name="gzip"/>
139-
<package name="udev"/>
140139
<package name="xz"/>
140+
<package name="libz1"/>
141141
<package name="shadow"/>
142142
<package name="filesystem"/>
143143
<package name="glibc-locale"/>

build-tests/x86/tumbleweed/test-image-MicroOS/disk.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
set -euxo pipefail
33

44
/usr/libexec/setup-etc-subvol
5+
6+
# test if there is a proper / mountpoint reference
7+
findmnt -no UUID /
8+
9+
# show layout
10+
findmnt

kiwi/volume_manager/btrfs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def post_init(self, custom_args):
9494

9595
self.subvol_mount_list = []
9696
self.toplevel_mount = None
97+
self.snapshots_root_mount = None
9798

9899
def setup(self, name=None):
99100
"""
@@ -162,6 +163,10 @@ def setup(self, name=None):
162163
mountpoint=snapshot + '/.snapshots'
163164
)
164165
self.subvol_mount_list.append(snapshots_mount)
166+
# make sure the snapshot appears as proper (/) in the chroot
167+
self.snapshots_root_mount = MountManager(
168+
device=self.get_mountpoint(), mountpoint=self.get_mountpoint()
169+
)
165170
elif self.root_volume_name != '/':
166171
self._set_default_volume(self.root_volume_name)
167172

@@ -362,6 +367,8 @@ def mount_volumes(self):
362367
for volume_mount in self.subvol_mount_list:
363368
if not os.path.exists(volume_mount.mountpoint):
364369
Path.create(volume_mount.mountpoint)
370+
if self.snapshots_root_mount:
371+
self.snapshots_root_mount.bind_mount()
365372
subvol_path = volume_mount.get_attributes().get('subvol_path')
366373
subvol_options = ','.join(
367374
[
@@ -380,6 +387,9 @@ def umount_volumes(self) -> None:
380387
if volume_mount.is_mounted():
381388
volume_mount.umount()
382389

390+
if self.snapshots_root_mount and self.snapshots_root_mount.is_mounted():
391+
self.snapshots_root_mount.umount()
392+
383393
if self.toplevel_mount.is_mounted():
384394
self.toplevel_mount.umount()
385395

test/unit/volume_manager/btrfs_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def test_setup_with_snapshot(
155155
'subvol_name': '@/.snapshots'
156156
},
157157
mountpoint='tmpdir/@/.snapshots/1/snapshot/.snapshots'
158+
),
159+
call(
160+
device='tmpdir/@/.snapshots/1/snapshot',
161+
mountpoint='tmpdir/@/.snapshots/1/snapshot'
158162
)
159163
]
160164
toplevel_mount.mount.assert_called_once_with([])
@@ -377,6 +381,7 @@ def test_mount_volumes(self, mock_path, mock_os_exists):
377381
return_value=False
378382
)
379383
mock_os_exists.return_value = False
384+
self.volume_manager.snapshots_root_mount = Mock()
380385
volume_mount = Mock()
381386
volume_mount.mountpoint = \
382387
'/var/tmp/kiwi_volumes.xx/@/.snapshots/1/snapshot/var/tmp'
@@ -388,6 +393,7 @@ def test_mount_volumes(self, mock_path, mock_os_exists):
388393

389394
self.volume_manager.mount_volumes()
390395

396+
self.volume_manager.snapshots_root_mount.bind_mount.assert_called_once_with()
391397
self.volume_manager.toplevel_mount.mount.assert_called_once_with([])
392398
mock_path.assert_called_once_with(volume_mount.mountpoint)
393399
volume_mount.mount.assert_called_once_with(
@@ -403,10 +409,18 @@ def test_umount_volumes(self):
403409
self.volume_manager.toplevel_mount.is_mounted = Mock(
404410
return_value=True
405411
)
412+
self.volume_manager.snapshots_root_mount = Mock()
413+
self.volume_manager.snapshots_root_mount.is_mounted = Mock(
414+
return_value=True
415+
)
406416
self.volume_manager.subvol_mount_list = [volume_mount]
417+
407418
self.volume_manager.umount_volumes()
419+
408420
volume_mount.is_mounted.assert_called_once_with()
409421
volume_mount.umount.assert_called_once_with()
422+
self.volume_manager.snapshots_root_mount.is_mounted.assert_called_once_with()
423+
self.volume_manager.snapshots_root_mount.umount.assert_called_once_with()
410424
self.volume_manager.toplevel_mount.is_mounted.assert_called_once_with()
411425
self.volume_manager.toplevel_mount.umount.assert_called_once_with()
412426

0 commit comments

Comments
 (0)