From: Yan, Zheng Date: Fri, 10 Oct 2014 08:00:44 +0000 (+0800) Subject: tasks/mds_client_recovery: file lock test X-Git-Tag: v0.94.10~27^2^2~259^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=88133719b720b8043dd2409d84e1930c60608391;p=ceph.git tasks/mds_client_recovery: file lock test check that file lock doesn't get lost after an MDS restart Signed-off-by: Yan, Zheng --- diff --git a/tasks/cephfs/mount.py b/tasks/cephfs/mount.py index 114c3f50dd222..57f9cb30064b6 100644 --- a/tasks/cephfs/mount.py +++ b/tasks/cephfs/mount.py @@ -147,6 +147,65 @@ class CephFSMount(object): raise RuntimeError("Timed out after {0}s waiting for {1} to become visible from {2}".format( i, basename, self.client_id)) + def lock_background(self, basename="background_file"): + """ + Open and lock a files for writing, hold the lock in a background process + """ + assert(self.is_mounted()) + + path = os.path.join(self.mountpoint, basename) + + pyscript = dedent(""" + import time + import fcntl + import struct + + f = open("{path}", 'w') + fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB) + lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 0, 0, 0) + fcntl.fcntl(f, fcntl.F_SETLK, lockdata) + while True: + time.sleep(1) + """).format(path=path) + + log.info("lock file {0}".format(basename)) + rproc = self._run_python(pyscript) + self.background_procs.append(rproc) + return rproc + + def check_filelock(self, basename="background_file"): + assert(self.is_mounted()) + + path = os.path.join(self.mountpoint, basename) + + pyscript = dedent(""" + import fcntl + import errno + import struct + + f = open("{path}", 'r') + try: + fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB) + except IOError, e: + if e.errno == errno.EAGAIN: + pass + else: + raise RuntimeError("flock on file {path} not found") + try: + lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 0, 0, 0) + fcntl.fcntl(f, fcntl.F_SETLK, lockdata) + except IOError, e: + if e.errno == errno.EAGAIN: + pass + else: + raise RuntimeError("posix lock on file {path} not found") + """).format(path=path) + + log.info("check lock on file {0}".format(basename)) + r = self.client_remote.run(args=[ + 'sudo', 'python', '-c', pyscript + ]) + def write_background(self, basename="background_file"): """ Open a file for writing, complete as soon as you can diff --git a/tasks/mds_client_recovery.py b/tasks/mds_client_recovery.py index fcbfc53a6977a..d92c0a9aa8a31 100644 --- a/tasks/mds_client_recovery.py +++ b/tasks/mds_client_recovery.py @@ -330,6 +330,20 @@ class TestClientRecovery(CephFSTestCase): self.assertLess(recovery_time, self.ms_max_backoff * 2) self.assert_session_state(client_id, "open") + def test_filelock(self): + # Check that file lock doesn't get lost after an MDS restart + # ===================================== + lock_holder = self.mount_a.lock_background() + + self.mount_b.wait_for_visible(); + self.mount_b.check_filelock(); + + self.fs.mds_stop() + self.fs.mds_fail() + self.fs.mds_restart() + self.fs.wait_for_state('up:active', timeout=MDS_RESTART_GRACE) + + self.mount_b.check_filelock(); class LogStream(object): def __init__(self):