Skip to content

Commit

Permalink
set zvol readonly prop if extent is changed
Browse files Browse the repository at this point in the history
(cherry picked from commit 89b85fc)
  • Loading branch information
yocalebo authored and bugclerk committed Dec 12, 2024
1 parent b9e424b commit 48a4e45
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/middlewared/middlewared/plugins/iscsi_/extents.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,26 @@ async def do_create(self, data):
`ro` when set to true prevents the initiator from writing to this LUN.
"""
await self.validate(data)
verrors = ValidationErrors()
await self.middleware.call('iscsi.extent.validate', data)
await self.clean(data, 'iscsi_extent_create', verrors)
verrors.check()

await self.middleware.call('iscsi.extent.save', data, 'iscsi_extent_create', verrors)
await self.save(data, 'iscsi_extent_create', verrors)

# This change is being made in conjunction with threads_num being specified in scst.conf
if data['type'] == 'DISK' and data['path'].startswith('zvol/'):
zvolname = zvol_path_to_name(os.path.join('/dev', data['path']))
await self.middleware.call('zfs.dataset.update', zvolname, {'properties': {'volthreading': {'value': 'off'}}})
await self.middleware.call(
'zfs.dataset.update',
zvolname,
{
'properties': {
'volthreading': {'value': 'off'},
'readonly': {'value': 'on' if data['ro'] else 'off'}
}
}
)

data['id'] = await self.middleware.call(
'datastore.insert', self._config.datastore, {**data, 'vendor': 'TrueNAS'},
Expand Down Expand Up @@ -145,15 +154,25 @@ async def do_update(self, audit_callback, id_, data):
new.update(data)

await self.middleware.call('iscsi.extent.validate', new)
await self.clean(
new, 'iscsi_extent_update', verrors, old=old
)
await self.clean(new, 'iscsi_extent_update', verrors, old=old)
verrors.check()

await self.middleware.call('iscsi.extent.save', new, 'iscsi_extent_create', verrors, old)
verrors.check()
new.pop(self.locked_field)

if data['path'] is not None and data['path'].startswith('zvol/'):
zvolname = zvol_path_to_name(os.path.join('/dev', data['path']))
await self.middleware.call(
'zfs.dataset.update',
zvolname,
{
'properties': {
'readonly': {'value': 'on' if data['ro'] else 'off'}
}
}
)

await self.middleware.call(
'datastore.update',
self._config.datastore,
Expand Down

0 comments on commit 48a4e45

Please sign in to comment.