From 61cd2da27e1618d99383f3fd9c8a9e1d11bcfcf7 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 18 Aug 2015 16:21:28 -0400 Subject: [PATCH] memstore: protect object xattrs with a mutex Signed-off-by: Casey Bodley --- src/os/MemStore.cc | 19 ++++++++++++++----- src/os/MemStore.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/os/MemStore.cc b/src/os/MemStore.cc index d0615c536b43..24470dcc4318 100644 --- a/src/os/MemStore.cc +++ b/src/os/MemStore.cc @@ -367,6 +367,7 @@ int MemStore::getattr(coll_t cid, const ghobject_t& oid, if (!o) return -ENOENT; string k(name); + std::lock_guard lock(o->xattr_mutex); if (!o->xattr.count(k)) { return -ENODATA; } @@ -386,6 +387,7 @@ int MemStore::getattrs(coll_t cid, const ghobject_t& oid, ObjectRef o = c->get_object(oid); if (!o) return -ENOENT; + std::lock_guard lock(o->xattr_mutex); aset = o->xattr; return 0; } @@ -1056,6 +1058,7 @@ int MemStore::_setattrs(coll_t cid, const ghobject_t& oid, ObjectRef o = c->get_object(oid); if (!o) return -ENOENT; + std::lock_guard lock(o->xattr_mutex); for (map::const_iterator p = aset.begin(); p != aset.end(); ++p) o->xattr[p->first] = p->second; return 0; @@ -1072,9 +1075,11 @@ int MemStore::_rmattr(coll_t cid, const ghobject_t& oid, const char *name) ObjectRef o = c->get_object(oid); if (!o) return -ENOENT; - if (!o->xattr.count(name)) + std::lock_guard lock(o->xattr_mutex); + auto i = o->xattr.find(name); + if (i == o->xattr.end()) return -ENODATA; - o->xattr.erase(name); + o->xattr.erase(i); return 0; } @@ -1089,6 +1094,7 @@ int MemStore::_rmattrs(coll_t cid, const ghobject_t& oid) ObjectRef o = c->get_object(oid); if (!o) return -ENOENT; + std::lock_guard lock(o->xattr_mutex); o->xattr.clear(); return 0; } @@ -1115,10 +1121,13 @@ int MemStore::_clone(coll_t cid, const ghobject_t& oldoid, used_bytes += oo->get_size() - no->get_size(); no->clone(oo.get(), 0, oo->get_size(), 0); - // take both omap locks with std::lock() - std::unique_lock oo_lock(oo->omap_mutex, std::defer_lock), + // take xattr and omap locks with std::lock() + std::unique_lock + ox_lock(oo->xattr_mutex, std::defer_lock), + nx_lock(no->xattr_mutex, std::defer_lock), + oo_lock(oo->omap_mutex, std::defer_lock), no_lock(no->omap_mutex, std::defer_lock); - std::lock(oo_lock, no_lock); + std::lock(ox_lock, nx_lock, oo_lock, no_lock); no->omap_header = oo->omap_header; no->omap = oo->omap; diff --git a/src/os/MemStore.h b/src/os/MemStore.h index d06f331c0687..0aeacca4d18d 100644 --- a/src/os/MemStore.h +++ b/src/os/MemStore.h @@ -30,6 +30,7 @@ class MemStore : public ObjectStore { public: struct Object : public RefCountedObject { + std::mutex xattr_mutex; std::mutex omap_mutex; map xattr; bufferlist omap_header; -- 2.47.3