1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
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"
40 #include "MetaSession.h"
64 class WritebackHandler
;
80 class MDSCommandOp
: public CommandOp
85 explicit MDSCommandOp(ceph_tid_t t
) : CommandOp(t
) {}
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) */
92 // ============================================
93 // types for my local metadata cache
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--)
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
) {}
122 class ceph_lock_state_t
;
124 // ========================================================
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);
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
) {}
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;
148 explicit dir_result_t(Inode
*in
, const UserPerm
& perms
);
151 static uint64_t make_fpos(unsigned h
, unsigned l
, bool hash
) {
152 uint64_t v
= ((uint64_t)h
<< SHIFT
) | (uint64_t)l
;
156 ceph_assert((v
& HASH
) != HASH
);
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
);
165 static unsigned fpos_low(uint64_t p
) {
168 static int fpos_cmp(uint64_t l
, uint64_t r
) {
169 int c
= ceph_frag_compare(fpos_high(l
), fpos_high(r
));
172 if (fpos_low(l
) == fpos_low(r
))
174 return fpos_low(l
) < fpos_low(r
) ? -1 : 1;
177 unsigned offset_high() { return fpos_high(offset
); }
178 unsigned offset_low() { return fpos_low(offset
); }
180 void set_end() { offset
|= END
; }
181 bool at_end() { return (offset
& END
); }
183 void set_hash_order() { offset
|= HASH
; }
184 bool hash_order() { return (offset
& HASH
) == HASH
; }
190 return buffer_frag
.contains(offset_high());
192 return buffer_frag
== frag_t(offset_high());
206 int64_t offset
; // hash order:
207 // (0xff << 52) | ((24 bits hash) << 28) |
208 // (the nth entry has hash collision);
210 // ((frag value) << 28) | (the nth entry in frag);
212 unsigned next_offset
; // offset of next chunk (last_name's + 1)
213 string last_name
; // last entry in previous chunk
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
223 vector
<dentry
> buffer
;
227 class Client
: public Dispatcher
, public md_config_obs_t
{
229 friend class C_Block_Sync
; // Calls block map and protected helpers
230 friend class C_Client_CacheInvalidate
; // calls ino_invalidate_cb
231 friend class C_Client_DentryInvalidate
; // calls dentry_invalidate_cb
232 friend class C_Client_FlushComplete
; // calls put_inode()
233 friend class C_Client_Remount
;
234 friend class C_Client_RequestInterrupt
;
235 friend class C_Deleg_Timeout
; // Asserts on client_lock, called when a delegation is unreturned
236 friend class C_Client_CacheRelease
; // Asserts on client_lock
237 friend class SyntheticClient
;
238 friend void intrusive_ptr_release(Inode
*in
);
240 using Dispatcher::cct
;
242 typedef int (*add_dirent_cb_t
)(void *p
, struct dirent
*de
, struct ceph_statx
*stx
, off_t off
, Inode
*in
);
244 class CommandHook
: public AdminSocketHook
{
246 explicit CommandHook(Client
*client
);
247 int call(std::string_view command
, const cmdmap_t
& cmdmap
,
250 bufferlist
& out
) override
;
255 Client(Messenger
*m
, MonClient
*mc
, Objecter
*objecter_
);
256 Client(const Client
&) = delete;
257 Client(const Client
&&) = delete;
258 virtual ~Client() override
;
260 static UserPerm
pick_my_perms(CephContext
*c
) {
261 uid_t uid
= c
->_conf
->client_mount_uid
>= 0 ? c
->_conf
->client_mount_uid
: -1;
262 gid_t gid
= c
->_conf
->client_mount_gid
>= 0 ? c
->_conf
->client_mount_gid
: -1;
263 return UserPerm(uid
, gid
);
265 UserPerm
pick_my_perms() {
266 uid_t uid
= user_id
>= 0 ? user_id
: -1;
267 gid_t gid
= group_id
>= 0 ? group_id
: -1;
268 return UserPerm(uid
, gid
);
271 int mount(const std::string
&mount_root
, const UserPerm
& perms
,
272 bool require_mds
=false, const std::string
&fs_name
="");
276 void set_uuid(const std::string
& uuid
);
277 void set_session_timeout(unsigned timeout
);
278 int start_reclaim(const std::string
& uuid
, unsigned flags
,
279 const std::string
& fs_name
);
280 void finish_reclaim();
282 fs_cluster_id_t
get_fs_cid() {
287 const std::string
&mds_spec
,
288 const std::vector
<std::string
>& cmd
,
289 const bufferlist
& inbl
,
290 bufferlist
*poutbl
, std::string
*prs
, Context
*onfinish
);
292 // these should (more or less) mirror the actual system calls.
293 int statfs(const char *path
, struct statvfs
*stbuf
, const UserPerm
& perms
);
296 int chdir(const char *s
, std::string
&new_cwd
, const UserPerm
& perms
);
297 void _getcwd(std::string
& cwd
, const UserPerm
& perms
);
298 void getcwd(std::string
& cwd
, const UserPerm
& perms
);
301 int opendir(const char *name
, dir_result_t
**dirpp
, const UserPerm
& perms
);
302 int closedir(dir_result_t
*dirp
);
305 * Fill a directory listing from dirp, invoking cb for each entry
306 * with the given pointer, the dirent, the struct stat, the stmask,
309 * Returns 0 if it reached the end of the directory.
310 * If @a cb returns a negative error code, stop and return that.
312 int readdir_r_cb(dir_result_t
*dirp
, add_dirent_cb_t cb
, void *p
,
313 unsigned want
=0, unsigned flags
=AT_NO_ATTR_SYNC
,
316 struct dirent
* readdir(dir_result_t
*d
);
317 int readdir_r(dir_result_t
*dirp
, struct dirent
*de
);
318 int readdirplus_r(dir_result_t
*dirp
, struct dirent
*de
, struct ceph_statx
*stx
, unsigned want
, unsigned flags
, Inode
**out
);
320 int getdir(const char *relpath
, list
<string
>& names
,
321 const UserPerm
& perms
); // get the whole dir at once.
324 * Returns the length of the buffer that got filled in, or -errno.
325 * If it returns -ERANGE you just need to increase the size of the
326 * buffer and try again.
328 int _getdents(dir_result_t
*dirp
, char *buf
, int buflen
, bool ful
); // get a bunch of dentries at once
329 int getdents(dir_result_t
*dirp
, char *buf
, int buflen
) {
330 return _getdents(dirp
, buf
, buflen
, true);
332 int getdnames(dir_result_t
*dirp
, char *buf
, int buflen
) {
333 return _getdents(dirp
, buf
, buflen
, false);
336 void rewinddir(dir_result_t
*dirp
);
337 loff_t
telldir(dir_result_t
*dirp
);
338 void seekdir(dir_result_t
*dirp
, loff_t offset
);
340 int link(const char *existing
, const char *newname
, const UserPerm
& perm
);
341 int unlink(const char *path
, const UserPerm
& perm
);
342 int rename(const char *from
, const char *to
, const UserPerm
& perm
);
345 int mkdir(const char *path
, mode_t mode
, const UserPerm
& perm
);
346 int mkdirs(const char *path
, mode_t mode
, const UserPerm
& perms
);
347 int rmdir(const char *path
, const UserPerm
& perms
);
350 int readlink(const char *path
, char *buf
, loff_t size
, const UserPerm
& perms
);
352 int symlink(const char *existing
, const char *newname
, const UserPerm
& perms
);
355 unsigned statx_to_mask(unsigned int flags
, unsigned int want
);
356 int stat(const char *path
, struct stat
*stbuf
, const UserPerm
& perms
,
357 frag_info_t
*dirstat
=0, int mask
=CEPH_STAT_CAP_INODE_ALL
);
358 int statx(const char *path
, struct ceph_statx
*stx
,
359 const UserPerm
& perms
,
360 unsigned int want
, unsigned int flags
);
361 int lstat(const char *path
, struct stat
*stbuf
, const UserPerm
& perms
,
362 frag_info_t
*dirstat
=0, int mask
=CEPH_STAT_CAP_INODE_ALL
);
364 int setattr(const char *relpath
, struct stat
*attr
, int mask
,
365 const UserPerm
& perms
);
366 int setattrx(const char *relpath
, struct ceph_statx
*stx
, int mask
,
367 const UserPerm
& perms
, int flags
=0);
368 int fsetattr(int fd
, struct stat
*attr
, int mask
, const UserPerm
& perms
);
369 int fsetattrx(int fd
, struct ceph_statx
*stx
, int mask
, const UserPerm
& perms
);
370 int chmod(const char *path
, mode_t mode
, const UserPerm
& perms
);
371 int fchmod(int fd
, mode_t mode
, const UserPerm
& perms
);
372 int lchmod(const char *path
, mode_t mode
, const UserPerm
& perms
);
373 int chown(const char *path
, uid_t new_uid
, gid_t new_gid
,
374 const UserPerm
& perms
);
375 int fchown(int fd
, uid_t new_uid
, gid_t new_gid
, const UserPerm
& perms
);
376 int lchown(const char *path
, uid_t new_uid
, gid_t new_gid
,
377 const UserPerm
& perms
);
378 int utime(const char *path
, struct utimbuf
*buf
, const UserPerm
& perms
);
379 int lutime(const char *path
, struct utimbuf
*buf
, const UserPerm
& perms
);
380 int futime(int fd
, struct utimbuf
*buf
, const UserPerm
& perms
);
381 int utimes(const char *relpath
, struct timeval times
[2], const UserPerm
& perms
);
382 int lutimes(const char *relpath
, struct timeval times
[2], const UserPerm
& perms
);
383 int futimes(int fd
, struct timeval times
[2], const UserPerm
& perms
);
384 int futimens(int fd
, struct timespec times
[2], const UserPerm
& perms
);
385 int flock(int fd
, int operation
, uint64_t owner
);
386 int truncate(const char *path
, loff_t size
, const UserPerm
& perms
);
389 int mknod(const char *path
, mode_t mode
, const UserPerm
& perms
, dev_t rdev
=0);
390 int open(const char *path
, int flags
, const UserPerm
& perms
, mode_t mode
=0);
391 int open(const char *path
, int flags
, const UserPerm
& perms
,
392 mode_t mode
, int stripe_unit
, int stripe_count
, int object_size
,
393 const char *data_pool
);
394 int lookup_hash(inodeno_t ino
, inodeno_t dirino
, const char *name
,
395 const UserPerm
& perms
);
396 int lookup_ino(inodeno_t ino
, const UserPerm
& perms
, Inode
**inode
=NULL
);
397 int lookup_name(Inode
*in
, Inode
*parent
, const UserPerm
& perms
);
399 loff_t
lseek(int fd
, loff_t offset
, int whence
);
400 int read(int fd
, char *buf
, loff_t size
, loff_t offset
=-1);
401 int preadv(int fd
, const struct iovec
*iov
, int iovcnt
, loff_t offset
=-1);
402 int write(int fd
, const char *buf
, loff_t size
, loff_t offset
=-1);
403 int pwritev(int fd
, const struct iovec
*iov
, int iovcnt
, loff_t offset
=-1);
404 int fake_write_size(int fd
, loff_t size
);
405 int ftruncate(int fd
, loff_t size
, const UserPerm
& perms
);
406 int fsync(int fd
, bool syncdataonly
);
407 int fstat(int fd
, struct stat
*stbuf
, const UserPerm
& perms
,
408 int mask
=CEPH_STAT_CAP_INODE_ALL
);
409 int fstatx(int fd
, struct ceph_statx
*stx
, const UserPerm
& perms
,
410 unsigned int want
, unsigned int flags
);
411 int fallocate(int fd
, int mode
, loff_t offset
, loff_t length
);
413 // full path xattr ops
414 int getxattr(const char *path
, const char *name
, void *value
, size_t size
,
415 const UserPerm
& perms
);
416 int lgetxattr(const char *path
, const char *name
, void *value
, size_t size
,
417 const UserPerm
& perms
);
418 int fgetxattr(int fd
, const char *name
, void *value
, size_t size
,
419 const UserPerm
& perms
);
420 int listxattr(const char *path
, char *list
, size_t size
, const UserPerm
& perms
);
421 int llistxattr(const char *path
, char *list
, size_t size
, const UserPerm
& perms
);
422 int flistxattr(int fd
, char *list
, size_t size
, const UserPerm
& perms
);
423 int removexattr(const char *path
, const char *name
, const UserPerm
& perms
);
424 int lremovexattr(const char *path
, const char *name
, const UserPerm
& perms
);
425 int fremovexattr(int fd
, const char *name
, const UserPerm
& perms
);
426 int setxattr(const char *path
, const char *name
, const void *value
,
427 size_t size
, int flags
, const UserPerm
& perms
);
428 int lsetxattr(const char *path
, const char *name
, const void *value
,
429 size_t size
, int flags
, const UserPerm
& perms
);
430 int fsetxattr(int fd
, const char *name
, const void *value
, size_t size
,
431 int flags
, const UserPerm
& perms
);
434 int64_t drop_caches();
437 int lazyio(int fd
, int enable
);
438 int lazyio_propagate(int fd
, loff_t offset
, size_t count
);
439 int lazyio_synchronize(int fd
, loff_t offset
, size_t count
);
441 // expose file layout
442 int describe_layout(const char *path
, file_layout_t
* layout
,
443 const UserPerm
& perms
);
444 int fdescribe_layout(int fd
, file_layout_t
* layout
);
445 int get_file_stripe_address(int fd
, loff_t offset
, vector
<entity_addr_t
>& address
);
446 int get_file_extent_osds(int fd
, loff_t off
, loff_t
*len
, vector
<int>& osds
);
447 int get_osd_addr(int osd
, entity_addr_t
& addr
);
450 int64_t get_default_pool_id();
454 int get_pool_replication(int64_t pool
);
455 int64_t get_pool_id(const char *pool_name
);
456 string
get_pool_name(int64_t pool
);
457 int get_osd_crush_location(int id
, vector
<pair
<string
, string
> >& path
);
459 int enumerate_layout(int fd
, vector
<ObjectExtent
>& result
,
460 loff_t length
, loff_t offset
);
462 int mksnap(const char *path
, const char *name
, const UserPerm
& perm
);
463 int rmsnap(const char *path
, const char *name
, const UserPerm
& perm
);
465 // Inode permission checking
466 int inode_permission(Inode
*in
, const UserPerm
& perms
, unsigned want
);
469 int get_caps_issued(int fd
);
470 int get_caps_issued(const char *path
, const UserPerm
& perms
);
472 snapid_t
ll_get_snapid(Inode
*in
);
473 vinodeno_t
ll_get_vino(Inode
*in
) {
474 std::lock_guard
lock(client_lock
);
475 return _get_vino(in
);
477 // get inode from faked ino
478 Inode
*ll_get_inode(ino_t ino
);
479 Inode
*ll_get_inode(vinodeno_t vino
);
480 int ll_lookup(Inode
*parent
, const char *name
, struct stat
*attr
,
481 Inode
**out
, const UserPerm
& perms
);
482 int ll_lookup_inode(struct inodeno_t ino
, const UserPerm
& perms
, Inode
**inode
);
483 int ll_lookupx(Inode
*parent
, const char *name
, Inode
**out
,
484 struct ceph_statx
*stx
, unsigned want
, unsigned flags
,
485 const UserPerm
& perms
);
486 bool ll_forget(Inode
*in
, uint64_t count
);
487 bool ll_put(Inode
*in
);
488 int ll_get_snap_ref(snapid_t snap
);
490 int ll_getattr(Inode
*in
, struct stat
*st
, const UserPerm
& perms
);
491 int ll_getattrx(Inode
*in
, struct ceph_statx
*stx
, unsigned int want
,
492 unsigned int flags
, const UserPerm
& perms
);
493 int ll_setattrx(Inode
*in
, struct ceph_statx
*stx
, int mask
,
494 const UserPerm
& perms
);
495 int ll_setattr(Inode
*in
, struct stat
*st
, int mask
,
496 const UserPerm
& perms
);
497 int ll_getxattr(Inode
*in
, const char *name
, void *value
, size_t size
,
498 const UserPerm
& perms
);
499 int ll_setxattr(Inode
*in
, const char *name
, const void *value
, size_t size
,
500 int flags
, const UserPerm
& perms
);
501 int ll_removexattr(Inode
*in
, const char *name
, const UserPerm
& perms
);
502 int ll_listxattr(Inode
*in
, char *list
, size_t size
, const UserPerm
& perms
);
503 int ll_opendir(Inode
*in
, int flags
, dir_result_t
**dirpp
,
504 const UserPerm
& perms
);
505 int ll_releasedir(dir_result_t
* dirp
);
506 int ll_fsyncdir(dir_result_t
* dirp
);
507 int ll_readlink(Inode
*in
, char *buf
, size_t bufsize
, const UserPerm
& perms
);
508 int ll_mknod(Inode
*in
, const char *name
, mode_t mode
, dev_t rdev
,
509 struct stat
*attr
, Inode
**out
, const UserPerm
& perms
);
510 int ll_mknodx(Inode
*parent
, const char *name
, mode_t mode
, dev_t rdev
,
511 Inode
**out
, struct ceph_statx
*stx
, unsigned want
,
512 unsigned flags
, const UserPerm
& perms
);
513 int ll_mkdir(Inode
*in
, const char *name
, mode_t mode
, struct stat
*attr
,
514 Inode
**out
, const UserPerm
& perm
);
515 int ll_mkdirx(Inode
*parent
, const char *name
, mode_t mode
, Inode
**out
,
516 struct ceph_statx
*stx
, unsigned want
, unsigned flags
,
517 const UserPerm
& perms
);
518 int ll_symlink(Inode
*in
, const char *name
, const char *value
,
519 struct stat
*attr
, Inode
**out
, const UserPerm
& perms
);
520 int ll_symlinkx(Inode
*parent
, const char *name
, const char *value
,
521 Inode
**out
, struct ceph_statx
*stx
, unsigned want
,
522 unsigned flags
, const UserPerm
& perms
);
523 int ll_unlink(Inode
*in
, const char *name
, const UserPerm
& perm
);
524 int ll_rmdir(Inode
*in
, const char *name
, const UserPerm
& perms
);
525 int ll_rename(Inode
*parent
, const char *name
, Inode
*newparent
,
526 const char *newname
, const UserPerm
& perm
);
527 int ll_link(Inode
*in
, Inode
*newparent
, const char *newname
,
528 const UserPerm
& perm
);
529 int ll_open(Inode
*in
, int flags
, Fh
**fh
, const UserPerm
& perms
);
530 int _ll_create(Inode
*parent
, const char *name
, mode_t mode
,
531 int flags
, InodeRef
*in
, int caps
, Fh
**fhp
,
532 const UserPerm
& perms
);
533 int ll_create(Inode
*parent
, const char *name
, mode_t mode
, int flags
,
534 struct stat
*attr
, Inode
**out
, Fh
**fhp
,
535 const UserPerm
& perms
);
536 int ll_createx(Inode
*parent
, const char *name
, mode_t mode
,
537 int oflags
, Inode
**outp
, Fh
**fhp
,
538 struct ceph_statx
*stx
, unsigned want
, unsigned lflags
,
539 const UserPerm
& perms
);
540 int ll_read_block(Inode
*in
, uint64_t blockid
, char *buf
, uint64_t offset
,
541 uint64_t length
, file_layout_t
* layout
);
543 int ll_write_block(Inode
*in
, uint64_t blockid
,
544 char* buf
, uint64_t offset
,
545 uint64_t length
, file_layout_t
* layout
,
546 uint64_t snapseq
, uint32_t sync
);
547 int ll_commit_blocks(Inode
*in
, uint64_t offset
, uint64_t length
);
549 int ll_statfs(Inode
*in
, struct statvfs
*stbuf
, const UserPerm
& perms
);
550 int ll_walk(const char* name
, Inode
**i
, struct ceph_statx
*stx
,
551 unsigned int want
, unsigned int flags
, const UserPerm
& perms
);
552 uint32_t ll_stripe_unit(Inode
*in
);
553 int ll_file_layout(Inode
*in
, file_layout_t
*layout
);
554 uint64_t ll_snap_seq(Inode
*in
);
556 int ll_read(Fh
*fh
, loff_t off
, loff_t len
, bufferlist
*bl
);
557 int ll_write(Fh
*fh
, loff_t off
, loff_t len
, const char *data
);
558 int64_t ll_readv(struct Fh
*fh
, const struct iovec
*iov
, int iovcnt
, int64_t off
);
559 int64_t ll_writev(struct Fh
*fh
, const struct iovec
*iov
, int iovcnt
, int64_t off
);
560 loff_t
ll_lseek(Fh
*fh
, loff_t offset
, int whence
);
561 int ll_flush(Fh
*fh
);
562 int ll_fsync(Fh
*fh
, bool syncdataonly
);
563 int ll_sync_inode(Inode
*in
, bool syncdataonly
);
564 int ll_fallocate(Fh
*fh
, int mode
, int64_t offset
, int64_t length
);
565 int ll_release(Fh
*fh
);
566 int ll_getlk(Fh
*fh
, struct flock
*fl
, uint64_t owner
);
567 int ll_setlk(Fh
*fh
, struct flock
*fl
, uint64_t owner
, int sleep
);
568 int ll_flock(Fh
*fh
, int cmd
, uint64_t owner
);
569 int ll_lazyio(Fh
*fh
, int enable
);
570 int ll_file_layout(Fh
*fh
, file_layout_t
*layout
);
571 void ll_interrupt(void *d
);
572 bool ll_handle_umask() {
573 return acl_type
!= NO_ACL
;
576 int ll_get_stripe_osd(struct Inode
*in
, uint64_t blockno
,
577 file_layout_t
* layout
);
578 uint64_t ll_get_internal_offset(struct Inode
*in
, uint64_t blockno
);
580 int ll_num_osds(void);
581 int ll_osdaddr(int osd
, uint32_t *addr
);
582 int ll_osdaddr(int osd
, char* buf
, size_t size
);
584 void ll_register_callbacks(struct ceph_client_callback_args
*args
);
585 int test_dentry_handling(bool can_invalidate
);
587 const char** get_tracked_conf_keys() const override
;
588 void handle_conf_change(const ConfigProxy
& conf
,
589 const std::set
<std::string
> &changed
) override
;
590 uint32_t get_deleg_timeout() { return deleg_timeout
; }
591 int set_deleg_timeout(uint32_t timeout
);
592 int ll_delegation(Fh
*fh
, unsigned cmd
, ceph_deleg_cb_t cb
, void *priv
);
594 entity_name_t
get_myname() { return messenger
->get_myname(); }
595 void wait_on_list(std::list
<ceph::condition_variable
*>& ls
);
596 void signal_cond_list(std::list
<ceph::condition_variable
*>& ls
);
598 void set_filer_flags(int flags
);
599 void clear_filer_flags(int flags
);
601 void tear_down_cache();
603 void update_metadata(std::string
const &k
, std::string
const &v
);
605 client_t
get_nodeid() { return whoami
; }
607 inodeno_t
get_root_ino();
611 virtual void shutdown();
614 void handle_mds_map(const MConstRef
<MMDSMap
>& m
);
615 void handle_fs_map(const MConstRef
<MFSMap
>& m
);
616 void handle_fs_map_user(const MConstRef
<MFSMapUser
>& m
);
617 void handle_osd_map(const MConstRef
<MOSDMap
>& m
);
619 void handle_lease(const MConstRef
<MClientLease
>& m
);
622 int uninline_data(Inode
*in
, Context
*onfinish
);
625 void check_cap_issue(Inode
*in
, unsigned issued
);
626 void add_update_cap(Inode
*in
, MetaSession
*session
, uint64_t cap_id
,
627 unsigned issued
, unsigned wanted
, unsigned seq
, unsigned mseq
,
628 inodeno_t realm
, int flags
, const UserPerm
& perms
);
629 void remove_cap(Cap
*cap
, bool queue_release
);
630 void remove_all_caps(Inode
*in
);
631 void remove_session_caps(MetaSession
*session
, int err
);
632 int mark_caps_flushing(Inode
*in
, ceph_tid_t
*ptid
);
633 void adjust_session_flushing_caps(Inode
*in
, MetaSession
*old_s
, MetaSession
*new_s
);
634 void flush_caps_sync();
635 void kick_flushing_caps(Inode
*in
, MetaSession
*session
);
636 void kick_flushing_caps(MetaSession
*session
);
637 void early_kick_flushing_caps(MetaSession
*session
);
638 int get_caps(Fh
*fh
, int need
, int want
, int *have
, loff_t endoff
);
639 int get_caps_used(Inode
*in
);
641 void maybe_update_snaprealm(SnapRealm
*realm
, snapid_t snap_created
, snapid_t snap_highwater
,
642 vector
<snapid_t
>& snaps
);
644 void handle_quota(const MConstRef
<MClientQuota
>& m
);
645 void handle_snap(const MConstRef
<MClientSnap
>& m
);
646 void handle_caps(const MConstRef
<MClientCaps
>& m
);
647 void handle_cap_import(MetaSession
*session
, Inode
*in
, const MConstRef
<MClientCaps
>& m
);
648 void handle_cap_export(MetaSession
*session
, Inode
*in
, const MConstRef
<MClientCaps
>& m
);
649 void handle_cap_trunc(MetaSession
*session
, Inode
*in
, const MConstRef
<MClientCaps
>& m
);
650 void handle_cap_flush_ack(MetaSession
*session
, Inode
*in
, Cap
*cap
, const MConstRef
<MClientCaps
>& m
);
651 void handle_cap_flushsnap_ack(MetaSession
*session
, Inode
*in
, const MConstRef
<MClientCaps
>& m
);
652 void handle_cap_grant(MetaSession
*session
, Inode
*in
, Cap
*cap
, const MConstRef
<MClientCaps
>& m
);
653 void cap_delay_requeue(Inode
*in
);
655 void send_cap(Inode
*in
, MetaSession
*session
, Cap
*cap
, int flags
,
656 int used
, int want
, int retain
, int flush
,
657 ceph_tid_t flush_tid
);
659 void send_flush_snap(Inode
*in
, MetaSession
*session
, snapid_t follows
, CapSnap
& capsnap
);
661 void flush_snaps(Inode
*in
);
662 void get_cap_ref(Inode
*in
, int cap
);
663 void put_cap_ref(Inode
*in
, int cap
);
664 void wait_sync_caps(Inode
*in
, ceph_tid_t want
);
665 void wait_sync_caps(ceph_tid_t want
);
666 void queue_cap_snap(Inode
*in
, SnapContext
&old_snapc
);
667 void finish_cap_snap(Inode
*in
, CapSnap
&capsnap
, int used
);
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
);
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
);
678 void _schedule_ino_release_callback(Inode
*in
);
679 void _async_inode_release(vinodeno_t ino
);
681 bool _release(Inode
*in
);
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.
692 * @returns true if the data was already flushed, false otherwise.
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
);
699 void close_release(Inode
*in
);
700 void close_safe(Inode
*in
);
702 void lock_fh_pos(Fh
*f
);
703 void unlock_fh_pos(Fh
*f
);
706 void update_dir_dist(Inode
*in
, DirStat
*st
);
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
);
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
);
723 bool use_faked_inos() { return _use_faked_inos
; }
724 vinodeno_t
map_faked_ino(ino_t ino
);
726 //notify the mds to flush the mdlog
727 void flush_mdlog_sync();
728 void flush_mdlog(MetaSession
*session
);
731 void renew_caps(MetaSession
*session
);
732 void flush_cap_releases();
735 xlist
<Inode
*> &get_dirty_list() { return dirty_list
; }
739 std::unique_ptr
<PerfCounters
> logger
;
740 std::unique_ptr
<MDSMap
> mdsmap
;
742 bool fuse_default_permissions
;
745 /* Flags for check_caps() */
746 static const unsigned CHECK_CAPS_NODELAY
= 0x1;
747 static const unsigned CHECK_CAPS_SYNCHRONOUS
= 0x2;
750 bool is_initialized() const { return initialized
; }
752 void check_caps(Inode
*in
, unsigned flags
);
754 void set_cap_epoch_barrier(epoch_t e
);
756 void handle_command_reply(const MConstRef
<MCommandReply
>& m
);
757 int fetch_fsmap(bool user
);
759 const std::string
&mds_spec
,
760 std::vector
<mds_gid_t
> *targets
);
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
, int err
=0, bool rejected
=false);
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();
777 void _sync_write_commit(Inode
*in
);
779 void dump_mds_requests(Formatter
*f
);
780 void dump_mds_sessions(Formatter
*f
, bool cap_dump
=false);
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
);
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
);
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
);
816 // Optional extra metadata about me to send to the MDS
817 void populate_metadata(const std::string
&mount_root
);
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
);
826 Inode
*open_snapdir(Inode
*diri
);
829 int fd
= free_fd_set
.range_start();
830 free_fd_set
.erase(fd
, 1);
833 void put_fd(int fd
) {
834 free_fd_set
.insert(fd
, 1);
838 * Resolve file descriptor, or return NULL.
840 Fh
*get_filehandle(int fd
) {
841 ceph::unordered_map
<int, Fh
*>::iterator p
= fd_map
.find(fd
);
842 if (p
== fd_map
.end())
848 void wake_up_session_caps(MetaSession
*s
, bool reconnect
);
850 void wait_on_context_list(list
<Context
*>& ls
);
851 void signal_context_list(list
<Context
*>& ls
);
853 // -- metadata cache stuff
855 // decrease inode ref. delete if dangling.
856 void put_inode(Inode
*in
, int n
=1);
857 void close_dir(Dir
*dir
);
859 int subscribe_mdsmap(const std::string
&fs_name
="");
861 void _abort_mds_sessions(int err
);
863 // same as unmount() but for when the client_lock is already held
864 void _unmount(bool abort
);
866 //int get_cache_size() { return lru.lru_get_size(); }
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
873 Dentry
* link(Dir
*dir
, const string
& name
, Inode
*in
, Dentry
*dn
);
874 void unlink(Dentry
*dn
, bool keepdir
, bool keepdentry
);
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);
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
);
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
);
890 void touch_dn(Dentry
*dn
);
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
);
900 void dump_inode(Formatter
*f
, Inode
*in
, set
<Inode
*>& did
, bool disconnected
);
901 void dump_cache(Formatter
*f
); // debug
904 void force_session_readonly(MetaSession
*s
);
906 void dump_status(Formatter
*f
); // debug
908 bool ms_dispatch2(const MessageRef
& m
) override
;
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
;
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
);
925 int check_pool_perm(Inode
*in
, int need
);
927 void handle_client_reclaim_reply(const MConstRef
<MClientReclaimReply
>& reply
);
930 * Call this when an OSDMap is seen with a full flag (global or per pool)
933 * @param pool the pool ID affected, or -1 if all.
935 void _handle_full_flag(int64_t pool
);
937 void _close_sessions();
942 * The basic housekeeping parts of init (perf counters, admin socket)
943 * that is independent of how objecters/monclient/messengers are
948 // global client lock
949 // - protects Client and buffer cache both!
950 ceph::mutex client_lock
= ceph::make_mutex("Client::client_lock");
953 std::map
<snapid_t
, int> ll_snap_ref
;
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.
962 std::unique_ptr
<Filer
> filer
;
963 std::unique_ptr
<ObjectCacher
> objectcacher
;
964 std::unique_ptr
<WritebackHandler
> writeback_handler
;
966 Messenger
*messenger
;
967 MonClient
*monclient
;
974 struct C_Readahead
: public Context
{
975 C_Readahead(Client
*c
, Fh
*f
);
976 ~C_Readahead() override
;
977 void finish(int r
) override
;
984 * These define virtual xattrs exposing the recursive directory
985 * statistics and layout metadata.
989 size_t (Client::*getxattr_cb
)(Inode
*in
, char *val
, size_t size
);
991 bool (Client::*exists_cb
)(Inode
*in
);
1007 /* Flags for VXattr */
1008 static const unsigned VXATTR_RSTAT
= 0x1;
1009 static const unsigned VXATTR_DIRSTAT
= 0x2;
1011 static const VXattr _dir_vxattrs
[];
1012 static const VXattr _file_vxattrs
[];
1013 static const VXattr _common_vxattrs
[];
1017 void fill_dirent(struct dirent
*de
, const char *name
, int type
, uint64_t ino
, loff_t next_off
);
1019 int _opendir(Inode
*in
, dir_result_t
**dirpp
, const UserPerm
& perms
);
1020 void _readdir_drop_dirp_buffer(dir_result_t
*dirp
);
1021 bool _readdir_have_frag(dir_result_t
*dirp
);
1022 void _readdir_next_frag(dir_result_t
*dirp
);
1023 void _readdir_rechoose_frag(dir_result_t
*dirp
);
1024 int _readdir_get_frag(dir_result_t
*dirp
);
1025 int _readdir_cache_cb(dir_result_t
*dirp
, add_dirent_cb_t cb
, void *p
, int caps
, bool getref
);
1026 void _closedir(dir_result_t
*dirp
);
1029 void _fragmap_remove_non_leaves(Inode
*in
);
1030 void _fragmap_remove_stopped_mds(Inode
*in
, mds_rank_t mds
);
1032 void _ll_get(Inode
*in
);
1033 int _ll_put(Inode
*in
, uint64_t num
);
1034 void _ll_drop_pins();
1036 Fh
*_create_fh(Inode
*in
, int flags
, int cmode
, const UserPerm
& perms
);
1037 int _release_fh(Fh
*fh
);
1038 void _put_fh(Fh
*fh
);
1040 int _do_remount(bool retry_on_error
);
1042 int _read_sync(Fh
*f
, uint64_t off
, uint64_t len
, bufferlist
*bl
, bool *checkeof
);
1043 int _read_async(Fh
*f
, uint64_t off
, uint64_t len
, bufferlist
*bl
);
1045 // internal interface
1046 // call these with client_lock held!
1047 int _do_lookup(Inode
*dir
, const string
& name
, int mask
, InodeRef
*target
,
1048 const UserPerm
& perms
);
1050 int _lookup(Inode
*dir
, const string
& dname
, int mask
, InodeRef
*target
,
1051 const UserPerm
& perm
);
1053 int _link(Inode
*in
, Inode
*dir
, const char *name
, const UserPerm
& perm
,
1055 int _unlink(Inode
*dir
, const char *name
, const UserPerm
& perm
);
1056 int _rename(Inode
*olddir
, const char *oname
, Inode
*ndir
, const char *nname
, const UserPerm
& perm
);
1057 int _mkdir(Inode
*dir
, const char *name
, mode_t mode
, const UserPerm
& perm
,
1059 int _rmdir(Inode
*dir
, const char *name
, const UserPerm
& perms
);
1060 int _symlink(Inode
*dir
, const char *name
, const char *target
,
1061 const UserPerm
& perms
, InodeRef
*inp
= 0);
1062 int _mknod(Inode
*dir
, const char *name
, mode_t mode
, dev_t rdev
,
1063 const UserPerm
& perms
, InodeRef
*inp
= 0);
1064 int _do_setattr(Inode
*in
, struct ceph_statx
*stx
, int mask
,
1065 const UserPerm
& perms
, InodeRef
*inp
);
1066 void stat_to_statx(struct stat
*st
, struct ceph_statx
*stx
);
1067 int __setattrx(Inode
*in
, struct ceph_statx
*stx
, int mask
,
1068 const UserPerm
& perms
, InodeRef
*inp
= 0);
1069 int _setattrx(InodeRef
&in
, struct ceph_statx
*stx
, int mask
,
1070 const UserPerm
& perms
);
1071 int _setattr(InodeRef
&in
, struct stat
*attr
, int mask
,
1072 const UserPerm
& perms
);
1073 int _ll_setattrx(Inode
*in
, struct ceph_statx
*stx
, int mask
,
1074 const UserPerm
& perms
, InodeRef
*inp
= 0);
1075 int _getattr(Inode
*in
, int mask
, const UserPerm
& perms
, bool force
=false);
1076 int _getattr(InodeRef
&in
, int mask
, const UserPerm
& perms
, bool force
=false) {
1077 return _getattr(in
.get(), mask
, perms
, force
);
1079 int _readlink(Inode
*in
, char *buf
, size_t size
);
1080 int _getxattr(Inode
*in
, const char *name
, void *value
, size_t len
,
1081 const UserPerm
& perms
);
1082 int _getxattr(InodeRef
&in
, const char *name
, void *value
, size_t len
,
1083 const UserPerm
& perms
);
1084 int _listxattr(Inode
*in
, char *names
, size_t len
, const UserPerm
& perms
);
1085 int _do_setxattr(Inode
*in
, const char *name
, const void *value
, size_t len
,
1086 int flags
, const UserPerm
& perms
);
1087 int _setxattr(Inode
*in
, const char *name
, const void *value
, size_t len
,
1088 int flags
, const UserPerm
& perms
);
1089 int _setxattr(InodeRef
&in
, const char *name
, const void *value
, size_t len
,
1090 int flags
, const UserPerm
& perms
);
1091 int _setxattr_check_data_pool(string
& name
, string
& value
, const OSDMap
*osdmap
);
1092 void _setxattr_maybe_wait_for_osdmap(const char *name
, const void *value
, size_t len
);
1093 int _removexattr(Inode
*in
, const char *nm
, const UserPerm
& perms
);
1094 int _removexattr(InodeRef
&in
, const char *nm
, const UserPerm
& perms
);
1095 int _open(Inode
*in
, int flags
, mode_t mode
, Fh
**fhp
,
1096 const UserPerm
& perms
);
1097 int _renew_caps(Inode
*in
);
1098 int _create(Inode
*in
, const char *name
, int flags
, mode_t mode
, InodeRef
*inp
,
1099 Fh
**fhp
, int stripe_unit
, int stripe_count
, int object_size
,
1100 const char *data_pool
, bool *created
, const UserPerm
&perms
);
1102 loff_t
_lseek(Fh
*fh
, loff_t offset
, int whence
);
1103 int64_t _read(Fh
*fh
, int64_t offset
, uint64_t size
, bufferlist
*bl
);
1104 int64_t _write(Fh
*fh
, int64_t offset
, uint64_t size
, const char *buf
,
1105 const struct iovec
*iov
, int iovcnt
);
1106 int64_t _preadv_pwritev_locked(Fh
*f
, const struct iovec
*iov
,
1107 unsigned iovcnt
, int64_t offset
, bool write
, bool clamp_to_int
);
1108 int _preadv_pwritev(int fd
, const struct iovec
*iov
, unsigned iovcnt
, int64_t offset
, bool write
);
1110 int _fsync(Fh
*fh
, bool syncdataonly
);
1111 int _fsync(Inode
*in
, bool syncdataonly
);
1113 int _fallocate(Fh
*fh
, int mode
, int64_t offset
, int64_t length
);
1114 int _getlk(Fh
*fh
, struct flock
*fl
, uint64_t owner
);
1115 int _setlk(Fh
*fh
, struct flock
*fl
, uint64_t owner
, int sleep
);
1116 int _flock(Fh
*fh
, int cmd
, uint64_t owner
);
1117 int _lazyio(Fh
*fh
, int enable
);
1119 int get_or_create(Inode
*dir
, const char* name
,
1120 Dentry
**pdn
, bool expect_null
=false);
1122 int xattr_permission(Inode
*in
, const char *name
, unsigned want
,
1123 const UserPerm
& perms
);
1124 int may_setattr(Inode
*in
, struct ceph_statx
*stx
, int mask
,
1125 const UserPerm
& perms
);
1126 int may_open(Inode
*in
, int flags
, const UserPerm
& perms
);
1127 int may_lookup(Inode
*dir
, const UserPerm
& perms
);
1128 int may_create(Inode
*dir
, const UserPerm
& perms
);
1129 int may_delete(Inode
*dir
, const char *name
, const UserPerm
& perms
);
1130 int may_hardlink(Inode
*in
, const UserPerm
& perms
);
1132 int _getattr_for_perm(Inode
*in
, const UserPerm
& perms
);
1134 vinodeno_t
_get_vino(Inode
*in
);
1136 bool _vxattrcb_quota_exists(Inode
*in
);
1137 size_t _vxattrcb_quota(Inode
*in
, char *val
, size_t size
);
1138 size_t _vxattrcb_quota_max_bytes(Inode
*in
, char *val
, size_t size
);
1139 size_t _vxattrcb_quota_max_files(Inode
*in
, char *val
, size_t size
);
1141 bool _vxattrcb_layout_exists(Inode
*in
);
1142 size_t _vxattrcb_layout(Inode
*in
, char *val
, size_t size
);
1143 size_t _vxattrcb_layout_stripe_unit(Inode
*in
, char *val
, size_t size
);
1144 size_t _vxattrcb_layout_stripe_count(Inode
*in
, char *val
, size_t size
);
1145 size_t _vxattrcb_layout_object_size(Inode
*in
, char *val
, size_t size
);
1146 size_t _vxattrcb_layout_pool(Inode
*in
, char *val
, size_t size
);
1147 size_t _vxattrcb_layout_pool_namespace(Inode
*in
, char *val
, size_t size
);
1148 size_t _vxattrcb_dir_entries(Inode
*in
, char *val
, size_t size
);
1149 size_t _vxattrcb_dir_files(Inode
*in
, char *val
, size_t size
);
1150 size_t _vxattrcb_dir_subdirs(Inode
*in
, char *val
, size_t size
);
1151 size_t _vxattrcb_dir_rentries(Inode
*in
, char *val
, size_t size
);
1152 size_t _vxattrcb_dir_rfiles(Inode
*in
, char *val
, size_t size
);
1153 size_t _vxattrcb_dir_rsubdirs(Inode
*in
, char *val
, size_t size
);
1154 size_t _vxattrcb_dir_rbytes(Inode
*in
, char *val
, size_t size
);
1155 size_t _vxattrcb_dir_rctime(Inode
*in
, char *val
, size_t size
);
1157 bool _vxattrcb_dir_pin_exists(Inode
*in
);
1158 size_t _vxattrcb_dir_pin(Inode
*in
, char *val
, size_t size
);
1160 bool _vxattrcb_snap_btime_exists(Inode
*in
);
1161 size_t _vxattrcb_snap_btime(Inode
*in
, char *val
, size_t size
);
1163 size_t _vxattrcb_cluster_fsid(Inode
*in
, char *val
, size_t size
);
1164 size_t _vxattrcb_client_id(Inode
*in
, char *val
, size_t size
);
1166 static const VXattr
*_get_vxattrs(Inode
*in
);
1167 static const VXattr
*_match_vxattr(Inode
*in
, const char *name
);
1169 int _do_filelock(Inode
*in
, Fh
*fh
, int lock_type
, int op
, int sleep
,
1170 struct flock
*fl
, uint64_t owner
, bool removing
=false);
1171 int _interrupt_filelock(MetaRequest
*req
);
1172 void _encode_filelocks(Inode
*in
, bufferlist
& bl
);
1173 void _release_filelocks(Fh
*fh
);
1174 void _update_lock_state(struct flock
*fl
, uint64_t owner
, ceph_lock_state_t
*lock_state
);
1176 int _posix_acl_create(Inode
*dir
, mode_t
*mode
, bufferlist
& xattrs_bl
,
1177 const UserPerm
& perms
);
1178 int _posix_acl_chmod(Inode
*in
, mode_t mode
, const UserPerm
& perms
);
1179 int _posix_acl_permission(Inode
*in
, const UserPerm
& perms
, unsigned want
);
1181 mds_rank_t
_get_random_up_mds() const;
1183 int _ll_getattr(Inode
*in
, int caps
, const UserPerm
& perms
);
1184 int _lookup_parent(Inode
*in
, const UserPerm
& perms
, Inode
**parent
=NULL
);
1185 int _lookup_name(Inode
*in
, Inode
*parent
, const UserPerm
& perms
);
1186 int _lookup_ino(inodeno_t ino
, const UserPerm
& perms
, Inode
**inode
=NULL
);
1187 bool _ll_forget(Inode
*in
, uint64_t count
);
1190 uint32_t deleg_timeout
= 0;
1192 client_switch_interrupt_callback_t switch_interrupt_cb
= nullptr;
1193 client_remount_callback_t remount_cb
= nullptr;
1194 client_ino_callback_t ino_invalidate_cb
= nullptr;
1195 client_dentry_callback_t dentry_invalidate_cb
= nullptr;
1196 client_umask_callback_t umask_cb
= nullptr;
1197 client_ino_release_t ino_release_cb
= nullptr;
1198 void *callback_handle
= nullptr;
1199 bool can_invalidate_dentries
= false;
1201 Finisher async_ino_invalidator
;
1202 Finisher async_dentry_invalidator
;
1203 Finisher interrupt_finisher
;
1204 Finisher remount_finisher
;
1205 Finisher async_ino_releasor
;
1206 Finisher objecter_finisher
;
1208 Context
*tick_event
= nullptr;
1209 utime_t last_cap_renew
;
1211 CommandHook m_command_hook
;
1213 int user_id
, group_id
;
1214 int acl_type
= NO_ACL
;
1216 epoch_t cap_epoch_barrier
= 0;
1219 map
<mds_rank_t
, MetaSession
> mds_sessions
; // mds -> push seq
1220 std::set
<mds_rank_t
> mds_ranks_closing
; // mds ranks currently tearing down sessions
1221 std::list
<ceph::condition_variable
*> waiting_for_mdsmap
;
1223 // FSMap, for when using mds_command
1224 std::list
<ceph::condition_variable
*> waiting_for_fsmap
;
1225 std::unique_ptr
<FSMap
> fsmap
;
1226 std::unique_ptr
<FSMapUser
> fsmap_user
;
1228 // MDS command state
1229 CommandTable
<MDSCommandOp
> command_table
;
1231 bool _use_faked_inos
;
1234 fs_cluster_id_t fscid
;
1236 // file handles, etc.
1237 interval_set
<int> free_fd_set
; // unused fds
1238 ceph::unordered_map
<int, Fh
*> fd_map
;
1239 set
<Fh
*> ll_unclosed_fh_set
;
1240 ceph::unordered_set
<dir_result_t
*> opened_dirs
;
1241 uint64_t fd_gen
= 1;
1243 bool initialized
= false;
1244 bool mounted
= false;
1245 bool unmounting
= false;
1246 bool blacklisted
= false;
1248 ceph::unordered_map
<vinodeno_t
, Inode
*> inode_map
;
1249 ceph::unordered_map
<ino_t
, vinodeno_t
> faked_ino_map
;
1250 interval_set
<ino_t
> free_faked_inos
;
1251 ino_t last_used_faked_ino
;
1252 ino_t last_used_faked_root
;
1254 int local_osd
= -ENXIO
;
1255 epoch_t local_osd_epoch
= 0;
1257 int unsafe_sync_write
= 0;
1260 ceph_tid_t last_tid
= 0;
1261 ceph_tid_t oldest_tid
= 0; // oldest incomplete mds request, excluding setfilelock requests
1262 map
<ceph_tid_t
, MetaRequest
*> mds_requests
;
1265 ceph_tid_t last_flush_tid
= 1;
1267 // dirty_list keeps all the dirty inodes before flushing.
1268 xlist
<Inode
*> delayed_list
, dirty_list
;
1269 int num_flushing_caps
= 0;
1270 ceph::unordered_map
<inodeno_t
,SnapRealm
*> snap_realms
;
1271 std::map
<std::string
, std::string
> metadata
;
1273 utime_t last_auto_reconnect
;
1278 ceph::condition_variable mount_cond
, sync_cond
;
1280 std::map
<std::pair
<int64_t,std::string
>, int> pool_perms
;
1281 std::list
<ceph::condition_variable
*> waiting_for_pool_perm
;
1283 uint64_t retries_on_invalidate
= 0;
1286 std::list
<ceph::condition_variable
*> waiting_for_reclaim
;
1287 int reclaim_errno
= 0;
1288 epoch_t reclaim_osd_epoch
= 0;
1289 entity_addrvec_t reclaim_target_addrs
;
1293 * Specialization of Client that manages its own Objecter instance
1294 * and handles init/shutdown of messenger/monclient
1296 class StandaloneClient
: public Client
1299 StandaloneClient(Messenger
*m
, MonClient
*mc
);
1301 ~StandaloneClient() override
;
1303 int init() override
;
1304 void shutdown() override
;