]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tasks/mds_client_recovery: file lock test
authorYan, Zheng <zyan@redhat.com>
Fri, 10 Oct 2014 08:00:44 +0000 (16:00 +0800)
committerYan, Zheng <zyan@redhat.com>
Fri, 10 Oct 2014 08:54:29 +0000 (16:54 +0800)
check that file lock doesn't get lost after an MDS restart

Signed-off-by: Yan, Zheng <zyan@redhat.com>
tasks/cephfs/mount.py
tasks/mds_client_recovery.py

index 114c3f50dd222f13bee1af5bec24e16d8fddfa83..57f9cb30064b6269ad70656f28886c1efe797b3a 100644 (file)
@@ -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
index fcbfc53a6977a688f91e2cbd05710d186b8951c2..d92c0a9aa8a31b33e9ee2d20e478f8037d2b0e11 100644 (file)
@@ -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):