1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Functions to handle the cached directory entries
*
* Copyright (c) 2022, Ronnie Sahlberg <lsahlber@redhat.com>
*/
#ifndef _CACHED_DIR_H
#define _CACHED_DIR_H
#include <linux/workqueue.h>
struct cached_dirent {
struct list_head entry;
char *name;
int namelen;
loff_t pos;
struct cifs_fattr fattr;
};
struct cached_dirents {
bool is_valid:1;
bool is_failed:1;
struct dir_context *ctx; /*
* Only used to make sure we only take entries
* from a single context. Never dereferenced.
*/
struct mutex de_mutex;
int pos; /* Expected ctx->pos */
struct list_head entries;
};
/*
* Internal representation of a cached dir (cfid).
*
* A cfid is valid/exists if it's the cfids->entries list. Otherwise it should be on cfids->dying
* list, where the cleanup worker will free it.
*
* ->refcount is used to keep the object alive to do such validations. It should be get on
* create/alloc or lookups only. It should only be put by close_cached_dir().
*/
struct cached_fid {
/*
* cfid metadata
*/
struct list_head head; /* Element in cfids->entries. Use cfids->lock to modify this */
spinlock_t lock; /* General lock; use it to modify any field _BELOW_! */
struct kref refcount; /* Refcounter for this cifd */
unsigned long time; /* Time when lease was taken (in jiffies), used to check
* dentry revalidation */
/*
* Local on-disk data
*/
const char *path; /* dir path in local disk */
struct dentry *dentry; /* path dentry. dget() when setting it, dput() on free,
* no more, no less */
/*
* Remote info
*/
struct cifs_fid fid; /* File ID information */
struct cifs_tcon *tcon; /* tcon this cfid is cached for */
bool info_valid;
struct smb2_file_all_info info; /* XXX: Can we check a field here to validate it instead? */
struct cached_dirents dirents; /* XXX: What are these for? Could it be merged here? */
};
/* default MAX_CACHED_FIDS is 16 (cf. fs_context.h, maybe move here?) */
struct cached_fids {
spinlock_t lock; /* General lock; use it to modify any field */
struct list_head entries; /* List of cached_fid entries */
int entries_count; /* Number of cached dirs, from 0 to MAX_CACHED_FIDS */
struct list_head dying; /* List of closed cached_fid's that needs to be freed */
struct work_struct work; /* cleanup_cifds work */
struct workqueue_struct *wq; /* Per-tcon (cfids) cleanup workqueue */
};
extern struct cached_fids *init_cached_dirs(void);
extern void destroy_cached_dirs(struct cifs_tcon *tcon, bool teardown);
extern struct cached_fid *find_cached_dir(struct cifs_tcon *tcon, const char *path);
extern void add_cached_dir(struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon, const char *path, struct cifs_fid *fid, struct smb2_file_all_info *info);
extern struct cached_fid *open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
const char *path, struct cifs_sb_info *cifs_sb);
extern struct cached_fid *open_query_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
const char *path, struct cifs_sb_info *cifs_sb);
extern struct cached_fid *open_cached_dir_by_dentry(struct cifs_tcon *tcon, struct dentry *dentry);
extern void close_cached_dir(struct cached_fid *cfid);
extern void close_cached_dir_by_name(struct cached_fids *cfids, const char *path);
extern void cached_dir_lease_break(struct cifs_tcon *tcon, u8 lease_key[16]);
extern void destroy_all_cached_dirs(struct cifs_sb_info *cifs_sb);
#endif /* _CACHED_DIR_H */
|