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;
51 /* wildcard file name */
52 struct pcc_match_fname {
54 struct list_head pmf_linkage;
65 struct pcc_expression {
66 enum pcc_field pe_field;
67 struct list_head pe_cond;
68 struct list_head pe_linkage;
71 struct pcc_conjunction {
72 /* link to disjunction */
73 struct list_head pc_linkage;
74 /* list of logical conjunction */
75 struct list_head pc_expressions;
79 * Match rule for auto PCC-cached files.
81 struct pcc_match_rule {
83 struct list_head pmr_conds;
93 enum pcc_dataset_flags {
94 PCC_DATASET_NONE = 0x0,
95 /* Try auto attach at open, enabled by default */
96 PCC_DATASET_OPEN_ATTACH = 0x01,
97 /* Try auto attach during IO when layout refresh, enabled by default */
98 PCC_DATASET_IO_ATTACH = 0x02,
99 /* Try auto attach at stat */
100 PCC_DATASET_STAT_ATTACH = 0x04,
101 PCC_DATASET_AUTO_ATTACH = PCC_DATASET_OPEN_ATTACH |
102 PCC_DATASET_IO_ATTACH |
103 PCC_DATASET_STAT_ATTACH,
104 /* PCC backend is only used for RW-PCC */
105 PCC_DATASET_RWPCC = 0x08,
106 /* PCC backend is only used for RO-PCC */
107 PCC_DATASET_ROPCC = 0x10,
108 /* PCC backend provides caching services for both RW-PCC and RO-PCC */
109 PCC_DATASET_PCC_ALL = PCC_DATASET_RWPCC | PCC_DATASET_ROPCC,
113 __u32 pccd_rwid; /* Archive ID */
114 __u32 pccd_roid; /* Readonly ID */
115 struct pcc_match_rule pccd_rule; /* Match rule */
116 enum pcc_dataset_flags pccd_flags; /* flags of PCC backend */
117 char pccd_pathname[PATH_MAX]; /* full path */
118 struct path pccd_path; /* Root path */
119 struct list_head pccd_linkage; /* Linked to pccs_datasets */
120 atomic_t pccd_refcount; /* Reference count */
124 /* Protect pccs_datasets */
125 struct rw_semaphore pccs_rw_sem;
126 /* List of datasets */
127 struct list_head pccs_datasets;
128 /* creds of process who forced instantiation of super block */
129 const struct cred *pccs_cred;
133 struct ll_inode_info *pcci_lli;
134 /* Cache path on local file system */
135 struct path pcci_path;
137 * If reference count is 0, then the cache is not inited, if 1, then
138 * no one is using it.
140 atomic_t pcci_refcount;
141 /* Whether readonly or readwrite PCC */
142 enum lu_pcc_type pcci_type;
143 /* Whether the inode attr is cached locally */
144 bool pcci_attr_valid;
145 /* Layout generation */
146 __u32 pcci_layout_gen;
148 * How many IOs are on going on this cached object. Layout can be
149 * changed only if there is no active IO.
151 atomic_t pcci_active_ios;
152 /* Waitq - wait for PCC I/O completion. */
153 wait_queue_head_t pcci_waitq;
157 /* Opened cache file */
158 struct file *pccf_file;
159 /* Whether readonly or readwrite PCC */
160 enum lu_pcc_type pccf_type;
164 /* read system call */
166 /* write system call */
168 /* truncate, utime system calls */
170 /* stat system call */
172 /* mmap write handling */
174 /* page fault handling */
176 /* fsync system call handling */
178 /* splice_read system call */
189 enum pcc_cmd_type pccc_cmd;
195 struct list_head pccc_conds;
196 char *pccc_conds_str;
197 enum pcc_dataset_flags pccc_flags;
205 struct pcc_create_attach {
206 struct pcc_dataset *pca_dataset;
207 struct dentry *pca_dentry;
210 int pcc_super_init(struct pcc_super *super);
211 void pcc_super_fini(struct pcc_super *super);
212 int pcc_cmd_handle(char *buffer, unsigned long count,
213 struct pcc_super *super);
214 int pcc_super_dump(struct pcc_super *super, struct seq_file *m);
215 int pcc_readwrite_attach(struct file *file, struct inode *inode,
217 int pcc_readwrite_attach_fini(struct file *file, struct inode *inode,
218 __u32 gen, bool lease_broken, int rc,
220 int pcc_ioctl_detach(struct inode *inode, __u32 opt);
221 int pcc_ioctl_state(struct file *file, struct inode *inode,
222 struct lu_pcc_state *state);
223 void pcc_file_init(struct pcc_file *pccf);
224 int pcc_file_open(struct inode *inode, struct file *file);
225 void pcc_file_release(struct inode *inode, struct file *file);
226 ssize_t pcc_file_read_iter(struct kiocb *iocb, struct iov_iter *iter,
228 ssize_t pcc_file_write_iter(struct kiocb *iocb, struct iov_iter *iter,
230 int pcc_inode_getattr(struct inode *inode, bool *cached);
231 int pcc_inode_setattr(struct inode *inode, struct iattr *attr, bool *cached);
232 ssize_t pcc_file_splice_read(struct file *in_file, loff_t *ppos,
233 struct pipe_inode_info *pipe, size_t count,
234 unsigned int flags, bool *cached);
235 int pcc_fsync(struct file *file, loff_t start, loff_t end,
236 int datasync, bool *cached);
237 int pcc_file_mmap(struct file *file, struct vm_area_struct *vma, bool *cached);
238 void pcc_vm_open(struct vm_area_struct *vma);
239 void pcc_vm_close(struct vm_area_struct *vma);
240 int pcc_fault(struct vm_area_struct *mva, struct vm_fault *vmf, bool *cached);
241 int pcc_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
243 int pcc_inode_create(struct super_block *sb, struct pcc_dataset *dataset,
244 struct lu_fid *fid, struct dentry **pcc_dentry);
245 int pcc_inode_create_fini(struct inode *inode, struct pcc_create_attach *pca);
246 void pcc_create_attach_cleanup(struct super_block *sb,
247 struct pcc_create_attach *pca);
248 struct pcc_dataset *pcc_dataset_match_get(struct pcc_super *super,
249 struct pcc_matcher *matcher);
250 void pcc_dataset_put(struct pcc_dataset *dataset);
251 void pcc_inode_free(struct inode *inode);
252 void pcc_layout_invalidate(struct inode *inode);
253 #endif /* LLITE_PCC_H */