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