]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMDSCacheRejoin.h
4b6f44cd81d3b672705bc809e3febe23312d001b
[ceph.git] / ceph / src / messages / MMDSCacheRejoin.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_MMDSCACHEREJOIN_H
16 #define CEPH_MMDSCACHEREJOIN_H
17
18 #include "msg/Message.h"
19
20 #include "include/types.h"
21
22 #include "mds/CInode.h"
23 #include "mds/CDir.h"
24 #include "mds/mdstypes.h"
25
26 // sent from replica to auth
27
28 class MMDSCacheRejoin : public Message {
29
30 static const int HEAD_VERSION = 1;
31 static const int COMPAT_VERSION = 1;
32
33 public:
34 static const int OP_WEAK = 1; // replica -> auth, i exist, + maybe open files.
35 static const int OP_STRONG = 2; // replica -> auth, i exist, + open files and lock state.
36 static const int OP_ACK = 3; // auth -> replica, here is your lock state.
37 static const char *get_opname(int op) {
38 switch (op) {
39 case OP_WEAK: return "weak";
40 case OP_STRONG: return "strong";
41 case OP_ACK: return "ack";
42 default: ceph_abort(); return 0;
43 }
44 }
45
46 // -- types --
47 struct inode_strong {
48 uint32_t nonce;
49 int32_t caps_wanted;
50 int32_t filelock, nestlock, dftlock;
51 inode_strong() {}
52 inode_strong(int n, int cw, int dl, int nl, int dftl) :
53 nonce(n), caps_wanted(cw),
54 filelock(dl), nestlock(nl), dftlock(dftl) { }
55 void encode(bufferlist &bl) const {
56 ::encode(nonce, bl);
57 ::encode(caps_wanted, bl);
58 ::encode(filelock, bl);
59 ::encode(nestlock, bl);
60 ::encode(dftlock, bl);
61 }
62 void decode(bufferlist::iterator &bl) {
63 ::decode(nonce, bl);
64 ::decode(caps_wanted, bl);
65 ::decode(filelock, bl);
66 ::decode(nestlock, bl);
67 ::decode(dftlock, bl);
68 }
69 };
70 WRITE_CLASS_ENCODER(inode_strong)
71
72 struct dirfrag_strong {
73 uint32_t nonce;
74 int8_t dir_rep;
75 dirfrag_strong() {}
76 dirfrag_strong(int n, int dr) : nonce(n), dir_rep(dr) {}
77 void encode(bufferlist &bl) const {
78 ::encode(nonce, bl);
79 ::encode(dir_rep, bl);
80 }
81 void decode(bufferlist::iterator &bl) {
82 ::decode(nonce, bl);
83 ::decode(dir_rep, bl);
84 }
85 };
86 WRITE_CLASS_ENCODER(dirfrag_strong)
87
88 struct dn_strong {
89 snapid_t first;
90 inodeno_t ino;
91 inodeno_t remote_ino;
92 unsigned char remote_d_type;
93 uint32_t nonce;
94 int32_t lock;
95 dn_strong() :
96 ino(0), remote_ino(0), remote_d_type(0), nonce(0), lock(0) {}
97 dn_strong(snapid_t f, inodeno_t pi, inodeno_t ri, unsigned char rdt, int n, int l) :
98 first(f), ino(pi), remote_ino(ri), remote_d_type(rdt), nonce(n), lock(l) {}
99 bool is_primary() { return ino > 0; }
100 bool is_remote() { return remote_ino > 0; }
101 bool is_null() { return ino == 0 && remote_ino == 0; }
102 void encode(bufferlist &bl) const {
103 ::encode(first, bl);
104 ::encode(ino, bl);
105 ::encode(remote_ino, bl);
106 ::encode(remote_d_type, bl);
107 ::encode(nonce, bl);
108 ::encode(lock, bl);
109 }
110 void decode(bufferlist::iterator &bl) {
111 ::decode(first, bl);
112 ::decode(ino, bl);
113 ::decode(remote_ino, bl);
114 ::decode(remote_d_type, bl);
115 ::decode(nonce, bl);
116 ::decode(lock, bl);
117 }
118 };
119 WRITE_CLASS_ENCODER(dn_strong)
120
121 struct dn_weak {
122 snapid_t first;
123 inodeno_t ino;
124 dn_weak() : ino(0) {}
125 dn_weak(snapid_t f, inodeno_t pi) : first(f), ino(pi) {}
126 void encode(bufferlist &bl) const {
127 ::encode(first, bl);
128 ::encode(ino, bl);
129 }
130 void decode(bufferlist::iterator &bl) {
131 ::decode(first, bl);
132 ::decode(ino, bl);
133 }
134 };
135 WRITE_CLASS_ENCODER(dn_weak)
136
137 // -- data --
138 int32_t op;
139
140 struct lock_bls {
141 bufferlist file, nest, dft;
142 void encode(bufferlist& bl) const {
143 ::encode(file, bl);
144 ::encode(nest, bl);
145 ::encode(dft, bl);
146 }
147 void decode(bufferlist::iterator& bl) {
148 ::decode(file, bl);
149 ::decode(nest, bl);
150 ::decode(dft, bl);
151 }
152 };
153 WRITE_CLASS_ENCODER(lock_bls)
154
155 // weak
156 map<inodeno_t, map<string_snap_t, dn_weak> > weak;
157 set<dirfrag_t> weak_dirfrags;
158 set<vinodeno_t> weak_inodes;
159 map<inodeno_t, lock_bls> inode_scatterlocks;
160
161 // strong
162 map<dirfrag_t, dirfrag_strong> strong_dirfrags;
163 map<dirfrag_t, map<string_snap_t, dn_strong> > strong_dentries;
164 map<vinodeno_t, inode_strong> strong_inodes;
165
166 // open
167 map<inodeno_t,map<client_t, cap_reconnect_t> > cap_exports;
168 map<client_t, entity_inst_t> client_map;
169 bufferlist imported_caps;
170
171 // full
172 bufferlist inode_base;
173 bufferlist inode_locks;
174 map<dirfrag_t, bufferlist> dirfrag_bases;
175
176 // authpins, xlocks
177 struct slave_reqid {
178 metareqid_t reqid;
179 __u32 attempt;
180 slave_reqid() : attempt(0) {}
181 slave_reqid(const metareqid_t& r, __u32 a)
182 : reqid(r), attempt(a) {}
183 void encode(bufferlist& bl) const {
184 ::encode(reqid, bl);
185 ::encode(attempt, bl);
186 }
187 void decode(bufferlist::iterator& bl) {
188 ::decode(reqid, bl);
189 ::decode(attempt, bl);
190 }
191 };
192 map<vinodeno_t, list<slave_reqid> > authpinned_inodes;
193 map<vinodeno_t, slave_reqid> frozen_authpin_inodes;
194 map<vinodeno_t, map<__s32, slave_reqid> > xlocked_inodes;
195 map<vinodeno_t, map<__s32, list<slave_reqid> > > wrlocked_inodes;
196 map<dirfrag_t, map<string_snap_t, list<slave_reqid> > > authpinned_dentries;
197 map<dirfrag_t, map<string_snap_t, slave_reqid> > xlocked_dentries;
198
199 MMDSCacheRejoin() :
200 Message(MSG_MDS_CACHEREJOIN, HEAD_VERSION, COMPAT_VERSION)
201 {}
202 MMDSCacheRejoin(int o) :
203 Message(MSG_MDS_CACHEREJOIN, HEAD_VERSION, COMPAT_VERSION),
204 op(o) {}
205 private:
206 ~MMDSCacheRejoin() override {}
207
208 public:
209 const char *get_type_name() const override { return "cache_rejoin"; }
210 void print(ostream& out) const override {
211 out << "cache_rejoin " << get_opname(op);
212 }
213
214 // -- builders --
215 // inodes
216 void add_weak_inode(vinodeno_t i) {
217 weak_inodes.insert(i);
218 }
219 void add_strong_inode(vinodeno_t i, int n, int cw, int dl, int nl, int dftl) {
220 strong_inodes[i] = inode_strong(n, cw, dl, nl, dftl);
221 }
222 void add_inode_locks(CInode *in, __u32 nonce, bufferlist& bl) {
223 ::encode(in->inode.ino, inode_locks);
224 ::encode(in->last, inode_locks);
225 ::encode(nonce, inode_locks);
226 ::encode(bl, inode_locks);
227 }
228 void add_inode_base(CInode *in, uint64_t features) {
229 ::encode(in->inode.ino, inode_base);
230 ::encode(in->last, inode_base);
231 bufferlist bl;
232 in->_encode_base(bl, features);
233 ::encode(bl, inode_base);
234 }
235 void add_inode_authpin(vinodeno_t ino, const metareqid_t& ri, __u32 attempt) {
236 authpinned_inodes[ino].push_back(slave_reqid(ri, attempt));
237 }
238 void add_inode_frozen_authpin(vinodeno_t ino, const metareqid_t& ri, __u32 attempt) {
239 frozen_authpin_inodes[ino] = slave_reqid(ri, attempt);
240 }
241 void add_inode_xlock(vinodeno_t ino, int lt, const metareqid_t& ri, __u32 attempt) {
242 xlocked_inodes[ino][lt] = slave_reqid(ri, attempt);
243 }
244 void add_inode_wrlock(vinodeno_t ino, int lt, const metareqid_t& ri, __u32 attempt) {
245 wrlocked_inodes[ino][lt].push_back(slave_reqid(ri, attempt));
246 }
247
248 void add_scatterlock_state(CInode *in) {
249 if (inode_scatterlocks.count(in->ino()))
250 return; // already added this one
251 in->encode_lock_state(CEPH_LOCK_IFILE, inode_scatterlocks[in->ino()].file);
252 in->encode_lock_state(CEPH_LOCK_INEST, inode_scatterlocks[in->ino()].nest);
253 in->encode_lock_state(CEPH_LOCK_IDFT, inode_scatterlocks[in->ino()].dft);
254 }
255
256 // dirfrags
257 void add_strong_dirfrag(dirfrag_t df, int n, int dr) {
258 strong_dirfrags[df] = dirfrag_strong(n, dr);
259 }
260 void add_dirfrag_base(CDir *dir) {
261 bufferlist& bl = dirfrag_bases[dir->dirfrag()];
262 dir->_encode_base(bl);
263 }
264
265 // dentries
266 void add_weak_dirfrag(dirfrag_t df) {
267 weak_dirfrags.insert(df);
268 }
269 void add_weak_dentry(inodeno_t dirino, const string& dname, snapid_t last, dn_weak& dnw) {
270 weak[dirino][string_snap_t(dname, last)] = dnw;
271 }
272 void add_weak_primary_dentry(inodeno_t dirino, const string& dname, snapid_t first, snapid_t last, inodeno_t ino) {
273 weak[dirino][string_snap_t(dname, last)] = dn_weak(first, ino);
274 }
275 void add_strong_dentry(dirfrag_t df, const string& dname, snapid_t first, snapid_t last, inodeno_t pi, inodeno_t ri, unsigned char rdt, int n, int ls) {
276 strong_dentries[df][string_snap_t(dname, last)] = dn_strong(first, pi, ri, rdt, n, ls);
277 }
278 void add_dentry_authpin(dirfrag_t df, const string& dname, snapid_t last,
279 const metareqid_t& ri, __u32 attempt) {
280 authpinned_dentries[df][string_snap_t(dname, last)].push_back(slave_reqid(ri, attempt));
281 }
282 void add_dentry_xlock(dirfrag_t df, const string& dname, snapid_t last,
283 const metareqid_t& ri, __u32 attempt) {
284 xlocked_dentries[df][string_snap_t(dname, last)] = slave_reqid(ri, attempt);
285 }
286
287 // -- encoding --
288 void encode_payload(uint64_t features) override {
289 ::encode(op, payload);
290 ::encode(strong_inodes, payload);
291 ::encode(inode_base, payload);
292 ::encode(inode_locks, payload);
293 ::encode(inode_scatterlocks, payload);
294 ::encode(authpinned_inodes, payload);
295 ::encode(frozen_authpin_inodes, payload);
296 ::encode(xlocked_inodes, payload);
297 ::encode(wrlocked_inodes, payload);
298 ::encode(cap_exports, payload);
299 ::encode(client_map, payload, features);
300 ::encode(imported_caps, payload);
301 ::encode(strong_dirfrags, payload);
302 ::encode(dirfrag_bases, payload);
303 ::encode(weak, payload);
304 ::encode(weak_dirfrags, payload);
305 ::encode(weak_inodes, payload);
306 ::encode(strong_dentries, payload);
307 ::encode(authpinned_dentries, payload);
308 ::encode(xlocked_dentries, payload);
309 }
310 void decode_payload() override {
311 bufferlist::iterator p = payload.begin();
312 ::decode(op, p);
313 ::decode(strong_inodes, p);
314 ::decode(inode_base, p);
315 ::decode(inode_locks, p);
316 ::decode(inode_scatterlocks, p);
317 ::decode(authpinned_inodes, p);
318 ::decode(frozen_authpin_inodes, p);
319 ::decode(xlocked_inodes, p);
320 ::decode(wrlocked_inodes, p);
321 ::decode(cap_exports, p);
322 ::decode(client_map, p);
323 ::decode(imported_caps, p);
324 ::decode(strong_dirfrags, p);
325 ::decode(dirfrag_bases, p);
326 ::decode(weak, p);
327 ::decode(weak_dirfrags, p);
328 ::decode(weak_inodes, p);
329 ::decode(strong_dentries, p);
330 ::decode(authpinned_dentries, p);
331 ::decode(xlocked_dentries, p);
332 }
333
334 };
335
336 WRITE_CLASS_ENCODER(MMDSCacheRejoin::inode_strong)
337 WRITE_CLASS_ENCODER(MMDSCacheRejoin::dirfrag_strong)
338 WRITE_CLASS_ENCODER(MMDSCacheRejoin::dn_strong)
339 WRITE_CLASS_ENCODER(MMDSCacheRejoin::dn_weak)
340 WRITE_CLASS_ENCODER(MMDSCacheRejoin::lock_bls)
341 WRITE_CLASS_ENCODER(MMDSCacheRejoin::slave_reqid)
342
343 inline ostream& operator<<(ostream& out, const MMDSCacheRejoin::slave_reqid& r) {
344 return out << r.reqid << '.' << r.attempt;
345 }
346
347 #endif