ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
*header = o->omap_header;
*out = o->omap;
return 0;
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
*header = o->omap_header;
return 0;
}
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
for (map<string,bufferlist>::iterator p = o->omap.begin();
p != o->omap.end();
++p)
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
for (set<string>::const_iterator p = keys.begin();
p != keys.end();
++p) {
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
for (set<string>::const_iterator p = keys.begin();
p != keys.end();
++p) {
}
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<std::mutex> oo_lock(oo->omap_mutex, std::defer_lock),
+ no_lock(no->omap_mutex, std::defer_lock);
+ std::lock(oo_lock, no_lock);
+
no->omap_header = oo->omap_header;
no->omap = oo->omap;
no->xattr = oo->xattr;
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
o->omap.clear();
o->omap_header.clear();
return 0;
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
for (map<string,bufferlist>::const_iterator p = aset.begin(); p != aset.end(); ++p)
o->omap[p->first] = p->second;
return 0;
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
for (set<string>::const_iterator p = keys.begin(); p != keys.end(); ++p)
o->omap.erase(*p);
return 0;
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
map<string,bufferlist>::iterator p = o->omap.lower_bound(first);
map<string,bufferlist>::iterator e = o->omap.lower_bound(last);
- while (p != e)
- o->omap.erase(p++);
+ o->omap.erase(p, e);
return 0;
}
ObjectRef o = c->get_object(oid);
if (!o)
return -ENOENT;
+ std::lock_guard<std::mutex> lock(o->omap_mutex);
o->omap_header = bl;
return 0;
}
#ifndef CEPH_MEMSTORE_H
#define CEPH_MEMSTORE_H
+#include <mutex>
#include <boost/intrusive_ptr.hpp>
#include "include/assert.h"
class MemStore : public ObjectStore {
public:
struct Object : public RefCountedObject {
+ std::mutex omap_mutex;
map<string,bufferptr> xattr;
bufferlist omap_header;
map<string,bufferlist> omap;
: c(c), o(o), it(o->omap.begin()) {}
int seek_to_first() {
- RWLock::RLocker l(c->lock);
+ std::lock_guard<std::mutex>(o->omap_mutex);
it = o->omap.begin();
return 0;
}
int upper_bound(const string &after) {
- RWLock::RLocker l(c->lock);
+ std::lock_guard<std::mutex>(o->omap_mutex);
it = o->omap.upper_bound(after);
return 0;
}
int lower_bound(const string &to) {
- RWLock::RLocker l(c->lock);
+ std::lock_guard<std::mutex>(o->omap_mutex);
it = o->omap.lower_bound(to);
return 0;
}
bool valid() {
- RWLock::RLocker l(c->lock);
+ std::lock_guard<std::mutex>(o->omap_mutex);
return it != o->omap.end();
}
int next() {
- RWLock::RLocker l(c->lock);
+ std::lock_guard<std::mutex>(o->omap_mutex);
++it;
return 0;
}
string key() {
- RWLock::RLocker l(c->lock);
+ std::lock_guard<std::mutex>(o->omap_mutex);
return it->first;
}
bufferlist value() {
- RWLock::RLocker l(c->lock);
+ std::lock_guard<std::mutex>(o->omap_mutex);
return it->second;
}
int status() {