]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MCacheExpire.h
import quincy beta 17.1.0
[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 <string_view>
19 #include "mds/mdstypes.h"
20 #include "messages/MMDSOp.h"
21
22 class MCacheExpire final : public MMDSOp {
23 private:
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 {
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;
35
36 void merge(const realm& o) {
37 inodes.insert(o.inodes.begin(), o.inodes.end());
38 dirs.insert(o.dirs.begin(), o.dirs.end());
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 }
44 }
45 }
46
47 void encode(ceph::buffer::list &bl) const {
48 using ceph::encode;
49 encode(inodes, bl);
50 encode(dirs, bl);
51 encode(dentries, bl);
52 }
53 void decode(ceph::buffer::list::const_iterator &bl) {
54 using ceph::decode;
55 decode(inodes, bl);
56 decode(dirs, bl);
57 decode(dentries, bl);
58 }
59 };
60 WRITE_CLASS_ENCODER(realm)
61
62 std::map<dirfrag_t, realm> realms;
63
64 int get_from() const { return from; }
65
66 protected:
67 MCacheExpire() : MMDSOp{MSG_MDS_CACHEEXPIRE}, from(-1) {}
68 MCacheExpire(int f) :
69 MMDSOp{MSG_MDS_CACHEEXPIRE},
70 from(f) { }
71 ~MCacheExpire() final {}
72
73 public:
74 std::string_view get_type_name() const override { return "cache_expire";}
75
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 }
82 void add_dentry(dirfrag_t r, dirfrag_t df, std::string_view dn, snapid_t last, unsigned nonce) {
83 realms[r].dentries[df][std::pair<std::string,snapid_t>(dn,last)] = nonce;
84 }
85
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 }
91 }
92
93 void decode_payload() override {
94 using ceph::decode;
95 auto p = payload.cbegin();
96 decode(from, p);
97 decode(realms, p);
98 }
99
100 void encode_payload(uint64_t features) override {
101 using ceph::encode;
102 encode(from, payload);
103 encode(realms, payload);
104 }
105 private:
106 template<class T, typename... Args>
107 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
108 template<class T, typename... Args>
109 friend MURef<T> crimson::make_message(Args&&... args);
110 };
111
112 WRITE_CLASS_ENCODER(MCacheExpire::realm)
113
114 #endif