]>
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_CLIENT_H | |
17 | #define CEPH_CLIENT_H | |
18 | ||
11fdf7f2 TL |
19 | #include "common/CommandTable.h" |
20 | #include "common/Finisher.h" | |
11fdf7f2 | 21 | #include "common/Timer.h" |
9f95a23c | 22 | #include "common/ceph_mutex.h" |
11fdf7f2 TL |
23 | #include "common/cmdparse.h" |
24 | #include "common/compiler_extensions.h" | |
9f95a23c | 25 | #include "include/common_fwd.h" |
e306af50 | 26 | #include "include/cephfs/ceph_ll_client.h" |
7c673cae FG |
27 | #include "include/filepath.h" |
28 | #include "include/interval_set.h" | |
29 | #include "include/lru.h" | |
11fdf7f2 TL |
30 | #include "include/types.h" |
31 | #include "include/unordered_map.h" | |
32 | #include "include/unordered_set.h" | |
f67539c2 | 33 | #include "include/cephfs/metrics/Types.h" |
7c673cae FG |
34 | #include "mds/mdstypes.h" |
35 | #include "msg/Dispatcher.h" | |
11fdf7f2 | 36 | #include "msg/MessageRef.h" |
7c673cae | 37 | #include "msg/Messenger.h" |
7c673cae FG |
38 | #include "osdc/ObjectCacher.h" |
39 | ||
f67539c2 | 40 | #include "RWRef.h" |
7c673cae | 41 | #include "InodeRef.h" |
11fdf7f2 | 42 | #include "MetaSession.h" |
7c673cae | 43 | #include "UserPerm.h" |
11fdf7f2 TL |
44 | |
45 | #include <fstream> | |
46 | #include <map> | |
47 | #include <memory> | |
48 | #include <set> | |
49 | #include <string> | |
f67539c2 | 50 | #include <thread> |
11fdf7f2 TL |
51 | |
52 | using std::set; | |
53 | using std::map; | |
54 | using std::fstream; | |
7c673cae FG |
55 | |
56 | class FSMap; | |
57 | class FSMapUser; | |
58 | class MonClient; | |
59 | ||
7c673cae FG |
60 | |
61 | struct DirStat; | |
62 | struct LeaseStat; | |
63 | struct InodeStat; | |
64 | ||
65 | class Filer; | |
66 | class Objecter; | |
67 | class WritebackHandler; | |
68 | ||
7c673cae FG |
69 | class MDSMap; |
70 | class Message; | |
f67539c2 | 71 | class destructive_lock_ref_t; |
7c673cae FG |
72 | |
73 | enum { | |
74 | l_c_first = 20000, | |
75 | l_c_reply, | |
76 | l_c_lat, | |
77 | l_c_wrlat, | |
11fdf7f2 TL |
78 | l_c_read, |
79 | l_c_fsync, | |
7c673cae FG |
80 | l_c_last, |
81 | }; | |
82 | ||
83 | ||
84 | class MDSCommandOp : public CommandOp | |
85 | { | |
86 | public: | |
87 | mds_gid_t mds_gid; | |
88 | ||
11fdf7f2 | 89 | explicit MDSCommandOp(ceph_tid_t t) : CommandOp(t) {} |
7c673cae FG |
90 | }; |
91 | ||
92 | /* error code for ceph_fuse */ | |
28e407b8 AA |
93 | #define CEPH_FUSE_NO_MDS_UP -((1<<16)+0) /* no mds up deteced in ceph_fuse */ |
94 | #define CEPH_FUSE_LAST -((1<<16)+1) /* (unused) */ | |
7c673cae FG |
95 | |
96 | // ============================================ | |
97 | // types for my local metadata cache | |
98 | /* basic structure: | |
99 | ||
100 | - Dentries live in an LRU loop. they get expired based on last access. | |
101 | see include/lru.h. items can be bumped to "mid" or "top" of list, etc. | |
102 | - Inode has ref count for each Fh, Dir, or Dentry that points to it. | |
103 | - when Inode ref goes to 0, it's expired. | |
104 | - when Dir is empty, it's removed (and it's Inode ref--) | |
105 | ||
106 | */ | |
107 | ||
108 | /* getdir result */ | |
109 | struct DirEntry { | |
20effc67 TL |
110 | explicit DirEntry(const std::string &s) : d_name(s), stmask(0) {} |
111 | DirEntry(const std::string &n, struct stat& s, int stm) | |
112 | : d_name(n), st(s), stmask(stm) {} | |
11fdf7f2 | 113 | |
20effc67 | 114 | std::string d_name; |
7c673cae FG |
115 | struct stat st; |
116 | int stmask; | |
7c673cae FG |
117 | }; |
118 | ||
119 | struct Cap; | |
120 | class Dir; | |
121 | class Dentry; | |
122 | struct SnapRealm; | |
123 | struct Fh; | |
124 | struct CapSnap; | |
125 | ||
7c673cae FG |
126 | struct MetaRequest; |
127 | class ceph_lock_state_t; | |
128 | ||
7c673cae FG |
129 | // ======================================================== |
130 | // client interface | |
131 | ||
132 | struct dir_result_t { | |
133 | static const int SHIFT = 28; | |
134 | static const int64_t MASK = (1 << SHIFT) - 1; | |
135 | static const int64_t HASH = 0xFFULL << (SHIFT + 24); // impossible frag bits | |
136 | static const loff_t END = 1ULL << (SHIFT + 32); | |
137 | ||
11fdf7f2 TL |
138 | struct dentry { |
139 | int64_t offset; | |
f67539c2 TL |
140 | std::string name; |
141 | std::string alternate_name; | |
11fdf7f2 TL |
142 | InodeRef inode; |
143 | explicit dentry(int64_t o) : offset(o) {} | |
f67539c2 TL |
144 | dentry(int64_t o, std::string n, std::string an, InodeRef in) : |
145 | offset(o), name(std::move(n)), alternate_name(std::move(an)), inode(std::move(in)) {} | |
11fdf7f2 TL |
146 | }; |
147 | struct dentry_off_lt { | |
148 | bool operator()(const dentry& d, int64_t off) const { | |
149 | return dir_result_t::fpos_cmp(d.offset, off) < 0; | |
150 | } | |
151 | }; | |
152 | ||
153 | ||
154 | explicit dir_result_t(Inode *in, const UserPerm& perms); | |
155 | ||
156 | ||
7c673cae FG |
157 | static uint64_t make_fpos(unsigned h, unsigned l, bool hash) { |
158 | uint64_t v = ((uint64_t)h<< SHIFT) | (uint64_t)l; | |
159 | if (hash) | |
160 | v |= HASH; | |
161 | else | |
11fdf7f2 | 162 | ceph_assert((v & HASH) != HASH); |
7c673cae FG |
163 | return v; |
164 | } | |
165 | static unsigned fpos_high(uint64_t p) { | |
166 | unsigned v = (p & (END-1)) >> SHIFT; | |
167 | if ((p & HASH) == HASH) | |
168 | return ceph_frag_value(v); | |
169 | return v; | |
170 | } | |
171 | static unsigned fpos_low(uint64_t p) { | |
172 | return p & MASK; | |
173 | } | |
174 | static int fpos_cmp(uint64_t l, uint64_t r) { | |
175 | int c = ceph_frag_compare(fpos_high(l), fpos_high(r)); | |
176 | if (c) | |
177 | return c; | |
178 | if (fpos_low(l) == fpos_low(r)) | |
179 | return 0; | |
180 | return fpos_low(l) < fpos_low(r) ? -1 : 1; | |
181 | } | |
182 | ||
7c673cae FG |
183 | unsigned offset_high() { return fpos_high(offset); } |
184 | unsigned offset_low() { return fpos_low(offset); } | |
185 | ||
186 | void set_end() { offset |= END; } | |
187 | bool at_end() { return (offset & END); } | |
188 | ||
189 | void set_hash_order() { offset |= HASH; } | |
190 | bool hash_order() { return (offset & HASH) == HASH; } | |
191 | ||
192 | bool is_cached() { | |
193 | if (buffer.empty()) | |
194 | return false; | |
195 | if (hash_order()) { | |
196 | return buffer_frag.contains(offset_high()); | |
197 | } else { | |
198 | return buffer_frag == frag_t(offset_high()); | |
199 | } | |
200 | } | |
201 | ||
202 | void reset() { | |
203 | last_name.clear(); | |
204 | next_offset = 2; | |
205 | offset = 0; | |
206 | ordered_count = 0; | |
207 | cache_index = 0; | |
208 | buffer.clear(); | |
209 | } | |
11fdf7f2 TL |
210 | |
211 | InodeRef inode; | |
212 | int64_t offset; // hash order: | |
213 | // (0xff << 52) | ((24 bits hash) << 28) | | |
214 | // (the nth entry has hash collision); | |
215 | // frag+name order; | |
216 | // ((frag value) << 28) | (the nth entry in frag); | |
217 | ||
218 | unsigned next_offset; // offset of next chunk (last_name's + 1) | |
20effc67 | 219 | std::string last_name; // last entry in previous chunk |
11fdf7f2 TL |
220 | |
221 | uint64_t release_count; | |
222 | uint64_t ordered_count; | |
223 | unsigned cache_index; | |
224 | int start_shared_gen; // dir shared_gen at start of readdir | |
225 | UserPerm perms; | |
226 | ||
227 | frag_t buffer_frag; | |
228 | ||
20effc67 | 229 | std::vector<dentry> buffer; |
f91f0fd5 | 230 | struct dirent de; |
7c673cae FG |
231 | }; |
232 | ||
233 | class Client : public Dispatcher, public md_config_obs_t { | |
11fdf7f2 TL |
234 | public: |
235 | friend class C_Block_Sync; // Calls block map and protected helpers | |
236 | friend class C_Client_CacheInvalidate; // calls ino_invalidate_cb | |
237 | friend class C_Client_DentryInvalidate; // calls dentry_invalidate_cb | |
238 | friend class C_Client_FlushComplete; // calls put_inode() | |
239 | friend class C_Client_Remount; | |
240 | friend class C_Client_RequestInterrupt; | |
241 | friend class C_Deleg_Timeout; // Asserts on client_lock, called when a delegation is unreturned | |
e306af50 | 242 | friend class C_Client_CacheRelease; // Asserts on client_lock |
11fdf7f2 TL |
243 | friend class SyntheticClient; |
244 | friend void intrusive_ptr_release(Inode *in); | |
f67539c2 TL |
245 | template <typename T> friend struct RWRefState; |
246 | template <typename T> friend class RWRef; | |
11fdf7f2 | 247 | |
7c673cae | 248 | using Dispatcher::cct; |
f67539c2 | 249 | using clock = ceph::coarse_mono_clock; |
7c673cae | 250 | |
11fdf7f2 | 251 | typedef int (*add_dirent_cb_t)(void *p, struct dirent *de, struct ceph_statx *stx, off_t off, Inode *in); |
7c673cae | 252 | |
f67539c2 TL |
253 | struct walk_dentry_result { |
254 | InodeRef in; | |
255 | std::string alternate_name; | |
256 | }; | |
257 | ||
7c673cae | 258 | class CommandHook : public AdminSocketHook { |
7c673cae FG |
259 | public: |
260 | explicit CommandHook(Client *client); | |
9f95a23c TL |
261 | int call(std::string_view command, const cmdmap_t& cmdmap, |
262 | Formatter *f, | |
263 | std::ostream& errss, | |
264 | bufferlist& out) override; | |
11fdf7f2 TL |
265 | private: |
266 | Client *m_client; | |
7c673cae | 267 | }; |
7c673cae | 268 | |
f67539c2 TL |
269 | // snapshot info returned via get_snap_info(). nothing to do |
270 | // with SnapInfo on the MDS. | |
271 | struct SnapInfo { | |
272 | snapid_t id; | |
273 | std::map<std::string, std::string> metadata; | |
274 | }; | |
275 | ||
11fdf7f2 TL |
276 | Client(Messenger *m, MonClient *mc, Objecter *objecter_); |
277 | Client(const Client&) = delete; | |
278 | Client(const Client&&) = delete; | |
279 | virtual ~Client() override; | |
7c673cae | 280 | |
11fdf7f2 TL |
281 | static UserPerm pick_my_perms(CephContext *c) { |
282 | uid_t uid = c->_conf->client_mount_uid >= 0 ? c->_conf->client_mount_uid : -1; | |
283 | gid_t gid = c->_conf->client_mount_gid >= 0 ? c->_conf->client_mount_gid : -1; | |
284 | return UserPerm(uid, gid); | |
285 | } | |
7c673cae FG |
286 | UserPerm pick_my_perms() { |
287 | uid_t uid = user_id >= 0 ? user_id : -1; | |
288 | gid_t gid = group_id >= 0 ? group_id : -1; | |
289 | return UserPerm(uid, gid); | |
290 | } | |
291 | ||
11fdf7f2 TL |
292 | int mount(const std::string &mount_root, const UserPerm& perms, |
293 | bool require_mds=false, const std::string &fs_name=""); | |
294 | void unmount(); | |
f67539c2 TL |
295 | bool is_unmounting() const { |
296 | return mount_state.check_current_state(CLIENT_UNMOUNTING); | |
297 | } | |
298 | bool is_mounted() const { | |
299 | return mount_state.check_current_state(CLIENT_MOUNTED); | |
300 | } | |
301 | bool is_mounting() const { | |
302 | return mount_state.check_current_state(CLIENT_MOUNTING); | |
303 | } | |
304 | bool is_initialized() const { | |
305 | return initialize_state.check_current_state(CLIENT_INITIALIZED); | |
306 | } | |
11fdf7f2 | 307 | void abort_conn(); |
7c673cae | 308 | |
11fdf7f2 TL |
309 | void set_uuid(const std::string& uuid); |
310 | void set_session_timeout(unsigned timeout); | |
311 | int start_reclaim(const std::string& uuid, unsigned flags, | |
312 | const std::string& fs_name); | |
313 | void finish_reclaim(); | |
7c673cae | 314 | |
11fdf7f2 TL |
315 | fs_cluster_id_t get_fs_cid() { |
316 | return fscid; | |
317 | } | |
7c673cae | 318 | |
11fdf7f2 TL |
319 | int mds_command( |
320 | const std::string &mds_spec, | |
321 | const std::vector<std::string>& cmd, | |
322 | const bufferlist& inbl, | |
323 | bufferlist *poutbl, std::string *prs, Context *onfinish); | |
7c673cae | 324 | |
11fdf7f2 TL |
325 | // these should (more or less) mirror the actual system calls. |
326 | int statfs(const char *path, struct statvfs *stbuf, const UserPerm& perms); | |
7c673cae | 327 | |
11fdf7f2 TL |
328 | // crap |
329 | int chdir(const char *s, std::string &new_cwd, const UserPerm& perms); | |
330 | void _getcwd(std::string& cwd, const UserPerm& perms); | |
331 | void getcwd(std::string& cwd, const UserPerm& perms); | |
7c673cae | 332 | |
11fdf7f2 TL |
333 | // namespace ops |
334 | int opendir(const char *name, dir_result_t **dirpp, const UserPerm& perms); | |
b3b6e05e | 335 | int fdopendir(int dirfd, dir_result_t **dirpp, const UserPerm& perms); |
11fdf7f2 | 336 | int closedir(dir_result_t *dirp); |
7c673cae | 337 | |
11fdf7f2 TL |
338 | /** |
339 | * Fill a directory listing from dirp, invoking cb for each entry | |
340 | * with the given pointer, the dirent, the struct stat, the stmask, | |
341 | * and the offset. | |
342 | * | |
343 | * Returns 0 if it reached the end of the directory. | |
344 | * If @a cb returns a negative error code, stop and return that. | |
345 | */ | |
346 | int readdir_r_cb(dir_result_t *dirp, add_dirent_cb_t cb, void *p, | |
347 | unsigned want=0, unsigned flags=AT_NO_ATTR_SYNC, | |
348 | bool getref=false); | |
7c673cae | 349 | |
11fdf7f2 TL |
350 | struct dirent * readdir(dir_result_t *d); |
351 | int readdir_r(dir_result_t *dirp, struct dirent *de); | |
352 | int readdirplus_r(dir_result_t *dirp, struct dirent *de, struct ceph_statx *stx, unsigned want, unsigned flags, Inode **out); | |
7c673cae | 353 | |
20effc67 | 354 | int getdir(const char *relpath, std::list<std::string>& names, |
11fdf7f2 | 355 | const UserPerm& perms); // get the whole dir at once. |
7c673cae | 356 | |
11fdf7f2 TL |
357 | /** |
358 | * Returns the length of the buffer that got filled in, or -errno. | |
f67539c2 | 359 | * If it returns -CEPHFS_ERANGE you just need to increase the size of the |
11fdf7f2 TL |
360 | * buffer and try again. |
361 | */ | |
362 | int _getdents(dir_result_t *dirp, char *buf, int buflen, bool ful); // get a bunch of dentries at once | |
363 | int getdents(dir_result_t *dirp, char *buf, int buflen) { | |
364 | return _getdents(dirp, buf, buflen, true); | |
365 | } | |
366 | int getdnames(dir_result_t *dirp, char *buf, int buflen) { | |
367 | return _getdents(dirp, buf, buflen, false); | |
368 | } | |
7c673cae | 369 | |
11fdf7f2 TL |
370 | void rewinddir(dir_result_t *dirp); |
371 | loff_t telldir(dir_result_t *dirp); | |
372 | void seekdir(dir_result_t *dirp, loff_t offset); | |
7c673cae | 373 | |
f67539c2 TL |
374 | int may_delete(const char *relpath, const UserPerm& perms); |
375 | int link(const char *existing, const char *newname, const UserPerm& perm, std::string alternate_name=""); | |
11fdf7f2 | 376 | int unlink(const char *path, const UserPerm& perm); |
b3b6e05e | 377 | int unlinkat(int dirfd, const char *relpath, int flags, const UserPerm& perm); |
f67539c2 | 378 | int rename(const char *from, const char *to, const UserPerm& perm, std::string alternate_name=""); |
11fdf7f2 TL |
379 | |
380 | // dirs | |
f67539c2 | 381 | int mkdir(const char *path, mode_t mode, const UserPerm& perm, std::string alternate_name=""); |
b3b6e05e TL |
382 | int mkdirat(int dirfd, const char *relpath, mode_t mode, const UserPerm& perm, |
383 | std::string alternate_name=""); | |
11fdf7f2 TL |
384 | int mkdirs(const char *path, mode_t mode, const UserPerm& perms); |
385 | int rmdir(const char *path, const UserPerm& perms); | |
386 | ||
387 | // symlinks | |
388 | int readlink(const char *path, char *buf, loff_t size, const UserPerm& perms); | |
b3b6e05e | 389 | int readlinkat(int dirfd, const char *relpath, char *buf, loff_t size, const UserPerm& perms); |
11fdf7f2 | 390 | |
f67539c2 | 391 | int symlink(const char *existing, const char *newname, const UserPerm& perms, std::string alternate_name=""); |
b3b6e05e TL |
392 | int symlinkat(const char *target, int dirfd, const char *relpath, const UserPerm& perms, |
393 | std::string alternate_name=""); | |
f67539c2 TL |
394 | |
395 | // path traversal for high-level interface | |
396 | int walk(std::string_view path, struct walk_dentry_result* result, const UserPerm& perms, bool followsym=true); | |
11fdf7f2 TL |
397 | |
398 | // inode stuff | |
399 | unsigned statx_to_mask(unsigned int flags, unsigned int want); | |
400 | int stat(const char *path, struct stat *stbuf, const UserPerm& perms, | |
401 | frag_info_t *dirstat=0, int mask=CEPH_STAT_CAP_INODE_ALL); | |
402 | int statx(const char *path, struct ceph_statx *stx, | |
403 | const UserPerm& perms, | |
404 | unsigned int want, unsigned int flags); | |
405 | int lstat(const char *path, struct stat *stbuf, const UserPerm& perms, | |
406 | frag_info_t *dirstat=0, int mask=CEPH_STAT_CAP_INODE_ALL); | |
407 | ||
408 | int setattr(const char *relpath, struct stat *attr, int mask, | |
409 | const UserPerm& perms); | |
410 | int setattrx(const char *relpath, struct ceph_statx *stx, int mask, | |
411 | const UserPerm& perms, int flags=0); | |
412 | int fsetattr(int fd, struct stat *attr, int mask, const UserPerm& perms); | |
413 | int fsetattrx(int fd, struct ceph_statx *stx, int mask, const UserPerm& perms); | |
414 | int chmod(const char *path, mode_t mode, const UserPerm& perms); | |
415 | int fchmod(int fd, mode_t mode, const UserPerm& perms); | |
b3b6e05e | 416 | int chmodat(int dirfd, const char *relpath, mode_t mode, int flags, const UserPerm& perms); |
11fdf7f2 TL |
417 | int lchmod(const char *path, mode_t mode, const UserPerm& perms); |
418 | int chown(const char *path, uid_t new_uid, gid_t new_gid, | |
419 | const UserPerm& perms); | |
420 | int fchown(int fd, uid_t new_uid, gid_t new_gid, const UserPerm& perms); | |
421 | int lchown(const char *path, uid_t new_uid, gid_t new_gid, | |
422 | const UserPerm& perms); | |
b3b6e05e TL |
423 | int chownat(int dirfd, const char *relpath, uid_t new_uid, gid_t new_gid, |
424 | int flags, const UserPerm& perms); | |
11fdf7f2 TL |
425 | int utime(const char *path, struct utimbuf *buf, const UserPerm& perms); |
426 | int lutime(const char *path, struct utimbuf *buf, const UserPerm& perms); | |
427 | int futime(int fd, struct utimbuf *buf, const UserPerm& perms); | |
428 | int utimes(const char *relpath, struct timeval times[2], const UserPerm& perms); | |
429 | int lutimes(const char *relpath, struct timeval times[2], const UserPerm& perms); | |
430 | int futimes(int fd, struct timeval times[2], const UserPerm& perms); | |
431 | int futimens(int fd, struct timespec times[2], const UserPerm& perms); | |
b3b6e05e TL |
432 | int utimensat(int dirfd, const char *relpath, struct timespec times[2], int flags, |
433 | const UserPerm& perms); | |
11fdf7f2 TL |
434 | int flock(int fd, int operation, uint64_t owner); |
435 | int truncate(const char *path, loff_t size, const UserPerm& perms); | |
436 | ||
437 | // file ops | |
438 | int mknod(const char *path, mode_t mode, const UserPerm& perms, dev_t rdev=0); | |
b3b6e05e | 439 | |
20effc67 TL |
440 | int create_and_open(int dirfd, const char *relpath, int flags, const UserPerm& perms, |
441 | mode_t mode, int stripe_unit, int stripe_count, int object_size, | |
442 | const char *data_pool, std::string alternate_name); | |
f67539c2 TL |
443 | int open(const char *path, int flags, const UserPerm& perms, mode_t mode=0, std::string alternate_name="") { |
444 | return open(path, flags, perms, mode, 0, 0, 0, NULL, alternate_name); | |
445 | } | |
11fdf7f2 TL |
446 | int open(const char *path, int flags, const UserPerm& perms, |
447 | mode_t mode, int stripe_unit, int stripe_count, int object_size, | |
f67539c2 | 448 | const char *data_pool, std::string alternate_name=""); |
b3b6e05e TL |
449 | int openat(int dirfd, const char *relpath, int flags, const UserPerm& perms, |
450 | mode_t mode, int stripe_unit, int stripe_count, | |
451 | int object_size, const char *data_pool, std::string alternate_name); | |
452 | int openat(int dirfd, const char *path, int flags, const UserPerm& perms, mode_t mode=0, | |
453 | std::string alternate_name="") { | |
454 | return openat(dirfd, path, flags, perms, mode, 0, 0, 0, NULL, alternate_name); | |
455 | } | |
456 | ||
11fdf7f2 TL |
457 | int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name, |
458 | const UserPerm& perms); | |
459 | int lookup_ino(inodeno_t ino, const UserPerm& perms, Inode **inode=NULL); | |
11fdf7f2 | 460 | int lookup_name(Inode *in, Inode *parent, const UserPerm& perms); |
b3b6e05e | 461 | int _close(int fd); |
11fdf7f2 TL |
462 | int close(int fd); |
463 | loff_t lseek(int fd, loff_t offset, int whence); | |
464 | int read(int fd, char *buf, loff_t size, loff_t offset=-1); | |
465 | int preadv(int fd, const struct iovec *iov, int iovcnt, loff_t offset=-1); | |
466 | int write(int fd, const char *buf, loff_t size, loff_t offset=-1); | |
467 | int pwritev(int fd, const struct iovec *iov, int iovcnt, loff_t offset=-1); | |
468 | int fake_write_size(int fd, loff_t size); | |
469 | int ftruncate(int fd, loff_t size, const UserPerm& perms); | |
470 | int fsync(int fd, bool syncdataonly); | |
471 | int fstat(int fd, struct stat *stbuf, const UserPerm& perms, | |
472 | int mask=CEPH_STAT_CAP_INODE_ALL); | |
473 | int fstatx(int fd, struct ceph_statx *stx, const UserPerm& perms, | |
474 | unsigned int want, unsigned int flags); | |
b3b6e05e TL |
475 | int statxat(int dirfd, const char *relpath, |
476 | struct ceph_statx *stx, const UserPerm& perms, | |
477 | unsigned int want, unsigned int flags); | |
11fdf7f2 TL |
478 | int fallocate(int fd, int mode, loff_t offset, loff_t length); |
479 | ||
480 | // full path xattr ops | |
481 | int getxattr(const char *path, const char *name, void *value, size_t size, | |
482 | const UserPerm& perms); | |
483 | int lgetxattr(const char *path, const char *name, void *value, size_t size, | |
484 | const UserPerm& perms); | |
485 | int fgetxattr(int fd, const char *name, void *value, size_t size, | |
486 | const UserPerm& perms); | |
487 | int listxattr(const char *path, char *list, size_t size, const UserPerm& perms); | |
488 | int llistxattr(const char *path, char *list, size_t size, const UserPerm& perms); | |
489 | int flistxattr(int fd, char *list, size_t size, const UserPerm& perms); | |
490 | int removexattr(const char *path, const char *name, const UserPerm& perms); | |
491 | int lremovexattr(const char *path, const char *name, const UserPerm& perms); | |
492 | int fremovexattr(int fd, const char *name, const UserPerm& perms); | |
493 | int setxattr(const char *path, const char *name, const void *value, | |
494 | size_t size, int flags, const UserPerm& perms); | |
495 | int lsetxattr(const char *path, const char *name, const void *value, | |
496 | size_t size, int flags, const UserPerm& perms); | |
497 | int fsetxattr(int fd, const char *name, const void *value, size_t size, | |
498 | int flags, const UserPerm& perms); | |
499 | ||
500 | int sync_fs(); | |
501 | int64_t drop_caches(); | |
502 | ||
f67539c2 TL |
503 | int get_snap_info(const char *path, const UserPerm &perms, SnapInfo *snap_info); |
504 | ||
11fdf7f2 TL |
505 | // hpc lazyio |
506 | int lazyio(int fd, int enable); | |
92f5a8d4 | 507 | int lazyio_propagate(int fd, loff_t offset, size_t count); |
11fdf7f2 TL |
508 | int lazyio_synchronize(int fd, loff_t offset, size_t count); |
509 | ||
510 | // expose file layout | |
511 | int describe_layout(const char *path, file_layout_t* layout, | |
512 | const UserPerm& perms); | |
513 | int fdescribe_layout(int fd, file_layout_t* layout); | |
20effc67 TL |
514 | int get_file_stripe_address(int fd, loff_t offset, std::vector<entity_addr_t>& address); |
515 | int get_file_extent_osds(int fd, loff_t off, loff_t *len, std::vector<int>& osds); | |
11fdf7f2 TL |
516 | int get_osd_addr(int osd, entity_addr_t& addr); |
517 | ||
518 | // expose mdsmap | |
519 | int64_t get_default_pool_id(); | |
520 | ||
521 | // expose osdmap | |
522 | int get_local_osd(); | |
523 | int get_pool_replication(int64_t pool); | |
524 | int64_t get_pool_id(const char *pool_name); | |
20effc67 TL |
525 | std::string get_pool_name(int64_t pool); |
526 | int get_osd_crush_location(int id, std::vector<std::pair<std::string, std::string> >& path); | |
11fdf7f2 | 527 | |
20effc67 | 528 | int enumerate_layout(int fd, std::vector<ObjectExtent>& result, |
11fdf7f2 TL |
529 | loff_t length, loff_t offset); |
530 | ||
f67539c2 TL |
531 | int mksnap(const char *path, const char *name, const UserPerm& perm, |
532 | mode_t mode=0, const std::map<std::string, std::string> &metadata={}); | |
533 | int rmsnap(const char *path, const char *name, const UserPerm& perm, bool check_perms=false); | |
11fdf7f2 TL |
534 | |
535 | // Inode permission checking | |
536 | int inode_permission(Inode *in, const UserPerm& perms, unsigned want); | |
537 | ||
538 | // expose caps | |
539 | int get_caps_issued(int fd); | |
540 | int get_caps_issued(const char *path, const UserPerm& perms); | |
541 | ||
542 | snapid_t ll_get_snapid(Inode *in); | |
543 | vinodeno_t ll_get_vino(Inode *in) { | |
544 | std::lock_guard lock(client_lock); | |
545 | return _get_vino(in); | |
546 | } | |
547 | // get inode from faked ino | |
548 | Inode *ll_get_inode(ino_t ino); | |
549 | Inode *ll_get_inode(vinodeno_t vino); | |
550 | int ll_lookup(Inode *parent, const char *name, struct stat *attr, | |
551 | Inode **out, const UserPerm& perms); | |
552 | int ll_lookup_inode(struct inodeno_t ino, const UserPerm& perms, Inode **inode); | |
f67539c2 | 553 | int ll_lookup_vino(vinodeno_t vino, const UserPerm& perms, Inode **inode); |
11fdf7f2 TL |
554 | int ll_lookupx(Inode *parent, const char *name, Inode **out, |
555 | struct ceph_statx *stx, unsigned want, unsigned flags, | |
556 | const UserPerm& perms); | |
494da23a | 557 | bool ll_forget(Inode *in, uint64_t count); |
11fdf7f2 TL |
558 | bool ll_put(Inode *in); |
559 | int ll_get_snap_ref(snapid_t snap); | |
560 | ||
561 | int ll_getattr(Inode *in, struct stat *st, const UserPerm& perms); | |
562 | int ll_getattrx(Inode *in, struct ceph_statx *stx, unsigned int want, | |
563 | unsigned int flags, const UserPerm& perms); | |
564 | int ll_setattrx(Inode *in, struct ceph_statx *stx, int mask, | |
565 | const UserPerm& perms); | |
566 | int ll_setattr(Inode *in, struct stat *st, int mask, | |
567 | const UserPerm& perms); | |
568 | int ll_getxattr(Inode *in, const char *name, void *value, size_t size, | |
569 | const UserPerm& perms); | |
570 | int ll_setxattr(Inode *in, const char *name, const void *value, size_t size, | |
571 | int flags, const UserPerm& perms); | |
572 | int ll_removexattr(Inode *in, const char *name, const UserPerm& perms); | |
573 | int ll_listxattr(Inode *in, char *list, size_t size, const UserPerm& perms); | |
574 | int ll_opendir(Inode *in, int flags, dir_result_t **dirpp, | |
575 | const UserPerm& perms); | |
576 | int ll_releasedir(dir_result_t* dirp); | |
577 | int ll_fsyncdir(dir_result_t* dirp); | |
578 | int ll_readlink(Inode *in, char *buf, size_t bufsize, const UserPerm& perms); | |
579 | int ll_mknod(Inode *in, const char *name, mode_t mode, dev_t rdev, | |
580 | struct stat *attr, Inode **out, const UserPerm& perms); | |
581 | int ll_mknodx(Inode *parent, const char *name, mode_t mode, dev_t rdev, | |
582 | Inode **out, struct ceph_statx *stx, unsigned want, | |
583 | unsigned flags, const UserPerm& perms); | |
584 | int ll_mkdir(Inode *in, const char *name, mode_t mode, struct stat *attr, | |
585 | Inode **out, const UserPerm& perm); | |
586 | int ll_mkdirx(Inode *parent, const char *name, mode_t mode, Inode **out, | |
587 | struct ceph_statx *stx, unsigned want, unsigned flags, | |
588 | const UserPerm& perms); | |
589 | int ll_symlink(Inode *in, const char *name, const char *value, | |
590 | struct stat *attr, Inode **out, const UserPerm& perms); | |
591 | int ll_symlinkx(Inode *parent, const char *name, const char *value, | |
592 | Inode **out, struct ceph_statx *stx, unsigned want, | |
593 | unsigned flags, const UserPerm& perms); | |
594 | int ll_unlink(Inode *in, const char *name, const UserPerm& perm); | |
595 | int ll_rmdir(Inode *in, const char *name, const UserPerm& perms); | |
596 | int ll_rename(Inode *parent, const char *name, Inode *newparent, | |
597 | const char *newname, const UserPerm& perm); | |
598 | int ll_link(Inode *in, Inode *newparent, const char *newname, | |
599 | const UserPerm& perm); | |
600 | int ll_open(Inode *in, int flags, Fh **fh, const UserPerm& perms); | |
601 | int _ll_create(Inode *parent, const char *name, mode_t mode, | |
602 | int flags, InodeRef *in, int caps, Fh **fhp, | |
603 | const UserPerm& perms); | |
604 | int ll_create(Inode *parent, const char *name, mode_t mode, int flags, | |
605 | struct stat *attr, Inode **out, Fh **fhp, | |
606 | const UserPerm& perms); | |
607 | int ll_createx(Inode *parent, const char *name, mode_t mode, | |
608 | int oflags, Inode **outp, Fh **fhp, | |
609 | struct ceph_statx *stx, unsigned want, unsigned lflags, | |
610 | const UserPerm& perms); | |
611 | int ll_read_block(Inode *in, uint64_t blockid, char *buf, uint64_t offset, | |
612 | uint64_t length, file_layout_t* layout); | |
613 | ||
614 | int ll_write_block(Inode *in, uint64_t blockid, | |
615 | char* buf, uint64_t offset, | |
616 | uint64_t length, file_layout_t* layout, | |
617 | uint64_t snapseq, uint32_t sync); | |
618 | int ll_commit_blocks(Inode *in, uint64_t offset, uint64_t length); | |
619 | ||
620 | int ll_statfs(Inode *in, struct statvfs *stbuf, const UserPerm& perms); | |
621 | int ll_walk(const char* name, Inode **i, struct ceph_statx *stx, | |
622 | unsigned int want, unsigned int flags, const UserPerm& perms); | |
623 | uint32_t ll_stripe_unit(Inode *in); | |
624 | int ll_file_layout(Inode *in, file_layout_t *layout); | |
625 | uint64_t ll_snap_seq(Inode *in); | |
626 | ||
627 | int ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl); | |
628 | int ll_write(Fh *fh, loff_t off, loff_t len, const char *data); | |
629 | int64_t ll_readv(struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off); | |
630 | int64_t ll_writev(struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off); | |
631 | loff_t ll_lseek(Fh *fh, loff_t offset, int whence); | |
632 | int ll_flush(Fh *fh); | |
633 | int ll_fsync(Fh *fh, bool syncdataonly); | |
634 | int ll_sync_inode(Inode *in, bool syncdataonly); | |
635 | int ll_fallocate(Fh *fh, int mode, int64_t offset, int64_t length); | |
636 | int ll_release(Fh *fh); | |
637 | int ll_getlk(Fh *fh, struct flock *fl, uint64_t owner); | |
638 | int ll_setlk(Fh *fh, struct flock *fl, uint64_t owner, int sleep); | |
639 | int ll_flock(Fh *fh, int cmd, uint64_t owner); | |
640 | int ll_lazyio(Fh *fh, int enable); | |
641 | int ll_file_layout(Fh *fh, file_layout_t *layout); | |
642 | void ll_interrupt(void *d); | |
643 | bool ll_handle_umask() { | |
644 | return acl_type != NO_ACL; | |
645 | } | |
646 | ||
647 | int ll_get_stripe_osd(struct Inode *in, uint64_t blockno, | |
648 | file_layout_t* layout); | |
649 | uint64_t ll_get_internal_offset(struct Inode *in, uint64_t blockno); | |
650 | ||
651 | int ll_num_osds(void); | |
652 | int ll_osdaddr(int osd, uint32_t *addr); | |
653 | int ll_osdaddr(int osd, char* buf, size_t size); | |
654 | ||
20effc67 TL |
655 | void _ll_register_callbacks(struct ceph_client_callback_args *args); |
656 | void ll_register_callbacks(struct ceph_client_callback_args *args); // deprecated | |
657 | int ll_register_callbacks2(struct ceph_client_callback_args *args); | |
11fdf7f2 TL |
658 | int test_dentry_handling(bool can_invalidate); |
659 | ||
660 | const char** get_tracked_conf_keys() const override; | |
661 | void handle_conf_change(const ConfigProxy& conf, | |
662 | const std::set <std::string> &changed) override; | |
663 | uint32_t get_deleg_timeout() { return deleg_timeout; } | |
664 | int set_deleg_timeout(uint32_t timeout); | |
665 | int ll_delegation(Fh *fh, unsigned cmd, ceph_deleg_cb_t cb, void *priv); | |
666 | ||
667 | entity_name_t get_myname() { return messenger->get_myname(); } | |
9f95a23c TL |
668 | void wait_on_list(std::list<ceph::condition_variable*>& ls); |
669 | void signal_cond_list(std::list<ceph::condition_variable*>& ls); | |
11fdf7f2 TL |
670 | |
671 | void set_filer_flags(int flags); | |
672 | void clear_filer_flags(int flags); | |
673 | ||
674 | void tear_down_cache(); | |
675 | ||
676 | void update_metadata(std::string const &k, std::string const &v); | |
677 | ||
678 | client_t get_nodeid() { return whoami; } | |
679 | ||
680 | inodeno_t get_root_ino(); | |
681 | Inode *get_root(); | |
682 | ||
683 | virtual int init(); | |
684 | virtual void shutdown(); | |
685 | ||
686 | // messaging | |
f67539c2 | 687 | void cancel_commands(const MDSMap& newmap); |
11fdf7f2 TL |
688 | void handle_mds_map(const MConstRef<MMDSMap>& m); |
689 | void handle_fs_map(const MConstRef<MFSMap>& m); | |
690 | void handle_fs_map_user(const MConstRef<MFSMapUser>& m); | |
691 | void handle_osd_map(const MConstRef<MOSDMap>& m); | |
692 | ||
693 | void handle_lease(const MConstRef<MClientLease>& m); | |
694 | ||
695 | // inline data | |
696 | int uninline_data(Inode *in, Context *onfinish); | |
697 | ||
698 | // file caps | |
699 | void check_cap_issue(Inode *in, unsigned issued); | |
700 | void add_update_cap(Inode *in, MetaSession *session, uint64_t cap_id, | |
701 | unsigned issued, unsigned wanted, unsigned seq, unsigned mseq, | |
702 | inodeno_t realm, int flags, const UserPerm& perms); | |
703 | void remove_cap(Cap *cap, bool queue_release); | |
704 | void remove_all_caps(Inode *in); | |
f6b5b4d7 | 705 | void remove_session_caps(MetaSession *session, int err); |
11fdf7f2 TL |
706 | int mark_caps_flushing(Inode *in, ceph_tid_t *ptid); |
707 | void adjust_session_flushing_caps(Inode *in, MetaSession *old_s, MetaSession *new_s); | |
708 | void flush_caps_sync(); | |
eafe8130 | 709 | void kick_flushing_caps(Inode *in, MetaSession *session); |
11fdf7f2 TL |
710 | void kick_flushing_caps(MetaSession *session); |
711 | void early_kick_flushing_caps(MetaSession *session); | |
f6b5b4d7 | 712 | int get_caps(Fh *fh, int need, int want, int *have, loff_t endoff); |
11fdf7f2 TL |
713 | int get_caps_used(Inode *in); |
714 | ||
715 | void maybe_update_snaprealm(SnapRealm *realm, snapid_t snap_created, snapid_t snap_highwater, | |
20effc67 | 716 | std::vector<snapid_t>& snaps); |
11fdf7f2 TL |
717 | |
718 | void handle_quota(const MConstRef<MClientQuota>& m); | |
719 | void handle_snap(const MConstRef<MClientSnap>& m); | |
720 | void handle_caps(const MConstRef<MClientCaps>& m); | |
721 | void handle_cap_import(MetaSession *session, Inode *in, const MConstRef<MClientCaps>& m); | |
722 | void handle_cap_export(MetaSession *session, Inode *in, const MConstRef<MClientCaps>& m); | |
723 | void handle_cap_trunc(MetaSession *session, Inode *in, const MConstRef<MClientCaps>& m); | |
724 | void handle_cap_flush_ack(MetaSession *session, Inode *in, Cap *cap, const MConstRef<MClientCaps>& m); | |
725 | void handle_cap_flushsnap_ack(MetaSession *session, Inode *in, const MConstRef<MClientCaps>& m); | |
726 | void handle_cap_grant(MetaSession *session, Inode *in, Cap *cap, const MConstRef<MClientCaps>& m); | |
727 | void cap_delay_requeue(Inode *in); | |
eafe8130 TL |
728 | |
729 | void send_cap(Inode *in, MetaSession *session, Cap *cap, int flags, | |
11fdf7f2 TL |
730 | int used, int want, int retain, int flush, |
731 | ceph_tid_t flush_tid); | |
732 | ||
eafe8130 TL |
733 | void send_flush_snap(Inode *in, MetaSession *session, snapid_t follows, CapSnap& capsnap); |
734 | ||
735 | void flush_snaps(Inode *in); | |
11fdf7f2 TL |
736 | void get_cap_ref(Inode *in, int cap); |
737 | void put_cap_ref(Inode *in, int cap); | |
11fdf7f2 TL |
738 | void wait_sync_caps(Inode *in, ceph_tid_t want); |
739 | void wait_sync_caps(ceph_tid_t want); | |
740 | void queue_cap_snap(Inode *in, SnapContext &old_snapc); | |
741 | void finish_cap_snap(Inode *in, CapSnap &capsnap, int used); | |
11fdf7f2 TL |
742 | |
743 | void _schedule_invalidate_dentry_callback(Dentry *dn, bool del); | |
20effc67 | 744 | void _async_dentry_invalidate(vinodeno_t dirino, vinodeno_t ino, std::string& name); |
11fdf7f2 TL |
745 | void _try_to_trim_inode(Inode *in, bool sched_inval); |
746 | ||
747 | void _schedule_invalidate_callback(Inode *in, int64_t off, int64_t len); | |
748 | void _invalidate_inode_cache(Inode *in); | |
749 | void _invalidate_inode_cache(Inode *in, int64_t off, int64_t len); | |
750 | void _async_invalidate(vinodeno_t ino, int64_t off, int64_t len); | |
e306af50 TL |
751 | |
752 | void _schedule_ino_release_callback(Inode *in); | |
753 | void _async_inode_release(vinodeno_t ino); | |
754 | ||
11fdf7f2 TL |
755 | bool _release(Inode *in); |
756 | ||
757 | /** | |
758 | * Initiate a flush of the data associated with the given inode. | |
759 | * If you specify a Context, you are responsible for holding an inode | |
760 | * reference for the duration of the flush. If not, _flush() will | |
761 | * take the reference for you. | |
762 | * @param in The Inode whose data you wish to flush. | |
763 | * @param c The Context you wish us to complete once the data is | |
764 | * flushed. If already flushed, this will be called in-line. | |
765 | * | |
766 | * @returns true if the data was already flushed, false otherwise. | |
767 | */ | |
768 | bool _flush(Inode *in, Context *c); | |
769 | void _flush_range(Inode *in, int64_t off, uint64_t size); | |
770 | void _flushed(Inode *in); | |
771 | void flush_set_callback(ObjectCacher::ObjectSet *oset); | |
772 | ||
773 | void close_release(Inode *in); | |
774 | void close_safe(Inode *in); | |
775 | ||
776 | void lock_fh_pos(Fh *f); | |
777 | void unlock_fh_pos(Fh *f); | |
778 | ||
779 | // metadata cache | |
522d829b | 780 | void update_dir_dist(Inode *in, DirStat *st, mds_rank_t from); |
11fdf7f2 TL |
781 | |
782 | void clear_dir_complete_and_ordered(Inode *diri, bool complete); | |
783 | void insert_readdir_results(MetaRequest *request, MetaSession *session, Inode *diri); | |
784 | Inode* insert_trace(MetaRequest *request, MetaSession *session); | |
785 | void update_inode_file_size(Inode *in, int issued, uint64_t size, | |
786 | uint64_t truncate_seq, uint64_t truncate_size); | |
787 | void update_inode_file_time(Inode *in, int issued, uint64_t time_warp_seq, | |
788 | utime_t ctime, utime_t mtime, utime_t atime); | |
789 | ||
790 | Inode *add_update_inode(InodeStat *st, utime_t ttl, MetaSession *session, | |
791 | const UserPerm& request_perms); | |
20effc67 | 792 | Dentry *insert_dentry_inode(Dir *dir, const std::string& dname, LeaseStat *dlease, |
11fdf7f2 TL |
793 | Inode *in, utime_t from, MetaSession *session, |
794 | Dentry *old_dentry = NULL); | |
795 | void update_dentry_lease(Dentry *dn, LeaseStat *dlease, utime_t from, MetaSession *session); | |
796 | ||
797 | bool use_faked_inos() { return _use_faked_inos; } | |
798 | vinodeno_t map_faked_ino(ino_t ino); | |
799 | ||
800 | //notify the mds to flush the mdlog | |
522d829b | 801 | void flush_mdlog_sync(Inode *in); |
11fdf7f2 TL |
802 | void flush_mdlog_sync(); |
803 | void flush_mdlog(MetaSession *session); | |
804 | ||
805 | void renew_caps(); | |
806 | void renew_caps(MetaSession *session); | |
807 | void flush_cap_releases(); | |
f67539c2 | 808 | void renew_and_flush_cap_releases(); |
11fdf7f2 | 809 | void tick(); |
f67539c2 TL |
810 | void start_tick_thread(); |
811 | ||
a4b75251 TL |
812 | void update_read_io_size(size_t size) { |
813 | total_read_ops++; | |
814 | total_read_size += size; | |
815 | } | |
816 | ||
817 | void update_write_io_size(size_t size) { | |
818 | total_write_ops++; | |
819 | total_write_size += size; | |
820 | } | |
821 | ||
f67539c2 TL |
822 | void inc_dentry_nr() { |
823 | ++dentry_nr; | |
824 | } | |
825 | void dec_dentry_nr() { | |
826 | --dentry_nr; | |
827 | } | |
828 | void dlease_hit() { | |
829 | ++dlease_hits; | |
830 | } | |
831 | void dlease_miss() { | |
832 | ++dlease_misses; | |
833 | } | |
834 | std::tuple<uint64_t, uint64_t, uint64_t> get_dlease_hit_rates() { | |
835 | return std::make_tuple(dlease_hits, dlease_misses, dentry_nr); | |
836 | } | |
837 | ||
838 | void cap_hit() { | |
839 | ++cap_hits; | |
840 | } | |
841 | void cap_miss() { | |
842 | ++cap_misses; | |
843 | } | |
844 | std::pair<uint64_t, uint64_t> get_cap_hit_rates() { | |
845 | return std::make_pair(cap_hits, cap_misses); | |
846 | } | |
847 | ||
848 | void inc_opened_files() { | |
849 | ++opened_files; | |
850 | } | |
851 | void dec_opened_files() { | |
852 | --opened_files; | |
853 | } | |
854 | std::pair<uint64_t, uint64_t> get_opened_files_rates() { | |
855 | return std::make_pair(opened_files, inode_map.size()); | |
856 | } | |
857 | ||
858 | void inc_pinned_icaps() { | |
859 | ++pinned_icaps; | |
860 | } | |
861 | void dec_pinned_icaps(uint64_t nr=1) { | |
862 | pinned_icaps -= nr; | |
863 | } | |
864 | std::pair<uint64_t, uint64_t> get_pinned_icaps_rates() { | |
865 | return std::make_pair(pinned_icaps, inode_map.size()); | |
866 | } | |
867 | ||
868 | void inc_opened_inodes() { | |
869 | ++opened_inodes; | |
870 | } | |
871 | void dec_opened_inodes() { | |
872 | --opened_inodes; | |
873 | } | |
874 | std::pair<uint64_t, uint64_t> get_opened_inodes_rates() { | |
875 | return std::make_pair(opened_inodes, inode_map.size()); | |
876 | } | |
11fdf7f2 | 877 | |
f67539c2 TL |
878 | /* timer_lock for 'timer' */ |
879 | ceph::mutex timer_lock = ceph::make_mutex("Client::timer_lock"); | |
11fdf7f2 TL |
880 | SafeTimer timer; |
881 | ||
f67539c2 TL |
882 | /* tick thread */ |
883 | std::thread upkeeper; | |
884 | ceph::condition_variable upkeep_cond; | |
885 | bool tick_thread_stopped = false; | |
886 | ||
11fdf7f2 TL |
887 | std::unique_ptr<PerfCounters> logger; |
888 | std::unique_ptr<MDSMap> mdsmap; | |
889 | ||
92f5a8d4 | 890 | bool fuse_default_permissions; |
11fdf7f2 TL |
891 | |
892 | protected: | |
893 | /* Flags for check_caps() */ | |
894 | static const unsigned CHECK_CAPS_NODELAY = 0x1; | |
895 | static const unsigned CHECK_CAPS_SYNCHRONOUS = 0x2; | |
896 | ||
11fdf7f2 TL |
897 | void check_caps(Inode *in, unsigned flags); |
898 | ||
899 | void set_cap_epoch_barrier(epoch_t e); | |
900 | ||
901 | void handle_command_reply(const MConstRef<MCommandReply>& m); | |
902 | int fetch_fsmap(bool user); | |
903 | int resolve_mds( | |
904 | const std::string &mds_spec, | |
905 | std::vector<mds_gid_t> *targets); | |
906 | ||
907 | void get_session_metadata(std::map<std::string, std::string> *meta) const; | |
908 | bool have_open_session(mds_rank_t mds); | |
909 | void got_mds_push(MetaSession *s); | |
20effc67 TL |
910 | MetaSessionRef _get_mds_session(mds_rank_t mds, Connection *con); ///< return session for mds *and* con; null otherwise |
911 | MetaSessionRef _get_or_open_mds_session(mds_rank_t mds); | |
912 | MetaSessionRef _open_mds_session(mds_rank_t mds); | |
11fdf7f2 | 913 | void _close_mds_session(MetaSession *s); |
f6b5b4d7 | 914 | void _closed_mds_session(MetaSession *s, int err=0, bool rejected=false); |
11fdf7f2 TL |
915 | bool _any_stale_sessions() const; |
916 | void _kick_stale_sessions(); | |
917 | void handle_client_session(const MConstRef<MClientSession>& m); | |
918 | void send_reconnect(MetaSession *s); | |
919 | void resend_unsafe_requests(MetaSession *s); | |
920 | void wait_unsafe_requests(); | |
921 | ||
11fdf7f2 | 922 | void dump_mds_requests(Formatter *f); |
adb31ebb | 923 | void dump_mds_sessions(Formatter *f, bool cap_dump=false); |
11fdf7f2 TL |
924 | |
925 | int make_request(MetaRequest *req, const UserPerm& perms, | |
926 | InodeRef *ptarget = 0, bool *pcreated = 0, | |
927 | mds_rank_t use_mds=-1, bufferlist *pdirbl=0); | |
928 | void put_request(MetaRequest *request); | |
929 | void unregister_request(MetaRequest *request); | |
930 | ||
9f95a23c TL |
931 | int verify_reply_trace(int r, MetaSession *session, MetaRequest *request, |
932 | const MConstRef<MClientReply>& reply, | |
11fdf7f2 TL |
933 | InodeRef *ptarget, bool *pcreated, |
934 | const UserPerm& perms); | |
935 | void encode_cap_releases(MetaRequest *request, mds_rank_t mds); | |
936 | int encode_inode_release(Inode *in, MetaRequest *req, | |
7c673cae FG |
937 | mds_rank_t mds, int drop, |
938 | int unless,int force=0); | |
939 | void encode_dentry_release(Dentry *dn, MetaRequest *req, | |
940 | mds_rank_t mds, int drop, int unless); | |
941 | mds_rank_t choose_target_mds(MetaRequest *req, Inode** phash_diri=NULL); | |
942 | void connect_mds_targets(mds_rank_t mds); | |
943 | void send_request(MetaRequest *request, MetaSession *session, | |
944 | bool drop_cap_releases=false); | |
11fdf7f2 | 945 | MRef<MClientRequest> build_client_request(MetaRequest *request); |
7c673cae FG |
946 | void kick_requests(MetaSession *session); |
947 | void kick_requests_closed(MetaSession *session); | |
11fdf7f2 TL |
948 | void handle_client_request_forward(const MConstRef<MClientRequestForward>& reply); |
949 | void handle_client_reply(const MConstRef<MClientReply>& reply); | |
7c673cae FG |
950 | bool is_dir_operation(MetaRequest *request); |
951 | ||
b3b6e05e TL |
952 | int path_walk(const filepath& fp, struct walk_dentry_result* result, const UserPerm& perms, bool followsym=true, int mask=0, |
953 | InodeRef dirinode=nullptr); | |
f67539c2 | 954 | int path_walk(const filepath& fp, InodeRef *end, const UserPerm& perms, |
b3b6e05e | 955 | bool followsym=true, int mask=0, InodeRef dirinode=nullptr); |
f67539c2 | 956 | |
7c673cae | 957 | // fake inode number for 32-bits ino_t |
7c673cae | 958 | void _assign_faked_ino(Inode *in); |
11fdf7f2 | 959 | void _assign_faked_root(Inode *in); |
7c673cae | 960 | void _release_faked_ino(Inode *in); |
7c673cae FG |
961 | void _reset_faked_inos(); |
962 | vinodeno_t _map_faked_ino(ino_t ino); | |
963 | ||
7c673cae | 964 | // Optional extra metadata about me to send to the MDS |
7c673cae FG |
965 | void populate_metadata(const std::string &mount_root); |
966 | ||
7c673cae FG |
967 | SnapRealm *get_snap_realm(inodeno_t r); |
968 | SnapRealm *get_snap_realm_maybe(inodeno_t r); | |
969 | void put_snap_realm(SnapRealm *realm); | |
970 | bool adjust_realm_parent(SnapRealm *realm, inodeno_t parent); | |
11fdf7f2 | 971 | void update_snap_trace(const bufferlist& bl, SnapRealm **realm_ret, bool must_flush=true); |
7c673cae FG |
972 | void invalidate_snaprealm_and_children(SnapRealm *realm); |
973 | ||
974 | Inode *open_snapdir(Inode *diri); | |
975 | ||
7c673cae FG |
976 | int get_fd() { |
977 | int fd = free_fd_set.range_start(); | |
978 | free_fd_set.erase(fd, 1); | |
979 | return fd; | |
980 | } | |
981 | void put_fd(int fd) { | |
982 | free_fd_set.insert(fd, 1); | |
983 | } | |
984 | ||
985 | /* | |
986 | * Resolve file descriptor, or return NULL. | |
987 | */ | |
988 | Fh *get_filehandle(int fd) { | |
f67539c2 TL |
989 | auto it = fd_map.find(fd); |
990 | if (it == fd_map.end()) | |
7c673cae | 991 | return NULL; |
f67539c2 | 992 | return it->second; |
7c673cae | 993 | } |
b3b6e05e | 994 | int get_fd_inode(int fd, InodeRef *in); |
7c673cae | 995 | |
7c673cae | 996 | // helpers |
a8e16298 | 997 | void wake_up_session_caps(MetaSession *s, bool reconnect); |
7c673cae | 998 | |
20effc67 TL |
999 | void wait_on_context_list(std::list<Context*>& ls); |
1000 | void signal_context_list(std::list<Context*>& ls); | |
7c673cae FG |
1001 | |
1002 | // -- metadata cache stuff | |
1003 | ||
1004 | // decrease inode ref. delete if dangling. | |
f67539c2 TL |
1005 | void _put_inode(Inode *in, int n); |
1006 | void delay_put_inodes(bool wakeup=false); | |
7c673cae FG |
1007 | void put_inode(Inode *in, int n=1); |
1008 | void close_dir(Dir *dir); | |
1009 | ||
11fdf7f2 | 1010 | int subscribe_mdsmap(const std::string &fs_name=""); |
b32b8144 | 1011 | |
11fdf7f2 TL |
1012 | void _abort_mds_sessions(int err); |
1013 | ||
1014 | // same as unmount() but for when the client_lock is already held | |
1015 | void _unmount(bool abort); | |
7c673cae FG |
1016 | |
1017 | //int get_cache_size() { return lru.lru_get_size(); } | |
7c673cae FG |
1018 | |
1019 | /** | |
1020 | * Don't call this with in==NULL, use get_or_create for that | |
1021 | * leave dn set to default NULL unless you're trying to add | |
1022 | * a new inode to a pre-created Dentry | |
1023 | */ | |
20effc67 | 1024 | Dentry* link(Dir *dir, const std::string& name, Inode *in, Dentry *dn); |
7c673cae FG |
1025 | void unlink(Dentry *dn, bool keepdir, bool keepdentry); |
1026 | ||
7c673cae FG |
1027 | int fill_stat(Inode *in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0); |
1028 | int fill_stat(InodeRef& in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0) { | |
1029 | return fill_stat(in.get(), st, dirstat, rstat); | |
1030 | } | |
1031 | ||
1032 | void fill_statx(Inode *in, unsigned int mask, struct ceph_statx *stx); | |
1033 | void fill_statx(InodeRef& in, unsigned int mask, struct ceph_statx *stx) { | |
1034 | return fill_statx(in.get(), mask, stx); | |
1035 | } | |
1036 | ||
1037 | void touch_dn(Dentry *dn); | |
1038 | ||
1039 | // trim cache. | |
1040 | void trim_cache(bool trim_kernel_dcache=false); | |
1041 | void trim_cache_for_reconnect(MetaSession *s); | |
1042 | void trim_dentry(Dentry *dn); | |
28e407b8 | 1043 | void trim_caps(MetaSession *s, uint64_t max); |
7c673cae | 1044 | void _invalidate_kernel_dcache(); |
91327a77 | 1045 | void _trim_negative_child_dentries(InodeRef& in); |
11fdf7f2 | 1046 | |
7c673cae FG |
1047 | void dump_inode(Formatter *f, Inode *in, set<Inode*>& did, bool disconnected); |
1048 | void dump_cache(Formatter *f); // debug | |
1049 | ||
1050 | // force read-only | |
1051 | void force_session_readonly(MetaSession *s); | |
1052 | ||
1053 | void dump_status(Formatter *f); // debug | |
7c673cae | 1054 | |
11fdf7f2 | 1055 | bool ms_dispatch2(const MessageRef& m) override; |
7c673cae FG |
1056 | |
1057 | void ms_handle_connect(Connection *con) override; | |
1058 | bool ms_handle_reset(Connection *con) override; | |
1059 | void ms_handle_remote_reset(Connection *con) override; | |
1060 | bool ms_handle_refused(Connection *con) override; | |
7c673cae FG |
1061 | |
1062 | int authenticate(); | |
1063 | ||
1064 | Inode* get_quota_root(Inode *in, const UserPerm& perms); | |
1065 | bool check_quota_condition(Inode *in, const UserPerm& perms, | |
1066 | std::function<bool (const Inode &)> test); | |
1067 | bool is_quota_files_exceeded(Inode *in, const UserPerm& perms); | |
1068 | bool is_quota_bytes_exceeded(Inode *in, int64_t new_bytes, | |
11fdf7f2 TL |
1069 | const UserPerm& perms); |
1070 | bool is_quota_bytes_approaching(Inode *in, const UserPerm& perms); | |
7c673cae | 1071 | |
7c673cae FG |
1072 | int check_pool_perm(Inode *in, int need); |
1073 | ||
11fdf7f2 TL |
1074 | void handle_client_reclaim_reply(const MConstRef<MClientReclaimReply>& reply); |
1075 | ||
7c673cae FG |
1076 | /** |
1077 | * Call this when an OSDMap is seen with a full flag (global or per pool) | |
1078 | * set. | |
1079 | * | |
1080 | * @param pool the pool ID affected, or -1 if all. | |
1081 | */ | |
1082 | void _handle_full_flag(int64_t pool); | |
1083 | ||
1084 | void _close_sessions(); | |
1085 | ||
e306af50 TL |
1086 | void _pre_init(); |
1087 | ||
7c673cae FG |
1088 | /** |
1089 | * The basic housekeeping parts of init (perf counters, admin socket) | |
1090 | * that is independent of how objecters/monclient/messengers are | |
1091 | * being set up. | |
1092 | */ | |
1093 | void _finish_init(); | |
1094 | ||
11fdf7f2 TL |
1095 | // global client lock |
1096 | // - protects Client and buffer cache both! | |
9f95a23c | 1097 | ceph::mutex client_lock = ceph::make_mutex("Client::client_lock"); |
7c673cae | 1098 | |
11fdf7f2 | 1099 | std::map<snapid_t, int> ll_snap_ref; |
7c673cae | 1100 | |
b3b6e05e | 1101 | InodeRef root = nullptr; |
11fdf7f2 TL |
1102 | map<Inode*, InodeRef> root_parents; |
1103 | Inode* root_ancestor = nullptr; | |
1104 | LRU lru; // lru list of Dentry's in our local metadata cache. | |
7c673cae | 1105 | |
11fdf7f2 | 1106 | InodeRef cwd; |
7c673cae | 1107 | |
11fdf7f2 TL |
1108 | std::unique_ptr<Filer> filer; |
1109 | std::unique_ptr<ObjectCacher> objectcacher; | |
1110 | std::unique_ptr<WritebackHandler> writeback_handler; | |
7c673cae | 1111 | |
11fdf7f2 TL |
1112 | Messenger *messenger; |
1113 | MonClient *monclient; | |
1114 | Objecter *objecter; | |
7c673cae | 1115 | |
11fdf7f2 | 1116 | client_t whoami; |
7c673cae | 1117 | |
f67539c2 TL |
1118 | /* The state migration mechanism */ |
1119 | enum _state { | |
1120 | /* For the initialize_state */ | |
1121 | CLIENT_NEW, // The initial state for the initialize_state or after Client::shutdown() | |
1122 | CLIENT_INITIALIZING, // At the beginning of the Client::init() | |
1123 | CLIENT_INITIALIZED, // At the end of CLient::init() | |
1124 | ||
1125 | /* For the mount_state */ | |
1126 | CLIENT_UNMOUNTED, // The initial state for the mount_state or after unmounted | |
1127 | CLIENT_MOUNTING, // At the beginning of Client::mount() | |
1128 | CLIENT_MOUNTED, // At the end of Client::mount() | |
1129 | CLIENT_UNMOUNTING, // At the beginning of the Client::_unmout() | |
1130 | }; | |
1131 | ||
1132 | typedef enum _state state_t; | |
1133 | using RWRef_t = RWRef<state_t>; | |
1134 | ||
1135 | struct mount_state_t : public RWRefState<state_t> { | |
1136 | public: | |
1137 | bool is_valid_state(state_t state) const override { | |
1138 | switch (state) { | |
1139 | case Client::CLIENT_MOUNTING: | |
1140 | case Client::CLIENT_MOUNTED: | |
1141 | case Client::CLIENT_UNMOUNTING: | |
1142 | case Client::CLIENT_UNMOUNTED: | |
1143 | return true; | |
1144 | default: | |
1145 | return false; | |
1146 | } | |
1147 | } | |
1148 | ||
1149 | int check_reader_state(state_t require) const override { | |
1150 | if (require == Client::CLIENT_MOUNTING && | |
1151 | (state == Client::CLIENT_MOUNTING || state == Client::CLIENT_MOUNTED)) | |
1152 | return true; | |
1153 | else | |
1154 | return false; | |
1155 | } | |
1156 | ||
1157 | /* The state migration check */ | |
1158 | int check_writer_state(state_t require) const override { | |
1159 | if (require == Client::CLIENT_MOUNTING && | |
1160 | state == Client::CLIENT_UNMOUNTED) | |
1161 | return true; | |
1162 | else if (require == Client::CLIENT_MOUNTED && | |
1163 | state == Client::CLIENT_MOUNTING) | |
1164 | return true; | |
1165 | else if (require == Client::CLIENT_UNMOUNTING && | |
1166 | state == Client::CLIENT_MOUNTED) | |
1167 | return true; | |
1168 | else if (require == Client::CLIENT_UNMOUNTED && | |
1169 | state == Client::CLIENT_UNMOUNTING) | |
1170 | return true; | |
1171 | else | |
1172 | return false; | |
1173 | } | |
1174 | ||
1175 | mount_state_t(state_t state, const char *lockname, uint64_t reader_cnt=0) | |
1176 | : RWRefState (state, lockname, reader_cnt) {} | |
1177 | ~mount_state_t() {} | |
1178 | }; | |
1179 | ||
1180 | struct initialize_state_t : public RWRefState<state_t> { | |
1181 | public: | |
1182 | bool is_valid_state(state_t state) const override { | |
1183 | switch (state) { | |
1184 | case Client::CLIENT_NEW: | |
1185 | case Client::CLIENT_INITIALIZING: | |
1186 | case Client::CLIENT_INITIALIZED: | |
1187 | return true; | |
1188 | default: | |
1189 | return false; | |
1190 | } | |
1191 | } | |
1192 | ||
1193 | int check_reader_state(state_t require) const override { | |
1194 | if (require == Client::CLIENT_INITIALIZED && | |
1195 | state >= Client::CLIENT_INITIALIZED) | |
1196 | return true; | |
1197 | else | |
1198 | return false; | |
1199 | } | |
1200 | ||
1201 | /* The state migration check */ | |
1202 | int check_writer_state(state_t require) const override { | |
1203 | if (require == Client::CLIENT_INITIALIZING && | |
1204 | (state == Client::CLIENT_NEW)) | |
1205 | return true; | |
1206 | else if (require == Client::CLIENT_INITIALIZED && | |
1207 | (state == Client::CLIENT_INITIALIZING)) | |
1208 | return true; | |
1209 | else if (require == Client::CLIENT_NEW && | |
1210 | (state == Client::CLIENT_INITIALIZED)) | |
1211 | return true; | |
1212 | else | |
1213 | return false; | |
1214 | } | |
1215 | ||
1216 | initialize_state_t(state_t state, const char *lockname, uint64_t reader_cnt=0) | |
1217 | : RWRefState (state, lockname, reader_cnt) {} | |
1218 | ~initialize_state_t() {} | |
1219 | }; | |
1220 | ||
1221 | struct mount_state_t mount_state; | |
1222 | struct initialize_state_t initialize_state; | |
7c673cae | 1223 | |
11fdf7f2 TL |
1224 | private: |
1225 | struct C_Readahead : public Context { | |
1226 | C_Readahead(Client *c, Fh *f); | |
1227 | ~C_Readahead() override; | |
1228 | void finish(int r) override; | |
7c673cae | 1229 | |
11fdf7f2 TL |
1230 | Client *client; |
1231 | Fh *f; | |
1232 | }; | |
7c673cae | 1233 | |
11fdf7f2 TL |
1234 | /* |
1235 | * These define virtual xattrs exposing the recursive directory | |
1236 | * statistics and layout metadata. | |
1237 | */ | |
1238 | struct VXattr { | |
20effc67 TL |
1239 | const std::string name; |
1240 | size_t (Client::*getxattr_cb)(Inode *in, char *val, size_t size); | |
1241 | bool readonly; | |
1242 | bool (Client::*exists_cb)(Inode *in); | |
1243 | unsigned int flags; | |
11fdf7f2 | 1244 | }; |
7c673cae | 1245 | |
11fdf7f2 TL |
1246 | enum { |
1247 | NO_ACL = 0, | |
1248 | POSIX_ACL, | |
1249 | }; | |
7c673cae | 1250 | |
11fdf7f2 TL |
1251 | enum { |
1252 | MAY_EXEC = 1, | |
1253 | MAY_WRITE = 2, | |
1254 | MAY_READ = 4, | |
1255 | }; | |
7c673cae | 1256 | |
f67539c2 | 1257 | std::unique_ptr<CephContext, std::function<void(CephContext*)>> cct_deleter; |
7c673cae | 1258 | |
11fdf7f2 TL |
1259 | /* Flags for VXattr */ |
1260 | static const unsigned VXATTR_RSTAT = 0x1; | |
adb31ebb | 1261 | static const unsigned VXATTR_DIRSTAT = 0x2; |
7c673cae | 1262 | |
11fdf7f2 TL |
1263 | static const VXattr _dir_vxattrs[]; |
1264 | static const VXattr _file_vxattrs[]; | |
adb31ebb | 1265 | static const VXattr _common_vxattrs[]; |
1adf2230 | 1266 | |
7c673cae | 1267 | |
b3b6e05e | 1268 | bool is_reserved_vino(vinodeno_t &vino); |
7c673cae FG |
1269 | |
1270 | void fill_dirent(struct dirent *de, const char *name, int type, uint64_t ino, loff_t next_off); | |
1271 | ||
7c673cae FG |
1272 | int _opendir(Inode *in, dir_result_t **dirpp, const UserPerm& perms); |
1273 | void _readdir_drop_dirp_buffer(dir_result_t *dirp); | |
1274 | bool _readdir_have_frag(dir_result_t *dirp); | |
1275 | void _readdir_next_frag(dir_result_t *dirp); | |
1276 | void _readdir_rechoose_frag(dir_result_t *dirp); | |
1277 | int _readdir_get_frag(dir_result_t *dirp); | |
1278 | int _readdir_cache_cb(dir_result_t *dirp, add_dirent_cb_t cb, void *p, int caps, bool getref); | |
1279 | void _closedir(dir_result_t *dirp); | |
1280 | ||
1281 | // other helpers | |
1282 | void _fragmap_remove_non_leaves(Inode *in); | |
1283 | void _fragmap_remove_stopped_mds(Inode *in, mds_rank_t mds); | |
1284 | ||
1285 | void _ll_get(Inode *in); | |
494da23a | 1286 | int _ll_put(Inode *in, uint64_t num); |
7c673cae FG |
1287 | void _ll_drop_pins(); |
1288 | ||
1289 | Fh *_create_fh(Inode *in, int flags, int cmode, const UserPerm& perms); | |
1290 | int _release_fh(Fh *fh); | |
1291 | void _put_fh(Fh *fh); | |
1292 | ||
91327a77 | 1293 | int _do_remount(bool retry_on_error); |
7c673cae FG |
1294 | |
1295 | int _read_sync(Fh *f, uint64_t off, uint64_t len, bufferlist *bl, bool *checkeof); | |
1296 | int _read_async(Fh *f, uint64_t off, uint64_t len, bufferlist *bl); | |
1297 | ||
f67539c2 TL |
1298 | bool _dentry_valid(const Dentry *dn); |
1299 | ||
7c673cae FG |
1300 | // internal interface |
1301 | // call these with client_lock held! | |
20effc67 | 1302 | int _do_lookup(Inode *dir, const std::string& name, int mask, InodeRef *target, |
7c673cae FG |
1303 | const UserPerm& perms); |
1304 | ||
20effc67 | 1305 | int _lookup(Inode *dir, const std::string& dname, int mask, InodeRef *target, |
f67539c2 | 1306 | const UserPerm& perm, std::string* alternate_name=nullptr); |
7c673cae | 1307 | |
f67539c2 | 1308 | int _link(Inode *in, Inode *dir, const char *name, const UserPerm& perm, std::string alternate_name, |
7c673cae FG |
1309 | InodeRef *inp = 0); |
1310 | int _unlink(Inode *dir, const char *name, const UserPerm& perm); | |
f67539c2 | 1311 | int _rename(Inode *olddir, const char *oname, Inode *ndir, const char *nname, const UserPerm& perm, std::string alternate_name); |
7c673cae | 1312 | int _mkdir(Inode *dir, const char *name, mode_t mode, const UserPerm& perm, |
f67539c2 TL |
1313 | InodeRef *inp = 0, const std::map<std::string, std::string> &metadata={}, |
1314 | std::string alternate_name=""); | |
7c673cae FG |
1315 | int _rmdir(Inode *dir, const char *name, const UserPerm& perms); |
1316 | int _symlink(Inode *dir, const char *name, const char *target, | |
f67539c2 | 1317 | const UserPerm& perms, std::string alternate_name, InodeRef *inp = 0); |
7c673cae FG |
1318 | int _mknod(Inode *dir, const char *name, mode_t mode, dev_t rdev, |
1319 | const UserPerm& perms, InodeRef *inp = 0); | |
1320 | int _do_setattr(Inode *in, struct ceph_statx *stx, int mask, | |
1321 | const UserPerm& perms, InodeRef *inp); | |
1322 | void stat_to_statx(struct stat *st, struct ceph_statx *stx); | |
1323 | int __setattrx(Inode *in, struct ceph_statx *stx, int mask, | |
1324 | const UserPerm& perms, InodeRef *inp = 0); | |
1325 | int _setattrx(InodeRef &in, struct ceph_statx *stx, int mask, | |
1326 | const UserPerm& perms); | |
1327 | int _setattr(InodeRef &in, struct stat *attr, int mask, | |
1328 | const UserPerm& perms); | |
1329 | int _ll_setattrx(Inode *in, struct ceph_statx *stx, int mask, | |
1330 | const UserPerm& perms, InodeRef *inp = 0); | |
1331 | int _getattr(Inode *in, int mask, const UserPerm& perms, bool force=false); | |
1332 | int _getattr(InodeRef &in, int mask, const UserPerm& perms, bool force=false) { | |
1333 | return _getattr(in.get(), mask, perms, force); | |
1334 | } | |
1335 | int _readlink(Inode *in, char *buf, size_t size); | |
1336 | int _getxattr(Inode *in, const char *name, void *value, size_t len, | |
1337 | const UserPerm& perms); | |
1338 | int _getxattr(InodeRef &in, const char *name, void *value, size_t len, | |
1339 | const UserPerm& perms); | |
1340 | int _listxattr(Inode *in, char *names, size_t len, const UserPerm& perms); | |
1341 | int _do_setxattr(Inode *in, const char *name, const void *value, size_t len, | |
1342 | int flags, const UserPerm& perms); | |
1343 | int _setxattr(Inode *in, const char *name, const void *value, size_t len, | |
1344 | int flags, const UserPerm& perms); | |
1345 | int _setxattr(InodeRef &in, const char *name, const void *value, size_t len, | |
1346 | int flags, const UserPerm& perms); | |
20effc67 | 1347 | int _setxattr_check_data_pool(std::string& name, std::string& value, const OSDMap *osdmap); |
7c673cae FG |
1348 | void _setxattr_maybe_wait_for_osdmap(const char *name, const void *value, size_t len); |
1349 | int _removexattr(Inode *in, const char *nm, const UserPerm& perms); | |
1350 | int _removexattr(InodeRef &in, const char *nm, const UserPerm& perms); | |
1351 | int _open(Inode *in, int flags, mode_t mode, Fh **fhp, | |
1352 | const UserPerm& perms); | |
1353 | int _renew_caps(Inode *in); | |
1354 | int _create(Inode *in, const char *name, int flags, mode_t mode, InodeRef *inp, | |
1355 | Fh **fhp, int stripe_unit, int stripe_count, int object_size, | |
f67539c2 TL |
1356 | const char *data_pool, bool *created, const UserPerm &perms, |
1357 | std::string alternate_name); | |
7c673cae FG |
1358 | |
1359 | loff_t _lseek(Fh *fh, loff_t offset, int whence); | |
11fdf7f2 TL |
1360 | int64_t _read(Fh *fh, int64_t offset, uint64_t size, bufferlist *bl); |
1361 | int64_t _write(Fh *fh, int64_t offset, uint64_t size, const char *buf, | |
7c673cae | 1362 | const struct iovec *iov, int iovcnt); |
f67539c2 TL |
1363 | int64_t _preadv_pwritev_locked(Fh *fh, const struct iovec *iov, |
1364 | unsigned iovcnt, int64_t offset, | |
20effc67 TL |
1365 | bool write, bool clamp_to_int); |
1366 | int _preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, | |
1367 | int64_t offset, bool write); | |
7c673cae FG |
1368 | int _flush(Fh *fh); |
1369 | int _fsync(Fh *fh, bool syncdataonly); | |
1370 | int _fsync(Inode *in, bool syncdataonly); | |
1371 | int _sync_fs(); | |
1372 | int _fallocate(Fh *fh, int mode, int64_t offset, int64_t length); | |
1373 | int _getlk(Fh *fh, struct flock *fl, uint64_t owner); | |
1374 | int _setlk(Fh *fh, struct flock *fl, uint64_t owner, int sleep); | |
1375 | int _flock(Fh *fh, int cmd, uint64_t owner); | |
11fdf7f2 | 1376 | int _lazyio(Fh *fh, int enable); |
7c673cae FG |
1377 | |
1378 | int get_or_create(Inode *dir, const char* name, | |
1379 | Dentry **pdn, bool expect_null=false); | |
1380 | ||
7c673cae FG |
1381 | int xattr_permission(Inode *in, const char *name, unsigned want, |
1382 | const UserPerm& perms); | |
1383 | int may_setattr(Inode *in, struct ceph_statx *stx, int mask, | |
1384 | const UserPerm& perms); | |
1385 | int may_open(Inode *in, int flags, const UserPerm& perms); | |
1386 | int may_lookup(Inode *dir, const UserPerm& perms); | |
1387 | int may_create(Inode *dir, const UserPerm& perms); | |
1388 | int may_delete(Inode *dir, const char *name, const UserPerm& perms); | |
1389 | int may_hardlink(Inode *in, const UserPerm& perms); | |
1390 | ||
1391 | int _getattr_for_perm(Inode *in, const UserPerm& perms); | |
7c673cae FG |
1392 | |
1393 | vinodeno_t _get_vino(Inode *in); | |
28e407b8 | 1394 | |
7c673cae FG |
1395 | bool _vxattrcb_quota_exists(Inode *in); |
1396 | size_t _vxattrcb_quota(Inode *in, char *val, size_t size); | |
1397 | size_t _vxattrcb_quota_max_bytes(Inode *in, char *val, size_t size); | |
1398 | size_t _vxattrcb_quota_max_files(Inode *in, char *val, size_t size); | |
1399 | ||
1400 | bool _vxattrcb_layout_exists(Inode *in); | |
1401 | size_t _vxattrcb_layout(Inode *in, char *val, size_t size); | |
1402 | size_t _vxattrcb_layout_stripe_unit(Inode *in, char *val, size_t size); | |
1403 | size_t _vxattrcb_layout_stripe_count(Inode *in, char *val, size_t size); | |
1404 | size_t _vxattrcb_layout_object_size(Inode *in, char *val, size_t size); | |
1405 | size_t _vxattrcb_layout_pool(Inode *in, char *val, size_t size); | |
1406 | size_t _vxattrcb_layout_pool_namespace(Inode *in, char *val, size_t size); | |
1407 | size_t _vxattrcb_dir_entries(Inode *in, char *val, size_t size); | |
1408 | size_t _vxattrcb_dir_files(Inode *in, char *val, size_t size); | |
1409 | size_t _vxattrcb_dir_subdirs(Inode *in, char *val, size_t size); | |
1410 | size_t _vxattrcb_dir_rentries(Inode *in, char *val, size_t size); | |
1411 | size_t _vxattrcb_dir_rfiles(Inode *in, char *val, size_t size); | |
1412 | size_t _vxattrcb_dir_rsubdirs(Inode *in, char *val, size_t size); | |
f67539c2 | 1413 | size_t _vxattrcb_dir_rsnaps(Inode *in, char *val, size_t size); |
7c673cae FG |
1414 | size_t _vxattrcb_dir_rbytes(Inode *in, char *val, size_t size); |
1415 | size_t _vxattrcb_dir_rctime(Inode *in, char *val, size_t size); | |
7c673cae | 1416 | |
11fdf7f2 TL |
1417 | bool _vxattrcb_dir_pin_exists(Inode *in); |
1418 | size_t _vxattrcb_dir_pin(Inode *in, char *val, size_t size); | |
1419 | ||
81eedcae TL |
1420 | bool _vxattrcb_snap_btime_exists(Inode *in); |
1421 | size_t _vxattrcb_snap_btime(Inode *in, char *val, size_t size); | |
7c673cae | 1422 | |
20effc67 TL |
1423 | size_t _vxattrcb_caps(Inode *in, char *val, size_t size); |
1424 | ||
f67539c2 TL |
1425 | bool _vxattrcb_mirror_info_exists(Inode *in); |
1426 | size_t _vxattrcb_mirror_info(Inode *in, char *val, size_t size); | |
1427 | ||
adb31ebb TL |
1428 | size_t _vxattrcb_cluster_fsid(Inode *in, char *val, size_t size); |
1429 | size_t _vxattrcb_client_id(Inode *in, char *val, size_t size); | |
1430 | ||
7c673cae FG |
1431 | static const VXattr *_get_vxattrs(Inode *in); |
1432 | static const VXattr *_match_vxattr(Inode *in, const char *name); | |
1433 | ||
7c673cae FG |
1434 | int _do_filelock(Inode *in, Fh *fh, int lock_type, int op, int sleep, |
1435 | struct flock *fl, uint64_t owner, bool removing=false); | |
1436 | int _interrupt_filelock(MetaRequest *req); | |
1437 | void _encode_filelocks(Inode *in, bufferlist& bl); | |
1438 | void _release_filelocks(Fh *fh); | |
1439 | void _update_lock_state(struct flock *fl, uint64_t owner, ceph_lock_state_t *lock_state); | |
1440 | ||
1441 | int _posix_acl_create(Inode *dir, mode_t *mode, bufferlist& xattrs_bl, | |
1442 | const UserPerm& perms); | |
1443 | int _posix_acl_chmod(Inode *in, mode_t mode, const UserPerm& perms); | |
1444 | int _posix_acl_permission(Inode *in, const UserPerm& perms, unsigned want); | |
1445 | ||
1446 | mds_rank_t _get_random_up_mds() const; | |
1447 | ||
1448 | int _ll_getattr(Inode *in, int caps, const UserPerm& perms); | |
1adf2230 AA |
1449 | int _lookup_parent(Inode *in, const UserPerm& perms, Inode **parent=NULL); |
1450 | int _lookup_name(Inode *in, Inode *parent, const UserPerm& perms); | |
f67539c2 | 1451 | int _lookup_vino(vinodeno_t ino, const UserPerm& perms, Inode **inode=NULL); |
494da23a | 1452 | bool _ll_forget(Inode *in, uint64_t count); |
7c673cae | 1453 | |
f67539c2 TL |
1454 | void collect_and_send_metrics(); |
1455 | void collect_and_send_global_metrics(); | |
7c673cae | 1456 | |
11fdf7f2 | 1457 | uint32_t deleg_timeout = 0; |
7c673cae | 1458 | |
11fdf7f2 TL |
1459 | client_switch_interrupt_callback_t switch_interrupt_cb = nullptr; |
1460 | client_remount_callback_t remount_cb = nullptr; | |
1461 | client_ino_callback_t ino_invalidate_cb = nullptr; | |
1462 | client_dentry_callback_t dentry_invalidate_cb = nullptr; | |
1463 | client_umask_callback_t umask_cb = nullptr; | |
e306af50 | 1464 | client_ino_release_t ino_release_cb = nullptr; |
11fdf7f2 TL |
1465 | void *callback_handle = nullptr; |
1466 | bool can_invalidate_dentries = false; | |
7c673cae | 1467 | |
11fdf7f2 TL |
1468 | Finisher async_ino_invalidator; |
1469 | Finisher async_dentry_invalidator; | |
1470 | Finisher interrupt_finisher; | |
1471 | Finisher remount_finisher; | |
e306af50 | 1472 | Finisher async_ino_releasor; |
11fdf7f2 | 1473 | Finisher objecter_finisher; |
7c673cae | 1474 | |
11fdf7f2 | 1475 | utime_t last_cap_renew; |
7c673cae | 1476 | |
11fdf7f2 | 1477 | CommandHook m_command_hook; |
7c673cae | 1478 | |
11fdf7f2 TL |
1479 | int user_id, group_id; |
1480 | int acl_type = NO_ACL; | |
7c673cae | 1481 | |
11fdf7f2 | 1482 | epoch_t cap_epoch_barrier = 0; |
7c673cae | 1483 | |
11fdf7f2 | 1484 | // mds sessions |
20effc67 | 1485 | map<mds_rank_t, MetaSessionRef> mds_sessions; // mds -> push seq |
f6b5b4d7 | 1486 | std::set<mds_rank_t> mds_ranks_closing; // mds ranks currently tearing down sessions |
9f95a23c | 1487 | std::list<ceph::condition_variable*> waiting_for_mdsmap; |
7c673cae | 1488 | |
11fdf7f2 | 1489 | // FSMap, for when using mds_command |
9f95a23c | 1490 | std::list<ceph::condition_variable*> waiting_for_fsmap; |
11fdf7f2 TL |
1491 | std::unique_ptr<FSMap> fsmap; |
1492 | std::unique_ptr<FSMapUser> fsmap_user; | |
7c673cae | 1493 | |
f67539c2 TL |
1494 | // This mutex only protects command_table |
1495 | ceph::mutex command_lock = ceph::make_mutex("Client::command_lock"); | |
11fdf7f2 TL |
1496 | // MDS command state |
1497 | CommandTable<MDSCommandOp> command_table; | |
7c673cae | 1498 | |
11fdf7f2 | 1499 | bool _use_faked_inos; |
7c673cae | 1500 | |
11fdf7f2 TL |
1501 | // Cluster fsid |
1502 | fs_cluster_id_t fscid; | |
7c673cae | 1503 | |
11fdf7f2 TL |
1504 | // file handles, etc. |
1505 | interval_set<int> free_fd_set; // unused fds | |
1506 | ceph::unordered_map<int, Fh*> fd_map; | |
1507 | set<Fh*> ll_unclosed_fh_set; | |
1508 | ceph::unordered_set<dir_result_t*> opened_dirs; | |
f6b5b4d7 | 1509 | uint64_t fd_gen = 1; |
7c673cae | 1510 | |
f67539c2 TL |
1511 | bool mount_aborted = false; |
1512 | bool blocklisted = false; | |
28e407b8 | 1513 | |
11fdf7f2 TL |
1514 | ceph::unordered_map<vinodeno_t, Inode*> inode_map; |
1515 | ceph::unordered_map<ino_t, vinodeno_t> faked_ino_map; | |
1516 | interval_set<ino_t> free_faked_inos; | |
1517 | ino_t last_used_faked_ino; | |
1518 | ino_t last_used_faked_root; | |
7c673cae | 1519 | |
f67539c2 | 1520 | int local_osd = -CEPHFS_ENXIO; |
11fdf7f2 | 1521 | epoch_t local_osd_epoch = 0; |
7c673cae | 1522 | |
11fdf7f2 TL |
1523 | // mds requests |
1524 | ceph_tid_t last_tid = 0; | |
1525 | ceph_tid_t oldest_tid = 0; // oldest incomplete mds request, excluding setfilelock requests | |
1526 | map<ceph_tid_t, MetaRequest*> mds_requests; | |
7c673cae | 1527 | |
11fdf7f2 TL |
1528 | // cap flushing |
1529 | ceph_tid_t last_flush_tid = 1; | |
7c673cae | 1530 | |
20effc67 | 1531 | xlist<Inode*> delayed_list; |
11fdf7f2 TL |
1532 | int num_flushing_caps = 0; |
1533 | ceph::unordered_map<inodeno_t,SnapRealm*> snap_realms; | |
1534 | std::map<std::string, std::string> metadata; | |
7c673cae | 1535 | |
f6b5b4d7 TL |
1536 | utime_t last_auto_reconnect; |
1537 | ||
11fdf7f2 | 1538 | // trace generation |
20effc67 | 1539 | std::ofstream traceout; |
7c673cae | 1540 | |
9f95a23c | 1541 | ceph::condition_variable mount_cond, sync_cond; |
11fdf7f2 TL |
1542 | |
1543 | std::map<std::pair<int64_t,std::string>, int> pool_perms; | |
9f95a23c | 1544 | std::list<ceph::condition_variable*> waiting_for_pool_perm; |
91327a77 | 1545 | |
91327a77 | 1546 | uint64_t retries_on_invalidate = 0; |
11fdf7f2 TL |
1547 | |
1548 | // state reclaim | |
9f95a23c | 1549 | std::list<ceph::condition_variable*> waiting_for_reclaim; |
11fdf7f2 TL |
1550 | int reclaim_errno = 0; |
1551 | epoch_t reclaim_osd_epoch = 0; | |
1552 | entity_addrvec_t reclaim_target_addrs; | |
f67539c2 TL |
1553 | |
1554 | // dentry lease metrics | |
1555 | uint64_t dentry_nr = 0; | |
1556 | uint64_t dlease_hits = 0; | |
1557 | uint64_t dlease_misses = 0; | |
1558 | ||
1559 | uint64_t cap_hits = 0; | |
1560 | uint64_t cap_misses = 0; | |
1561 | ||
1562 | uint64_t opened_files = 0; | |
1563 | uint64_t pinned_icaps = 0; | |
1564 | uint64_t opened_inodes = 0; | |
1565 | ||
a4b75251 TL |
1566 | uint64_t total_read_ops = 0; |
1567 | uint64_t total_read_size = 0; | |
1568 | ||
1569 | uint64_t total_write_ops = 0; | |
1570 | uint64_t total_write_size = 0; | |
1571 | ||
f67539c2 TL |
1572 | ceph::spinlock delay_i_lock; |
1573 | std::map<Inode*,int> delay_i_release; | |
7c673cae FG |
1574 | }; |
1575 | ||
1576 | /** | |
1577 | * Specialization of Client that manages its own Objecter instance | |
1578 | * and handles init/shutdown of messenger/monclient | |
1579 | */ | |
1580 | class StandaloneClient : public Client | |
1581 | { | |
11fdf7f2 | 1582 | public: |
f67539c2 | 1583 | StandaloneClient(Messenger *m, MonClient *mc, boost::asio::io_context& ictx); |
7c673cae FG |
1584 | |
1585 | ~StandaloneClient() override; | |
1586 | ||
1587 | int init() override; | |
1588 | void shutdown() override; | |
1589 | }; | |
1590 | ||
1591 | #endif |