Whamcloud - gitweb
land v0.9.1 on HEAD, in preparation for a 1.0.x branch
[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/fs.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         void   *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
47                                  int niocount, 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
94 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
95                                  int op, struct obd_trans_info *oti)
96 {
97         unsigned long now = jiffies;
98         void *parent_handle = oti ? oti->oti_handle : NULL;
99         void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle);
100         CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
101
102         if (oti != NULL) {
103                 if (parent_handle == NULL) {
104                         oti->oti_handle = handle;
105                 } else if (handle != parent_handle) {
106                         CERROR("mismatch: parent %p, handle %p, oti %p\n",
107                                parent_handle, handle, oti->oti_handle);
108                         LBUG();
109                 }
110         }
111         if (time_after(jiffies, now + 15 * HZ))
112                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
113         return handle;
114 }
115
116 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
117                                      struct fsfilt_objinfo *fso, int niocount,
118                                      struct obd_trans_info *oti)
119 {
120         unsigned long now = jiffies;
121         void *parent_handle = oti ? oti->oti_handle : NULL;
122         void *handle;
123
124         handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount,
125                                               parent_handle);
126         CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
127
128         if (oti != NULL) {
129                 if (parent_handle == NULL) {
130                         oti->oti_handle = handle;
131                 } else if (handle != parent_handle) {
132                         CERROR("mismatch: parent %p, handle %p, oti %p\n",
133                                parent_handle, handle, oti->oti_handle);
134                         LBUG();
135                 }
136         }
137         if (time_after(jiffies, now + 15 * HZ))
138                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
139         return handle;
140 }
141
142 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
143                                 void *handle, int force_sync)
144 {
145         unsigned long now = jiffies;
146         int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
147         CDEBUG(D_HA, "committing handle %p\n", handle);
148         if (time_after(jiffies, now + 15 * HZ))
149                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
150         return rc;
151 }
152
153 static inline int fsfilt_commit_async(struct obd_device *obd,
154                                          struct inode *inode,
155                                          void *handle,
156                                          void **wait_handle)
157 {
158         unsigned long now = jiffies;
159         int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
160         CDEBUG(D_HA, "committing handle %p (async)\n", *wait_handle);
161         if (time_after(jiffies, now + 15 * HZ))
162                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
163         return rc;
164 }
165
166 static inline int fsfilt_commit_wait(struct obd_device *obd, struct inode *inode,
167                                         void *handle)
168 {
169         unsigned long now = jiffies;
170         int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
171         CDEBUG(D_HA, "waiting for completion %p\n", handle);
172         if (time_after(jiffies, now + 15 * HZ))
173                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
174         return rc;
175 }
176
177 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
178                                  void *handle, struct iattr *iattr,int do_trunc)
179 {
180         unsigned long now = jiffies;
181         int rc;
182         rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
183         if (time_after(jiffies, now + 15 * HZ))
184                 CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
185         return rc;
186 }
187
188 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
189                                    struct file *file, unsigned int cmd,
190                                    unsigned long arg)
191 {
192         return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
193 }
194
195 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
196                                 void *handle, void *md, int size)
197 {
198         return obd->obd_fsops->fs_set_md(inode, handle, md, size);
199 }
200
201 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
202                                 void *md, int size)
203 {
204         return obd->obd_fsops->fs_get_md(inode, md, size);
205 }
206
207 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
208                                       struct file *file, char *buf,
209                                       size_t count, loff_t *offset)
210 {
211         return obd->obd_fsops->fs_readpage(file, buf, count, offset);
212 }
213
214 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
215                                         void *handle, fsfilt_cb_t cb_func,
216                                         void *cb_data)
217 {
218         return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd, handle,
219                                                  cb_func, cb_data);
220 }
221
222 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
223                                 struct obd_statfs *osfs)
224 {
225         return obd->obd_fsops->fs_statfs(sb, osfs);
226 }
227
228 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
229 {
230         return obd->obd_fsops->fs_sync(sb);
231 }
232
233 static inline int fsfilt_map_inode_page(struct obd_device *obd,
234                                         struct inode *inode, struct page *page,
235                                         unsigned long *blocks, int *created,
236                                         int create)
237 {
238         return obd->obd_fsops->fs_map_inode_page(inode, page, blocks, created,
239                                                  create);
240 }
241
242 static inline int fs_prep_san_write(struct obd_device *obd,
243                                     struct inode *inode,
244                                     long *blocks,
245                                     int nblocks,
246                                     loff_t newsize)
247 {
248         return obd->obd_fsops->fs_prep_san_write(inode, blocks,
249                                                  nblocks, newsize);
250 }
251
252 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
253                                      void *buf, loff_t size, loff_t *offs)
254 {
255         return obd->obd_fsops->fs_read_record(file, buf, size, offs);
256 }
257
258 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
259                                       void *buf, loff_t size, loff_t *offs,
260                                       int force_sync)
261 {
262         return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
263 }
264
265 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
266 {
267         if (obd->obd_fsops->fs_setup)
268                 return obd->obd_fsops->fs_setup(fs);
269         return 0;
270 }
271
272 #endif /* __KERNEL__ */
273
274 #endif