]>
git.proxmox.com Git - ceph.git/blob - 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
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 <boost/utility/string_view.hpp>
20 #include "msg/Message.h"
22 #include "include/types.h"
24 #include "mds/CInode.h"
26 #include "mds/mdstypes.h"
28 // sent from replica to auth
30 class MMDSCacheRejoin
: public Message
{
32 static const int HEAD_VERSION
= 1;
33 static const int COMPAT_VERSION
= 1;
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
) {
41 case OP_WEAK
: return "weak";
42 case OP_STRONG
: return "strong";
43 case OP_ACK
: return "ack";
44 default: ceph_abort(); return 0;
52 int32_t filelock
, nestlock
, dftlock
;
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 {
59 ::encode(caps_wanted
, bl
);
60 ::encode(filelock
, bl
);
61 ::encode(nestlock
, bl
);
62 ::encode(dftlock
, bl
);
64 void decode(bufferlist::iterator
&bl
) {
66 ::decode(caps_wanted
, bl
);
67 ::decode(filelock
, bl
);
68 ::decode(nestlock
, bl
);
69 ::decode(dftlock
, bl
);
72 WRITE_CLASS_ENCODER(inode_strong
)
74 struct dirfrag_strong
{
78 dirfrag_strong(int n
, int dr
) : nonce(n
), dir_rep(dr
) {}
79 void encode(bufferlist
&bl
) const {
81 ::encode(dir_rep
, bl
);
83 void decode(bufferlist::iterator
&bl
) {
85 ::decode(dir_rep
, bl
);
88 WRITE_CLASS_ENCODER(dirfrag_strong
)
94 unsigned char remote_d_type
;
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 {
107 ::encode(remote_ino
, bl
);
108 ::encode(remote_d_type
, bl
);
112 void decode(bufferlist::iterator
&bl
) {
115 ::decode(remote_ino
, bl
);
116 ::decode(remote_d_type
, bl
);
121 WRITE_CLASS_ENCODER(dn_strong
)
126 dn_weak() : ino(0) {}
127 dn_weak(snapid_t f
, inodeno_t pi
) : first(f
), ino(pi
) {}
128 void encode(bufferlist
&bl
) const {
132 void decode(bufferlist::iterator
&bl
) {
137 WRITE_CLASS_ENCODER(dn_weak
)
143 bufferlist file
, nest
, dft
;
144 void encode(bufferlist
& bl
) const {
149 void decode(bufferlist::iterator
& bl
) {
155 WRITE_CLASS_ENCODER(lock_bls
)
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
;
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
;
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
;
174 bufferlist inode_base
;
175 bufferlist inode_locks
;
176 map
<dirfrag_t
, bufferlist
> dirfrag_bases
;
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 {
187 ::encode(attempt
, bl
);
189 void decode(bufferlist::iterator
& bl
) {
191 ::decode(attempt
, bl
);
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
;
202 Message(MSG_MDS_CACHEREJOIN
, HEAD_VERSION
, COMPAT_VERSION
),
204 MMDSCacheRejoin(int o
) :
205 Message(MSG_MDS_CACHEREJOIN
, HEAD_VERSION
, COMPAT_VERSION
),
208 ~MMDSCacheRejoin() override
{}
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
);
218 void add_weak_inode(vinodeno_t i
) {
219 weak_inodes
.insert(i
);
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
);
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
);
230 void add_inode_base(CInode
*in
, uint64_t features
) {
231 ::encode(in
->inode
.ino
, inode_base
);
232 ::encode(in
->last
, inode_base
);
234 in
->_encode_base(bl
, features
);
235 ::encode(bl
, inode_base
);
237 void add_inode_authpin(vinodeno_t ino
, const metareqid_t
& ri
, __u32 attempt
) {
238 authpinned_inodes
[ino
].push_back(slave_reqid(ri
, attempt
));
240 void add_inode_frozen_authpin(vinodeno_t ino
, const metareqid_t
& ri
, __u32 attempt
) {
241 frozen_authpin_inodes
[ino
] = slave_reqid(ri
, attempt
);
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
);
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
));
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
);
259 void add_strong_dirfrag(dirfrag_t df
, int n
, int dr
) {
260 strong_dirfrags
[df
] = dirfrag_strong(n
, dr
);
262 void add_dirfrag_base(CDir
*dir
) {
263 bufferlist
& bl
= dirfrag_bases
[dir
->dirfrag()];
264 dir
->_encode_base(bl
);
268 void add_weak_dirfrag(dirfrag_t df
) {
269 weak_dirfrags
.insert(df
);
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
;
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
);
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
);
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
));
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
);
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
);
312 void decode_payload() override
{
313 bufferlist::iterator p
= payload
.begin();
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
);
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
);
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
)
345 inline ostream
& operator<<(ostream
& out
, const MMDSCacheRejoin::slave_reqid
& r
) {
346 return out
<< r
.reqid
<< '.' << r
.attempt
;