]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_volume_client: modify locking of meta files
authorRamana Raja <rraja@redhat.com>
Thu, 23 Jun 2016 10:36:53 +0000 (16:06 +0530)
committerRamana Raja <rraja@redhat.com>
Tue, 2 Aug 2016 10:57:57 +0000 (16:27 +0530)
File locks are applied on meta files before updating the meta
file contents. These meta files would need to be cleaned up
sometime, which could lead to locks being held on unlinked meta
files. Prevent this by checking whether the file had been deleted
after lock was acquired on it.

Signed-off-by: Ramana Raja <rraja@redhat.com>
(cherry picked from commit f7c037229bcf3f5a3d06897ec7fe0c5419dd7143)

src/pybind/ceph_volume_client.py

index aba28a3431f72049b530cda87fc8526cd8c9a6b4..174b4b85cceedbb37228d5c22f09c8f5c2c0961e 100644 (file)
@@ -738,8 +738,24 @@ class CephFSVolumeClient(object):
     def _lock(self, path):
         @contextmanager
         def fn():
-            fd = self.fs.open(path, os.O_CREAT, 0755)
-            self.fs.flock(fd, fcntl.LOCK_EX, self._id)
+            while(1):
+                fd = self.fs.open(path, os.O_CREAT, 0755)
+                self.fs.flock(fd, fcntl.LOCK_EX, self._id)
+
+                # The locked file will be cleaned up sometime. It could be
+                # unlinked e.g., by an another manila share instance, before
+                # lock was applied on it. Perform checks to ensure that this
+                # does not happen.
+                try:
+                    statbuf = self.fs.stat(path)
+                except cephfs.ObjectNotFound:
+                    self.fs.close(fd)
+                    continue
+
+                fstatbuf = self.fs.fstat(fd)
+                if statbuf.st_ino == fstatbuf.st_ino:
+                    break
+
             try:
                 yield
             finally: