Whamcloud - gitweb
LU-10499 pcc: test interoperability with PCC-RO
[fs/lustre-release.git] / lustre / llite / pcc.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2017, DDN Storage Corporation.
24  */
25 /*
26  *
27  * Persistent Client Cache
28  *
29  * Author: Li Xi <lixi@ddn.com>
30  */
31
32 #ifndef LLITE_PCC_H
33 #define LLITE_PCC_H
34
35 #include <linux/types.h>
36 #include <linux/fs.h>
37 #include <linux/seq_file.h>
38 #include <linux/mm.h>
39 #include <uapi/linux/lustre/lustre_user.h>
40
41 extern struct kmem_cache *pcc_inode_slab;
42
43 #define LPROCFS_WR_PCC_MAX_CMD 4096
44
45 /* User/Group/Project ID */
46 struct pcc_match_id {
47         __u32                   pmi_id;
48         struct list_head        pmi_linkage;
49 };
50
51 /* wildcard file name */
52 struct pcc_match_fname {
53         char                    *pmf_name;
54         struct list_head         pmf_linkage;
55 };
56
57 enum pcc_field {
58         PCC_FIELD_UID,
59         PCC_FIELD_GID,
60         PCC_FIELD_PROJID,
61         PCC_FIELD_FNAME,
62         PCC_FIELD_MAX
63 };
64
65 struct pcc_expression {
66         enum pcc_field          pe_field;
67         struct list_head        pe_cond;
68         struct list_head        pe_linkage;
69 };
70
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;
76 };
77
78 /**
79  * Match rule for auto PCC-cached files.
80  */
81 struct pcc_match_rule {
82         char                    *pmr_conds_str;
83         struct list_head         pmr_conds;
84 };
85
86 struct pcc_matcher {
87         __u32            pm_uid;
88         __u32            pm_gid;
89         __u32            pm_projid;
90         struct qstr     *pm_name;
91 };
92
93 enum pcc_dataset_flags {
94         PCC_DATASET_INVALID     = 0x0,
95         /* Indicate that known the file is not in PCC. */
96         PCC_DATASET_NONE        = 0x01,
97         /* Try auto attach at open, enabled by default */
98         PCC_DATASET_OPEN_ATTACH = 0x02,
99         /* Try auto attach during IO when layout refresh, enabled by default */
100         PCC_DATASET_IO_ATTACH   = 0x04,
101         /* Try auto attach at stat */
102         PCC_DATASET_STAT_ATTACH = 0x08,
103         PCC_DATASET_AUTO_ATTACH = PCC_DATASET_OPEN_ATTACH |
104                                   PCC_DATASET_IO_ATTACH |
105                                   PCC_DATASET_STAT_ATTACH,
106         /* PCC backend is only used for PCC-RW */
107         PCC_DATASET_PCCRW       = 0x10,
108         /* PCC backend is only used for PCC-RO */
109         PCC_DATASET_PCCRO       = 0x20,
110         /* PCC backend provides caching services for both PCC-RW and PCC-RO */
111         PCC_DATASET_PCC_ALL     = PCC_DATASET_PCCRW | PCC_DATASET_PCCRO,
112         /* Default PCC caching mode: PCC-RO mode */
113         PCC_DATASET_PCC_DEFAULT = PCC_DATASET_PCCRO,
114 };
115
116 struct pcc_dataset {
117         __u32                   pccd_rwid;       /* Archive ID */
118         __u32                   pccd_roid;       /* Readonly ID */
119         struct pcc_match_rule   pccd_rule;       /* Match rule */
120         enum pcc_dataset_flags  pccd_flags;      /* Flags of PCC backend */
121         char                    pccd_pathname[PATH_MAX]; /* full path */
122         struct path             pccd_path;       /* Root path */
123         struct list_head        pccd_linkage;  /* Linked to pccs_datasets */
124         atomic_t                pccd_refcount; /* Reference count */
125 };
126
127 struct pcc_super {
128         /* Protect pccs_datasets */
129         struct rw_semaphore      pccs_rw_sem;
130         /* List of datasets */
131         struct list_head         pccs_datasets;
132         /* creds of process who forced instantiation of super block */
133         const struct cred       *pccs_cred;
134         /*
135          * Gobal PCC Generation: it will be increased once the configuration
136          * for PCC is changed, i.e. add or delete a PCC backend, modify the
137          * parameters for PCC.
138          */
139         __u64                    pccs_generation;
140 };
141
142 struct pcc_inode {
143         struct ll_inode_info    *pcci_lli;
144         /* Cache path on local file system */
145         struct path              pcci_path;
146         /*
147          * If reference count is 0, then the cache is not inited, if 1, then
148          * no one is using it.
149          */
150         atomic_t                 pcci_refcount;
151         /* Whether readonly or readwrite PCC */
152         enum lu_pcc_type         pcci_type:8;
153         /* Whether the inode attr is cached locally */
154         bool                     pcci_attr_valid;
155         /* Whether the PCC inode is unlinked at detach */
156         bool                     pcci_unlinked;
157         /* Layout generation */
158         __u32                    pcci_layout_gen;
159         /*
160          * How many IOs are on going on this cached object. Layout can be
161          * changed only if there is no active IO.
162          */
163         atomic_t                 pcci_active_ios;
164         /* Waitq - wait for PCC I/O completion. */
165         wait_queue_head_t        pcci_waitq;
166 };
167
168 struct pcc_file {
169         /* Opened cache file */
170         struct file             *pccf_file;
171         /* Whether readonly or readwrite PCC */
172         enum lu_pcc_type         pccf_type;
173 };
174
175 enum pcc_io_type {
176         /* read system call */
177         PIT_READ = 1,
178         /* write system call */
179         PIT_WRITE,
180         /* truncate, utime system calls */
181         PIT_SETATTR,
182         /* stat system call */
183         PIT_GETATTR,
184         /* mmap write handling */
185         PIT_PAGE_MKWRITE,
186         /* page fault handling */
187         PIT_FAULT,
188         /* fsync system call handling */
189         PIT_FSYNC,
190         /* splice_read system call */
191         PIT_SPLICE_READ,
192         /* open system call */
193         PIT_OPEN
194 };
195
196 enum pcc_cmd_type {
197         PCC_ADD_DATASET = 0,
198         PCC_DEL_DATASET,
199         PCC_CLEAR_ALL,
200 };
201
202 struct pcc_cmd {
203         enum pcc_cmd_type                        pccc_cmd;
204         char                                    *pccc_pathname;
205         union {
206                 struct pcc_cmd_add {
207                         __u32                    pccc_rwid;
208                         __u32                    pccc_roid;
209                         struct list_head         pccc_conds;
210                         char                    *pccc_conds_str;
211                         enum pcc_dataset_flags   pccc_flags;
212                 } pccc_add;
213                 struct pcc_cmd_del {
214                         __u32                    pccc_pad;
215                 } pccc_del;
216         } u;
217 };
218
219 struct pcc_create_attach {
220         struct pcc_dataset *pca_dataset;
221         struct dentry *pca_dentry;
222 };
223
224 int pcc_super_init(struct pcc_super *super);
225 void pcc_super_fini(struct pcc_super *super);
226 int pcc_cmd_handle(char *buffer, unsigned long count,
227                    struct pcc_super *super);
228 int pcc_super_dump(struct pcc_super *super, struct seq_file *m);
229 int pcc_readwrite_attach(struct file *file, struct inode *inode,
230                          __u32 arch_id);
231 int pcc_readwrite_attach_fini(struct file *file, struct inode *inode,
232                               __u32 gen, bool lease_broken, int rc,
233                               bool attached);
234 int pcc_ioctl_attach(struct file *file, struct inode *inode,
235                      struct lu_pcc_attach *attach);
236 int pcc_ioctl_detach(struct inode *inode, __u32 opt);
237 int pcc_ioctl_state(struct file *file, struct inode *inode,
238                     struct lu_pcc_state *state);
239 void pcc_file_init(struct pcc_file *pccf);
240 int pcc_file_open(struct inode *inode, struct file *file);
241 void pcc_file_release(struct inode *inode, struct file *file);
242 ssize_t pcc_file_read_iter(struct kiocb *iocb, struct iov_iter *iter,
243                            bool *cached);
244 ssize_t pcc_file_write_iter(struct kiocb *iocb, struct iov_iter *iter,
245                             bool *cached);
246 int pcc_inode_getattr(struct inode *inode, u32 request_mask,
247                       unsigned int flags, bool *cached);
248 int pcc_inode_setattr(struct inode *inode, struct iattr *attr, bool *cached);
249 #ifdef HAVE_DEFAULT_FILE_SPLICE_READ_EXPORT
250 ssize_t pcc_file_splice_read(struct file *in_file, loff_t *ppos,
251                              struct pipe_inode_info *pipe, size_t count,
252                              unsigned int flags);
253 #endif
254 int pcc_fsync(struct file *file, loff_t start, loff_t end,
255               int datasync, bool *cached);
256 int pcc_file_mmap(struct file *file, struct vm_area_struct *vma, bool *cached);
257 void pcc_vm_open(struct vm_area_struct *vma);
258 void pcc_vm_close(struct vm_area_struct *vma);
259 int pcc_fault(struct vm_area_struct *mva, struct vm_fault *vmf, bool *cached);
260 int pcc_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
261                      bool *cached);
262 int pcc_inode_create(struct super_block *sb, struct pcc_dataset *dataset,
263                      struct lu_fid *fid, struct dentry **pcc_dentry);
264 int pcc_inode_create_fini(struct inode *inode, struct pcc_create_attach *pca);
265 void pcc_create_attach_cleanup(struct super_block *sb,
266                                struct pcc_create_attach *pca);
267 struct pcc_dataset *pcc_dataset_match_get(struct pcc_super *super,
268                                           struct pcc_matcher *matcher);
269 void pcc_dataset_put(struct pcc_dataset *dataset);
270 void pcc_inode_free(struct inode *inode);
271 void pcc_layout_invalidate(struct inode *inode);
272 #endif /* LLITE_PCC_H */