Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / lvfs / fsfilt_reiserfs.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/lib/fsfilt_reiserfs.c
5  *  Lustre filesystem abstraction routines
6  *
7  *  Copyright (C) 2002 Cluster File Systems, Inc.
8  *   Author: Andreas Dilger <adilger@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org.
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 /*
27  * NOTE - According to Hans Reiser, this could actually be implemented more
28  *        efficiently than creating a directory and putting ASCII objids in it.
29  *        Instead, we should return the reiserfs object ID as the lustre objid
30  *        (although I'm not sure what impact that would have on backup/restore).
31  */
32
33 #define DEBUG_SUBSYSTEM S_FILTER
34
35 #include <linux/fs.h>
36 #include <linux/slab.h>
37 #include <linux/pagemap.h>
38 #include <linux/quotaops.h>
39 #include <linux/version.h>
40 #include <linux/init.h>
41 #include <asm/statfs.h>
42 #include <libcfs/libcfs.h>
43 #include <lustre_fsfilt.h>
44 #include <obd.h>
45 #include <linux/module.h>
46 #include <linux/init.h>
47
48 /* XXX We cannot include linux/reiserfs_fs.h here, because of symbols clash,
49    but we need MAX_HEIGHT definition for proper reserve calculations
50 #include <linux/reiserfs_fs.h>
51 */
52 #define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without
53                         changing JOURNAL_PER_BALANCE_CNT */
54
55 static void *fsfilt_reiserfs_start(struct inode *inode, int op,
56                                    void *desc_private, int logs)
57 {
58         return (void *)0xf00f00be;
59 }
60
61 static void *fsfilt_reiserfs_brw_start(int objcount, struct fsfilt_objinfo *fso,
62                                        int niocount, struct niobuf_local *nb,
63                                        void *desc_private, int logs)
64 {
65         return (void *)0xf00f00be;
66 }
67
68 static int fsfilt_reiserfs_commit(struct inode *inode, void *handle,
69                                   int force_sync)
70 {
71         if (handle != (void *)0xf00f00be) {
72                 CERROR("bad handle %p", handle);
73                 return -EINVAL;
74         }
75
76         return 0;
77 }
78
79 static int fsfilt_reiserfs_setattr(struct dentry *dentry, void *handle,
80                                struct iattr *iattr, int do_trunc)
81 {
82         struct inode *inode = dentry->d_inode;
83         int rc;
84
85         lock_kernel();
86
87         /* A _really_ horrible hack to avoid removing the data stored
88          * in the block pointers; this is really the "small" stripe MD data.
89          * We can avoid further hackery by virtue of the MDS file size being
90          * zero all the time (which doesn't invoke block truncate at unlink
91          * time), so we assert we never change the MDS file size from zero.
92          */
93         if (iattr->ia_valid & ATTR_SIZE && !do_trunc) {
94                 /* ATTR_SIZE would invoke truncate: clear it */
95                 iattr->ia_valid &= ~ATTR_SIZE;
96                 i_size_write(inode, iattr->ia_size);
97
98                 /* make sure _something_ gets set - so new inode
99                  * goes to disk (probably won't work over XFS
100                  */
101                 if (!iattr->ia_valid & ATTR_MODE) {
102                         iattr->ia_valid |= ATTR_MODE;
103                         iattr->ia_mode = inode->i_mode;
104                 }
105         }
106
107         /* We set these flags on the client, but have already checked perms
108          * so don't confuse inode_change_ok. */
109         iattr->ia_valid &= ~(ATTR_MTIME_SET | ATTR_ATIME_SET);
110
111         if (inode->i_op->setattr) {
112                 rc = inode->i_op->setattr(dentry, iattr);
113         } else {
114                 rc = inode_change_ok(inode, iattr);
115                 if (!rc)
116                         rc = inode_setattr(inode, iattr);
117         }
118
119         unlock_kernel();
120
121         return rc;
122 }
123
124 static int fsfilt_reiserfs_set_md(struct inode *inode, void *handle,
125                                   void *lmm, int lmm_size, const char *name)
126 {
127         /* XXX write stripe data into MDS file itself */
128         CERROR("not implemented yet\n");
129
130         return -ENOSYS;
131 }
132
133 static int fsfilt_reiserfs_get_md(struct inode *inode, void *lmm, int lmm_size,
134                                   const char *name)
135 {
136         if (lmm == NULL)
137                 return i_size_read(inode);
138
139         CERROR("not implemented yet\n");
140         return -ENOSYS;
141 }
142
143 static ssize_t fsfilt_reiserfs_readpage(struct file *file, char *buf, size_t count,
144                                         loff_t *offset)
145 {
146         return file->f_op->read(file, buf, count, offset);
147 }
148
149 static int fsfilt_reiserfs_add_journal_cb(struct obd_device *obd,
150                                           __u64 last_rcvd, void *handle,
151                                           fsfilt_cb_t cb_func, void *cb_data)
152 {
153         static unsigned long next = 0;
154
155         if (time_after(jiffies, next)) {
156                 CERROR("no journal callback kernel patch, faking it...\n");
157                 next = jiffies + 300 * HZ;
158         }
159
160         cb_func(obd, last_rcvd, cb_data, 0);
161
162         return 0;
163 }
164
165 static int fsfilt_reiserfs_statfs(struct super_block *sb,
166                                   struct obd_statfs *osfs)
167 {
168         struct kstatfs sfs;
169         int rc;
170
171         memset(&sfs, 0, sizeof(sfs));
172
173         rc = ll_do_statfs(sb, &sfs);
174
175         statfs_pack(osfs, &sfs);
176         return rc;
177 }
178
179 static int fsfilt_reiserfs_sync(struct super_block *sb)
180 {
181         return fsync_dev(sb->s_dev);
182 }
183
184 /* If fso is NULL, op is FSFILT operation, otherwise op is number of fso
185    objects. Logs is number of logfiles to update */
186 static int fsfilt_reiserfs_get_op_len(int op, struct fsfilt_objinfo *fso,
187                                       int logs)
188 {
189         if ( !fso ) {
190                 switch(op) {
191                 case FSFILT_OP_CREATE:
192                                  /* directory leaf, index & indirect & EA*/
193                         return MAX_HEIGHT + logs;
194                 case FSFILT_OP_UNLINK:
195                         return MAX_HEIGHT + logs;
196                 }
197
198         } else {
199                 int i;
200                 int needed = MAX_HEIGHT;
201                 struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
202                 int blockpp = 1 << (CFS_PAGE_SHIFT - sb->s_blocksize_bits);
203                 for (i = 0; i < op; i++, fso++) {
204                         int nblocks = fso->fso_bufcnt * blockpp;
205
206                         needed += nblocks;
207                 }
208                 return needed + logs;
209         }
210
211         return 0;
212 }
213 static struct fsfilt_operations fsfilt_reiserfs_ops = {
214         .fs_type                = "reiserfs",
215         .fs_owner               = THIS_MODULE,
216         .fs_start               = fsfilt_reiserfs_start,
217         .fs_brw_start           = fsfilt_reiserfs_brw_start,
218         .fs_commit              = fsfilt_reiserfs_commit,
219         .fs_setattr             = fsfilt_reiserfs_setattr,
220         .fs_set_md              = fsfilt_reiserfs_set_md,
221         .fs_get_md              = fsfilt_reiserfs_get_md,
222         .fs_readpage            = fsfilt_reiserfs_readpage,
223         .fs_add_journal_cb      = fsfilt_reiserfs_add_journal_cb,
224         .fs_statfs              = fsfilt_reiserfs_statfs,
225         .fs_sync                = fsfilt_reiserfs_sync,
226         .fs_get_op_len          = fsfilt_reiserfs_get_op_len,
227 };
228
229 static int __init fsfilt_reiserfs_init(void)
230 {
231         return fsfilt_register_ops(&fsfilt_reiserfs_ops);
232 }
233
234 static void __exit fsfilt_reiserfs_exit(void)
235 {
236         fsfilt_unregister_ops(&fsfilt_reiserfs_ops);
237 }
238
239 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
240 MODULE_DESCRIPTION("Lustre reiserfs Filesystem Helper v0.1");
241 MODULE_LICENSE("GPL");
242
243 module_init(fsfilt_reiserfs_init);
244 module_exit(fsfilt_reiserfs_exit);