Commit 18872250 authored by themylogin's avatar themylogin Committed by William Grzybowski
Browse files

Don't offer to restart disabled and stopped services on pool unlock

parent a9bffd96
Showing with 50 additions and 27 deletions
+50 -27
......@@ -1514,23 +1514,62 @@ class PoolService(CRUDService):
return True
@accepts()
async def unlock_services_restart_choices(self):
@accepts(Int('id'))
async def unlock_services_restart_choices(self, oid):
"""
Get a mapping of services identifiers and labels that can be restart
on volume unlock.
"""
svcs = {
pool = await self._get_instance(oid)
services = {
'afp': 'AFP',
'cifs': 'SMB',
'ftp': 'FTP',
'iscsitarget': 'iSCSI',
'nfs': 'NFS',
'webdav': 'WebDAV',
'jails': 'Jails/Plugins',
'vms': 'Virtual Machines',
}
return svcs
result = {}
for k, v in services.items():
service = await self.middleware.call('service.query', [['service', '=', k]], {'get': True})
if service['enable'] or service['state'] == 'RUNNING':
result[k] = v
try:
activated_pool = await self.middleware.call('jail.get_activated_pool')
except Exception:
activated_pool = None
# If iocage is not activated yet, there is a chance that this pool might have it activated there
if activated_pool is None:
result['jails'] = 'Jails/Plugins'
if await self._unlock_restarted_vms(pool['name']):
result['vms'] = 'Virtual Machines'
return result
async def _unlock_restarted_vms(self, pool_name):
result = []
vms = (await self.middleware.call(
'vm.query', [('autostart', '=', True)])
)
for vm in vms:
for device in vm['devices']:
if device['dtype'] not in ('DISK', 'RAW'):
continue
path = device['attributes'].get('path')
if not path:
continue
if path.startswith(f'/dev/zvol/{pool_name}/') or path.startswith(f'/mnt/{pool_name}/'):
result.append(vm)
break
return result
@item_method
@accepts(Int('id'), Dict(
......@@ -1585,14 +1624,6 @@ class PoolService(CRUDService):
'options.passphrase', 'Provide a passphrase or a recovery key.'
)
services_restart_choices = set((await self.unlock_services_restart_choices()).keys())
options_services_restart = set(options['services_restart'])
invalid_choices = options_services_restart - services_restart_choices
if invalid_choices:
verrors.add(
'options.services_restart', f'Invalid choices: {", ".join(invalid_choices)}'
)
if verrors:
raise verrors
......@@ -1631,22 +1662,14 @@ class PoolService(CRUDService):
await self.middleware.call('pool.sync_encrypted', oid)
await self.middleware.call('core.bulk', 'service.restart', [
[i] for i in options['services_restart'] + ['system_datasets', 'disk']
[i] for i in set(options['services_restart']) | {'system_datasets', 'disk'} - {'jails', 'vms'}
])
if 'jails' in options['services_restart']:
await self.middleware.call('core.bulk', 'jail.rc_action', [['RESTART']])
if 'vms' in options['services_restart']:
vms = (await self.middleware.call(
'vm.query', [('autostart', '=', True)])
)
pool_name = pool['name']
for vm in vms:
for device in vm['devices']:
path = device['attributes'].get('path', '')
if f'/dev/zvol/{pool_name}/' in path or \
f'/mnt/{pool_name}/' in path:
await self.middleware.call('vm.stop', vm['id'])
await self.middleware.call('vm.start', vm['id'])
for vm in await self._unlock_restarted_vms(pool['name']):
await self.middleware.call('vm.stop', vm['id'])
await self.middleware.call('vm.start', vm['id'])
await self.middleware.call_hook('pool.post_unlock', pool=pool)
......
......@@ -1679,7 +1679,7 @@ class VMFSAttachmentDelegate(FSAttachmentDelegate):
if device['dtype'] not in ('DISK', 'RAW'):
continue
disk = device['attributes'].get('path', None)
disk = device['attributes'].get('path')
if not disk:
continue
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment