Whamcloud - gitweb
r=zab,phil
[fs/lustre-release.git] / lustre / include / linux / lustre_fsfilt.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <info@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Filesystem interface helper.
22  *
23  */
24
25 #ifndef _LUSTRE_FSFILT_H
26 #define _LUSTRE_FSFILT_H
27
28 #ifdef __KERNEL__
29
30 #include <linux/obd.h>
31
32 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd,
33                             void *data, int error);
34
35 struct fsfilt_objinfo {
36         struct dentry *fso_dentry;
37         int fso_bufcnt;
38 };
39
40 struct fsfilt_operations {
41         struct list_head fs_list;
42         struct module *fs_owner;
43         char   *fs_type;
44         void   *(* fs_start)(struct inode *inode, int op, void *desc_private);
45         void   *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
46                                  int niocount, void *desc_private);
47         int     (* fs_commit)(struct inode *inode, void *handle,int force_sync);
48         int     (* fs_commit_async)(struct inode *inode, void *handle,
49                                         void **wait_handle);
50         int     (* fs_commit_wait)(struct inode *inode, void *handle);
51         int     (* fs_setattr)(struct dentry *dentry, void *handle,
52                                struct iattr *iattr, int do_trunc);
53         int     (* fs_iocontrol)(struct inode *inode, struct file *file,
54                                  unsigned int cmd, unsigned long arg);
55         int     (* fs_set_md)(struct inode *inode, void *handle, void *md,
56                               int size);
57         int     (* fs_get_md)(struct inode *inode, void *md, int size);
58         ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
59                                 loff_t *offset);
60         int     (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
61                                       void *handle, fsfilt_cb_t cb_func,
62                                       void *cb_data);
63         int     (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
64         int     (* fs_sync)(struct super_block *sb);
65         int     (* fs_map_inode_page)(struct inode *inode, struct page *page,
66                                       unsigned long *blocks, int *created,
67                                       int create);
68         int     (* fs_prep_san_write)(struct inode *inode, long *blocks,
69                                       int nblocks, loff_t newsize);
70         int     (* fs_write_record)(struct file *, void *, int size, loff_t *,
71                                     int force_sync);
72         int     (* fs_read_record)(struct file *, void *, int size, loff_t *);
73         int     (* fs_setup)(struct super_block *sb);
74 };
75
76 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
77 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
78 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
79 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
80
81 #define FSFILT_OP_UNLINK         1
82 #define FSFILT_OP_RMDIR          2
83 #define FSFILT_OP_RENAME         3
84 #define FSFILT_OP_CREATE         4
85 #define FSFILT_OP_MKDIR          5
86 #define FSFILT_OP_SYMLINK        6
87 #define FSFILT_OP_MKNOD          7
88 #define FSFILT_OP_SETATTR        8
89 #define FSFILT_OP_LINK           9
90 #define FSFILT_OP_CREATE_LOG    10
91 #define FSFILT_OP_UNLINK_LOG    11
92
93 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
94                                  int op, struct obd_trans_info *oti)
95 {
96         unsigned long now = jiffies;
97         void *parent_handle = oti ? oti->oti_handle : NULL;
98         void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle);
99         CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
100
101         if (oti != NULL) {
102                 if (parent_handle == NULL) {
103                         oti->oti_handle = handle;
104                 } else if (handle != parent_handle) {
105                         CERROR("mismatch: parent %p, handle %p, oti %p\n",
106                                parent_handle, handle, oti->oti_handle);
107                         LBUG();
108                 }
109         }
110         if (time_after(jiffies, now + 15 * HZ))
111                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
112         return handle;
113 }
114
115 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
116                                      struct fsfilt_objinfo *fso, int niocount,
117                                      struct obd_trans_info *oti)
118 {
119         unsigned long now = jiffies;
120         void *parent_handle = oti ? oti->oti_handle : NULL;
121         void *handle;
122
123         handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount,
124                                               parent_handle);
125         CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
126
127         if (oti != NULL) {
128                 if (parent_handle == NULL) {
129                         oti->oti_handle = handle;
130                 } else if (handle != parent_handle) {
131                         CERROR("mismatch: parent %p, handle %p, oti %p\n",
132                                parent_handle, handle, oti->oti_handle);
133                         LBUG();
134                 }
135         }
136         if (time_after(jiffies, now + 15 * HZ))
137                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
138         return handle;
139 }
140
141 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
142                                 void *handle, int force_sync)
143 {
144         unsigned long now = jiffies;
145         int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
146         CDEBUG(D_HA, "committing handle %p\n", handle);
147         if (time_after(jiffies, now + 15 * HZ))
148                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
149         return rc;
150 }
151
152 static inline int fsfilt_commit_async(struct obd_device *obd,
153                                          struct inode *inode,
154                                          void *handle,
155                                          void **wait_handle)
156 {
157         unsigned long now = jiffies;
158         int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
159         CDEBUG(D_HA, "committing handle %p (async)\n", *wait_handle);
160         if (time_after(jiffies, now + 15 * HZ))
161                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
162         return rc;
163 }
164
165 static inline int fsfilt_commit_wait(struct obd_device *obd, struct inode *inode,
166                                         void *handle)
167 {
168         unsigned long now = jiffies;
169         int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
170         CDEBUG(D_HA, "waiting for completion %p\n", handle);
171         if (time_after(jiffies, now + 15 * HZ))
172                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
173         return rc;
174 }
175
176 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
177                                  void *handle, struct iattr *iattr,int do_trunc)
178 {
179         unsigned long now = jiffies;
180         int rc;
181         rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
182         if (time_after(jiffies, now + 15 * HZ))
183                 CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
184         return rc;
185 }
186
187 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
188                                    struct file *file, unsigned int cmd,
189                                    unsigned long arg)
190 {
191         return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
192 }
193
194 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
195                                 void *handle, void *md, int size)
196 {
197         return obd->obd_fsops->fs_set_md(inode, handle, md, size);
198 }
199
200 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
201                                 void *md, int size)
202 {
203         return obd->obd_fsops->fs_get_md(inode, md, size);
204 }
205
206 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
207                                       struct file *file, char *buf,
208                                       size_t count, loff_t *offset)
209 {
210         return obd->obd_fsops->fs_readpage(file, buf, count, offset);
211 }
212
213 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
214                                         void *handle, fsfilt_cb_t cb_func,
215                                         void *cb_data)
216 {
217         return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd, handle,
218                                                  cb_func, cb_data);
219 }
220
221 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
222 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
223                                 unsigned long max_age)
224 {
225         int rc = 0;
226
227         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
228         if (time_before(obd->obd_osfs_age, max_age)) {
229                 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
230                 if (rc == 0) /* N.B. statfs can't really fail */
231                         obd->obd_osfs_age = jiffies;
232         } else {
233                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
234         }
235
236         return rc;
237 }
238
239 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
240 {
241         return obd->obd_fsops->fs_sync(sb);
242 }
243
244 static inline int fsfilt_map_inode_page(struct obd_device *obd,
245                                         struct inode *inode, struct page *page,
246                                         unsigned long *blocks, int *created,
247                                         int create)
248 {
249         return obd->obd_fsops->fs_map_inode_page(inode, page, blocks, created,
250                                                  create);
251 }
252
253 static inline int fs_prep_san_write(struct obd_device *obd,
254                                     struct inode *inode,
255                                     long *blocks,
256                                     int nblocks,
257                                     loff_t newsize)
258 {
259         return obd->obd_fsops->fs_prep_san_write(inode, blocks,
260                                                  nblocks, newsize);
261 }
262
263 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
264                                      void *buf, loff_t size, loff_t *offs)
265 {
266         return obd->obd_fsops->fs_read_record(file, buf, size, offs);
267 }
268
269 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
270                                       void *buf, loff_t size, loff_t *offs,
271                                       int force_sync)
272 {
273         return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
274 }
275
276 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
277 {
278         if (obd->obd_fsops->fs_setup)
279                 return obd->obd_fsops->fs_setup(fs);
280         return 0;
281 }
282
283 #endif /* __KERNEL__ */
284
285 #endif