Whamcloud - gitweb
Land b1_2 onto HEAD (20040317_2319)
[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 #include <linux/obd_class.h>
32
33 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd,
34                             void *data, int error);
35
36 struct fsfilt_objinfo {
37         struct dentry *fso_dentry;
38         int fso_bufcnt;
39 };
40
41 struct fsfilt_operations {
42         struct list_head fs_list;
43         struct module *fs_owner;
44         char   *fs_type;
45         void   *(* fs_start)(struct inode *inode, int op, void *desc_private,
46                              int logs);
47         void   *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
48                                  int niocount, struct niobuf_local *nb,
49                                  void *desc_private, int logs);
50         int     (* fs_commit)(struct inode *inode, void *handle,int force_sync);
51         int     (* fs_commit_async)(struct inode *inode, void *handle,
52                                         void **wait_handle);
53         int     (* fs_commit_wait)(struct inode *inode, void *handle);
54         int     (* fs_setattr)(struct dentry *dentry, void *handle,
55                                struct iattr *iattr, int do_trunc);
56         int     (* fs_iocontrol)(struct inode *inode, struct file *file,
57                                  unsigned int cmd, unsigned long arg);
58         int     (* fs_set_md)(struct inode *inode, void *handle, void *md,
59                               int size);
60         int     (* fs_get_md)(struct inode *inode, void *md, int size);
61         ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
62                                 loff_t *offset);
63         int     (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
64                                       void *handle, fsfilt_cb_t cb_func,
65                                       void *cb_data);
66         int     (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
67         int     (* fs_sync)(struct super_block *sb);
68         int     (* fs_map_inode_page)(struct inode *inode, struct page *page,
69                                       unsigned long *blocks, int *created,
70                                       int create);
71         int     (* fs_prep_san_write)(struct inode *inode, long *blocks,
72                                       int nblocks, loff_t newsize);
73         int     (* fs_write_record)(struct file *, void *, int size, loff_t *,
74                                     int force_sync);
75         int     (* fs_read_record)(struct file *, void *, int size, loff_t *);
76         int     (* fs_setup)(struct super_block *sb);
77         int     (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
78 };
79
80 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
81 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
82 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
83 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
84
85 #define FSFILT_OP_UNLINK         1
86 #define FSFILT_OP_RMDIR          2
87 #define FSFILT_OP_RENAME         3
88 #define FSFILT_OP_CREATE         4
89 #define FSFILT_OP_MKDIR          5
90 #define FSFILT_OP_SYMLINK        6
91 #define FSFILT_OP_MKNOD          7
92 #define FSFILT_OP_SETATTR        8
93 #define FSFILT_OP_LINK           9
94 #define FSFILT_OP_CANCEL_UNLINK 10
95
96 static inline void *fsfilt_start_log(struct obd_device *obd,
97                                      struct inode *inode, int op,
98                                      struct obd_trans_info *oti, int logs)
99 {
100         unsigned long now = jiffies;
101         void *parent_handle = oti ? oti->oti_handle : NULL;
102         void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
103         CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
104
105         if (oti != NULL) {
106                 if (parent_handle == NULL) {
107                         oti->oti_handle = handle;
108                 } else if (handle != parent_handle) {
109                         CERROR("mismatch: parent %p, handle %p, oti %p\n",
110                                parent_handle, handle, oti);
111                         LBUG();
112                 }
113         }
114         if (time_after(jiffies, now + 15 * HZ))
115                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
116         return handle;
117 }
118
119 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
120                                  int op, struct obd_trans_info *oti)
121 {
122         return fsfilt_start_log(obd, inode, op, oti, 0);
123 }
124
125 static inline void *fsfilt_brw_start_log(struct obd_device *obd,
126                                          int objcount,
127                                          struct fsfilt_objinfo *fso,
128                                          int niocount, struct niobuf_local *nb,
129                                          struct obd_trans_info *oti, int logs)
130 {
131         unsigned long now = jiffies;
132         void *parent_handle = oti ? oti->oti_handle : NULL;
133         void *handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
134                                                     parent_handle, logs);
135         CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
136
137         if (oti != NULL) {
138                 if (parent_handle == NULL) {
139                         oti->oti_handle = handle;
140                 } else if (handle != parent_handle) {
141                         CERROR("mismatch: parent %p, handle %p, oti %p\n",
142                                parent_handle, handle, oti);
143                         LBUG();
144                 }
145         }
146         if (time_after(jiffies, now + 15 * HZ))
147                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
148
149         return handle;
150 }
151
152 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
153                                      struct fsfilt_objinfo *fso, int niocount,
154                                      struct niobuf_local *nb,
155                                      struct obd_trans_info *oti)
156 {
157         return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
158 }
159
160 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
161                                 void *handle, int force_sync)
162 {
163         unsigned long now = jiffies;
164         int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
165         CDEBUG(D_HA, "committing handle %p\n", handle);
166
167         if (time_after(jiffies, now + 15 * HZ))
168                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
169
170         return rc;
171 }
172
173 static inline int fsfilt_commit_async(struct obd_device *obd,
174                                       struct inode *inode, void *handle,
175                                       void **wait_handle)
176 {
177         unsigned long now = jiffies;
178         int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
179
180         CDEBUG(D_HA, "committing handle %p (async)\n", *wait_handle);
181         if (time_after(jiffies, now + 15 * HZ))
182                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
183
184         return rc;
185 }
186
187 static inline int fsfilt_commit_wait(struct obd_device *obd,
188                                      struct inode *inode, void *handle)
189 {
190         unsigned long now = jiffies;
191         int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
192         CDEBUG(D_HA, "waiting for completion %p\n", handle);
193         if (time_after(jiffies, now + 15 * HZ))
194                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
195         return rc;
196 }
197
198 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
199                                  void *handle, struct iattr *iattr,int do_trunc)
200 {
201         unsigned long now = jiffies;
202         int rc;
203         rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
204         if (time_after(jiffies, now + 15 * HZ))
205                 CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
206         return rc;
207 }
208
209 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
210                                    struct file *file, unsigned int cmd,
211                                    unsigned long arg)
212 {
213         return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
214 }
215
216 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
217                                 void *handle, void *md, int size)
218 {
219         return obd->obd_fsops->fs_set_md(inode, handle, md, size);
220 }
221
222 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
223                                 void *md, int size)
224 {
225         return obd->obd_fsops->fs_get_md(inode, md, size);
226 }
227
228 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
229                                       struct file *file, char *buf,
230                                       size_t count, loff_t *offset)
231 {
232         return obd->obd_fsops->fs_readpage(file, buf, count, offset);
233 }
234
235 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
236                                         void *handle, fsfilt_cb_t cb_func,
237                                         void *cb_data)
238 {
239         return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd,
240                                                  handle, cb_func, cb_data);
241 }
242
243 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
244 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
245                                 unsigned long max_age)
246 {
247         int rc = 0;
248
249         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
250         if (time_before(obd->obd_osfs_age, max_age)) {
251                 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
252                 if (rc == 0) /* N.B. statfs can't really fail */
253                         obd->obd_osfs_age = jiffies;
254         } else {
255                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
256         }
257
258         return rc;
259 }
260
261 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
262 {
263         return obd->obd_fsops->fs_sync(sb);
264 }
265
266 static inline int fsfilt_map_inode_page(struct obd_device *obd,
267                                         struct inode *inode, struct page *page,
268                                         unsigned long *blocks, int *created,
269                                         int create)
270 {
271         return obd->obd_fsops->fs_map_inode_page(inode, page, blocks, created,
272                                                  create);
273 }
274
275 static inline int fs_prep_san_write(struct obd_device *obd,
276                                     struct inode *inode,
277                                     long *blocks,
278                                     int nblocks,
279                                     loff_t newsize)
280 {
281         return obd->obd_fsops->fs_prep_san_write(inode, blocks,
282                                                  nblocks, newsize);
283 }
284
285 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
286                                      void *buf, loff_t size, loff_t *offs)
287 {
288         return obd->obd_fsops->fs_read_record(file, buf, size, offs);
289 }
290
291 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
292                                       void *buf, loff_t size, loff_t *offs,
293                                       int force_sync)
294 {
295         return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
296 }
297
298 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
299 {
300         if (obd->obd_fsops->fs_setup)
301                 return obd->obd_fsops->fs_setup(fs);
302         return 0;
303 }
304
305 #endif /* __KERNEL__ */
306
307 #endif