1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_CLIENT_INODE_H
5 #define CEPH_CLIENT_INODE_H
7 #include "include/types.h"
8 #include "include/xlist.h"
10 #include "mds/mdstypes.h" // hrm
12 #include "osdc/ObjectCacher.h"
13 #include "include/assert.h"
24 class ceph_lock_state_t
;
32 xlist
<Cap
*>::item cap_item
;
37 unsigned wanted
; // as known to mds.
38 uint64_t seq
, issue_seq
;
39 __u32 mseq
; // migration seq
41 UserPerm latest_perms
;
43 Cap() : session(NULL
), inode(NULL
), cap_item(this), cap_id(0), issued(0),
44 implemented(0), wanted(0), seq(0), issue_seq(0), mseq(0), gen(0),
47 void dump(Formatter
*f
) const;
51 //snapid_t follows; // map key
57 utime_t ctime
, btime
, mtime
, atime
;
58 version_t time_warp_seq
;
63 map
<string
,bufferptr
> xattrs
;
64 version_t xattr_version
;
66 bufferlist inline_data
;
67 version_t inline_version
;
69 bool writing
, dirty_data
;
72 explicit CapSnap(Inode
*i
)
73 : in(i
), issued(0), dirty(0), size(0), time_warp_seq(0), change_attr(0),
74 mode(0), uid(0), gid(0), xattr_version(0), inline_version(0),
75 writing(false), dirty_data(false), flush_tid(0)
78 void dump(Formatter
*f
) const;
83 #define I_DIR_ORDERED 2
84 #define I_CAP_DROPPED 4
85 #define I_SNAPDIR_OPEN 8
90 // -- the actual inode --
91 inodeno_t ino
; // ORDER DEPENDENCY: oset
95 uint32_t rdev
; // if special file
97 // affected by any inode change...
98 utime_t ctime
; // inode change time
99 utime_t btime
; // birth time
101 // perm (namespace permissions)
109 // file (data access)
110 ceph_dir_layout dir_layout
;
111 file_layout_t layout
;
112 uint64_t size
; // on directory, # dentries
113 uint32_t truncate_seq
;
114 uint64_t truncate_size
;
115 utime_t mtime
; // file data modify time.
116 utime_t atime
; // file data access time.
117 uint32_t time_warp_seq
; // count of (potential) mtime/atime timewarps (i.e., utimes())
118 uint64_t change_attr
;
120 uint64_t max_size
; // max size we can write to
122 // dirfrag, recursive accountin
127 version_t version
; // auth only
128 version_t xattr_version
;
131 version_t inline_version
;
132 bufferlist inline_data
;
134 bool is_root() const { return ino
== MDS_INO_ROOT
; }
135 bool is_symlink() const { return (mode
& S_IFMT
) == S_IFLNK
; }
136 bool is_dir() const { return (mode
& S_IFMT
) == S_IFDIR
; }
137 bool is_file() const { return (mode
& S_IFMT
) == S_IFREG
; }
139 bool has_dir_layout() const {
140 return layout
!= file_layout_t();
143 __u32
hash_dentry_name(const string
&dn
) {
144 int which
= dir_layout
.dl_dir_hash
;
146 which
= CEPH_STR_HASH_LINUX
;
147 assert(ceph_str_hash_valid(which
));
148 return ceph_str_hash(which
, dn
.data(), dn
.length());
155 bool is_complete_and_ordered() {
156 static const unsigned wants
= I_COMPLETE
| I_DIR_ORDERED
;
157 return (flags
& wants
) == wants
;
160 // about the dir (if this is one!)
161 Dir
*dir
; // if i'm a dir.
162 fragtree_t dirfragtree
;
163 set
<int> dir_contacts
;
164 uint64_t dir_release_count
, dir_ordered_count
;
165 bool dir_hashed
, dir_replicated
;
168 map
<mds_rank_t
, Cap
*> caps
; // mds -> Cap
170 int64_t cap_dirtier_uid
;
171 int64_t cap_dirtier_gid
;
172 unsigned dirty_caps
, flushing_caps
;
173 std::map
<ceph_tid_t
, int> flushing_cap_tids
;
174 int shared_gen
, cache_gen
;
175 int snap_caps
, snap_cap_refs
;
176 utime_t hold_caps_until
;
177 xlist
<Inode
*>::item cap_item
, flushing_cap_item
;
179 SnapRealm
*snaprealm
;
180 xlist
<Inode
*>::item snaprealm_item
;
181 InodeRef snapdir_parent
; // only if we are a snapdir inode
182 map
<snapid_t
,CapSnap
> cap_snaps
; // pending flush to mds
184 //int open_by_mode[CEPH_FILE_MODE_NUM];
185 map
<int,int> open_by_mode
;
186 map
<int,int> cap_refs
;
188 ObjectCacher::ObjectSet oset
; // ORDER DEPENDENCY: ino
190 uint64_t reported_size
, wanted_max_size
, requested_max_size
;
192 int _ref
; // ref count. 1 for each dentry, fh that links to me.
193 int ll_ref
; // separate ref count for ll client
194 set
<Dentry
*> dn_set
; // if i'm linked to a dentry.
195 string symlink
; // symlink content, if it's a symlink
196 map
<string
,bufferptr
> xattrs
;
197 map
<frag_t
,int> fragmap
; // known frag -> mds mappings
199 list
<Cond
*> waitfor_caps
;
200 list
<Cond
*> waitfor_commit
;
202 Dentry
*get_first_parent() {
203 assert(!dn_set
.empty());
204 return *dn_set
.begin();
207 void make_long_path(filepath
& p
);
208 void make_nosnap_relative_path(filepath
& p
);
220 void ll_put(int n
=1) {
226 ceph_lock_state_t
*fcntl_locks
;
227 ceph_lock_state_t
*flock_locks
;
229 xlist
<MetaRequest
*> unsafe_ops
;
233 Inode(Client
*c
, vinodeno_t vino
, file_layout_t
*newlayout
)
234 : client(c
), ino(vino
.ino
), snapid(vino
.snapid
), faked_ino(0),
235 rdev(0), mode(0), uid(0), gid(0), nlink(0),
236 size(0), truncate_seq(1), truncate_size(-1),
237 time_warp_seq(0), change_attr(0), max_size(0), version(0),
238 xattr_version(0), inline_version(0), flags(0),
239 dir(0), dir_release_count(1), dir_ordered_count(1),
240 dir_hashed(false), dir_replicated(false), auth_cap(NULL
),
241 cap_dirtier_uid(-1), cap_dirtier_gid(-1),
242 dirty_caps(0), flushing_caps(0), shared_gen(0), cache_gen(0),
243 snap_caps(0), snap_cap_refs(0),
244 cap_item(this), flushing_cap_item(this),
245 snaprealm(0), snaprealm_item(this),
246 oset((void *)this, newlayout
->pool_id
, this->ino
),
247 reported_size(0), wanted_max_size(0), requested_max_size(0),
248 _ref(0), ll_ref(0), dn_set(),
249 fcntl_locks(NULL
), flock_locks(NULL
)
251 memset(&dir_layout
, 0, sizeof(dir_layout
));
252 memset("a
, 0, sizeof(quota
));
256 vinodeno_t
vino() const { return vinodeno_t(ino
, snapid
); }
259 bool operator() (Inode
* const & left
, Inode
* const & right
) {
260 if (left
->ino
.val
< right
->ino
.val
) {
261 return (left
->snapid
.val
< right
->snapid
.val
);
267 bool check_mode(const UserPerm
& perms
, unsigned want
);
270 void get_open_ref(int mode
);
271 bool put_open_ref(int mode
);
273 void get_cap_ref(int cap
);
274 int put_cap_ref(int cap
);
276 bool cap_is_valid(Cap
* cap
) const;
277 int caps_issued(int *implemented
= 0) const;
278 void touch_cap(Cap
*cap
);
279 void try_touch_cap(mds_rank_t mds
);
280 bool caps_issued_mask(unsigned mask
);
282 int caps_file_wanted();
284 int caps_mds_wanted();
286 const UserPerm
*get_best_perms();
288 bool have_valid_size();
291 void add_fh(Fh
*f
) {fhs
.insert(f
);}
292 void rm_fh(Fh
*f
) {fhs
.erase(f
);}
293 void set_async_err(int r
);
294 void dump(Formatter
*f
) const;
297 ostream
& operator<<(ostream
&out
, const Inode
&in
);