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