]>
git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMDSCacheRejoin.h
4b6f44cd81d3b672705bc809e3febe23312d001b
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef CEPH_MMDSCACHEREJOIN_H
16 #define CEPH_MMDSCACHEREJOIN_H
18 #include "msg/Message.h"
20 #include "include/types.h"
22 #include "mds/CInode.h"
24 #include "mds/mdstypes.h"
26 // sent from replica to auth
28 class MMDSCacheRejoin
: public Message
{
30 static const int HEAD_VERSION
= 1;
31 static const int COMPAT_VERSION
= 1;
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
) {
39 case OP_WEAK
: return "weak";
40 case OP_STRONG
: return "strong";
41 case OP_ACK
: return "ack";
42 default: ceph_abort(); return 0;
50 int32_t filelock
, nestlock
, dftlock
;
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 {
57 ::encode(caps_wanted
, bl
);
58 ::encode(filelock
, bl
);
59 ::encode(nestlock
, bl
);
60 ::encode(dftlock
, bl
);
62 void decode(bufferlist::iterator
&bl
) {
64 ::decode(caps_wanted
, bl
);
65 ::decode(filelock
, bl
);
66 ::decode(nestlock
, bl
);
67 ::decode(dftlock
, bl
);
70 WRITE_CLASS_ENCODER(inode_strong
)
72 struct dirfrag_strong
{
76 dirfrag_strong(int n
, int dr
) : nonce(n
), dir_rep(dr
) {}
77 void encode(bufferlist
&bl
) const {
79 ::encode(dir_rep
, bl
);
81 void decode(bufferlist::iterator
&bl
) {
83 ::decode(dir_rep
, bl
);
86 WRITE_CLASS_ENCODER(dirfrag_strong
)
92 unsigned char remote_d_type
;
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 {
105 ::encode(remote_ino
, bl
);
106 ::encode(remote_d_type
, bl
);
110 void decode(bufferlist::iterator
&bl
) {
113 ::decode(remote_ino
, bl
);
114 ::decode(remote_d_type
, bl
);
119 WRITE_CLASS_ENCODER(dn_strong
)
124 dn_weak() : ino(0) {}
125 dn_weak(snapid_t f
, inodeno_t pi
) : first(f
), ino(pi
) {}
126 void encode(bufferlist
&bl
) const {
130 void decode(bufferlist::iterator
&bl
) {
135 WRITE_CLASS_ENCODER(dn_weak
)
141 bufferlist file
, nest
, dft
;
142 void encode(bufferlist
& bl
) const {
147 void decode(bufferlist::iterator
& bl
) {
153 WRITE_CLASS_ENCODER(lock_bls
)
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
;
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
;
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
;
172 bufferlist inode_base
;
173 bufferlist inode_locks
;
174 map
<dirfrag_t
, bufferlist
> dirfrag_bases
;
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 {
185 ::encode(attempt
, bl
);
187 void decode(bufferlist::iterator
& bl
) {
189 ::decode(attempt
, bl
);
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
;
200 Message(MSG_MDS_CACHEREJOIN
, HEAD_VERSION
, COMPAT_VERSION
)
202 MMDSCacheRejoin(int o
) :
203 Message(MSG_MDS_CACHEREJOIN
, HEAD_VERSION
, COMPAT_VERSION
),
206 ~MMDSCacheRejoin() override
{}
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
);
216 void add_weak_inode(vinodeno_t i
) {
217 weak_inodes
.insert(i
);
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
);
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
);
228 void add_inode_base(CInode
*in
, uint64_t features
) {
229 ::encode(in
->inode
.ino
, inode_base
);
230 ::encode(in
->last
, inode_base
);
232 in
->_encode_base(bl
, features
);
233 ::encode(bl
, inode_base
);
235 void add_inode_authpin(vinodeno_t ino
, const metareqid_t
& ri
, __u32 attempt
) {
236 authpinned_inodes
[ino
].push_back(slave_reqid(ri
, attempt
));
238 void add_inode_frozen_authpin(vinodeno_t ino
, const metareqid_t
& ri
, __u32 attempt
) {
239 frozen_authpin_inodes
[ino
] = slave_reqid(ri
, attempt
);
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
);
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
));
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
);
257 void add_strong_dirfrag(dirfrag_t df
, int n
, int dr
) {
258 strong_dirfrags
[df
] = dirfrag_strong(n
, dr
);
260 void add_dirfrag_base(CDir
*dir
) {
261 bufferlist
& bl
= dirfrag_bases
[dir
->dirfrag()];
262 dir
->_encode_base(bl
);
266 void add_weak_dirfrag(dirfrag_t df
) {
267 weak_dirfrags
.insert(df
);
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
;
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
);
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
);
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
));
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
);
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
);
310 void decode_payload() override
{
311 bufferlist::iterator p
= payload
.begin();
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
);
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
);
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
)
343 inline ostream
& operator<<(ostream
& out
, const MMDSCacheRejoin::slave_reqid
& r
) {
344 return out
<< r
.reqid
<< '.' << r
.attempt
;