1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef CEPH_MCLIENTCAPS_H
16 #define CEPH_MCLIENTCAPS_H
18 #include "msg/Message.h"
19 #include "include/ceph_features.h"
21 #define CLIENT_CAPS_SYNC (0x1)
23 class MClientCaps
: public Message
{
24 static const int HEAD_VERSION
= 11;
25 static const int COMPAT_VERSION
= 1;
28 struct ceph_mds_caps_head head
;
31 uint64_t max_size
= 0;
32 uint64_t truncate_size
= 0;
33 uint64_t change_attr
= 0;
34 uint32_t truncate_seq
= 0;
35 utime_t mtime
, atime
, ctime
, btime
;
36 uint32_t time_warp_seq
= 0;
37 int64_t nfiles
= -1; // files in dir
38 int64_t nsubdirs
= -1; // subdirs in dir
40 struct ceph_mds_cap_peer peer
;
45 version_t inline_version
= 0;
46 bufferlist inline_data
;
48 // Receivers may not use their new caps until they have this OSD map
49 epoch_t osd_epoch_barrier
= 0;
50 ceph_tid_t oldest_flush_tid
= 0;
51 uint32_t caller_uid
= 0;
52 uint32_t caller_gid
= 0;
54 /* advisory CLIENT_CAPS_* flags to send to mds */
57 int get_caps() { return head
.caps
; }
58 int get_wanted() { return head
.wanted
; }
59 int get_dirty() { return head
.dirty
; }
60 ceph_seq_t
get_seq() { return head
.seq
; }
61 ceph_seq_t
get_issue_seq() { return head
.issue_seq
; }
62 ceph_seq_t
get_mseq() { return head
.migrate_seq
; }
64 inodeno_t
get_ino() { return inodeno_t(head
.ino
); }
65 inodeno_t
get_realm() { return inodeno_t(head
.realm
); }
66 uint64_t get_cap_id() { return head
.cap_id
; }
68 uint64_t get_size() { return size
; }
69 uint64_t get_max_size() { return max_size
; }
70 __u32
get_truncate_seq() { return truncate_seq
; }
71 uint64_t get_truncate_size() { return truncate_size
; }
72 utime_t
get_ctime() { return ctime
; }
73 utime_t
get_btime() { return btime
; }
74 utime_t
get_mtime() { return mtime
; }
75 utime_t
get_atime() { return atime
; }
76 __u64
get_change_attr() { return change_attr
; }
77 __u32
get_time_warp_seq() { return time_warp_seq
; }
78 uint64_t get_nfiles() { return nfiles
; }
79 uint64_t get_nsubdirs() { return nsubdirs
; }
80 bool dirstat_is_valid() const { return nfiles
!= -1 || nsubdirs
!= -1; }
82 const file_layout_t
& get_layout() {
86 void set_layout(const file_layout_t
&l
) {
90 int get_migrate_seq() { return head
.migrate_seq
; }
91 int get_op() { return head
.op
; }
93 uint64_t get_client_tid() { return get_tid(); }
94 void set_client_tid(uint64_t s
) { set_tid(s
); }
96 snapid_t
get_snap_follows() { return snapid_t(head
.snap_follows
); }
97 void set_snap_follows(snapid_t s
) { head
.snap_follows
= s
; }
99 void set_caps(int c
) { head
.caps
= c
; }
100 void set_wanted(int w
) { head
.wanted
= w
; }
102 void set_max_size(uint64_t ms
) { max_size
= ms
; }
104 void set_migrate_seq(unsigned m
) { head
.migrate_seq
= m
; }
105 void set_op(int o
) { head
.op
= o
; }
107 void set_size(loff_t s
) { size
= s
; }
108 void set_mtime(const utime_t
&t
) { mtime
= t
; }
109 void set_ctime(const utime_t
&t
) { ctime
= t
; }
110 void set_atime(const utime_t
&t
) { atime
= t
; }
112 void set_cap_peer(uint64_t id
, ceph_seq_t seq
, ceph_seq_t mseq
, int mds
, int flags
) {
120 void set_oldest_flush_tid(ceph_tid_t tid
) { oldest_flush_tid
= tid
; }
121 ceph_tid_t
get_oldest_flush_tid() { return oldest_flush_tid
; }
123 void clear_dirty() { head
.dirty
= 0; }
126 : Message(CEPH_MSG_CLIENT_CAPS
, HEAD_VERSION
, COMPAT_VERSION
) {}
137 : Message(CEPH_MSG_CLIENT_CAPS
, HEAD_VERSION
, COMPAT_VERSION
),
138 osd_epoch_barrier(oeb
) {
139 memset(&head
, 0, sizeof(head
));
146 head
.wanted
= wanted
;
148 head
.migrate_seq
= mseq
;
149 memset(&peer
, 0, sizeof(peer
));
152 inodeno_t ino
, inodeno_t realm
,
153 uint64_t id
, int mseq
, epoch_t oeb
)
154 : Message(CEPH_MSG_CLIENT_CAPS
, HEAD_VERSION
, COMPAT_VERSION
),
155 osd_epoch_barrier(oeb
) {
156 memset(&head
, 0, sizeof(head
));
161 head
.migrate_seq
= mseq
;
162 memset(&peer
, 0, sizeof(peer
));
165 file_layout_t layout
;
167 ~MClientCaps() override
{}
170 const char *get_type_name() const override
{ return "Cfcap";}
171 void print(ostream
& out
) const override
{
172 out
<< "client_caps(" << ceph_cap_op_name(head
.op
)
173 << " ino " << inodeno_t(head
.ino
)
174 << " " << head
.cap_id
175 << " seq " << head
.seq
;
177 out
<< " tid " << get_tid();
178 out
<< " caps=" << ccap_string(head
.caps
)
179 << " dirty=" << ccap_string(head
.dirty
)
180 << " wanted=" << ccap_string(head
.wanted
);
181 out
<< " follows " << snapid_t(head
.snap_follows
);
182 if (head
.migrate_seq
)
183 out
<< " mseq " << head
.migrate_seq
;
185 out
<< " size " << size
<< "/" << max_size
;
187 out
<< " ts " << truncate_seq
<< "/" << truncate_size
;
188 out
<< " mtime " << mtime
;
190 out
<< " tws " << time_warp_seq
;
192 if (head
.xattr_version
)
193 out
<< " xattrs(v=" << head
.xattr_version
<< " l=" << xattrbl
.length() << ")";
198 void decode_payload() override
{
199 bufferlist::iterator p
= payload
.begin();
201 ceph_mds_caps_body_legacy body
;
203 if (head
.op
== CEPH_CAP_OP_EXPORT
) {
207 max_size
= body
.max_size
;
208 truncate_size
= body
.truncate_size
;
209 truncate_seq
= body
.truncate_seq
;
210 mtime
= utime_t(body
.mtime
);
211 atime
= utime_t(body
.atime
);
212 ctime
= utime_t(body
.ctime
);
213 layout
.from_legacy(body
.layout
);
214 time_warp_seq
= body
.time_warp_seq
;
216 ::decode_nohead(head
.snap_trace_len
, snapbl
, p
);
218 assert(middle
.length() == head
.xattr_len
);
222 // conditionally decode flock metadata
223 if (header
.version
>= 2)
224 ::decode(flockbl
, p
);
226 if (header
.version
>= 3) {
227 if (head
.op
== CEPH_CAP_OP_IMPORT
)
231 if (header
.version
>= 4) {
232 ::decode(inline_version
, p
);
233 ::decode(inline_data
, p
);
235 inline_version
= CEPH_INLINE_NONE
;
238 if (header
.version
>= 5) {
239 ::decode(osd_epoch_barrier
, p
);
241 if (header
.version
>= 6) {
242 ::decode(oldest_flush_tid
, p
);
244 if (header
.version
>= 7) {
245 ::decode(caller_uid
, p
);
246 ::decode(caller_gid
, p
);
248 if (header
.version
>= 8) {
249 ::decode(layout
.pool_ns
, p
);
251 if (header
.version
>= 9) {
253 ::decode(change_attr
, p
);
255 if (header
.version
>= 10) {
258 if (header
.version
>= 11) {
263 void encode_payload(uint64_t features
) override
{
264 header
.version
= HEAD_VERSION
;
265 head
.snap_trace_len
= snapbl
.length();
266 head
.xattr_len
= xattrbl
.length();
268 ::encode(head
, payload
);
269 ceph_mds_caps_body_legacy body
;
270 if (head
.op
== CEPH_CAP_OP_EXPORT
) {
271 memset(&body
, 0, sizeof(body
));
275 body
.max_size
= max_size
;
276 body
.truncate_size
= truncate_size
;
277 body
.truncate_seq
= truncate_seq
;
278 mtime
.encode_timeval(&body
.mtime
);
279 atime
.encode_timeval(&body
.atime
);
280 ctime
.encode_timeval(&body
.ctime
);
281 layout
.to_legacy(&body
.layout
);
282 body
.time_warp_seq
= time_warp_seq
;
284 ::encode(body
, payload
);
285 ::encode_nohead(snapbl
, payload
);
289 // conditionally include flock metadata
290 if (features
& CEPH_FEATURE_FLOCK
) {
291 ::encode(flockbl
, payload
);
297 if (features
& CEPH_FEATURE_EXPORT_PEER
) {
298 if (head
.op
== CEPH_CAP_OP_IMPORT
)
299 ::encode(peer
, payload
);
305 if (features
& CEPH_FEATURE_MDS_INLINE_DATA
) {
306 ::encode(inline_version
, payload
);
307 ::encode(inline_data
, payload
);
309 ::encode(inline_version
, payload
);
310 ::encode(bufferlist(), payload
);
313 ::encode(osd_epoch_barrier
, payload
);
314 ::encode(oldest_flush_tid
, payload
);
315 ::encode(caller_uid
, payload
);
316 ::encode(caller_gid
, payload
);
318 ::encode(layout
.pool_ns
, payload
);
319 ::encode(btime
, payload
);
320 ::encode(change_attr
, payload
);
321 ::encode(flags
, payload
);
322 ::encode(nfiles
, payload
);
323 ::encode(nsubdirs
, payload
);