From bf7eab67632536038e3d38ae1eac9001fe6b70dd Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Tue, 5 Mar 2019 17:40:08 +0800 Subject: [PATCH] qa/cephfs: update tests for stale session handling Signed-off-by: "Yan, Zheng" (cherry picked from commit 1c8be588e32f47ca712561711ad1ffdddc54b330) Conflicts: qa/tasks/cephfs/test_client_recovery.py --- qa/tasks/cephfs/mount.py | 29 ++++++++++++++++--------- qa/tasks/cephfs/test_client_recovery.py | 28 +++++++++++++++++++++--- src/common/options.cc | 3 +++ src/mds/Server.cc | 4 +++- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/qa/tasks/cephfs/mount.py b/qa/tasks/cephfs/mount.py index 0e8059d505d22..431fc2e004a66 100644 --- a/qa/tasks/cephfs/mount.py +++ b/qa/tasks/cephfs/mount.py @@ -175,7 +175,7 @@ class CephFSMount(object): )) p.wait() - def open_background(self, basename="background_file"): + def open_background(self, basename="background_file", write=True): """ Open a file for writing, then block such that the client will hold a capability. @@ -187,16 +187,25 @@ class CephFSMount(object): path = os.path.join(self.mountpoint, basename) - pyscript = dedent(""" - import time + if write: + pyscript = dedent(""" + import time - f = open("{path}", 'w') - f.write('content') - f.flush() - f.write('content2') - while True: - time.sleep(1) - """).format(path=path) + f = open("{path}", 'w') + f.write('content') + f.flush() + f.write('content2') + while True: + time.sleep(1) + """).format(path=path) + else: + pyscript = dedent(""" + import time + + f = open("{path}", 'r') + while True: + time.sleep(1) + """).format(path=path) rproc = self._run_python(pyscript) self.background_procs.append(rproc) diff --git a/qa/tasks/cephfs/test_client_recovery.py b/qa/tasks/cephfs/test_client_recovery.py index 2a2fa0a31e3a0..b3532434fe62a 100644 --- a/qa/tasks/cephfs/test_client_recovery.py +++ b/qa/tasks/cephfs/test_client_recovery.py @@ -45,6 +45,7 @@ class TestClientNetworkRecovery(CephFSTestCase): """ session_timeout = self.fs.get_var("session_timeout") + self.fs.mds_asok(['config', 'set', 'mds_defer_session_stale', 'false']) # We only need one client self.mount_b.umount_wait() @@ -213,12 +214,22 @@ class TestClientRecovery(CephFSTestCase): self.mount_a.wait_until_mounted() self.mount_a.create_destroy() - def test_stale_caps(self): + def _test_stale_caps(self, write): session_timeout = self.fs.get_var("session_timeout") # Capability release from stale session # ===================================== - cap_holder = self.mount_a.open_background() + if write: + cap_holder = self.mount_a.open_background() + else: + self.mount_a.run_shell(["touch", "background_file"]) + self.mount_a.umount_wait() + self.mount_a.mount() + self.mount_a.wait_until_mounted() + cap_holder = self.mount_a.open_background(write=False) + + self.assert_session_count(2) + mount_a_gid = self.mount_a.get_global_id() # Wait for the file to be visible from another client, indicating # that mount_a has completed its network ops @@ -242,6 +253,11 @@ class TestClientRecovery(CephFSTestCase): # Should have succeeded self.assertEqual(cap_waiter.exitstatus, 0) + if write: + self.assert_session_count(1) + else: + self.assert_session_state(mount_a_gid, "stale") + cap_waited = b - a log.info("cap_waiter waited {0}s".format(cap_waited)) self.assertTrue(session_timeout / 2.0 <= cap_waited <= session_timeout * 2.0, @@ -262,6 +278,12 @@ class TestClientRecovery(CephFSTestCase): self.mount_a.mount() self.mount_a.wait_until_mounted() + def test_stale_read_caps(self): + self._test_stale_caps(False) + + def test_stale_write_caps(self): + self._test_stale_caps(True) + def test_evicted_caps(self): # Eviction while holding a capability # =================================== @@ -517,9 +539,9 @@ class TestClientRecovery(CephFSTestCase): self.assert_session_state(mount_b_gid, "open") time.sleep(session_timeout * 1.5) # Long enough for MDS to consider session stale - self.assert_session_state(mount_b_gid, "stale") self.mount_a.run_shell(["touch", "testdir/file2"]) + self.assert_session_state(mount_b_gid, "stale") # resume ceph-fuse process of mount_b self.mount_b.client_remote.run(args=["sudo", "kill", "-CONT", mount_b_pid]) diff --git a/src/common/options.cc b/src/common/options.cc index 70af216ba13b9..2dc986f4153bb 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -7163,6 +7163,9 @@ std::vector