#include "tools/rbd/ArgumentTypes.h"
#include "tools/rbd/Shell.h"
#include "tools/rbd/Utils.h"
-#include "include/atomic.h"
#include "include/Context.h"
#include "include/stringify.h"
#include "include/rbd/librbd.hpp"
#include <boost/regex.hpp>
#include "include/assert.h"
+#include <atomic>
+
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
class PromoteImageRequest : public ImageRequestBase {
public:
PromoteImageRequest(librados::IoCtx &io_ctx, OrderedThrottle &throttle,
- const std::string &image_name, atomic_t *counter,
+ const std::string &image_name, std::atomic<unsigned> *counter,
bool force)
: ImageRequestBase(io_ctx, throttle, image_name), m_counter(counter),
m_force(force) {
librbd::RBD::AioCompletion *aio_comp) override {
image.aio_mirror_image_promote(m_force, aio_comp);
}
+
void handle_execute_action(int r) override {
if (r >= 0) {
- m_counter->inc();
+ (*m_counter)++;
}
- ImageRequestBase::handle_execute_action(r);
}
std::string get_action_type() const override {
}
private:
- atomic_t *m_counter;
+ std::atomic<unsigned> *m_counter = nullptr;
bool m_force;
};
class DemoteImageRequest : public ImageRequestBase {
public:
DemoteImageRequest(librados::IoCtx &io_ctx, OrderedThrottle &throttle,
- const std::string &image_name, atomic_t *counter)
+ const std::string &image_name, std::atomic<unsigned> *counter)
: ImageRequestBase(io_ctx, throttle, image_name), m_counter(counter) {
}
}
void handle_execute_action(int r) override {
if (r >= 0) {
- m_counter->inc();
+ (*m_counter)++;
}
ImageRequestBase::handle_execute_action(r);
}
}
private:
- atomic_t *m_counter;
+ std::atomic<unsigned> *m_counter = nullptr;
};
class StatusImageRequest : public ImageRequestBase {
return r;
}
- atomic_t counter;
+ std::atomic<unsigned> counter = { 0 };
ImageRequestGenerator<PromoteImageRequest> generator(io_ctx, &counter,
vm["force"].as<bool>());
r = generator.execute();
- std::cout << "Promoted " << counter.read() << " mirrored images" << std::endl;
+ std::cout << "Promoted " << counter.load() << " mirrored images" << std::endl;
return r;
}
return r;
}
- atomic_t counter;
+ std::atomic<unsigned> counter { 0 };
ImageRequestGenerator<DemoteImageRequest> generator(io_ctx, &counter);
r = generator.execute();
- std::cout << "Demoted " << counter.read() << " mirrored images" << std::endl;
+ std::cout << "Demoted " << counter.load() << " mirrored images" << std::endl;
return r;
}
ImageDeleter::ImageDeleter(ContextWQ *work_queue, SafeTimer *timer,
Mutex *timer_lock)
- : m_running(1),
+ : m_running(true),
m_work_queue(work_queue),
m_delete_lock("rbd::mirror::ImageDeleter::Delete"),
m_image_deleter_thread(this),
ImageDeleter::~ImageDeleter() {
dout(20) << "enter" << dendl;
- m_running.set(0);
+ m_running = false;
{
Mutex::Locker l (m_delete_lock);
m_delete_queue_cond.Signal();
void ImageDeleter::run() {
dout(20) << "enter" << dendl;
- while(m_running.read()) {
+ while(m_running) {
m_delete_lock.Lock();
while (m_delete_queue.empty()) {
dout(20) << "waiting for delete requests" << dendl;
m_delete_queue_cond.Wait(m_delete_lock);
- if (!m_running.read()) {
+ if (!m_running) {
m_delete_lock.Unlock();
dout(20) << "return" << dendl;
return;
bool move_to_next = process_image_delete();
if (!move_to_next) {
- if (!m_running.read()) {
+ if (!m_running) {
dout(20) << "return" << dendl;
return;
}
#ifndef CEPH_RBD_MIRROR_IMAGEDELETER_H
#define CEPH_RBD_MIRROR_IMAGEDELETER_H
-#include <deque>
-#include <vector>
-#include "include/atomic.h"
#include "common/Mutex.h"
#include "common/Cond.h"
#include "common/Thread.h"
#include "common/Timer.h"
#include "types.h"
+#include <deque>
+#include <vector>
+#include <atomic>
+
class ContextWQ;
namespace rbd {
bool print_failure_info=false);
};
- atomic_t m_running;
+ std::atomic<unsigned> m_running { 0 };
ContextWQ *m_work_queue;
#ifndef CEPH_RBD_MIRROR_IMAGE_REPLAYER_H
#define CEPH_RBD_MIRROR_IMAGE_REPLAYER_H
-#include <map>
-#include <string>
-#include <vector>
-
-#include "include/atomic.h"
#include "common/AsyncOpTracker.h"
#include "common/Mutex.h"
#include "common/WorkQueue.h"
#include "ImageDeleter.h"
#include "ProgressContext.h"
#include "types.h"
-#include <set>
+
#include <boost/noncopyable.hpp>
#include <boost/optional.hpp>
+#include <set>
+#include <map>
+#include <atomic>
+#include <string>
+#include <vector>
+
class AdminSocketHook;
namespace journal {
void Mirror::handle_signal(int signum)
{
- m_stopping.set(1);
+ m_stopping = true;
{
Mutex::Locker l(m_lock);
m_cond.Signal();
void Mirror::run()
{
dout(20) << "enter" << dendl;
- while (!m_stopping.read()) {
+ while (!m_stopping) {
m_local_cluster_watcher->refresh_pools();
Mutex::Locker l(m_lock);
if (!m_manual_stop) {
Mutex::Locker l(m_lock);
- if (m_stopping.read()) {
+ if (m_stopping) {
return;
}
dout(20) << "enter" << dendl;
Mutex::Locker l(m_lock);
- if (m_stopping.read()) {
+ if (m_stopping) {
return;
}
dout(20) << "enter" << dendl;
Mutex::Locker l(m_lock);
- if (m_stopping.read()) {
+ if (m_stopping) {
return;
}
dout(20) << "enter" << dendl;
Mutex::Locker l(m_lock);
- if (m_stopping.read()) {
+ if (m_stopping) {
return;
}
dout(20) << "enter" << dendl;
Mutex::Locker l(m_lock);
- if (m_stopping.read() || m_manual_stop) {
+ if (m_stopping || m_manual_stop) {
return;
}
dout(20) << "enter" << dendl;
Mutex::Locker l(m_lock);
- if (m_stopping.read()) {
+ if (m_stopping) {
return;
}
#ifndef CEPH_RBD_MIRROR_H
#define CEPH_RBD_MIRROR_H
-#include <map>
-#include <memory>
-#include <set>
-
#include "common/ceph_context.h"
#include "common/Mutex.h"
-#include "include/atomic.h"
#include "include/rados/librados.hpp"
#include "ClusterWatcher.h"
#include "PoolReplayer.h"
#include "ImageDeleter.h"
#include "types.h"
+#include <set>
+#include <map>
+#include <memory>
+#include <atomic>
+
namespace librbd { struct ImageCtx; }
namespace rbd {
{
delete m_asok_hook;
- m_stopping.set(1);
+ m_stopping = true;
{
Mutex::Locker l(m_lock);
m_cond.Signal();
{
dout(20) << "enter" << dendl;
- while (!m_stopping.read()) {
+ while (!m_stopping) {
std::string asok_hook_name = m_local_io_ctx.get_pool_name() + " " +
m_peer.cluster_name;
if (m_asok_hook_name != asok_hook_name || m_asok_hook == nullptr) {
if ((m_local_pool_watcher && m_local_pool_watcher->is_blacklisted()) ||
(m_remote_pool_watcher && m_remote_pool_watcher->is_blacklisted())) {
m_blacklisted = true;
- m_stopping.set(1);
+ m_stopping = true;
break;
}
Mutex::Locker l(m_lock);
- if (m_stopping.read()) {
+ if (m_stopping) {
return;
}
Mutex::Locker l(m_lock);
if (!manual) {
- m_stopping.set(1);
+ m_stopping = true;
m_cond.Signal();
return;
- } else if (m_stopping.read()) {
+ } else if (m_stopping) {
return;
}
Mutex::Locker l(m_lock);
- if (m_stopping.read()) {
+ if (m_stopping) {
return;
}
Mutex::Locker l(m_lock);
- if (m_stopping.read() || m_manual_stop) {
+ if (m_stopping || m_manual_stop) {
return;
}
Mutex::Locker l(m_lock);
- if (m_stopping.read() || !m_leader_watcher) {
+ if (m_stopping || !m_leader_watcher) {
return;
}
void PoolReplayer::handle_update(const std::string &mirror_uuid,
ImageIds &&added_image_ids,
ImageIds &&removed_image_ids) {
- if (m_stopping.read()) {
+ if (m_stopping) {
return;
}
#ifndef CEPH_RBD_MIRROR_POOL_REPLAYER_H
#define CEPH_RBD_MIRROR_POOL_REPLAYER_H
-#include <map>
-#include <memory>
-#include <set>
-#include <string>
-
#include "common/AsyncOpTracker.h"
#include "common/Cond.h"
#include "common/Mutex.h"
#include "common/WorkQueue.h"
-#include "include/atomic.h"
#include "include/rados/librados.hpp"
#include "ClusterWatcher.h"
#include "ImageDeleter.h"
#include "types.h"
+#include <set>
+#include <map>
+#include <memory>
+#include <atomic>
+#include <string>
+
class AdminSocketHook;
namespace librbd { class ImageCtx; }
NBDServer(int _fd, librbd::Image& _image)
: fd(_fd)
, image(_image)
- , terminated(false)
, lock("NBDServer::Locker")
, reader_thread(*this, &NBDServer::reader_entry)
, writer_thread(*this, &NBDServer::writer_entry)
{}
private:
- atomic_t terminated;
+ std::atomic<bool> terminated = { false };
void shutdown()
{
- if (terminated.compare_and_swap(false, true)) {
+ bool expected = false;
+ if (terminated.compare_exchange_weak(expected, true)) {
::shutdown(fd, SHUT_RDWR);
Mutex::Locker l(lock);
IOContext *wait_io_finish()
{
Mutex::Locker l(lock);
- while(io_finished.empty() && !terminated.read())
+ while(io_finished.empty() && !terminated)
cond.Wait(lock);
if (io_finished.empty())
void reader_entry()
{
- while (!terminated.read()) {
+ while (!terminated) {
ceph::unique_ptr<IOContext> ctx(new IOContext());
ctx->server = this;
void writer_entry()
{
- while (!terminated.read()) {
+ while (!terminated) {
dout(20) << __func__ << ": waiting for io request" << dendl;
ceph::unique_ptr<IOContext> ctx(wait_io_finish());
if (!ctx) {