From 7cea0eee455c83fbdd64fff192c6aa10235a2c40 Mon Sep 17 00:00:00 2001 From: Ramana Raja Date: Thu, 23 Jun 2016 16:06:53 +0530 Subject: [PATCH] ceph_volume_client: modify locking of meta files 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 (cherry picked from commit f7c037229bcf3f5a3d06897ec7fe0c5419dd7143) --- src/pybind/ceph_volume_client.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pybind/ceph_volume_client.py b/src/pybind/ceph_volume_client.py index aba28a3431f72..174b4b85cceed 100644 --- a/src/pybind/ceph_volume_client.py +++ b/src/pybind/ceph_volume_client.py @@ -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: -- 2.39.5