Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mds / locks.h
1
2 #ifndef CEPH_MDS_LOCKS_H
3 #define CEPH_MDS_LOCKS_H
4
5 struct sm_state_t {
6   int next;         // 0 if stable
7   char loner;
8   int replica_state;
9   char can_read;
10   char can_read_projected;
11   char can_rdlock;
12   char can_wrlock;
13   char can_force_wrlock;
14   char can_lease;
15   char can_xlock;
16   int caps;
17   int loner_caps;
18   int xlocker_caps;
19   int replica_caps;
20 };
21
22 struct sm_t {
23   const struct sm_state_t *states;
24   int allowed_ever_auth;
25   int allowed_ever_replica;
26   int careful;
27   int can_remote_xlock;
28 };
29
30 #define ANY  1 // auth or replica
31 #define AUTH 2 // auth only
32 #define XCL  3 // auth or exclusive client
33 //#define FW   4 // fw to auth, if replica
34 #define REQ  5 // req state change from auth, if replica
35
36 extern const struct sm_t sm_simplelock;
37 extern const struct sm_t sm_filelock;
38 extern const struct sm_t sm_scatterlock;
39 extern const struct sm_t sm_locallock;
40
41
42
43 // -- lock states --
44 // sync <-> lock
45 enum {
46   LOCK_UNDEF = 0,
47
48   //                                    auth               rep
49   LOCK_SYNC,    // AR   R . RD L . / C .   R RD L . / C . 
50   LOCK_LOCK,    // AR   R . .. . X / . .   . .. . . / . .
51
52   LOCK_PREXLOCK,    // A    . . .. . . / . .   (lock)
53   LOCK_XLOCK,       // A    . . .. . . / . .   (lock)
54   LOCK_XLOCKDONE,   // A    r p rd l x / . .   (lock)  <-- by same client only!!
55   LOCK_XLOCKSNAP,   // also revoke Fb
56   LOCK_LOCK_XLOCK,
57
58   LOCK_SYNC_LOCK,    // AR   R . .. . . / . .   R .. . . / . .
59   LOCK_LOCK_SYNC,    // A    R p rd l . / . .   (lock)  <-- lc by same client only
60
61   LOCK_EXCL,         // A    . . .. . . / c x * (lock)
62   LOCK_EXCL_SYNC,    // A    . . .. . . / c . * (lock)
63   LOCK_EXCL_LOCK,    // A    . . .. . . / . .   (lock)
64   LOCK_SYNC_EXCL,    // Ar   R . .. . . / c . * (sync->lock)
65   LOCK_LOCK_EXCL,    // A    R . .. . . / . .   (lock)
66
67   LOCK_REMOTEXLOCK,  // on NON-auth
68
69   // * = loner mode
70
71   LOCK_MIX,
72   LOCK_SYNC_MIX,
73   LOCK_SYNC_MIX2,
74   LOCK_LOCK_MIX,
75   LOCK_EXCL_MIX,
76   LOCK_MIX_SYNC,
77   LOCK_MIX_SYNC2,
78   LOCK_MIX_LOCK,
79   LOCK_MIX_LOCK2,
80   LOCK_MIX_EXCL,
81
82   LOCK_TSYN,
83   LOCK_TSYN_LOCK,
84   LOCK_TSYN_MIX,
85   LOCK_LOCK_TSYN,
86   LOCK_MIX_TSYN,
87
88   LOCK_PRE_SCAN,
89   LOCK_SCAN,
90
91   LOCK_SNAP_SYNC,
92
93   LOCK_XSYN,
94   LOCK_XSYN_EXCL,
95   LOCK_EXCL_XSYN,
96   LOCK_XSYN_SYNC,
97
98   LOCK_MAX,
99 };
100
101 // -------------------------
102 // lock actions
103
104 // for replicas
105 #define LOCK_AC_SYNC        -1
106 #define LOCK_AC_MIX         -2
107 #define LOCK_AC_LOCK        -3
108 #define LOCK_AC_LOCKFLUSHED -4
109
110 // for auth
111 #define LOCK_AC_SYNCACK      1
112 #define LOCK_AC_MIXACK     2
113 #define LOCK_AC_LOCKACK      3
114
115 #define LOCK_AC_REQSCATTER   7
116 #define LOCK_AC_REQUNSCATTER 8
117 #define LOCK_AC_NUDGE        9
118 #define LOCK_AC_REQRDLOCK   10
119
120 #define LOCK_AC_FOR_REPLICA(a)  ((a) < 0)
121 #define LOCK_AC_FOR_AUTH(a)     ((a) > 0)
122
123
124 static inline const char *get_lock_action_name(int a) {
125   switch (a) {
126   case LOCK_AC_SYNC: return "sync";
127   case LOCK_AC_MIX: return "mix";
128   case LOCK_AC_LOCK: return "lock";
129   case LOCK_AC_LOCKFLUSHED: return "lockflushed";
130
131   case LOCK_AC_SYNCACK: return "syncack";
132   case LOCK_AC_MIXACK: return "mixack";
133   case LOCK_AC_LOCKACK: return "lockack";
134
135   case LOCK_AC_REQSCATTER: return "reqscatter";
136   case LOCK_AC_REQUNSCATTER: return "requnscatter";
137   case LOCK_AC_NUDGE: return "nudge";
138   case LOCK_AC_REQRDLOCK: return "reqrdlock";
139   default: return "???";
140   }
141 }
142
143
144
145 #endif