Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[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, 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);
45         void   *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
46                                  int niocount, struct niobuf_remote *nb);
47         int     (* fs_commit)(struct inode *inode, void *handle,int force_sync);
48         int     (* fs_setattr)(struct dentry *dentry, void *handle,
49                                struct iattr *iattr);
50         int     (* fs_set_md)(struct inode *inode, void *handle, void *md,
51                               int size);
52         int     (* fs_get_md)(struct inode *inode, void *md, int size);
53         ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
54                                 loff_t *offset);
55         int     (* fs_journal_data)(struct file *file);
56         int     (* fs_set_last_rcvd)(struct obd_device *obd, __u64 last_rcvd,
57                                      void *handle, fsfilt_cb_t cb_func);
58         int     (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
59         int     (* fs_sync)(struct super_block *sb);
60         int     (* fs_prep_san_write)(struct inode *inode, long *blocks,
61                                       int nblocks, loff_t newsize);
62 };
63
64 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
65 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
66 extern struct fsfilt_operations *fsfilt_get_ops(char *type);
67 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
68
69 #define FSFILT_OP_UNLINK         1
70 #define FSFILT_OP_RMDIR          2
71 #define FSFILT_OP_RENAME         3
72 #define FSFILT_OP_CREATE         4
73 #define FSFILT_OP_MKDIR          5
74 #define FSFILT_OP_SYMLINK        6
75 #define FSFILT_OP_MKNOD          7
76 #define FSFILT_OP_SETATTR        8
77 #define FSFILT_OP_LINK           9
78
79 static inline void *fsfilt_start(struct obd_device *obd,
80                                  struct inode *inode, int op)
81 {
82         void *handle = obd->obd_fsops->fs_start(inode, op);
83         CDEBUG(D_HA, "starting handle %p\n", handle);
84         return handle;
85 }
86
87 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
88                                      struct fsfilt_objinfo *fso, int niocount,
89                                      struct niobuf_remote *nb)
90 {
91         void *handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount,nb);
92         CDEBUG(D_HA, "starting handle %p\n", handle);
93         return handle;
94 }
95
96 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
97                                 void *handle, int force_sync)
98 {
99         CDEBUG(D_HA, "committing handle %p\n", handle);
100         return obd->obd_fsops->fs_commit(inode, handle, force_sync);
101 }
102
103 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
104                                  void *handle, struct iattr *iattr)
105 {
106         int rc;
107         /*
108          * NOTE: we probably don't need to take i_sem here when changing
109          *       ATTR_SIZE because the MDS never needs to truncate a file.
110          *       The ext2/ext3 code never truncates a directory, and files
111          *       stored on the MDS are entirely sparse (no data blocks).
112          *       If we do need to get it, we can do it here.
113          */
114         lock_kernel();
115         rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr);
116         unlock_kernel();
117
118         return rc;
119 }
120
121 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
122                                 void *handle, void *md, int size)
123 {
124         return obd->obd_fsops->fs_set_md(inode, handle, md, size);
125 }
126
127 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
128                                 void *md, int size)
129 {
130         return obd->obd_fsops->fs_get_md(inode, md, size);
131 }
132
133 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
134                                       struct file *file, char *buf,
135                                       size_t count, loff_t *offset)
136 {
137         return obd->obd_fsops->fs_readpage(file, buf, count, offset);
138 }
139
140 static inline int fsfilt_journal_data(struct obd_device *obd, struct file *file)
141 {
142         return obd->obd_fsops->fs_journal_data(file);
143 }
144
145 static inline int fsfilt_set_last_rcvd(struct obd_device *obd, __u64 last_rcvd,
146                                        void *handle, fsfilt_cb_t cb_func)
147 {
148         return obd->obd_fsops->fs_set_last_rcvd(obd, last_rcvd,handle,cb_func);
149 }
150
151 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *fs,
152                                 struct obd_statfs *osfs)
153 {
154         return obd->obd_fsops->fs_statfs(fs, osfs);
155 }
156
157 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *fs)
158 {
159         return obd->obd_fsops->fs_sync(fs);
160 }
161
162 static inline int fs_prep_san_write(struct obd_device *obd,
163                                     struct inode *inode,
164                                     long *blocks,
165                                     int nblocks,
166                                     loff_t newsize)
167 {
168         return obd->obd_fsops->fs_prep_san_write(inode, blocks,
169                                                  nblocks, newsize);
170 }
171 #endif /* __KERNEL__ */
172
173 #endif