]>
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 | ||
16 | #ifndef CEPH_MDISCOVERREPLY_H | |
17 | #define CEPH_MDISCOVERREPLY_H | |
18 | ||
19 | #include "msg/Message.h" | |
20 | #include "include/filepath.h" | |
21 | ||
22 | #include <string> | |
23 | ||
24 | ||
25 | ||
26 | /** | |
27 | * MDiscoverReply - return new replicas (of inodes, dirs, dentries) | |
28 | * | |
29 | * we group returned items by (dir, dentry, inode). each | |
30 | * item in each set shares an index (it's "depth"). | |
31 | * | |
32 | * we can start and end with any type. | |
33 | * no_base_dir = true if the first group has an inode but no dir | |
34 | * no_base_dentry = true if the first group has an inode but no dentry | |
35 | * they are false if there is no returned data, ie the first group is empty. | |
36 | * | |
37 | * we also return errors: | |
38 | * error_flag_dn(std::string) - the specified dentry dne | |
39 | * error_flag_dir - the last item wasn't a dir, so we couldn't continue. | |
40 | * | |
41 | * and sometimes, | |
42 | * dir_auth_hint - where we think the dir auth is | |
43 | * | |
44 | * depth() gives us the number of depth units/indices for which we have | |
45 | * information. this INCLUDES those for which we have errors but no data. | |
46 | * | |
47 | * see MDCache::handle_discover, handle_discover_reply. | |
48 | * | |
49 | * | |
50 | * so basically, we get | |
51 | * | |
52 | * dir den ino i | |
53 | * x 0 | |
54 | * x x x 1 | |
55 | * or | |
56 | * x x 0 | |
57 | * x x x 1 | |
58 | * or | |
59 | * x x x 0 | |
60 | * x x x 1 | |
61 | * ...and trail off however we want. | |
62 | * | |
63 | * | |
64 | */ | |
65 | ||
11fdf7f2 TL |
66 | class MDiscoverReply : public MessageInstance<MDiscoverReply> { |
67 | public: | |
68 | friend factory; | |
69 | private: | |
70 | static constexpr int HEAD_VERSION = 2; | |
7c673cae FG |
71 | |
72 | // info about original request | |
73 | inodeno_t base_ino; | |
74 | frag_t base_dir_frag; | |
11fdf7f2 TL |
75 | bool wanted_base_dir = false; |
76 | bool wanted_xlocked = false; | |
7c673cae FG |
77 | snapid_t wanted_snapid; |
78 | ||
79 | // and the response | |
11fdf7f2 TL |
80 | bool flag_error_dn = false; |
81 | bool flag_error_dir = false; | |
7c673cae | 82 | std::string error_dentry; // dentry that was not found (to trigger waiters on asker) |
11fdf7f2 | 83 | bool unsolicited = false; |
7c673cae | 84 | |
11fdf7f2 | 85 | mds_rank_t dir_auth_hint = 0; |
7c673cae FG |
86 | |
87 | public: | |
11fdf7f2 | 88 | __u8 starts_with = 0; |
7c673cae FG |
89 | bufferlist trace; |
90 | ||
91 | enum { DIR, DENTRY, INODE }; | |
92 | ||
93 | // accessors | |
11fdf7f2 TL |
94 | inodeno_t get_base_ino() const { return base_ino; } |
95 | frag_t get_base_dir_frag() const { return base_dir_frag; } | |
96 | bool get_wanted_base_dir() const { return wanted_base_dir; } | |
97 | bool get_wanted_xlocked() const { return wanted_xlocked; } | |
98 | snapid_t get_wanted_snapid() const { return wanted_snapid; } | |
7c673cae | 99 | |
11fdf7f2 TL |
100 | bool is_flag_error_dn() const { return flag_error_dn; } |
101 | bool is_flag_error_dir() const { return flag_error_dir; } | |
102 | const std::string& get_error_dentry() const { return error_dentry; } | |
7c673cae | 103 | |
11fdf7f2 | 104 | int get_starts_with() const { return starts_with; } |
7c673cae FG |
105 | |
106 | mds_rank_t get_dir_auth_hint() const { return dir_auth_hint; } | |
107 | ||
11fdf7f2 | 108 | bool is_unsolicited() const { return unsolicited; } |
7c673cae FG |
109 | void mark_unsolicited() { unsolicited = true; } |
110 | ||
111 | void set_base_dir_frag(frag_t df) { base_dir_frag = df; } | |
112 | ||
11fdf7f2 TL |
113 | protected: |
114 | MDiscoverReply() : MessageInstance(MSG_MDS_DISCOVERREPLY, HEAD_VERSION) { } | |
115 | MDiscoverReply(const MDiscover &dis) : | |
116 | MessageInstance(MSG_MDS_DISCOVERREPLY, HEAD_VERSION), | |
117 | base_ino(dis.get_base_ino()), | |
118 | base_dir_frag(dis.get_base_dir_frag()), | |
119 | wanted_base_dir(dis.wants_base_dir()), | |
120 | wanted_xlocked(dis.wants_xlocked()), | |
121 | wanted_snapid(dis.get_snapid()), | |
7c673cae FG |
122 | flag_error_dn(false), |
123 | flag_error_dir(false), | |
124 | unsolicited(false), | |
125 | dir_auth_hint(CDIR_AUTH_UNKNOWN), | |
126 | starts_with(DIR) | |
127 | { | |
11fdf7f2 | 128 | header.tid = dis.get_tid(); |
7c673cae FG |
129 | } |
130 | MDiscoverReply(dirfrag_t df) : | |
11fdf7f2 | 131 | MessageInstance(MSG_MDS_DISCOVERREPLY, HEAD_VERSION), |
7c673cae FG |
132 | base_ino(df.ino), |
133 | base_dir_frag(df.frag), | |
134 | wanted_base_dir(false), | |
135 | wanted_xlocked(false), | |
136 | wanted_snapid(CEPH_NOSNAP), | |
137 | flag_error_dn(false), | |
138 | flag_error_dir(false), | |
139 | unsolicited(false), | |
140 | dir_auth_hint(CDIR_AUTH_UNKNOWN), | |
141 | starts_with(DIR) | |
142 | { | |
143 | header.tid = 0; | |
144 | } | |
7c673cae FG |
145 | ~MDiscoverReply() override {} |
146 | ||
147 | public: | |
11fdf7f2 | 148 | std::string_view get_type_name() const override { return "discover_reply"; } |
7c673cae FG |
149 | void print(ostream& out) const override { |
150 | out << "discover_reply(" << header.tid << " " << base_ino << ")"; | |
151 | } | |
152 | ||
153 | // builders | |
11fdf7f2 | 154 | bool is_empty() const { |
7c673cae FG |
155 | return trace.length() == 0 && |
156 | !flag_error_dn && | |
157 | !flag_error_dir && | |
158 | dir_auth_hint == CDIR_AUTH_UNKNOWN; | |
159 | } | |
160 | ||
161 | // void set_flag_forward() { flag_forward = true; } | |
11fdf7f2 | 162 | void set_flag_error_dn(std::string_view dn) { |
7c673cae | 163 | flag_error_dn = true; |
11fdf7f2 | 164 | error_dentry = dn; |
7c673cae FG |
165 | } |
166 | void set_flag_error_dir() { | |
167 | flag_error_dir = true; | |
168 | } | |
169 | void set_dir_auth_hint(int a) { | |
170 | dir_auth_hint = a; | |
171 | } | |
11fdf7f2 TL |
172 | void set_error_dentry(std::string_view dn) { |
173 | error_dentry = dn; | |
7c673cae FG |
174 | } |
175 | ||
176 | ||
177 | // ... | |
178 | void decode_payload() override { | |
11fdf7f2 TL |
179 | auto p = payload.cbegin(); |
180 | decode(base_ino, p); | |
181 | decode(base_dir_frag, p); | |
182 | decode(wanted_base_dir, p); | |
183 | decode(wanted_xlocked, p); | |
184 | decode(wanted_snapid, p); | |
185 | decode(flag_error_dn, p); | |
186 | decode(flag_error_dir, p); | |
187 | decode(error_dentry, p); | |
188 | decode(dir_auth_hint, p); | |
189 | decode(unsolicited, p); | |
190 | ||
191 | decode(starts_with, p); | |
192 | decode(trace, p); | |
7c673cae FG |
193 | } |
194 | void encode_payload(uint64_t features) override { | |
11fdf7f2 TL |
195 | using ceph::encode; |
196 | encode(base_ino, payload); | |
197 | encode(base_dir_frag, payload); | |
198 | encode(wanted_base_dir, payload); | |
199 | encode(wanted_xlocked, payload); | |
200 | encode(wanted_snapid, payload); | |
201 | encode(flag_error_dn, payload); | |
202 | encode(flag_error_dir, payload); | |
203 | encode(error_dentry, payload); | |
204 | encode(dir_auth_hint, payload); | |
205 | encode(unsolicited, payload); | |
206 | ||
207 | encode(starts_with, payload); | |
208 | encode(trace, payload); | |
7c673cae FG |
209 | } |
210 | }; | |
211 | ||
212 | #endif |