#include "librbd/AsyncOperation.h"
#include "librbd/AsyncRequest.h"
#include "librbd/ExclusiveLock.h"
+#include "librbd/exclusive_lock/StandardPolicy.h"
#include "librbd/internal.h"
#include "librbd/ImageCtx.h"
#include "librbd/ImageState.h"
op_work_queue = new ContextWQ("librbd::op_work_queue",
cct->_conf->rbd_op_thread_timeout,
thread_pool_singleton);
+
+ exclusive_lock_policy = new exclusive_lock::StandardPolicy(this);
}
ImageCtx::~ImageCtx() {
op_work_queue->drain();
aio_work_queue->drain();
+ delete exclusive_lock_policy;
delete op_work_queue;
delete aio_work_queue;
delete operations;
state->handle_update_notification();
image_watcher->notify_header_update(on_finish);
}
+
+ exclusive_lock::Policy *ImageCtx::get_exclusive_lock_policy() const {
+ assert(owner_lock.is_locked());
+ assert(exclusive_lock_policy != nullptr);
+ return exclusive_lock_policy;
+ }
+
+ void ImageCtx::set_exclusive_lock_policy(exclusive_lock::Policy *policy) {
+ assert(owner_lock.is_wlocked());
+ assert(policy != nullptr);
+ delete exclusive_lock_policy;
+ exclusive_lock_policy = policy;
+ }
}
class ObjectMap;
template <typename> class Operations;
+ namespace exclusive_lock { struct Policy; }
+
namespace operation {
template <typename> class ResizeRequest;
}
LibrbdAdminSocketHook *asok_hook;
+ exclusive_lock::Policy *exclusive_lock_policy = nullptr;
+
static bool _filter_metadata_confs(const string &prefix, std::map<string, bool> &configs,
map<string, bufferlist> &pairs, map<string, bufferlist> *res);
void notify_update();
void notify_update(Context *on_finish);
+
+ exclusive_lock::Policy *get_exclusive_lock_policy() const;
+ void set_exclusive_lock_policy(exclusive_lock::Policy *policy);
};
}
#include "librbd/Operations.h"
#include "librbd/TaskFinisher.h"
#include "librbd/Utils.h"
+#include "librbd/exclusive_lock/Policy.h"
#include "librbd/image_watcher/Notifier.h"
#include "librbd/image_watcher/NotifyLockOwner.h"
#include "include/encoding.h"
ldout(m_image_ctx.cct, 10) << this << " queuing release of exclusive lock"
<< dendl;
- m_image_ctx.exclusive_lock->release_lock(nullptr);
+ m_image_ctx.get_exclusive_lock_policy()->lock_requested(false);
}
return true;
}
librbd/Utils.cc \
librbd/exclusive_lock/AcquireRequest.cc \
librbd/exclusive_lock/ReleaseRequest.cc \
+ librbd/exclusive_lock/StandardPolicy.cc \
librbd/image/CloseRequest.cc \
librbd/image/OpenRequest.cc \
librbd/image/RefreshParentRequest.cc \
librbd/Utils.h \
librbd/WatchNotifyTypes.h \
librbd/exclusive_lock/AcquireRequest.h \
+ librbd/exclusive_lock/Policy.h \
librbd/exclusive_lock/ReleaseRequest.h \
+ librbd/exclusive_lock/StandardPolicy.h \
librbd/image/CloseRequest.h \
librbd/image/OpenRequest.h \
librbd/image/RefreshParentRequest.h \
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_EXCLUSIVE_LOCK_POLICY_H
+#define CEPH_LIBRBD_EXCLUSIVE_LOCK_POLICY_H
+
+namespace librbd {
+namespace exclusive_lock {
+
+struct Policy {
+ virtual ~Policy() {
+ }
+
+ virtual void lock_requested(bool force) = 0;
+};
+
+} // namespace exclusive_lock
+} // namespace librbd
+
+#endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_POLICY_H
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "librbd/exclusive_lock/StandardPolicy.h"
+#include "librbd/ImageCtx.h"
+#include "librbd/ExclusiveLock.h"
+
+namespace librbd {
+namespace exclusive_lock {
+
+void StandardPolicy::lock_requested(bool force) {
+ assert(m_image_ctx->owner_lock.is_locked());
+ assert(m_image_ctx->exclusive_lock != nullptr);
+
+ // release the lock upon request (ignore forced requests)
+ m_image_ctx->exclusive_lock->release_lock(nullptr);
+}
+
+} // namespace exclusive_lock
+} // namespace librbd
+
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_EXCLUSIVE_LOCK_STANDARD_POLICY_H
+#define CEPH_LIBRBD_EXCLUSIVE_LOCK_STANDARD_POLICY_H
+
+#include "librbd/exclusive_lock/Policy.h"
+
+namespace librbd {
+
+struct ImageCtx;
+
+namespace exclusive_lock {
+
+class StandardPolicy : public Policy{
+public:
+ StandardPolicy(ImageCtx *image_ctx) : m_image_ctx(image_ctx) {
+ }
+
+ virtual void lock_requested(bool force);
+
+private:
+ ImageCtx *m_image_ctx;
+
+};
+
+} // namespace exclusive_lock
+} // namespace librbd
+
+#endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_STANDARD_POLICY_H