Whamcloud - gitweb
7e4996e20b9deb3f3a26d94217079d7964e89ae6
[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 struct pcc_dataset {
46         __u32                   pccd_id;         /* Archive ID */
47         __u32                   pccd_projid;     /* Project ID */
48         char                    pccd_pathname[PATH_MAX]; /* full path */
49         struct path             pccd_path;       /* Root path */
50         struct list_head        pccd_linkage;  /* Linked to pccs_datasets */
51         atomic_t                pccd_refcount; /* reference count */
52 };
53
54 struct pcc_super {
55         /* Protect pccs_datasets */
56         spinlock_t               pccs_lock;
57         /* List of datasets */
58         struct list_head         pccs_datasets;
59         /* creds of process who forced instantiation of super block */
60         const struct cred       *pccs_cred;
61 };
62
63 struct pcc_inode {
64         struct ll_inode_info    *pcci_lli;
65         /* Cache path on local file system */
66         struct path              pcci_path;
67         /*
68          * If reference count is 0, then the cache is not inited, if 1, then
69          * no one is using it.
70          */
71         atomic_t                 pcci_refcount;
72         /* Whether readonly or readwrite PCC */
73         enum lu_pcc_type         pcci_type;
74         /* Whether the inode attr is cached locally */
75         bool                     pcci_attr_valid;
76         /* Layout generation */
77         __u32                    pcci_layout_gen;
78         /*
79          * How many IOs are on going on this cached object. Layout can be
80          * changed only if there is no active IO.
81          */
82         atomic_t                 pcci_active_ios;
83         /* Waitq - wait for PCC I/O completion. */
84         wait_queue_head_t        pcci_waitq;
85 };
86
87 struct pcc_file {
88         /* Opened cache file */
89         struct file             *pccf_file;
90         /* Whether readonly or readwrite PCC */
91         enum lu_pcc_type         pccf_type;
92 };
93
94 enum pcc_cmd_type {
95         PCC_ADD_DATASET = 0,
96         PCC_DEL_DATASET,
97         PCC_CLEAR_ALL,
98 };
99
100 struct pcc_cmd {
101         enum pcc_cmd_type                        pccc_cmd;
102         char                                    *pccc_pathname;
103         union {
104                 struct pcc_cmd_add {
105                         __u32                    pccc_id;
106                         __u32                    pccc_projid;
107                 } pccc_add;
108                 struct pcc_cmd_del {
109                         __u32                    pccc_pad;
110                 } pccc_del;
111         } u;
112 };
113
114 int pcc_super_init(struct pcc_super *super);
115 void pcc_super_fini(struct pcc_super *super);
116 int pcc_cmd_handle(char *buffer, unsigned long count,
117                    struct pcc_super *super);
118 int pcc_super_dump(struct pcc_super *super, struct seq_file *m);
119 int pcc_readwrite_attach(struct file *file, struct inode *inode,
120                          __u32 arch_id);
121 int pcc_readwrite_attach_fini(struct file *file, struct inode *inode,
122                               __u32 gen, bool lease_broken, int rc,
123                               bool attached);
124 int pcc_ioctl_detach(struct inode *inode);
125 int pcc_ioctl_state(struct file *file, struct inode *inode,
126                     struct lu_pcc_state *state);
127 void pcc_file_init(struct pcc_file *pccf);
128 int pcc_file_open(struct inode *inode, struct file *file);
129 void pcc_file_release(struct inode *inode, struct file *file);
130 ssize_t pcc_file_read_iter(struct kiocb *iocb, struct iov_iter *iter,
131                            bool *cached);
132 ssize_t pcc_file_write_iter(struct kiocb *iocb, struct iov_iter *iter,
133                             bool *cached);
134 int pcc_inode_getattr(struct inode *inode, bool *cached);
135 int pcc_inode_setattr(struct inode *inode, struct iattr *attr, bool *cached);
136 ssize_t pcc_file_splice_read(struct file *in_file, loff_t *ppos,
137                              struct pipe_inode_info *pipe, size_t count,
138                              unsigned int flags, bool *cached);
139 int pcc_fsync(struct file *file, loff_t start, loff_t end,
140               int datasync, bool *cached);
141 int pcc_file_mmap(struct file *file, struct vm_area_struct *vma, bool *cached);
142 void pcc_vm_open(struct vm_area_struct *vma);
143 void pcc_vm_close(struct vm_area_struct *vma);
144 int pcc_fault(struct vm_area_struct *mva, struct vm_fault *vmf, bool *cached);
145 int pcc_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
146                      bool *cached);
147 int pcc_inode_create(struct super_block *sb, struct pcc_dataset *dataset,
148                      struct lu_fid *fid, struct dentry **pcc_dentry);
149 int pcc_inode_create_fini(struct pcc_dataset *dataset, struct inode *inode,
150                            struct dentry *pcc_dentry);
151 struct pcc_dataset *pcc_dataset_get(struct pcc_super *super, __u32 projid,
152                                     __u32 archive_id);
153 void pcc_dataset_put(struct pcc_dataset *dataset);
154 void pcc_inode_free(struct inode *inode);
155 void pcc_layout_invalidate(struct inode *inode);
156
157 #endif /* LLITE_PCC_H */