1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Functions to handle the cached directory entries 4 * 5 * Copyright (c) 2022, Ronnie Sahlberg <lsahlber@redhat.com> 6 */ 7 8 #ifndef _CACHED_DIR_H 9 #define _CACHED_DIR_H 10 11 12 struct cached_dirent { 13 struct list_head entry; 14 char *name; 15 int namelen; 16 loff_t pos; 17 struct cifs_fattr fattr; 18 }; 19 20 struct cached_dirents { 21 bool is_valid:1; 22 bool is_failed:1; 23 struct file *file; /* 24 * Used to associate the cache with a single 25 * open file instance. 26 */ 27 struct mutex de_mutex; 28 loff_t pos; /* Expected ctx->pos */ 29 struct list_head entries; 30 /* accounting for cached entries in this directory */ 31 unsigned long entries_count; 32 unsigned long bytes_used; 33 }; 34 35 struct cached_fid { 36 struct list_head entry; 37 struct cached_fids *cfids; 38 const char *path; 39 bool has_lease:1; 40 bool is_open:1; 41 bool on_list:1; 42 bool file_all_info_is_valid:1; 43 unsigned long time; /* jiffies of when lease was taken */ 44 unsigned long last_access_time; /* jiffies of when last accessed */ 45 struct kref refcount; 46 struct cifs_fid fid; 47 struct cifs_tcon *tcon; 48 struct dentry *dentry; 49 struct work_struct put_work; 50 struct work_struct close_work; 51 struct smb2_file_all_info file_all_info; 52 struct cached_dirents dirents; 53 }; 54 55 /* default MAX_CACHED_FIDS is 16 */ 56 struct cached_fids { 57 /* Must be held when: 58 * - accessing the cfids->entries list 59 * - accessing the cfids->dying list 60 */ 61 spinlock_t cfid_list_lock; 62 int num_entries; 63 struct list_head entries; 64 struct list_head dying; 65 struct work_struct invalidation_work; 66 struct delayed_work laundromat_work; 67 /* aggregate accounting for all cached dirents under this tcon */ 68 atomic_long_t total_dirents_entries; 69 atomic64_t total_dirents_bytes; 70 }; 71 72 /* Module-wide directory cache accounting (defined in cifsfs.c) */ 73 extern atomic64_t cifs_dircache_bytes_used; /* bytes across all mounts */ 74 75 static inline bool 76 is_valid_cached_dir(struct cached_fid *cfid) 77 { 78 return cfid->time && cfid->has_lease; 79 } 80 81 extern struct cached_fids *init_cached_dirs(void); 82 extern void free_cached_dirs(struct cached_fids *cfids); 83 extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, 84 const char *path, 85 struct cifs_sb_info *cifs_sb, 86 bool lookup_only, struct cached_fid **cfid); 87 extern int open_cached_dir_by_dentry(struct cifs_tcon *tcon, 88 struct dentry *dentry, 89 struct cached_fid **cfid); 90 extern void close_cached_dir(struct cached_fid *cfid); 91 extern void drop_cached_dir_by_name(const unsigned int xid, 92 struct cifs_tcon *tcon, 93 const char *name, 94 struct cifs_sb_info *cifs_sb); 95 extern void close_all_cached_dirs(struct cifs_sb_info *cifs_sb); 96 extern void invalidate_all_cached_dirs(struct cifs_tcon *tcon); 97 extern bool cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16]); 98 99 #endif /* _CACHED_DIR_H */ 100