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