2016-01-15 05:25:54 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
from textwrap import dedent
|
2016-06-30 08:26:35 +00:00
|
|
|
from tasks.cephfs.cephfs_test_case import CephFSTestCase, for_teuthology
|
2016-01-15 05:25:54 +00:00
|
|
|
|
|
|
|
class TestCapFlush(CephFSTestCase):
|
2016-06-30 08:26:35 +00:00
|
|
|
@for_teuthology
|
2016-01-15 05:25:54 +00:00
|
|
|
def test_replay_create(self):
|
|
|
|
"""
|
|
|
|
MDS starts to handle client caps when it enters clientreplay stage.
|
|
|
|
When handling a client cap in clientreplay stage, it's possible that
|
|
|
|
corresponding inode does not exist because the client request which
|
|
|
|
creates inode hasn't been replayed.
|
|
|
|
"""
|
|
|
|
|
|
|
|
dir_path = os.path.join(self.mount_a.mountpoint, "testdir")
|
|
|
|
py_script = dedent("""
|
|
|
|
import os
|
|
|
|
os.mkdir("{0}")
|
|
|
|
fd = os.open("{0}", os.O_RDONLY)
|
2020-01-03 04:41:57 +00:00
|
|
|
os.fchmod(fd, 0o777)
|
2016-01-15 05:25:54 +00:00
|
|
|
os.fsync(fd)
|
|
|
|
""").format(dir_path)
|
|
|
|
self.mount_a.run_python(py_script)
|
|
|
|
|
|
|
|
self.fs.mds_asok(["flush", "journal"])
|
|
|
|
|
|
|
|
# client will only get unsafe replay
|
|
|
|
self.fs.mds_asok(["config", "set", "mds_log_pause", "1"])
|
|
|
|
|
|
|
|
file_name = "testfile"
|
|
|
|
file_path = dir_path + "/" + file_name
|
|
|
|
|
|
|
|
# Create a file and modify its mode. ceph-fuse will mark Ax cap dirty
|
|
|
|
py_script = dedent("""
|
|
|
|
import os
|
|
|
|
os.chdir("{0}")
|
|
|
|
os.setgid(65534)
|
|
|
|
os.setuid(65534)
|
2020-01-07 21:04:32 +00:00
|
|
|
fd = os.open("{1}", os.O_CREAT | os.O_RDWR, 0o644)
|
2020-01-03 04:41:57 +00:00
|
|
|
os.fchmod(fd, 0o640)
|
2016-01-15 05:25:54 +00:00
|
|
|
""").format(dir_path, file_name)
|
2021-06-29 16:47:21 +00:00
|
|
|
self.mount_a.run_python(py_script, sudo=True)
|
2016-01-15 05:25:54 +00:00
|
|
|
|
|
|
|
# Modify file mode by different user. ceph-fuse will send a setattr request
|
2022-05-06 16:41:40 +00:00
|
|
|
self.mount_a.run_shell(["sudo", "chmod", "600", file_path], wait=False, omit_sudo=False)
|
2016-01-15 05:25:54 +00:00
|
|
|
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
# Restart mds. Client will re-send the unsafe request and cap flush
|
2021-03-11 19:06:23 +00:00
|
|
|
self.fs.rank_fail()
|
2016-01-15 05:25:54 +00:00
|
|
|
self.fs.wait_for_daemons()
|
|
|
|
|
|
|
|
mode = self.mount_a.run_shell(['stat', '-c' '%a', file_path]).stdout.getvalue().strip()
|
|
|
|
# If the cap flush get dropped, mode should be 0644.
|
|
|
|
# (Ax cap stays in dirty state, which prevents setattr reply from updating file mode)
|
|
|
|
self.assertEqual(mode, "600")
|