4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2017, DDN Storage Corporation.
27 * Persistent Client Cache
29 * Author: Li Xi <lixi@ddn.com>
35 #include <linux/types.h>
37 #include <linux/seq_file.h>
39 #include <uapi/linux/lustre/lustre_user.h>
41 extern struct kmem_cache *pcc_inode_slab;
43 #define LPROCFS_WR_PCC_MAX_CMD 4096
45 /* User/Group/Project ID */
48 struct list_head pmi_linkage;
52 struct pcc_match_size {
54 struct list_head pms_linkage;
57 /* wildcard file name */
58 struct pcc_match_fname {
60 struct list_head pmf_linkage;
78 PCC_FIELD_OP_INV = PCC_FIELD_MAX,
81 struct pcc_expression {
82 struct list_head pe_linkage;
83 enum pcc_field pe_field;
84 enum pcc_field_op pe_opc;
86 struct list_head pe_cond;
87 __u64 pe_size; /* file size in bytes */
88 __u64 pe_mtime; /* relative age in seconds */
89 __u32 pe_id; /* UID/GID/PROJID */
93 struct pcc_conjunction {
94 /* link to disjunction */
95 struct list_head pc_linkage;
96 /* list of logical conjunction */
97 struct list_head pc_expressions;
101 * Match rule for auto PCC-cached files.
103 struct pcc_match_rule {
105 struct list_head pmr_conds;
114 struct qstr *pm_name;
117 enum pcc_dataset_flags {
118 PCC_DATASET_INVALID = 0x0,
119 /* Indicate that known the file is not in PCC. */
120 PCC_DATASET_NONE = 0x01,
121 /* Try auto attach at open, enabled by default */
122 PCC_DATASET_OPEN_ATTACH = 0x02,
123 /* Try auto attach during IO when layout refresh, enabled by default */
124 PCC_DATASET_IO_ATTACH = 0x04,
125 /* Try auto attach at stat */
126 PCC_DATASET_STAT_ATTACH = 0x08,
127 PCC_DATASET_AUTO_ATTACH = PCC_DATASET_OPEN_ATTACH |
128 PCC_DATASET_IO_ATTACH |
129 PCC_DATASET_STAT_ATTACH,
130 /* PCC backend is only used for PCC-RW */
131 PCC_DATASET_PCCRW = 0x10,
132 /* PCC backend is only used for PCC-RO */
133 PCC_DATASET_PCCRO = 0x20,
134 /* PCC backend provides caching services for both PCC-RW and PCC-RO */
135 PCC_DATASET_PCC_ALL = PCC_DATASET_PCCRW | PCC_DATASET_PCCRO,
136 /* Default PCC caching mode: PCC-RO mode */
137 PCC_DATASET_PCC_DEFAULT = PCC_DATASET_PCCRO,
141 __u32 pccd_rwid; /* Archive ID */
142 __u32 pccd_roid; /* Readonly ID */
143 struct pcc_match_rule pccd_rule; /* Match rule */
144 enum pcc_dataset_flags pccd_flags; /* Flags of PCC backend */
145 char pccd_pathname[PATH_MAX]; /* full path */
146 struct path pccd_path; /* Root path */
147 struct list_head pccd_linkage; /* Linked to pccs_datasets */
148 atomic_t pccd_refcount; /* Reference count */
149 enum hsmtool_type pccd_hsmtool_type; /*HSM copytool type */
153 /* Protect pccs_datasets */
154 struct rw_semaphore pccs_rw_sem;
155 /* List of datasets */
156 struct list_head pccs_datasets;
157 /* creds of process who forced instantiation of super block */
158 const struct cred *pccs_cred;
160 * Gobal PCC Generation: it will be increased once the configuration
161 * for PCC is changed, i.e. add or delete a PCC backend, modify the
162 * parameters for PCC.
164 __u64 pccs_generation;
168 struct ll_inode_info *pcci_lli;
169 /* Cache path on local file system */
170 struct path pcci_path;
172 * If reference count is 0, then the cache is not inited, if 1, then
173 * no one is using it.
175 atomic_t pcci_refcount;
176 /* Whether readonly or readwrite PCC */
177 enum lu_pcc_type pcci_type:8;
178 /* Whether the inode attr is cached locally */
179 bool pcci_attr_valid;
180 /* Whether the PCC inode is unlinked at detach */
182 /* Layout generation */
183 __u32 pcci_layout_gen;
185 * How many IOs are on going on this cached object. Layout can be
186 * changed only if there is no active IO.
188 atomic_t pcci_active_ios;
189 /* Waitq - wait for PCC I/O completion. */
190 wait_queue_head_t pcci_waitq;
194 /* Opened cache file */
195 struct file *pccf_file;
196 /* Whether readonly or readwrite PCC */
197 enum lu_pcc_type pccf_type;
201 /* read system call */
203 /* write system call */
205 /* truncate, utime system calls */
207 /* stat system call */
209 /* mmap write handling */
211 /* page fault handling */
213 /* fsync system call handling */
215 /* splice_read system call */
217 /* open system call */
228 enum pcc_cmd_type pccc_cmd;
234 struct list_head pccc_conds;
235 char *pccc_conds_str;
236 enum pcc_dataset_flags pccc_flags;
237 enum hsmtool_type pccc_hsmtool_type;
245 struct pcc_create_attach {
246 struct pcc_dataset *pca_dataset;
247 struct dentry *pca_dentry;
250 int pcc_super_init(struct pcc_super *super);
251 void pcc_super_fini(struct pcc_super *super);
252 int pcc_cmd_handle(char *buffer, unsigned long count,
253 struct pcc_super *super);
254 int pcc_super_dump(struct pcc_super *super, struct seq_file *m);
255 int pcc_readwrite_attach(struct file *file, struct inode *inode,
257 int pcc_readwrite_attach_fini(struct file *file, struct inode *inode,
258 __u32 gen, bool lease_broken, int rc,
260 int pcc_ioctl_attach(struct file *file, struct inode *inode,
261 struct lu_pcc_attach *attach);
262 int pcc_ioctl_detach(struct inode *inode, __u32 *flags);
263 int pcc_ioctl_state(struct file *file, struct inode *inode,
264 struct lu_pcc_state *state);
265 void pcc_file_init(struct pcc_file *pccf);
266 int pcc_file_open(struct inode *inode, struct file *file);
267 void pcc_file_release(struct inode *inode, struct file *file);
268 ssize_t pcc_file_read_iter(struct kiocb *iocb, struct iov_iter *iter,
270 ssize_t pcc_file_write_iter(struct kiocb *iocb, struct iov_iter *iter,
272 int pcc_inode_getattr(struct inode *inode, u32 request_mask,
273 unsigned int flags, bool *cached);
274 int pcc_inode_setattr(struct inode *inode, struct iattr *attr, bool *cached);
275 #ifdef HAVE_DEFAULT_FILE_SPLICE_READ_EXPORT
276 ssize_t pcc_file_splice_read(struct file *in_file, loff_t *ppos,
277 struct pipe_inode_info *pipe, size_t count,
280 int pcc_fsync(struct file *file, loff_t start, loff_t end,
281 int datasync, bool *cached);
282 int pcc_file_mmap(struct file *file, struct vm_area_struct *vma, bool *cached);
283 void pcc_vm_open(struct vm_area_struct *vma);
284 void pcc_vm_close(struct vm_area_struct *vma);
285 int pcc_fault(struct vm_area_struct *mva, struct vm_fault *vmf, bool *cached);
286 int pcc_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
288 int pcc_inode_create(struct super_block *sb, struct pcc_dataset *dataset,
289 struct lu_fid *fid, struct dentry **pcc_dentry);
290 int pcc_inode_create_fini(struct inode *inode, struct pcc_create_attach *pca);
291 void pcc_create_attach_cleanup(struct super_block *sb,
292 struct pcc_create_attach *pca);
293 struct pcc_dataset *pcc_dataset_match_get(struct pcc_super *super,
294 enum lu_pcc_type type,
295 struct pcc_matcher *matcher);
296 void pcc_dataset_put(struct pcc_dataset *dataset);
297 void pcc_inode_free(struct inode *inode);
298 void pcc_layout_invalidate(struct inode *inode);
299 #endif /* LLITE_PCC_H */