]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMDSResolve.h
d636bdcd559edf14246944418d7c7c9f6c2c948a
[ceph.git] / ceph / src / messages / MMDSResolve.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_MMDSRESOLVE_H
16 #define CEPH_MMDSRESOLVE_H
17
18 #include "include/types.h"
19 #include "mds/Capability.h"
20 #include "messages/MMDSOp.h"
21
22 class MMDSResolve final : public MMDSOp {
23 static constexpr int HEAD_VERSION = 1;
24 static constexpr int COMPAT_VERSION = 1;
25
26 public:
27 std::map<dirfrag_t, std::vector<dirfrag_t>> subtrees;
28 std::map<dirfrag_t, std::vector<dirfrag_t>> ambiguous_imports;
29
30 class peer_inode_cap {
31 public:
32 inodeno_t ino;
33 std::map<client_t,Capability::Export> cap_exports;
34 peer_inode_cap() {}
35 peer_inode_cap(inodeno_t a, map<client_t, Capability::Export> b) : ino(a), cap_exports(b) {}
36 void encode(ceph::buffer::list &bl) const
37 {
38 ENCODE_START(1, 1, bl);
39 encode(ino, bl);
40 encode(cap_exports, bl);
41 ENCODE_FINISH(bl);
42 }
43 void decode(ceph::buffer::list::const_iterator &blp)
44 {
45 DECODE_START(1, blp);
46 decode(ino, blp);
47 decode(cap_exports, blp);
48 DECODE_FINISH(blp);
49 }
50 };
51 WRITE_CLASS_ENCODER(peer_inode_cap)
52
53 struct peer_request {
54 ceph::buffer::list inode_caps;
55 bool committing;
56 peer_request() : committing(false) {}
57 void encode(ceph::buffer::list &bl) const {
58 ENCODE_START(1, 1, bl);
59 encode(inode_caps, bl);
60 encode(committing, bl);
61 ENCODE_FINISH(bl);
62 }
63 void decode(ceph::buffer::list::const_iterator &blp) {
64 DECODE_START(1, blp);
65 decode(inode_caps, blp);
66 decode(committing, blp);
67 DECODE_FINISH(blp);
68 }
69 };
70
71 std::map<metareqid_t, peer_request> peer_requests;
72
73 // table client information
74 struct table_client {
75 __u8 type;
76 std::set<version_t> pending_commits;
77
78 table_client() : type(0) {}
79 table_client(int _type, const std::set<version_t>& commits)
80 : type(_type), pending_commits(commits) {}
81
82 void encode(ceph::buffer::list& bl) const {
83 using ceph::encode;
84 encode(type, bl);
85 encode(pending_commits, bl);
86 }
87 void decode(ceph::buffer::list::const_iterator& bl) {
88 using ceph::decode;
89 decode(type, bl);
90 decode(pending_commits, bl);
91 }
92 };
93
94 std::list<table_client> table_clients;
95
96 protected:
97 MMDSResolve() : MMDSOp{MSG_MDS_RESOLVE, HEAD_VERSION, COMPAT_VERSION}
98 {}
99 ~MMDSResolve() final {}
100
101 public:
102 std::string_view get_type_name() const override { return "mds_resolve"; }
103
104 void print(std::ostream& out) const override {
105 out << "mds_resolve(" << subtrees.size()
106 << "+" << ambiguous_imports.size()
107 << " subtrees +" << peer_requests.size() << " peer requests)";
108 }
109
110 void add_subtree(dirfrag_t im) {
111 subtrees[im].clear();
112 }
113 void add_subtree_bound(dirfrag_t im, dirfrag_t ex) {
114 subtrees[im].push_back(ex);
115 }
116
117 void add_ambiguous_import(dirfrag_t im, const std::vector<dirfrag_t>& m) {
118 ambiguous_imports[im] = m;
119 }
120
121 void add_peer_request(metareqid_t reqid, bool committing) {
122 peer_requests[reqid].committing = committing;
123 }
124
125 void add_peer_request(metareqid_t reqid, ceph::buffer::list& bl) {
126 peer_requests[reqid].inode_caps = std::move(bl);
127 }
128
129 void add_table_commits(int table, const std::set<version_t>& pending_commits) {
130 table_clients.push_back(table_client(table, pending_commits));
131 }
132
133 void encode_payload(uint64_t features) override {
134 using ceph::encode;
135 encode(subtrees, payload);
136 encode(ambiguous_imports, payload);
137 encode(peer_requests, payload);
138 encode(table_clients, payload);
139 }
140 void decode_payload() override {
141 using ceph::decode;
142 auto p = payload.cbegin();
143 decode(subtrees, p);
144 decode(ambiguous_imports, p);
145 decode(peer_requests, p);
146 decode(table_clients, p);
147 }
148 private:
149 template<class T, typename... Args>
150 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
151 };
152
153 inline std::ostream& operator<<(std::ostream& out, const MMDSResolve::peer_request&) {
154 return out;
155 }
156
157 WRITE_CLASS_ENCODER(MMDSResolve::peer_request)
158 WRITE_CLASS_ENCODER(MMDSResolve::table_client)
159 WRITE_CLASS_ENCODER(MMDSResolve::peer_inode_cap)
160 #endif