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