Skip to content

Commit

Permalink
Apply share_type preset prior to validation (#13296)
Browse files Browse the repository at this point in the history
In certain scenarios parameter combinations provided by API
consumers could cause spurious validation errors on mismatch
between acltype and aclmode.

(cherry picked from commit 653cbcc)

Co-authored-by: Andrew Walker <[email protected]>
  • Loading branch information
bugclerk and anodos325 authored Mar 7, 2024
1 parent 69cf2cb commit 3c561e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/middlewared/middlewared/plugins/pool_/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,20 @@ async def do_create(self, app, data):
[('id', '=', parent_name)],
{'extra': {'retrieve_children': False}}
)

match data['share_type']:
case 'SMB':
data['casesensitivity'] = 'INSENSITIVE'
data['acltype'] = 'NFSV4'
data['aclmode'] = 'RESTRICTED'
case 'APPS' | 'MULTIPROTOCOL' | 'NFS':
data['casesensitivity'] = 'SENSITIVE'
data['atime'] = 'OFF'
data['acltype'] = 'NFSV4'
data['aclmode'] = 'PASSTHROUGH'
case _:
pass

await self.__common_validation(verrors, 'pool_dataset_create', data, 'CREATE', parent_ds)

verrors.check()
Expand All @@ -569,9 +583,6 @@ async def do_create(self, app, data):
raise

if data['share_type'] == 'SMB':
data['casesensitivity'] = 'INSENSITIVE'
data['acltype'] = 'NFSV4'
data['aclmode'] = 'RESTRICTED'
if parent_st['acl'] and parent_st['acltype'] == 'NFS4':
acl_to_set = await self.middleware.call('filesystem.get_inherited_acl', {
'path': os.path.join('/mnt', parent_name),
Expand All @@ -582,10 +593,6 @@ async def do_create(self, app, data):
'format-options': {'canonicalize': True, 'ensure_builtins': True},
}))[0]['acl']
elif data['share_type'] == 'APPS':
data['casesensitivity'] = 'SENSITIVE'
data['atime'] = 'OFF'
data['acltype'] = 'NFSV4'
data['aclmode'] = 'PASSTHROUGH'
if parent_st['acl'] and parent_st['acltype'] == 'NFS4':
acl_to_set = await self.middleware.call('filesystem.get_inherited_acl', {
'path': os.path.join('/mnt', parent_name),
Expand All @@ -604,10 +611,6 @@ async def do_create(self, app, data):
'type': 'ALLOW'
})
elif data['share_type'] in ('MULTIPROTOCOL', 'NFS'):
data['casesensitivity'] = 'SENSITIVE'
data['atime'] = 'OFF'
data['acltype'] = 'NFSV4'
data['aclmode'] = 'PASSTHROUGH'
if parent_st['acl'] and parent_st['acltype'] == 'NFS4':
acl_to_set = await self.middleware.call('filesystem.get_inherited_acl', {
'path': os.path.join('/mnt', parent_name),
Expand Down
12 changes: 12 additions & 0 deletions tests/api2/test_340_pool_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,15 @@ def test_35_create_ancestors(request):
assert ds['aclmode']['value'] == 'RESTRICTED'
st = call('filesystem.stat', ds['mountpoint'])
assert st['acl'] is True, str(st)


def test_36_nested_smb_dataset(request):
with dataset_asset('parent', {'share_type': 'GENERIC'}) as d:
ds = call('pool.dataset.get_instance', d)
assert ds['acltype']['value'] == 'POSIX'
assert ds['aclmode']['value'] == 'DISCARD'

with dataset_asset('parent/child', {'share_type': 'SMB'}) as d:
ds = call('pool.dataset.get_instance', d)
assert ds['acltype']['value'] == 'NFSV4'
assert ds['aclmode']['value'] == 'RESTRICTED'

0 comments on commit 3c561e4

Please sign in to comment.