]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librgw: add intrusive refcnt to RGWLibFS
authorMatt Benjamin <mbenjamin@redhat.com>
Mon, 25 Jan 2016 22:09:47 +0000 (17:09 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:07:10 +0000 (12:07 -0500)
Ensures that file system instances cannot be disposed while (e.g.)
background processing is ongoing.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_file.cc
src/rgw/rgw_file.h
src/rgw/rgw_lib.h

index 92419dc8aba90dbc30f7f66a0dad76dcf9bade0e..a5e32fbf1d8db33bbc465e3d47c04c3cea1f6c78 100644 (file)
@@ -410,7 +410,7 @@ int rgw_umount(struct rgw_fs *rgw_fs)
 {
   RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
   fs->close();
-  delete fs;
+  fs->rele();
   return 0;
 }
 
index c25231abe8f6acf089a3aa6280abfbd09de13a78..c33b14436186547e600a5b49c583c241230c0773 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <atomic>
 #include <mutex>
+#include <vector>
+#include <deque>
 #include <boost/intrusive_ptr.hpp>
 #include <boost/range/adaptor/reversed.hpp>
 #include <boost/container/flat_map.hpp>
@@ -500,6 +502,8 @@ namespace rgw {
     struct rgw_fs fs;
     RGWFileHandle root_fh;
 
+    mutable std::atomic<uint64_t> refcnt;
+
     RGWFileHandle::FHCache fh_cache;
     RGWFileHandle::FhLRU fh_lru;
     
@@ -521,7 +525,7 @@ namespace rgw {
 
     RGWLibFS(CephContext* _cct, const char *_uid, const char *_user_id,
            const char* _key)
-      : cct(_cct), root_fh(this, get_inst()),
+      : cct(_cct), root_fh(this, get_inst()), refcnt(1),
        fh_cache(cct->_conf->rgw_nfs_fhcache_partitions,
                 cct->_conf->rgw_nfs_fhcache_size),
        fh_lru(cct->_conf->rgw_nfs_lru_lanes,
@@ -542,6 +546,26 @@ namespace rgw {
       fs.root_fh = root_fh.get_fh();
     }
 
+    friend void intrusive_ptr_add_ref(const RGWLibFS* fs) {
+      fs->refcnt.fetch_add(1, std::memory_order_relaxed);
+    }
+
+    friend void intrusive_ptr_release(const RGWLibFS* fs) {
+      if (fs->refcnt.fetch_sub(1, std::memory_order_release) == 0) {
+       std::atomic_thread_fence(std::memory_order_acquire);
+       delete fs;
+      }
+    }
+
+    RGWLibFS* ref() {
+      intrusive_ptr_add_ref(this);
+      return this;
+    }
+
+    inline void rele() {
+      intrusive_ptr_release(this);
+    }
+
     int authorize(RGWRados* store) {
       int ret = rgw_get_user_info_by_access_key(store, key.id, user);
       if (ret == 0) {
index 4b704dc0ef8b0a64a7ed427642eb1e8b21a532ac..fc4aa771b5e444bbd2761d9fb6f455c9dbfadba3 100644 (file)
@@ -3,6 +3,7 @@
 #ifndef RGW_LIB_H
 #define RGW_LIB_H
 
+#include <mutex>
 #include "include/unordered_map.h"
 #include "rgw_common.h"
 #include "rgw_client_io.h"