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