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