xref: /openbmc/linux/fs/smb/client/cached_dir.h (revision e5242c5f)
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 
18 	struct cifs_fattr fattr;
19 };
20 
21 struct cached_dirents {
22 	bool is_valid:1;
23 	bool is_failed:1;
24 	struct dir_context *ctx; /*
25 				  * Only used to make sure we only take entries
26 				  * from a single context. Never dereferenced.
27 				  */
28 	struct mutex de_mutex;
29 	int pos;		 /* Expected ctx->pos */
30 	struct list_head entries;
31 };
32 
33 struct cached_fid {
34 	struct list_head entry;
35 	struct cached_fids *cfids;
36 	const char *path;
37 	bool has_lease:1;
38 	bool is_open:1;
39 	bool on_list:1;
40 	bool file_all_info_is_valid:1;
41 	unsigned long time; /* jiffies of when lease was taken */
42 	struct kref refcount;
43 	struct cifs_fid fid;
44 	spinlock_t fid_lock;
45 	struct cifs_tcon *tcon;
46 	struct dentry *dentry;
47 	struct work_struct put_work;
48 	struct work_struct close_work;
49 	struct smb2_file_all_info file_all_info;
50 	struct cached_dirents dirents;
51 };
52 
53 /* default MAX_CACHED_FIDS is 16 */
54 struct cached_fids {
55 	/* Must be held when:
56 	 * - accessing the cfids->entries list
57 	 * - accessing the cfids->dying list
58 	 */
59 	spinlock_t cfid_list_lock;
60 	int num_entries;
61 	struct list_head entries;
62 	struct list_head dying;
63 	struct work_struct invalidation_work;
64 	struct delayed_work laundromat_work;
65 };
66 
67 extern struct cached_fids *init_cached_dirs(void);
68 extern void free_cached_dirs(struct cached_fids *cfids);
69 extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
70 			   const char *path,
71 			   struct cifs_sb_info *cifs_sb,
72 			   bool lookup_only, struct cached_fid **cfid);
73 extern int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
74 				     struct dentry *dentry,
75 				     struct cached_fid **cfid);
76 extern void close_cached_dir(struct cached_fid *cfid);
77 extern void drop_cached_dir_by_name(const unsigned int xid,
78 				    struct cifs_tcon *tcon,
79 				    const char *name,
80 				    struct cifs_sb_info *cifs_sb);
81 extern void close_all_cached_dirs(struct cifs_sb_info *cifs_sb);
82 extern void invalidate_all_cached_dirs(struct cifs_tcon *tcon);
83 extern int cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16]);
84 
85 #endif			/* _CACHED_DIR_H */
86