summaryrefslogtreecommitdiffstats
path: root/src/librbd/io/FlushTracker.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/librbd/io/FlushTracker.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/librbd/io/FlushTracker.h b/src/librbd/io/FlushTracker.h
new file mode 100644
index 000000000..cc7fcd9ae
--- /dev/null
+++ b/src/librbd/io/FlushTracker.h
@@ -0,0 +1,61 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_IO_FLUSH_TRACKER_H
+#define CEPH_LIBRBD_IO_FLUSH_TRACKER_H
+
+#include "include/int_types.h"
+#include "common/ceph_mutex.h"
+#include <atomic>
+#include <list>
+#include <map>
+#include <set>
+#include <unordered_map>
+
+struct Context;
+
+namespace librbd {
+
+struct ImageCtx;
+
+namespace io {
+
+struct AioCompletion;
+
+template <typename ImageCtxT>
+class FlushTracker {
+public:
+ FlushTracker(ImageCtxT* image_ctx);
+ ~FlushTracker();
+
+ void shut_down();
+
+ uint64_t start_io(uint64_t tid);
+ void finish_io(uint64_t tid);
+
+ void flush(Context* on_finish);
+
+private:
+ typedef std::list<Context*> Contexts;
+ typedef std::map<uint64_t, Contexts> FlushContexts;
+ typedef std::set<uint64_t> Tids;
+ typedef std::unordered_map<uint64_t, uint64_t> TidToFlushTid;
+
+ ImageCtxT* m_image_ctx;
+
+ std::atomic<uint32_t> m_next_flush_tid{0};
+
+ mutable ceph::shared_mutex m_lock;
+ TidToFlushTid m_tid_to_flush_tid;
+
+ Tids m_in_flight_flush_tids;
+ FlushContexts m_flush_contexts;
+
+};
+
+} // namespace io
+} // namespace librbd
+
+extern template class librbd::io::FlushTracker<librbd::ImageCtx>;
+
+#endif // CEPH_LIBRBD_IO_FLUSH_TRACKER_H