Skip to content

Commit

Permalink
update iscsi ro prop if zvol readonly changes
Browse files Browse the repository at this point in the history
(cherry picked from commit 9a264ed)
  • Loading branch information
yocalebo authored and bugclerk committed Dec 12, 2024
1 parent 63c0f6b commit b9e424b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/middlewared/middlewared/plugins/iscsi_/global_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from middlewared.schema import Bool, Dict, Int, Str
from middlewared.service import filterable, filterable_returns, private, Service
from middlewared.service_exception import MatchNotFound
from middlewared.utils import filter_list, run


Expand Down Expand Up @@ -94,6 +95,22 @@ def sessions(self, filters, options):
sessions.append(session_dict)
return filter_list(sessions, filters, options)

@private
def resync_readonly_property_for_zvol(self, id_, read_only_value):
if not self.middleware.call_sync('service.started', 'iscsitarget'):
return

try:
extent = self.middleware.call_sync(
'iscsi.extent.query',
[['enabled', '=', True], ['path', '=', f'zvol/{id_}']],
{'get': True}
)
ro = True if read_only_value.lower() == 'on' else False
self.middleware.call_sync('iscsi.extent.update', extent['id'], {'ro': ro})
except MatchNotFound:
return

@private
def resync_lun_size_for_zvol(self, id_):
if not self.middleware.call_sync('service.started', 'iscsitarget'):
Expand Down
16 changes: 12 additions & 4 deletions src/middlewared/middlewared/plugins/pool_/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,10 +939,18 @@ async def do_update(self, audit_callback, id_, data):
verrors.add_child('pool_dataset_update', self.__handle_zfs_set_property_error(e, properties_definitions))
raise verrors

if data['type'] == 'VOLUME' and 'volsize' in data and data['volsize'] > dataset[0]['volsize']['parsed']:
# means the zvol size has increased so we need to check if this zvol is shared via SCST (iscsi)
# and if it is, resync it so the connected initiators can see the new size of the zvol
await self.middleware.call('iscsi.global.resync_lun_size_for_zvol', id_)
if data['type'] == 'VOLUME':
if 'volsize' in data and data['volsize'] > dataset[0]['volsize']['parsed']:
# means the zvol size has increased so we need to check if this zvol is shared via SCST (iscsi)
# and if it is, resync it so the connected initiators can see the new size of the zvol
await self.middleware.call('iscsi.global.resync_lun_size_for_zvol', id_)

if 'readonly' in data:
# depending on the iscsi client connected to us, if someone marks a zvol
# as R/O (or R/W), we need to be sure and update the associated extent so
# that we don't get into a scenario where the iscsi extent is R/W but the
# underlying zvol is R/O. Windows clients seem to not handle this very well.
await self.middleware.call('iscsi.global.resync_readonly_property_for_zvol', id_)

updated_ds = await self.get_instance(id_)
self.middleware.send_event('pool.dataset.query', 'CHANGED', id=id_, fields=updated_ds)
Expand Down

0 comments on commit b9e424b

Please sign in to comment.