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