]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MCacheExpire.h
update sources to v12.2.5
[ceph.git] / ceph / src / messages / MCacheExpire.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_MCACHEEXPIRE_H
16 #define CEPH_MCACHEEXPIRE_H
17
18 #include <boost/utility/string_view.hpp>
19
20 #include "mds/mdstypes.h"
21
22 class MCacheExpire : public Message {
23 __s32 from;
24
25 public:
26 /*
27 group things by realm (auth delgation root), since that's how auth is determined.
28 that makes it less work to process when exports are in progress.
29 */
30 struct realm {
31 map<vinodeno_t, uint32_t> inodes;
32 map<dirfrag_t, uint32_t> dirs;
33 map<dirfrag_t, map<pair<string,snapid_t>,uint32_t> > dentries;
34
35 void merge(realm& o) {
36 inodes.insert(o.inodes.begin(), o.inodes.end());
37 dirs.insert(o.dirs.begin(), o.dirs.end());
38 for (map<dirfrag_t,map<pair<string,snapid_t>,uint32_t> >::iterator p = o.dentries.begin();
39 p != o.dentries.end();
40 ++p) {
41 if (dentries.count(p->first) == 0)
42 dentries[p->first] = p->second;
43 else
44 dentries[p->first].insert(p->second.begin(), p->second.end());
45 }
46 }
47
48 void encode(bufferlist &bl) const {
49 ::encode(inodes, bl);
50 ::encode(dirs, bl);
51 ::encode(dentries, bl);
52 }
53 void decode(bufferlist::iterator &bl) {
54 ::decode(inodes, bl);
55 ::decode(dirs, bl);
56 ::decode(dentries, bl);
57 }
58 };
59 WRITE_CLASS_ENCODER(realm)
60
61 map<dirfrag_t, realm> realms;
62
63 int get_from() { return from; }
64
65 MCacheExpire() : Message(MSG_MDS_CACHEEXPIRE), from(-1) {}
66 MCacheExpire(int f) :
67 Message(MSG_MDS_CACHEEXPIRE),
68 from(f) { }
69 private:
70 ~MCacheExpire() override {}
71
72 public:
73 const char *get_type_name() const override { return "cache_expire";}
74
75 void add_inode(dirfrag_t r, vinodeno_t vino, unsigned nonce) {
76 realms[r].inodes[vino] = nonce;
77 }
78 void add_dir(dirfrag_t r, dirfrag_t df, unsigned nonce) {
79 realms[r].dirs[df] = nonce;
80 }
81 void add_dentry(dirfrag_t r, dirfrag_t df, boost::string_view dn, snapid_t last, unsigned nonce) {
82 realms[r].dentries[df][pair<string,snapid_t>(std::string(dn),last)] = nonce;
83 }
84
85 void add_realm(dirfrag_t df, realm& r) {
86 if (realms.count(df) == 0)
87 realms[df] = r;
88 else
89 realms[df].merge(r);
90 }
91
92 void decode_payload() override {
93 bufferlist::iterator p = payload.begin();
94 ::decode(from, p);
95 ::decode(realms, p);
96 }
97
98 void encode_payload(uint64_t features) override {
99 ::encode(from, payload);
100 ::encode(realms, payload);
101 }
102 };
103
104 WRITE_CLASS_ENCODER(MCacheExpire::realm)
105
106 #endif