// vim: ts=8 sw=2 smarttab
#include "include/int_types.h"
-#include "common/Mutex.h"
-#include "common/Cond.h"
+#include "common/ceph_mutex.h"
#include "include/rados/librados.hpp"
#include <iostream>
class TestWatchContext : public librados::WatchCtx2 {
TestWatchContext(const TestWatchContext&);
public:
- Cond cond;
- uint64_t handle;
- bool waiting;
- Mutex lock;
- TestWatchContext() : handle(0), waiting(false),
- lock("watch lock") {}
+ ceph::condition_variable cond;
+ uint64_t handle = 0;
+ bool waiting = false;
+ ceph::mutex lock = ceph::make_mutex("watch lock");
+ TestWatchContext() = default;
void handle_notify(uint64_t notify_id, uint64_t cookie,
uint64_t notifier_id,
bufferlist &bl) override {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
waiting = false;
- cond.SignalAll();
+ cond.notify_all();
}
void handle_error(uint64_t cookie, int err) override {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
cout << "watch handle_error " << err << std::endl;
}
void start() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
waiting = true;
}
void wait() {
- Mutex::Locker l(lock);
- while (waiting)
- cond.Wait(lock);
+ std::unique_lock l{lock};
+ cond.wait(l, [this] { return !waiting; });
}
uint64_t &get_handle() {
return handle;
class RadosTestContext {
public:
- Mutex state_lock;
- Cond wait_cond;
+ ceph::mutex state_lock = ceph::make_mutex("Context Lock");
+ ceph::condition_variable wait_cond;
map<int, map<string,ObjectDesc> > pool_obj_cont;
set<string> oid_in_use;
set<string> oid_not_in_use;
const string &low_tier_pool_name,
bool enable_dedup,
const char *id = 0) :
- state_lock("Context Lock"),
pool_obj_cont(),
current_snap(0),
pool_name(pool_name),
{
ceph_assert(initialized);
list<TestOp*> inflight;
- state_lock.Lock();
+ std::unique_lock state_locker{state_lock};
TestOp *next = gen->next(*this);
TestOp *waiting = NULL;
if (next) {
inflight.push_back(next);
}
- state_lock.Unlock();
+ state_lock.unlock();
if (next) {
(*inflight.rbegin())->begin();
}
- state_lock.Lock();
+ state_lock.lock();
while (1) {
for (list<TestOp*>::iterator i = inflight.begin();
i != inflight.end();) {
if (inflight.size() >= (unsigned) max_in_flight || (!next && !inflight.empty())) {
cout << " waiting on " << inflight.size() << std::endl;
- wait();
+ wait_cond.wait(state_locker);
} else {
break;
}
next = gen->next(*this);
}
}
- state_lock.Unlock();
- }
-
- void wait()
- {
- wait_cond.Wait(state_lock);
}
void kick()
{
- wait_cond.Signal();
+ wait_cond.notify_all();
}
TestWatchContext *get_watch_context(const string &oid) {
ContDesc cont;
set<string> to_remove;
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
ObjectDesc obj;
if (!context->find_object(oid, &obj)) {
context->kick();
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
done = true;
context->update_object_version(oid, comp->get_version64());
context->oid_in_use.erase(oid);
{
ContDesc cont;
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
cont = ContDesc(context->seq_num, context->current_snap,
context->seq_num, "");
context->oid_in_use.insert(oid);
}
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
context->update_object_header(oid, header);
context->update_object_attrs(oid, omap);
}
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
int r;
if ((r = comp->get_return_value())) {
cerr << "err " << r << std::endl;
void _begin() override
{
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
done = 0;
stringstream acc;
acc << context->prefix << "OID: " << oid << " snap " << context->current_snap << std::endl;
&read_op,
librados::OPERATION_ORDER_READS_WRITES, // order wrt previous write/update
0);
- context->state_lock.Unlock();
}
void _finish(CallbackInfo *info) override
{
ceph_assert(info);
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
uint64_t tid = info->id;
cout << num << ": finishing write tid " << tid << " to " << context->prefix + oid << std::endl;
context->kick();
done = true;
}
- context->state_lock.Unlock();
}
bool finished() override
void _begin() override
{
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
done = 0;
stringstream acc;
acc << context->prefix << "OID: " << oid << " snap " << context->current_snap << std::endl;
&read_op,
librados::OPERATION_ORDER_READS_WRITES, // order wrt previous write/update
0);
- context->state_lock.Unlock();
}
void _finish(CallbackInfo *info) override
{
ceph_assert(info);
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
uint64_t tid = info->id;
cout << num << ": finishing writesame tid " << tid << " to " << context->prefix + oid << std::endl;
context->kick();
done = true;
}
- context->state_lock.Unlock();
}
bool finished() override
void _begin() override
{
- context->state_lock.Lock();
+ std::unique_lock state_locker{context->state_lock};
if (context->get_watch_context(oid)) {
context->kick();
- context->state_lock.Unlock();
return;
}
context->remove_object(oid);
interval_set<uint64_t> ranges;
- context->state_lock.Unlock();
+ state_locker.unlock();
int r = 0;
if (rand() % 2) {
ceph_abort();
}
- context->state_lock.Lock();
+ state_locker.lock();
context->oid_in_use.erase(oid);
context->oid_not_in_use.insert(oid);
context->kick();
- context->state_lock.Unlock();
}
string getType() override
void _begin() override
{
- context->state_lock.Lock();
+ std::unique_lock state_locker{context->state_lock};
if (!(rand() % 4) && !context->snaps.empty()) {
snap = rand_choose(context->snaps)->first;
in_use = context->snaps_in_use.lookup_or_create(snap, snap);
std::cout << num << ": expect " << old_value.most_recent() << std::endl;
TestWatchContext *ctx = context->get_watch_context(oid);
- context->state_lock.Unlock();
+ state_locker.unlock();
if (ctx) {
ceph_assert(old_value.exists);
TestAlarm alarm;
std::cerr << num << ": notified, waiting" << std::endl;
ctx->wait();
}
- context->state_lock.Lock();
+ state_locker.lock();
if (snap >= 0) {
context->io_ctx.snap_set_read(context->snaps[snap]);
}
if (snap >= 0) {
context->io_ctx.snap_set_read(0);
}
- context->state_lock.Unlock();
}
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::unique_lock state_locker{context->state_lock};
ceph_assert(!done);
ceph_assert(waiting_on > 0);
if (--waiting_on) {
ceph_assert(!context->io_ctx.selfmanaged_snap_create(&snap));
}
- context->state_lock.Lock();
+ std::unique_lock state_locker{context->state_lock};
context->add_snap(snap);
- if (context->pool_snaps) {
- context->state_lock.Unlock();
- } else {
+ if (!context->pool_snaps) {
vector<uint64_t> snapset(context->snaps.size());
int j = 0;
snapset[j] = i->second;
}
- context->state_lock.Unlock();
+ state_locker.unlock();
int r = context->io_ctx.selfmanaged_snap_set_write_ctx(context->seq, snapset);
if (r) {
void _begin() override
{
- context->state_lock.Lock();
+ std::unique_lock state_locker{context->state_lock};
uint64_t snap = context->snaps[to_remove];
context->remove_snap(to_remove);
ceph_abort();
}
}
- context->state_lock.Unlock();
}
string getType() override
void _begin() override
{
- context->state_lock.Lock();
+ std::unique_lock state_locker{context->state_lock};
ObjectDesc contents;
context->find_object(oid, &contents);
if (contents.deleted()) {
context->kick();
- context->state_lock.Unlock();
return;
}
context->oid_in_use.insert(oid);
context->oid_not_in_use.erase(oid);
TestWatchContext *ctx = context->get_watch_context(oid);
- context->state_lock.Unlock();
+ state_locker.unlock();
int r;
if (!ctx) {
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
ctx = context->watch(oid);
}
} else {
r = context->io_ctx.unwatch2(ctx->get_handle());
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
context->unwatch(oid);
}
}
}
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
context->oid_in_use.erase(oid);
context->oid_not_in_use.insert(oid);
}
void _begin() override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
if (context->get_watch_context(oid)) {
context->kick();
- context->state_lock.Unlock();
+ context->state_lock.unlock();
return;
}
if (context->snaps.empty()) {
context->kick();
- context->state_lock.Unlock();
+ context->state_lock.unlock();
done = true;
return;
}
outstanding -= (!existed_before) + (!existed_after);
- context->state_lock.Unlock();
+ context->state_lock.unlock();
bufferlist bl, bl2;
zero_write_op1.append(bl);
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
uint64_t tid = info->id;
cout << num << ": finishing rollback tid " << tid
<< " to " << context->prefix + oid << std::endl;
{
ContDesc cont;
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
cont = ContDesc(context->seq_num, context->current_snap,
context->seq_num, "");
context->oid_in_use.insert(oid);
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
// note that the read can (and atm will) come back before the
// write reply, but will reflect the update and the versions will
void _begin() override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
std::cout << num << ": chunk read oid " << oid << " snap " << snap << std::endl;
done = 0;
for (uint32_t i = 0; i < 2; i++) {
if (old_value.chunk_info.size() == 0) {
std::cout << ": no chunks" << std::endl;
context->kick();
- context->state_lock.Unlock();
+ context->state_lock.unlock();
done = true;
return;
}
<< " tgt_oid " << tgt_oid << std::endl;
TestWatchContext *ctx = context->get_watch_context(oid);
- context->state_lock.Unlock();
+ context->state_lock.unlock();
if (ctx) {
ceph_assert(old_value.exists);
TestAlarm alarm;
std::cerr << num << ": notified, waiting" << std::endl;
ctx->wait();
}
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
_do_read(op, offset, length, 0);
flags, NULL));
waiting_on++;
- context->state_lock.Unlock();
}
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
ceph_assert(!done);
ceph_assert(waiting_on > 0);
if (--waiting_on) {
void _begin() override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
context->oid_in_use.insert(oid_src);
context->oid_not_in_use.erase(oid_src);
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
if (info->id == 0) {
ceph_assert(comp->is_complete());
void _begin() override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
context->oid_in_use.insert(oid);
context->oid_not_in_use.erase(oid);
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
if (info->id == 0) {
ceph_assert(comp->is_complete());
void _begin() override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
context->oid_in_use.insert(oid);
context->oid_not_in_use.erase(oid);
context->oid_redirect_in_use.insert(oid_tgt);
void _finish(CallbackInfo *info) override
{
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
if (info->id == 0) {
ceph_assert(comp->is_complete());
void _begin() override
{
- context->state_lock.Lock();
+ std::unique_lock state_locker{context->state_lock};
if (context->get_watch_context(oid)) {
context->kick();
- context->state_lock.Unlock();
return;
}
context->remove_object(oid);
- context->state_lock.Unlock();
+ state_locker.unlock();
comp = context->rados.aio_create_completion();
op.remove();
cerr << "r is " << r << " while deleting " << oid << " and present is " << present << std::endl;
ceph_abort();
}
-
- context->state_lock.Lock();
+ state_locker.lock();
context->oid_in_use.erase(oid);
context->oid_not_in_use.insert(oid);
if(!context->redirect_objs[oid].empty()) {
context->update_object_redirect_target(oid, string());
}
context->kick();
- context->state_lock.Unlock();
}
string getType() override
void _begin() override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
context->oid_in_use.insert(oid);
context->oid_not_in_use.erase(oid);
new TestOp::CallbackInfo(0));
completion = context->rados.aio_create_completion((void *) cb_arg, NULL,
&write_callback);
- context->state_lock.Unlock();
+ context->state_lock.unlock();
op.tier_promote();
int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
void _finish(CallbackInfo *info) override
{
- context->state_lock.Lock();
+ std::lock_guard l{context->state_lock};
ceph_assert(!done);
ceph_assert(completion->is_complete());
context->oid_not_in_use.insert(oid);
context->kick();
done = true;
- context->state_lock.Unlock();
}
bool finished() override
void _begin() override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
context->oid_in_use.insert(oid);
context->oid_not_in_use.erase(oid);
new TestOp::CallbackInfo(0));
completion = context->rados.aio_create_completion((void *) cb_arg, NULL,
&write_callback);
- context->state_lock.Unlock();
+ context->state_lock.unlock();
op.tier_flush();
int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
void _finish(CallbackInfo *info) override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
ceph_assert(!done);
ceph_assert(completion->is_complete());
context->oid_not_in_use.insert(oid);
context->kick();
done = true;
- context->state_lock.Unlock();
+ context->state_lock.unlock();
}
bool finished() override
}
void _finish(CallbackInfo *info) override {
- Mutex::Locker l(context->state_lock);
+ std::lock_guard l{context->state_lock};
if (!comp2) {
if (ls.empty()) {
cerr << num << ": no hitsets" << std::endl;
void _begin() override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
pair<TestOp*, TestOp::CallbackInfo*> *cb_arg =
new pair<TestOp*, TestOp::CallbackInfo*>(this,
new TestOp::CallbackInfo(0));
context->oid_in_use.insert(oid);
context->oid_not_in_use.erase(oid);
context->update_object_undirty(oid);
- context->state_lock.Unlock();
+ context->state_lock.unlock();
op.undirty();
int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
void _finish(CallbackInfo *info) override
{
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
ceph_assert(!done);
ceph_assert(completion->is_complete());
context->oid_in_use.erase(oid);
context->update_object_version(oid, completion->get_version64());
context->kick();
done = true;
- context->state_lock.Unlock();
}
bool finished() override
void _begin() override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
if (!(rand() % 4) && !context->snaps.empty()) {
snap = rand_choose(context->snaps)->first;
context->oid_in_use.insert(oid);
context->oid_not_in_use.erase(oid);
- context->state_lock.Unlock();
+ context->state_lock.unlock();
if (snap >= 0) {
context->io_ctx.snap_set_read(context->snaps[snap]);
void _finish(CallbackInfo *info) override
{
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
ceph_assert(!done);
ceph_assert(completion->is_complete());
context->oid_in_use.erase(oid);
}
context->kick();
done = true;
- context->state_lock.Unlock();
}
bool finished() override
void _begin() override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
if (!(rand() % 4) && !context->snaps.empty()) {
snap = rand_choose(context->snaps)->first;
&write_callback);
context->oid_flushing.insert(oid);
context->oid_not_flushing.erase(oid);
- context->state_lock.Unlock();
+ context->state_lock.unlock();
unsigned flags = librados::OPERATION_IGNORE_CACHE;
if (blocking) {
void _finish(CallbackInfo *info) override
{
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
ceph_assert(!done);
ceph_assert(completion->is_complete());
context->oid_flushing.erase(oid);
}
context->kick();
done = true;
- context->state_lock.Unlock();
}
bool finished() override
void _begin() override
{
- context->state_lock.Lock();
+ context->state_lock.lock();
int snap;
if (!(rand() % 4) && !context->snaps.empty()) {
new TestOp::CallbackInfo(0));
completion = context->rados.aio_create_completion((void *) cb_arg, NULL,
&write_callback);
- context->state_lock.Unlock();
+ context->state_lock.unlock();
op.cache_evict();
int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
void _finish(CallbackInfo *info) override
{
- context->state_lock.Lock();
+ std::lock_guard state_locker{context->state_lock};
ceph_assert(!done);
ceph_assert(completion->is_complete());
}
context->kick();
done = true;
- context->state_lock.Unlock();
}
bool finished() override