]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
FileStore: perform LFNIndex lookup without holding fdcache lock
authorSamuel Just <sam.just@inktank.com>
Mon, 4 Nov 2013 22:02:28 +0000 (14:02 -0800)
committerGreg Farnum <greg@inktank.com>
Thu, 23 Jan 2014 20:48:26 +0000 (12:48 -0800)
Fixes: #7207
Signed-off-by: Samuel Just <sam.just@inktank.com>
Signed-off-by: Greg Farnum <greg@inktank.com>
src/os/FileStore.cc

index 64428f15807fa357aa44d95fddc5c167a8fe98f3..e7490048ccb3499a16321c805872142a9c6c5a1e 100644 (file)
@@ -225,50 +225,63 @@ int FileStore::lfn_open(coll_t cid,
   if (!(*index)) {
     r = get_index(cid, index);
   }
-  Mutex::Locker l(fdcache_lock);
-  if (!replaying)
-    *outfd = fdcache.lookup(oid);
-  if (*outfd) {
-    return 0;
-  }
-  IndexedPath path2;
-  if (!path)
-    path = &path2;
+
   int fd, exist;
-  if (r < 0) {
-    derr << "error getting collection index for " << cid
-        << ": " << cpp_strerror(-r) << dendl;
-    goto fail;
-  }
-  r = (*index)->lookup(oid, path, &exist);
-  if (r < 0) {
-    derr << "could not find " << oid << " in index: "
-        << cpp_strerror(-r) << dendl;
-    goto fail;
+  if (!replaying) {
+    Mutex::Locker l(fdcache_lock);
+    *outfd = fdcache.lookup(oid);
+    if (*outfd)
+      return 0;
   }
 
-  r = ::open((*path)->path(), flags, 0644);
-  if (r < 0) {
-    r = -errno;
-    dout(10) << "error opening file " << (*path)->path() << " with flags="
-            << flags << ": " << cpp_strerror(-r) << dendl;
-    goto fail;
-  }
-  fd = r;
+  {
+    IndexedPath path2;
+    if (!path)
+      path = &path2;
+    if (r < 0) {
+      derr << "error getting collection index for " << cid
+          << ": " << cpp_strerror(-r) << dendl;
+      goto fail;
+    }
+    r = (*index)->lookup(oid, path, &exist);
+    if (r < 0) {
+      derr << "could not find " << oid << " in index: "
+          << cpp_strerror(-r) << dendl;
+      goto fail;
+    }
 
-  if (create && (!exist)) {
-    r = (*index)->created(oid, (*path)->path());
+    r = ::open((*path)->path(), flags, 0644);
     if (r < 0) {
-      TEMP_FAILURE_RETRY(::close(fd));
-      derr << "error creating " << oid << " (" << (*path)->path()
-          << ") in index: " << cpp_strerror(-r) << dendl;
+      r = -errno;
+      dout(10) << "error opening file " << (*path)->path() << " with flags="
+              << flags << ": " << cpp_strerror(-r) << dendl;
       goto fail;
     }
+    fd = r;
+
+    if (create && (!exist)) {
+      r = (*index)->created(oid, (*path)->path());
+      if (r < 0) {
+       TEMP_FAILURE_RETRY(::close(fd));
+       derr << "error creating " << oid << " (" << (*path)->path()
+            << ") in index: " << cpp_strerror(-r) << dendl;
+       goto fail;
+      }
+    }
   }
-  if (!replaying)
-    *outfd = fdcache.add(oid, fd);
-  else
+
+  if (!replaying) {
+    Mutex::Locker l(fdcache_lock);
+    *outfd = fdcache.lookup(oid);
+    if (*outfd) {
+      TEMP_FAILURE_RETRY(::close(fd));
+      return 0;
+    } else {
+      *outfd = fdcache.add(oid, fd);
+    }
+  } else {
     *outfd = FDRef(new FDCache::FD(fd));
+  }
   return 0;
 
  fail: