-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-131208 / 25.04 / Improvements to mounting/umounting docker datase…
…ts (#14525) * Introduce a simple service to manage docker dataset mounts * Use docker.fs_manage service for mounting/umounting datasets * Raise proper exception with code if ds does not exist * Add a util method to see if some ds is mounted on ix-apps * Umount docker datasets if docker pool is changed * Mount docker datasets if pool is changed * Add a sanity test to ensure correct ix-apps is mounted before trying to start docker service * Mount docker datasets on system boot if docker is configured * Do not mount/umount docker datasets on docker service start/stop * Minor fixes
- Loading branch information
Showing
6 changed files
with
85 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import errno | ||
|
||
from middlewared.service import CallError, Service | ||
|
||
from .state_utils import IX_APPS_MOUNT_PATH, Status | ||
|
||
|
||
class DockerFilesystemManageService(Service): | ||
|
||
class Config: | ||
namespace = 'docker.fs_manage' | ||
private = True | ||
|
||
async def common_func(self, mount): | ||
if docker_ds := (await self.middleware.call('docker.config'))['dataset']: | ||
try: | ||
if mount: | ||
await self.middleware.call('zfs.dataset.mount', docker_ds, {'recursive': True, 'force_mount': True}) | ||
else: | ||
await self.middleware.call('zfs.dataset.umount', docker_ds, {'force': True}) | ||
await self.middleware.call('catalog.sync') | ||
except Exception as e: | ||
await self.middleware.call( | ||
'docker.state.set_status', Status.FAILED.value, | ||
f'Failed to {"mount" if mount else "umount"} {docker_ds!r}: {e}', | ||
) | ||
raise | ||
|
||
async def mount(self): | ||
await self.common_func(True) | ||
|
||
async def umount(self): | ||
await self.common_func(False) | ||
|
||
async def ix_apps_is_mounted(self, dataset_to_check=None): | ||
""" | ||
This will tell us if some dataset is mounted on /mnt/.ix-apps or not. | ||
""" | ||
try: | ||
fs_details = await self.middleware.call('filesystem.statfs', IX_APPS_MOUNT_PATH) | ||
except CallError as e: | ||
if e.errno == errno.ENOENT: | ||
return False | ||
raise | ||
|
||
if fs_details['source'].startswith('boot-pool/'): | ||
return False | ||
|
||
if dataset_to_check: | ||
return fs_details['source'] == dataset_to_check | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters