From: Matt Benjamin Date: Mon, 25 Jan 2016 22:09:47 +0000 (-0500) Subject: librgw: add intrusive refcnt to RGWLibFS X-Git-Tag: v10.1.0~382^2~81 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3237f0b96a7e58e4334d57f9008b496fb8932a79;p=ceph.git librgw: add intrusive refcnt to RGWLibFS Ensures that file system instances cannot be disposed while (e.g.) background processing is ongoing. Signed-off-by: Matt Benjamin --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 92419dc8aba9..a5e32fbf1d8d 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -410,7 +410,7 @@ int rgw_umount(struct rgw_fs *rgw_fs) { RGWLibFS *fs = static_cast(rgw_fs->fs_private); fs->close(); - delete fs; + fs->rele(); return 0; } diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index c25231abe8f6..c33b14436186 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -12,6 +12,8 @@ #include #include +#include +#include #include #include #include @@ -500,6 +502,8 @@ namespace rgw { struct rgw_fs fs; RGWFileHandle root_fh; + mutable std::atomic 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) { diff --git a/src/rgw/rgw_lib.h b/src/rgw/rgw_lib.h index 4b704dc0ef8b..fc4aa771b5e4 100644 --- a/src/rgw/rgw_lib.h +++ b/src/rgw/rgw_lib.h @@ -3,6 +3,7 @@ #ifndef RGW_LIB_H #define RGW_LIB_H +#include #include "include/unordered_map.h" #include "rgw_common.h" #include "rgw_client_io.h"