]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw_file: interned RGWFileHandle objects need parent refs
authorMatt Benjamin <mbenjamin@redhat.com>
Sat, 31 Dec 2016 04:30:16 +0000 (23:30 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Tue, 24 Jan 2017 17:57:11 +0000 (12:57 -0500)
RGW NFS fhcache/RGWFileHandle operators assume existence of the
full chain of parents from any object to the its fs_root--this is
a consequence of the weakly-connected namespace design goal, and
not a defect.

This change ensures the invariant by taking a parent ref when
objects are interned (when a parent ref is guaranteed).  Parent
refs are returned when objects are destroyed--essentially by the
invariant, such a ref must exist.

The extra ref is omitted when parent->is_root(), as that node is
not in the LRU cache.

Fixes: http://tracker.ceph.com/issues/18650
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_file.cc
src/rgw/rgw_file.h

index 63e3b094f9d43117c0045468476569c111b87604..f8a57735fd84fb6a627eee4acdb6ea0cdad55725 100644 (file)
@@ -716,6 +716,19 @@ namespace rgw {
     } while (! (stop || shutdown));
   } /* RGWLibFS::gc */
 
+  RGWFileHandle::~RGWFileHandle() {
+    if (parent && (! parent->is_root())) {
+      /* safe because if parent->unref causes its deletion,
+       * there are a) by refcnt, no other objects/paths pointing
+       * to it and b) by the semantics of valid iteration of
+       * fh_lru (observed, e.g., by cohort_lru<T,...>::drain())
+       * no unsafe iterators reaching it either--n.b., this constraint
+       * is binding oncode which may in future attempt to e.g.,
+       * cause the eviction of objects in LRU order */
+      (void) get_fs()->fh_lru.unref(parent, cohort::lru::FLAG_NONE);
+    }
+  }
+
   void RGWFileHandle::encode_attrs(ceph::buffer::list& ux_key1,
                                   ceph::buffer::list& ux_attrs1)
   {
index d594494e288e69537b0bfd6353c53ccc227dd568..9cc55ac0b946e3260489fa0a890035d42251f907 100644 (file)
@@ -640,7 +640,7 @@ namespace rgw {
     typedef cohort::lru::TreeX<RGWFileHandle, FhTree, FhLT, FhEQ, fh_key,
                               std::mutex> FHCache;
 
-    virtual ~RGWFileHandle() {}
+    virtual ~RGWFileHandle();
 
     class Factory : public cohort::lru::ObjectFactory
     {
@@ -958,6 +958,10 @@ namespace rgw {
          /* inserts, releasing latch */
          fh_cache.insert_latched(fh, lat, RGWFileHandle::FHCache::FLAG_UNLOCK);
          get<1>(fhr) |= RGWFileHandle::FLAG_CREATE;
+         /* ref parent (non-initial ref cannot fail on valid object) */
+         if (! parent->is_root()) {
+           (void) fh_lru.ref(parent, cohort::lru::FLAG_NONE);
+         }
          goto out; /* !LATCHED */
        } else {
          lat.lock->unlock();