Whamcloud - gitweb
LU-10092 llite: Add persistent cache on client
[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 <uapi/linux/lustre/lustre_user.h>
39
40 extern struct kmem_cache *pcc_inode_slab;
41
42 #define LPROCFS_WR_PCC_MAX_CMD 4096
43
44 struct pcc_dataset {
45         __u32                   pccd_id;         /* Archive ID */
46         __u32                   pccd_projid;     /* Project ID */
47         char                    pccd_pathname[PATH_MAX]; /* full path */
48         struct path             pccd_path;       /* Root path */
49         struct list_head        pccd_linkage;  /* Linked to pccs_datasets */
50         atomic_t                pccd_refcount; /* reference count */
51 };
52
53 struct pcc_super {
54         spinlock_t              pccs_lock;      /* Protect pccs_datasets */
55         struct list_head        pccs_datasets;  /* List of datasets */
56 };
57
58 struct pcc_inode {
59         /* Cache path on local file system */
60         struct path                      pcci_path;
61         /*
62          * If reference count is 0, then the cache is not inited, if 1, then
63          * no one is using it.
64          */
65         atomic_t                         pcci_refcount;
66         /* Whether readonly or readwrite PCC */
67         enum lu_pcc_type                 pcci_type;
68         /* Whether the inode is cached locally */
69         bool                             pcci_attr_valid;
70 };
71
72 struct pcc_file {
73         /* Opened cache file */
74         struct file             *pccf_file;
75         /* Whether readonly or readwrite PCC */
76         enum lu_pcc_type         pccf_type;
77 };
78
79 enum pcc_cmd_type {
80         PCC_ADD_DATASET = 0,
81         PCC_DEL_DATASET,
82         PCC_CLEAR_ALL,
83 };
84
85 struct pcc_cmd {
86         enum pcc_cmd_type                        pccc_cmd;
87         char                                    *pccc_pathname;
88         union {
89                 struct pcc_cmd_add {
90                         __u32                    pccc_id;
91                         __u32                    pccc_projid;
92                 } pccc_add;
93                 struct pcc_cmd_del {
94                         __u32                    pccc_pad;
95                 } pccc_del;
96         } u;
97 };
98
99 void pcc_super_init(struct pcc_super *super);
100 void pcc_super_fini(struct pcc_super *super);
101 int pcc_cmd_handle(char *buffer, unsigned long count,
102                    struct pcc_super *super);
103 int
104 pcc_super_dump(struct pcc_super *super, struct seq_file *m);
105 int pcc_readwrite_attach(struct file *file,
106                          struct inode *inode, __u32 arch_id);
107 int pcc_readwrite_attach_fini(struct file *file, struct inode *inode,
108                               bool lease_broken, int rc, bool attached);
109 int pcc_ioctl_detach(struct inode *inode);
110 int pcc_ioctl_state(struct inode *inode, struct lu_pcc_state *state);
111 void pcc_file_init(struct pcc_file *pccf);
112 int pcc_file_open(struct inode *inode, struct file *file);
113 void pcc_file_release(struct inode *inode, struct file *file);
114 ssize_t pcc_file_read_iter(struct kiocb *iocb, struct iov_iter *iter,
115                            bool *cached);
116 ssize_t pcc_file_write_iter(struct kiocb *iocb, struct iov_iter *iter,
117                             bool *cached);
118 int pcc_inode_getattr(struct inode *inode, bool *cached);
119 int pcc_inode_setattr(struct inode *inode, struct iattr *attr, bool *cached);
120 int pcc_inode_create(struct pcc_dataset *dataset, struct lu_fid *fid,
121                      struct dentry **pcc_dentry);
122 int pcc_inode_create_fini(struct pcc_dataset *dataset, struct inode *inode,
123                           struct dentry *pcc_dentry);
124 struct pcc_dataset *
125 pcc_dataset_get(struct pcc_super *super, __u32 projid, __u32 archive_id);
126 void pcc_dataset_put(struct pcc_dataset *dataset);
127 void pcc_inode_free(struct inode *inode);
128 #endif /* LLITE_PCC_H */