Skip to content

Commit e23ec03

Browse files
committed
Merge PR ceph#58878 into main
* refs/pull/58878/head: client: Fix leading / issue with mds_check_access qa: Add mds caps test for testing fs read and a path rw Reviewed-by: Venky Shankar <[email protected]> Reviewed-by: Xiubo Li <[email protected]> Reviewed-by: Patrick Donnelly <[email protected]>
2 parents 67ff11f + 2e2adb2 commit e23ec03

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

qa/tasks/cephfs/caps_helper.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,14 @@ def _create_test_files(self, mount, path):
204204
"""
205205
# CephFS mount where read/write test will be conducted.
206206
self.mount = mount
207+
# Set new file creation path
208+
self.new_file = os_path_join(self.mount.hostfs_mntpt, path.lstrip('/'), 'new_file')
207209
# Path where out test file located.
208210
self.path = self._gen_test_file_path(path)
209211
# Data that out test file will contain.
210212
self.data = self._gen_test_file_data()
211213

214+
212215
self.mount.write_file(self.path, self.data)
213216
log.info(f'Test file has been created on FS '
214217
f'"{self.mount.cephfs_name}" at path "{self.path}" with the '
@@ -242,7 +245,8 @@ def _gen_test_file_data(self):
242245
self.path = {self.path}
243246
cephfs_name = {self.mount.cephfs_name}
244247
cephfs_mntpt = {self.mount.cephfs_mntpt}
245-
hostfs_mntpt = {self.mount.hostfs_mntpt}''')
248+
hostfs_mntpt = {self.mount.hostfs_mntpt}
249+
self.new_file_path = {self.new_file}''')
246250

247251
def run_mds_cap_tests(self, perm, mntpt=None):
248252
"""
@@ -260,11 +264,13 @@ def run_mds_cap_tests(self, perm, mntpt=None):
260264
# cephfs dir serving as root for current mnt: /dir1/dir2
261265
# therefore, final path: /mnt/cephfs_x/testdir
262266
self.path = self.path.replace(mntpt, '')
267+
self.new_file = self.new_file.replace(mntpt, '')
263268

264269
self.conduct_pos_test_for_read_caps()
265270

266271
if perm == 'rw':
267272
self.conduct_pos_test_for_write_caps()
273+
self.conduct_pos_test_for_new_file_creation()
268274
elif perm == 'r':
269275
self.conduct_neg_test_for_write_caps()
270276
else:
@@ -302,6 +308,12 @@ def conduct_neg_test_for_write_caps(self, sudo_write=False):
302308
log.info('absence of write perm was tested successfully: '
303309
f'failed to be write data to file {self.path}.')
304310

311+
def conduct_pos_test_for_new_file_creation(self, sudo_write=False):
312+
log.info(f'test write perm: try creating a new "{self.new_file}"')
313+
self.mount.create_file(self.new_file)
314+
log.info(f'write perm was tested successfully: new file "{self.new_file}" '
315+
'created successfully')
316+
305317

306318
class CapTester(MonCapTester, MdsCapTester):
307319
'''

qa/tasks/cephfs/test_admin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,28 @@ def test_single_path_authorize_on_nonalphanumeric_fsname(self):
18181818
self._remount(keyring)
18191819
self.captester.run_mds_cap_tests(PERM)
18201820

1821+
def test_fs_read_and_single_path_rw(self):
1822+
"""
1823+
Tests the file creation using 'touch' cmd on a specific path
1824+
which has 'rw' caps and 'r' caps on the rest of the fs.
1825+
1826+
The mds auth caps with 'rw' caps on a specific path and 'r' caps
1827+
on the rest of the fs has an issue. The file creation using 'touch'
1828+
cmd on the fuse client used to fail while doing setattr.
1829+
Please see https://tracker.ceph.com/issues/67212
1830+
1831+
The new file creation test using 'touch' cmd is added to
1832+
'MdsCapTester.run_mds_cap_tests' which eventually gets
1833+
called by '_remount_and_run_tests'
1834+
"""
1835+
FS_AUTH_CAPS = (('/', 'r'), ('/dir2', 'rw'))
1836+
self.mount_a.run_shell('mkdir -p ./dir2')
1837+
self.captesters = (CapTester(self.mount_a, '/'),
1838+
CapTester(self.mount_a, '/dir2'))
1839+
keyring = self.fs.authorize(self.client_id, FS_AUTH_CAPS)
1840+
1841+
self._remount_and_run_tests(FS_AUTH_CAPS, keyring)
1842+
18211843
def test_multiple_path_r(self):
18221844
PERM = 'r'
18231845
FS_AUTH_CAPS = (('/dir1/dir12', PERM), ('/dir2/dir22', PERM))

src/client/Client.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5933,6 +5933,11 @@ int Client::mds_check_access(std::string& path, const UserPerm& perms, int mask)
59335933
}
59345934
}
59355935

5936+
// drop any leading /
5937+
while (path.length() && path[0] == '/') {
5938+
path = path.substr(1);
5939+
}
5940+
59365941
for (auto& s: cap_auths) {
59375942
ldout(cct, 20) << __func__ << " auth match path " << s.match.path << " r: " << s.readable
59385943
<< " w: " << s.writeable << dendl;
@@ -8039,6 +8044,10 @@ bool Client::make_absolute_path_string(Inode *in, std::string& path)
80398044
return false;
80408045
}
80418046

8047+
// Make sure this function returns path with single leading '/'
8048+
if (path.length() && path[0] == '/' && path[1] == '/')
8049+
path = path.substr(1);
8050+
80428051
return true;
80438052
}
80448053

@@ -8086,8 +8095,6 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask,
80868095
std::string path;
80878096
if (make_absolute_path_string(in, path)) {
80888097
ldout(cct, 20) << " absolute path: " << path << dendl;
8089-
if (path.length())
8090-
path = path.substr(1); // drop leading /
80918098
res = mds_check_access(path, perms, MAY_WRITE);
80928099
if (res) {
80938100
goto out;
@@ -10329,8 +10336,6 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp,
1032910336
std::string path;
1033010337
if (make_absolute_path_string(in, path)) {
1033110338
ldout(cct, 20) << __func__ << " absolute path: " << path << dendl;
10332-
if (path.length())
10333-
path = path.substr(1); // drop leading /
1033410339
result = mds_check_access(path, perms, mask);
1033510340
if (result) {
1033610341
return result;

0 commit comments

Comments
 (0)