]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MClientCaps.h
500a6fc83b1ae5495f65ca2bccb5737ca4654b82
[ceph.git] / ceph / src / messages / MClientCaps.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_MCLIENTCAPS_H
16 #define CEPH_MCLIENTCAPS_H
17
18 #include "msg/Message.h"
19 #include "mds/mdstypes.h"
20 #include "include/ceph_features.h"
21
22 class MClientCaps final : public SafeMessage {
23 private:
24
25 static constexpr int HEAD_VERSION = 11;
26 static constexpr int COMPAT_VERSION = 1;
27
28 public:
29 static constexpr unsigned FLAG_SYNC = (1<<0);
30 static constexpr unsigned FLAG_NO_CAPSNAP = (1<<1); // unused
31 static constexpr unsigned FLAG_PENDING_CAPSNAP = (1<<2);
32
33 struct ceph_mds_caps_head head;
34
35 uint64_t size = 0;
36 uint64_t max_size = 0;
37 uint64_t truncate_size = 0;
38 uint64_t change_attr = 0;
39 uint32_t truncate_seq = 0;
40 utime_t mtime, atime, ctime, btime;
41 uint32_t time_warp_seq = 0;
42 int64_t nfiles = -1; // files in dir
43 int64_t nsubdirs = -1; // subdirs in dir
44
45 struct ceph_mds_cap_peer peer;
46
47 ceph::buffer::list snapbl;
48 ceph::buffer::list xattrbl;
49 ceph::buffer::list flockbl;
50 version_t inline_version = 0;
51 ceph::buffer::list inline_data;
52
53 // Receivers may not use their new caps until they have this OSD map
54 epoch_t osd_epoch_barrier = 0;
55 ceph_tid_t oldest_flush_tid = 0;
56 uint32_t caller_uid = 0;
57 uint32_t caller_gid = 0;
58
59 /* advisory CLIENT_CAPS_* flags to send to mds */
60 unsigned flags = 0;
61
62 int get_caps() const { return head.caps; }
63 int get_wanted() const { return head.wanted; }
64 int get_dirty() const { return head.dirty; }
65 ceph_seq_t get_seq() const { return head.seq; }
66 ceph_seq_t get_issue_seq() const { return head.issue_seq; }
67 ceph_seq_t get_mseq() const { return head.migrate_seq; }
68
69 inodeno_t get_ino() const { return inodeno_t(head.ino); }
70 inodeno_t get_realm() const { return inodeno_t(head.realm); }
71 uint64_t get_cap_id() const { return head.cap_id; }
72
73 uint64_t get_size() const { return size; }
74 uint64_t get_max_size() const { return max_size; }
75 __u32 get_truncate_seq() const { return truncate_seq; }
76 uint64_t get_truncate_size() const { return truncate_size; }
77 utime_t get_ctime() const { return ctime; }
78 utime_t get_btime() const { return btime; }
79 utime_t get_mtime() const { return mtime; }
80 utime_t get_atime() const { return atime; }
81 __u64 get_change_attr() const { return change_attr; }
82 __u32 get_time_warp_seq() const { return time_warp_seq; }
83 uint64_t get_nfiles() const { return nfiles; }
84 uint64_t get_nsubdirs() const { return nsubdirs; }
85 bool dirstat_is_valid() const { return nfiles != -1 || nsubdirs != -1; }
86
87 const file_layout_t& get_layout() const {
88 return layout;
89 }
90
91 void set_layout(const file_layout_t &l) {
92 layout = l;
93 }
94
95 int get_migrate_seq() const { return head.migrate_seq; }
96 int get_op() const { return head.op; }
97
98 uint64_t get_client_tid() const { return get_tid(); }
99 void set_client_tid(uint64_t s) { set_tid(s); }
100
101 snapid_t get_snap_follows() const { return snapid_t(head.snap_follows); }
102 void set_snap_follows(snapid_t s) { head.snap_follows = s; }
103
104 void set_caps(int c) { head.caps = c; }
105 void set_wanted(int w) { head.wanted = w; }
106
107 void set_max_size(uint64_t ms) { max_size = ms; }
108
109 void set_migrate_seq(unsigned m) { head.migrate_seq = m; }
110 void set_op(int o) { head.op = o; }
111
112 void set_size(loff_t s) { size = s; }
113 void set_mtime(const utime_t &t) { mtime = t; }
114 void set_ctime(const utime_t &t) { ctime = t; }
115 void set_atime(const utime_t &t) { atime = t; }
116
117 void set_cap_peer(uint64_t id, ceph_seq_t seq, ceph_seq_t mseq, int mds, int flags) {
118 peer.cap_id = id;
119 peer.seq = seq;
120 peer.mseq = mseq;
121 peer.mds = mds;
122 peer.flags = flags;
123 }
124
125 void set_oldest_flush_tid(ceph_tid_t tid) { oldest_flush_tid = tid; }
126 ceph_tid_t get_oldest_flush_tid() const { return oldest_flush_tid; }
127
128 void clear_dirty() { head.dirty = 0; }
129
130 protected:
131 MClientCaps()
132 : SafeMessage{CEPH_MSG_CLIENT_CAPS, HEAD_VERSION, COMPAT_VERSION} {}
133 MClientCaps(int op,
134 inodeno_t ino,
135 inodeno_t realm,
136 uint64_t id,
137 long seq,
138 int caps,
139 int wanted,
140 int dirty,
141 int mseq,
142 epoch_t oeb)
143 : SafeMessage{CEPH_MSG_CLIENT_CAPS, HEAD_VERSION, COMPAT_VERSION},
144 osd_epoch_barrier(oeb) {
145 memset(&head, 0, sizeof(head));
146 head.op = op;
147 head.ino = ino;
148 head.realm = realm;
149 head.cap_id = id;
150 head.seq = seq;
151 head.caps = caps;
152 head.wanted = wanted;
153 head.dirty = dirty;
154 head.migrate_seq = mseq;
155 memset(&peer, 0, sizeof(peer));
156 }
157 MClientCaps(int op,
158 inodeno_t ino, inodeno_t realm,
159 uint64_t id, int mseq, epoch_t oeb)
160 : SafeMessage{CEPH_MSG_CLIENT_CAPS, HEAD_VERSION, COMPAT_VERSION},
161 osd_epoch_barrier(oeb) {
162 memset(&head, 0, sizeof(head));
163 head.op = op;
164 head.ino = ino;
165 head.realm = realm;
166 head.cap_id = id;
167 head.migrate_seq = mseq;
168 memset(&peer, 0, sizeof(peer));
169 }
170 ~MClientCaps() final {}
171
172 private:
173 file_layout_t layout;
174
175 public:
176 std::string_view get_type_name() const override { return "Cfcap";}
177 void print(std::ostream& out) const override {
178 out << "client_caps(" << ceph_cap_op_name(head.op)
179 << " ino " << inodeno_t(head.ino)
180 << " " << head.cap_id
181 << " seq " << head.seq;
182 if (get_tid())
183 out << " tid " << get_tid();
184 out << " caps=" << ccap_string(head.caps)
185 << " dirty=" << ccap_string(head.dirty)
186 << " wanted=" << ccap_string(head.wanted);
187 out << " follows " << snapid_t(head.snap_follows);
188 if (head.migrate_seq)
189 out << " mseq " << head.migrate_seq;
190
191 out << " size " << size << "/" << max_size;
192 if (truncate_seq)
193 out << " ts " << truncate_seq << "/" << truncate_size;
194 out << " mtime " << mtime;
195 if (time_warp_seq)
196 out << " tws " << time_warp_seq;
197
198 if (head.xattr_version)
199 out << " xattrs(v=" << head.xattr_version << " l=" << xattrbl.length() << ")";
200
201 out << ")";
202 }
203
204 void decode_payload() override {
205 using ceph::decode;
206 auto p = payload.cbegin();
207 decode(head, p);
208 if (head.op == CEPH_CAP_OP_EXPORT) {
209 ceph_mds_caps_export_body body;
210 decode(body, p);
211 peer = body.peer;
212 p += (sizeof(ceph_mds_caps_non_export_body) -
213 sizeof(ceph_mds_caps_export_body));
214 } else {
215 ceph_mds_caps_non_export_body body;
216 decode(body, p);
217 size = body.size;
218 max_size = body.max_size;
219 truncate_size = body.truncate_size;
220 truncate_seq = body.truncate_seq;
221 mtime = utime_t(body.mtime);
222 atime = utime_t(body.atime);
223 ctime = utime_t(body.ctime);
224 layout.from_legacy(body.layout);
225 time_warp_seq = body.time_warp_seq;
226 }
227 ceph::decode_nohead(head.snap_trace_len, snapbl, p);
228
229 ceph_assert(middle.length() == head.xattr_len);
230 if (head.xattr_len)
231 xattrbl = middle;
232
233 // conditionally decode flock metadata
234 if (header.version >= 2)
235 decode(flockbl, p);
236
237 if (header.version >= 3) {
238 if (head.op == CEPH_CAP_OP_IMPORT)
239 decode(peer, p);
240 }
241
242 if (header.version >= 4) {
243 decode(inline_version, p);
244 decode(inline_data, p);
245 } else {
246 inline_version = CEPH_INLINE_NONE;
247 }
248
249 if (header.version >= 5) {
250 decode(osd_epoch_barrier, p);
251 }
252 if (header.version >= 6) {
253 decode(oldest_flush_tid, p);
254 }
255 if (header.version >= 7) {
256 decode(caller_uid, p);
257 decode(caller_gid, p);
258 }
259 if (header.version >= 8) {
260 decode(layout.pool_ns, p);
261 }
262 if (header.version >= 9) {
263 decode(btime, p);
264 decode(change_attr, p);
265 }
266 if (header.version >= 10) {
267 decode(flags, p);
268 }
269 if (header.version >= 11) {
270 decode(nfiles, p);
271 decode(nsubdirs, p);
272 }
273 }
274 void encode_payload(uint64_t features) override {
275 using ceph::encode;
276 header.version = HEAD_VERSION;
277 head.snap_trace_len = snapbl.length();
278 head.xattr_len = xattrbl.length();
279
280 encode(head, payload);
281 static_assert(sizeof(ceph_mds_caps_non_export_body) >
282 sizeof(ceph_mds_caps_export_body));
283 if (head.op == CEPH_CAP_OP_EXPORT) {
284 ceph_mds_caps_export_body body;
285 body.peer = peer;
286 encode(body, payload);
287 payload.append_zero(sizeof(ceph_mds_caps_non_export_body) -
288 sizeof(ceph_mds_caps_export_body));
289 } else {
290 ceph_mds_caps_non_export_body body;
291 body.size = size;
292 body.max_size = max_size;
293 body.truncate_size = truncate_size;
294 body.truncate_seq = truncate_seq;
295 mtime.encode_timeval(&body.mtime);
296 atime.encode_timeval(&body.atime);
297 ctime.encode_timeval(&body.ctime);
298 layout.to_legacy(&body.layout);
299 body.time_warp_seq = time_warp_seq;
300 encode(body, payload);
301 }
302 ceph::encode_nohead(snapbl, payload);
303
304 middle = xattrbl;
305
306 // conditionally include flock metadata
307 if (features & CEPH_FEATURE_FLOCK) {
308 encode(flockbl, payload);
309 } else {
310 header.version = 1;
311 return;
312 }
313
314 if (features & CEPH_FEATURE_EXPORT_PEER) {
315 if (head.op == CEPH_CAP_OP_IMPORT)
316 encode(peer, payload);
317 } else {
318 header.version = 2;
319 return;
320 }
321
322 if (features & CEPH_FEATURE_MDS_INLINE_DATA) {
323 encode(inline_version, payload);
324 encode(inline_data, payload);
325 } else {
326 encode(inline_version, payload);
327 encode(ceph::buffer::list(), payload);
328 }
329
330 encode(osd_epoch_barrier, payload);
331 encode(oldest_flush_tid, payload);
332 encode(caller_uid, payload);
333 encode(caller_gid, payload);
334
335 encode(layout.pool_ns, payload);
336 encode(btime, payload);
337 encode(change_attr, payload);
338 encode(flags, payload);
339 encode(nfiles, payload);
340 encode(nsubdirs, payload);
341 }
342 private:
343 template<class T, typename... Args>
344 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
345 template<class T, typename... Args>
346 friend MURef<T> crimson::make_message(Args&&... args);
347 };
348
349 #endif