Whamcloud - gitweb
LU-10092 pcc: auto attach during open for valid cache
[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_NONE        = 0x0,
95         /* Try auto attach at open, disabled by default */
96         PCC_DATASET_OPEN_ATTACH = 0x1,
97         /* PCC backend is only used for RW-PCC */
98         PCC_DATASET_RWPCC       = 0x2,
99         /* PCC backend is only used for RO-PCC */
100         PCC_DATASET_ROPCC       = 0x4,
101         /* PCC backend provides caching services for both RW-PCC and RO-PCC */
102         PCC_DATASET_PCC_ALL     = PCC_DATASET_RWPCC | PCC_DATASET_ROPCC,
103 };
104
105 struct pcc_dataset {
106         __u32                   pccd_rwid;       /* Archive ID */
107         __u32                   pccd_roid;       /* Readonly ID */
108         struct pcc_match_rule   pccd_rule;       /* Match rule */
109         enum pcc_dataset_flags  pccd_flags;      /* flags of PCC backend */
110         char                    pccd_pathname[PATH_MAX]; /* full path */
111         struct path             pccd_path;       /* Root path */
112         struct list_head        pccd_linkage;  /* Linked to pccs_datasets */
113         atomic_t                pccd_refcount; /* Reference count */
114 };
115
116 struct pcc_super {
117         /* Protect pccs_datasets */
118         struct rw_semaphore      pccs_rw_sem;
119         /* List of datasets */
120         struct list_head         pccs_datasets;
121         /* creds of process who forced instantiation of super block */
122         const struct cred       *pccs_cred;
123 };
124
125 struct pcc_inode {
126         struct ll_inode_info    *pcci_lli;
127         /* Cache path on local file system */
128         struct path              pcci_path;
129         /*
130          * If reference count is 0, then the cache is not inited, if 1, then
131          * no one is using it.
132          */
133         atomic_t                 pcci_refcount;
134         /* Whether readonly or readwrite PCC */
135         enum lu_pcc_type         pcci_type;
136         /* Whether the inode attr is cached locally */
137         bool                     pcci_attr_valid;
138         /* Layout generation */
139         __u32                    pcci_layout_gen;
140         /*
141          * How many IOs are on going on this cached object. Layout can be
142          * changed only if there is no active IO.
143          */
144         atomic_t                 pcci_active_ios;
145         /* Waitq - wait for PCC I/O completion. */
146         wait_queue_head_t        pcci_waitq;
147 };
148
149 struct pcc_file {
150         /* Opened cache file */
151         struct file             *pccf_file;
152         /* Whether readonly or readwrite PCC */
153         enum lu_pcc_type         pccf_type;
154 };
155
156 enum pcc_cmd_type {
157         PCC_ADD_DATASET = 0,
158         PCC_DEL_DATASET,
159         PCC_CLEAR_ALL,
160 };
161
162 struct pcc_cmd {
163         enum pcc_cmd_type                        pccc_cmd;
164         char                                    *pccc_pathname;
165         union {
166                 struct pcc_cmd_add {
167                         __u32                    pccc_rwid;
168                         __u32                    pccc_roid;
169                         struct list_head         pccc_conds;
170                         char                    *pccc_conds_str;
171                         enum pcc_dataset_flags   pccc_flags;
172                 } pccc_add;
173                 struct pcc_cmd_del {
174                         __u32                    pccc_pad;
175                 } pccc_del;
176         } u;
177 };
178
179 int pcc_super_init(struct pcc_super *super);
180 void pcc_super_fini(struct pcc_super *super);
181 int pcc_cmd_handle(char *buffer, unsigned long count,
182                    struct pcc_super *super);
183 int pcc_super_dump(struct pcc_super *super, struct seq_file *m);
184 int pcc_readwrite_attach(struct file *file, struct inode *inode,
185                          __u32 arch_id);
186 int pcc_readwrite_attach_fini(struct file *file, struct inode *inode,
187                               __u32 gen, bool lease_broken, int rc,
188                               bool attached);
189 int pcc_ioctl_detach(struct inode *inode);
190 int pcc_ioctl_state(struct file *file, struct inode *inode,
191                     struct lu_pcc_state *state);
192 void pcc_file_init(struct pcc_file *pccf);
193 int pcc_file_open(struct inode *inode, struct file *file);
194 void pcc_file_release(struct inode *inode, struct file *file);
195 ssize_t pcc_file_read_iter(struct kiocb *iocb, struct iov_iter *iter,
196                            bool *cached);
197 ssize_t pcc_file_write_iter(struct kiocb *iocb, struct iov_iter *iter,
198                             bool *cached);
199 int pcc_inode_getattr(struct inode *inode, bool *cached);
200 int pcc_inode_setattr(struct inode *inode, struct iattr *attr, bool *cached);
201 ssize_t pcc_file_splice_read(struct file *in_file, loff_t *ppos,
202                              struct pipe_inode_info *pipe, size_t count,
203                              unsigned int flags, bool *cached);
204 int pcc_fsync(struct file *file, loff_t start, loff_t end,
205               int datasync, bool *cached);
206 int pcc_file_mmap(struct file *file, struct vm_area_struct *vma, bool *cached);
207 void pcc_vm_open(struct vm_area_struct *vma);
208 void pcc_vm_close(struct vm_area_struct *vma);
209 int pcc_fault(struct vm_area_struct *mva, struct vm_fault *vmf, bool *cached);
210 int pcc_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
211                      bool *cached);
212 int pcc_inode_create(struct super_block *sb, struct pcc_dataset *dataset,
213                      struct lu_fid *fid, struct dentry **pcc_dentry);
214 int pcc_inode_create_fini(struct pcc_dataset *dataset, struct inode *inode,
215                            struct dentry *pcc_dentry);
216 struct pcc_dataset *pcc_dataset_match_get(struct pcc_super *super,
217                                           struct pcc_matcher *matcher);
218 void pcc_dataset_put(struct pcc_dataset *dataset);
219 void pcc_inode_free(struct inode *inode);
220 void pcc_layout_invalidate(struct inode *inode);
221
222 #endif /* LLITE_PCC_H */