File Index
Files and directories
Sign in
FILE

cached_dir.h

File preview with syntax highlighting.

linux-6.19.14/fs/smb/client/cached_dir.h C
 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
12struct cached_dirent {
13	struct list_head entry;
14	char *name;
15	int namelen;
16	loff_t pos;
17	struct cifs_fattr fattr;
18};
19
20struct 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
35struct cached_fid {
36	struct list_head entry;
37	struct cached_fids *cfids;
38	const char *path;
39	bool has_lease;
40	bool is_open;
41	bool on_list;
42	bool file_all_info_is_valid;
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 */
56struct 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 delayed_work laundromat_work;
66	/* aggregate accounting for all cached dirents under this tcon */
67	atomic_long_t total_dirents_entries;
68	atomic64_t total_dirents_bytes;
69};
70
71/* Module-wide directory cache accounting (defined in cifsfs.c) */
72extern atomic64_t cifs_dircache_bytes_used; /* bytes across all mounts */
73
74static inline bool
75is_valid_cached_dir(struct cached_fid *cfid)
76{
77	return cfid->time && cfid->has_lease;
78}
79
80extern struct cached_fids *init_cached_dirs(void);
81extern void free_cached_dirs(struct cached_fids *cfids);
82extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
83			   const char *path,
84			   struct cifs_sb_info *cifs_sb,
85			   bool lookup_only, struct cached_fid **cfid);
86extern int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
87				     struct dentry *dentry,
88				     struct cached_fid **cfid);
89extern void close_cached_dir(struct cached_fid *cfid);
90extern void drop_cached_dir_by_name(const unsigned int xid,
91				    struct cifs_tcon *tcon,
92				    const char *name,
93				    struct cifs_sb_info *cifs_sb);
94extern void close_all_cached_dirs(struct cifs_sb_info *cifs_sb);
95extern void invalidate_all_cached_dirs(struct cifs_tcon *tcon);
96extern bool cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16]);
97
98#endif			/* _CACHED_DIR_H */
~/ Read-only file preview.