]> git.proxmox.com Git - ceph.git/blame - ceph/src/client/barrier.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / client / barrier.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 *
5 * Copyright (C) 2012 CohortFS, LLC.
6 *
7 * This is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License version 2.1, as published by the Free Software
10 * Foundation. See file COPYING.
11 *
12 */
13
14#ifndef BARRIER_H
15#define BARRIER_H
16
17#include "include/types.h"
18#include <boost/intrusive/list.hpp>
19#define BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS
20#include <boost/icl/interval_set.hpp>
21#include "common/Mutex.h"
22#include "common/Cond.h"
23
24class Client;
25
26typedef boost::icl::interval<uint64_t>::type barrier_interval;
27
28using namespace std;
29
30/*
31 * we keep count of uncommitted writes on the inode, so that
32 * ll_commit_blocks can do the right thing.
33 *
34 * This is just a hacked copy of Ceph's sync callback.
35 */
36
37enum CBlockSync_State
38{
39 CBlockSync_State_None, /* initial state */
40 CBlockSync_State_Unclaimed, /* outstanding write */
41 CBlockSync_State_Committing, /* commit in progress */
42 CBlockSync_State_Completed,
43};
44
45class BarrierContext;
46
47class C_Block_Sync;
48
49typedef boost::intrusive::list< C_Block_Sync,
50 boost::intrusive::member_hook<
51 C_Block_Sync,
52 boost::intrusive::list_member_hook<>,
53 &C_Block_Sync::intervals_hook >
54 > BlockSyncList;
55
56class Barrier
57{
58private:
59 Cond cond;
60 boost::icl::interval_set<uint64_t> span;
61 BlockSyncList write_list;
62
63public:
64 boost::intrusive::list_member_hook<> active_commits_hook;
65
66 Barrier();
67 ~Barrier();
68
69 friend class BarrierContext;
70};
71
72typedef boost::intrusive::list< Barrier,
73 boost::intrusive::member_hook<
74 Barrier,
75 boost::intrusive::list_member_hook<>,
76 &Barrier::active_commits_hook >
77 > BarrierList;
78
79class BarrierContext
80{
81private:
82 Client *cl;
83 uint64_t ino;
84 Mutex lock;
85
86 // writes not claimed by a commit
87 BlockSyncList outstanding_writes;
88
89 // commits in progress, with their claimed writes
90 BarrierList active_commits;
91
92public:
93 BarrierContext(Client *c, uint64_t ino);
94 void write_nobarrier(C_Block_Sync &cbs);
95 void write_barrier(C_Block_Sync &cbs);
96 void commit_barrier(barrier_interval &civ);
97 void complete(C_Block_Sync &cbs);
98 ~BarrierContext();
99};
100
101#endif