Whamcloud - gitweb
37ffc4f531cdb1fc040b011aef421353aa30c171
[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_setattr)(struct dentry *dentry, void *handle,
50                                struct iattr *iattr, int do_trunc);
51         int     (* fs_set_md)(struct inode *inode, void *handle, void *md,
52                               int size);
53         int     (* fs_get_md)(struct inode *inode, void *md, int size);
54         ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
55                                 loff_t *offset);
56         int     (* fs_journal_data)(struct file *file);
57         int     (* fs_set_last_rcvd)(struct obd_device *obd, __u64 last_rcvd,
58                                      void *handle, fsfilt_cb_t cb_func,
59                                      void *cb_data);
60         int     (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
61         int     (* fs_sync)(struct super_block *sb);
62         int     (* fs_prep_san_write)(struct inode *inode, long *blocks,
63                                       int nblocks, loff_t newsize);
64         int     (* fs_write_record)(struct file *, char *, int size, loff_t *);
65         int     (* fs_read_record)(struct file *, char *, int size, loff_t *);
66 };
67
68 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
69 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
70 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
71 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
72
73 #define FSFILT_OP_UNLINK         1
74 #define FSFILT_OP_RMDIR          2
75 #define FSFILT_OP_RENAME         3
76 #define FSFILT_OP_CREATE         4
77 #define FSFILT_OP_MKDIR          5
78 #define FSFILT_OP_SYMLINK        6
79 #define FSFILT_OP_MKNOD          7
80 #define FSFILT_OP_SETATTR        8
81 #define FSFILT_OP_LINK           9
82 #define FSFILT_OP_CREATE_LOG    10
83 #define FSFILT_OP_UNLINK_LOG    11
84
85 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
86                                  int op, struct obd_trans_info *oti)
87 {
88         unsigned long now = jiffies;
89         void *parent_handle = oti ? oti->oti_handle : NULL;
90         void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle);
91         CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
92
93         if (oti != NULL) {
94                 if (parent_handle == NULL) {
95                         oti->oti_handle = handle;
96                 } else if (handle != parent_handle) {
97                         CERROR("mismatch: parent %p, handle %p, oti %p\n",
98                                parent_handle, handle, oti->oti_handle);
99                         LBUG();
100                 }
101         }
102         if (time_after(jiffies, now + 15 * HZ))
103                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
104         return handle;
105 }
106
107 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
108                                      struct fsfilt_objinfo *fso, int niocount,
109                                      struct obd_trans_info *oti)
110 {
111         unsigned long now = jiffies;
112         void *parent_handle = oti ? oti->oti_handle : NULL;
113         void *handle;
114
115         handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount,
116                                               parent_handle);
117         CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
118
119         if (oti != NULL) {
120                 if (parent_handle == NULL) {
121                         oti->oti_handle = handle;
122                 } else if (handle != parent_handle) {
123                         CERROR("mismatch: parent %p, handle %p, oti %p\n",
124                                parent_handle, handle, oti->oti_handle);
125                         LBUG();
126                 }
127         }
128         if (time_after(jiffies, now + 15 * HZ))
129                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
130         return handle;
131 }
132
133 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
134                                 void *handle, int force_sync)
135 {
136         unsigned long now = jiffies;
137         int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
138         CDEBUG(D_HA, "committing handle %p\n", handle);
139         if (time_after(jiffies, now + 15 * HZ))
140                 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
141         return rc;
142 }
143
144 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
145                                  void *handle, struct iattr *iattr,int do_trunc)
146 {
147         unsigned long now = jiffies;
148         int rc;
149         rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
150         if (time_after(jiffies, now + 15 * HZ))
151                 CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
152         return rc;
153 }
154
155 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
156                                 void *handle, void *md, int size)
157 {
158         return obd->obd_fsops->fs_set_md(inode, handle, md, size);
159 }
160
161 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
162                                 void *md, int size)
163 {
164         return obd->obd_fsops->fs_get_md(inode, md, size);
165 }
166
167 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
168                                       struct file *file, char *buf,
169                                       size_t count, loff_t *offset)
170 {
171         return obd->obd_fsops->fs_readpage(file, buf, count, offset);
172 }
173
174 static inline int fsfilt_journal_data(struct obd_device *obd, struct file *file)
175 {
176         return obd->obd_fsops->fs_journal_data(file);
177 }
178
179 static inline int fsfilt_set_last_rcvd(struct obd_device *obd, __u64 last_rcvd,
180                                        void *handle, fsfilt_cb_t cb_func,
181                                        void *cb_data)
182 {
183         return obd->obd_fsops->fs_set_last_rcvd(obd, last_rcvd, handle,
184                                                 cb_func, cb_data);
185 }
186
187 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *fs,
188                                 struct obd_statfs *osfs)
189 {
190         return obd->obd_fsops->fs_statfs(fs, osfs);
191 }
192
193 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *fs)
194 {
195         return obd->obd_fsops->fs_sync(fs);
196 }
197
198 static inline int fs_prep_san_write(struct obd_device *obd,
199                                     struct inode *inode,
200                                     long *blocks,
201                                     int nblocks,
202                                     loff_t newsize)
203 {
204         return obd->obd_fsops->fs_prep_san_write(inode, blocks,
205                                                  nblocks, newsize);
206 }
207
208 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
209                                      char *buf, loff_t size, loff_t *offs)
210 {
211         return obd->obd_fsops->fs_read_record(file, buf, size, offs);
212 }
213
214 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
215                                       char *buf, loff_t size, loff_t *offs)
216 {
217         return obd->obd_fsops->fs_write_record(file, buf, size, offs);
218 }
219
220 #endif /* __KERNEL__ */
221
222 #endif