]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
11fdf7f2 | 18 | #include <string_view> |
7c673cae | 19 | #include "mds/mdstypes.h" |
f67539c2 | 20 | #include "messages/MMDSOp.h" |
7c673cae | 21 | |
f67539c2 | 22 | class MCacheExpire final : public MMDSOp { |
11fdf7f2 | 23 | private: |
7c673cae FG |
24 | __s32 from; |
25 | ||
26 | public: | |
27 | /* | |
28 | group things by realm (auth delgation root), since that's how auth is determined. | |
29 | that makes it less work to process when exports are in progress. | |
30 | */ | |
31 | struct realm { | |
f67539c2 TL |
32 | std::map<vinodeno_t, uint32_t> inodes; |
33 | std::map<dirfrag_t, uint32_t> dirs; | |
34 | std::map<dirfrag_t, std::map<std::pair<std::string,snapid_t>,uint32_t> > dentries; | |
7c673cae | 35 | |
11fdf7f2 | 36 | void merge(const realm& o) { |
7c673cae FG |
37 | inodes.insert(o.inodes.begin(), o.inodes.end()); |
38 | dirs.insert(o.dirs.begin(), o.dirs.end()); | |
11fdf7f2 TL |
39 | for (const auto &p : o.dentries) { |
40 | auto em = dentries.emplace(std::piecewise_construct, std::forward_as_tuple(p.first), std::forward_as_tuple(p.second)); | |
41 | if (!em.second) { | |
42 | em.first->second.insert(p.second.begin(), p.second.end()); | |
43 | } | |
7c673cae FG |
44 | } |
45 | } | |
46 | ||
f67539c2 | 47 | void encode(ceph::buffer::list &bl) const { |
11fdf7f2 TL |
48 | using ceph::encode; |
49 | encode(inodes, bl); | |
50 | encode(dirs, bl); | |
51 | encode(dentries, bl); | |
7c673cae | 52 | } |
f67539c2 | 53 | void decode(ceph::buffer::list::const_iterator &bl) { |
11fdf7f2 TL |
54 | using ceph::decode; |
55 | decode(inodes, bl); | |
56 | decode(dirs, bl); | |
57 | decode(dentries, bl); | |
7c673cae FG |
58 | } |
59 | }; | |
60 | WRITE_CLASS_ENCODER(realm) | |
61 | ||
f67539c2 | 62 | std::map<dirfrag_t, realm> realms; |
7c673cae | 63 | |
11fdf7f2 | 64 | int get_from() const { return from; } |
7c673cae | 65 | |
11fdf7f2 | 66 | protected: |
f67539c2 TL |
67 | MCacheExpire() : MMDSOp{MSG_MDS_CACHEEXPIRE}, from(-1) {} |
68 | MCacheExpire(int f) : | |
69 | MMDSOp{MSG_MDS_CACHEEXPIRE}, | |
7c673cae | 70 | from(f) { } |
f67539c2 | 71 | ~MCacheExpire() final {} |
7c673cae FG |
72 | |
73 | public: | |
11fdf7f2 | 74 | std::string_view get_type_name() const override { return "cache_expire";} |
f67539c2 | 75 | |
7c673cae FG |
76 | void add_inode(dirfrag_t r, vinodeno_t vino, unsigned nonce) { |
77 | realms[r].inodes[vino] = nonce; | |
78 | } | |
79 | void add_dir(dirfrag_t r, dirfrag_t df, unsigned nonce) { | |
80 | realms[r].dirs[df] = nonce; | |
81 | } | |
11fdf7f2 | 82 | void add_dentry(dirfrag_t r, dirfrag_t df, std::string_view dn, snapid_t last, unsigned nonce) { |
f67539c2 | 83 | realms[r].dentries[df][std::pair<std::string,snapid_t>(dn,last)] = nonce; |
7c673cae FG |
84 | } |
85 | ||
11fdf7f2 TL |
86 | void add_realm(dirfrag_t df, const realm& r) { |
87 | auto em = realms.emplace(std::piecewise_construct, std::forward_as_tuple(df), std::forward_as_tuple(r)); | |
88 | if (!em.second) { | |
89 | em.first->second.merge(r); | |
90 | } | |
7c673cae FG |
91 | } |
92 | ||
93 | void decode_payload() override { | |
11fdf7f2 TL |
94 | using ceph::decode; |
95 | auto p = payload.cbegin(); | |
96 | decode(from, p); | |
97 | decode(realms, p); | |
7c673cae | 98 | } |
f67539c2 | 99 | |
7c673cae | 100 | void encode_payload(uint64_t features) override { |
11fdf7f2 TL |
101 | using ceph::encode; |
102 | encode(from, payload); | |
103 | encode(realms, payload); | |
7c673cae | 104 | } |
9f95a23c TL |
105 | private: |
106 | template<class T, typename... Args> | |
107 | friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); | |
20effc67 TL |
108 | template<class T, typename... Args> |
109 | friend MURef<T> crimson::make_message(Args&&... args); | |
7c673cae FG |
110 | }; |
111 | ||
112 | WRITE_CLASS_ENCODER(MCacheExpire::realm) | |
113 | ||
114 | #endif |