Whamcloud - gitweb
landing b_cmobd_merge on 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 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
41 #include <linux/init.h>
42 #include <asm/statfs.h>
43 #endif
44 #include <linux/kp30.h>
45 #include <linux/lustre_fsfilt.h>
46 #include <linux/obd.h>
47 #include <linux/obd_class.h>
48 #include <linux/module.h>
49 #include <linux/init.h>
50
51 /* XXX We cannot include linux/reiserfs_fs.h here, because of symbols clash,
52    but we need MAX_HEIGHT definition for proper reserve calculations
53 #include <linux/reiserfs_fs.h>
54 */
55 #define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without
56                         changing JOURNAL_PER_BALANCE_CNT */
57
58 static void *fsfilt_reiserfs_start(struct inode *inode, int op,
59                                    void *desc_private, int logs)
60 {
61         return (void *)0xf00f00be;
62 }
63
64 static void *fsfilt_reiserfs_brw_start(int objcount, struct fsfilt_objinfo *fso,
65                                        int niocount, struct niobuf_local *nb,
66                                        void *desc_private, int logs)
67 {
68         return (void *)0xf00f00be;
69 }
70
71 static int fsfilt_reiserfs_commit(struct inode *inode, void *handle,
72                                   int force_sync)
73 {
74         if (handle != (void *)0xf00f00be) {
75                 CERROR("bad handle %p", handle);
76                 return -EINVAL;
77         }
78
79         return 0;
80 }
81
82 static int fsfilt_reiserfs_setattr(struct dentry *dentry, void *handle,
83                                struct iattr *iattr, int do_trunc)
84 {
85         struct inode *inode = dentry->d_inode;
86         int rc;
87
88         lock_kernel();
89
90         /* A _really_ horrible hack to avoid removing the data stored
91          * in the block pointers; this is really the "small" stripe MD data.
92          * We can avoid further hackery by virtue of the MDS file size being
93          * zero all the time (which doesn't invoke block truncate at unlink
94          * time), so we assert we never change the MDS file size from zero.
95          */
96         if (iattr->ia_valid & ATTR_SIZE && !do_trunc) {
97                 /* ATTR_SIZE would invoke truncate: clear it */
98                 iattr->ia_valid &= ~ATTR_SIZE;
99                 inode->i_size = iattr->ia_size;
100
101                 /* make sure _something_ gets set - so new inode
102                  * goes to disk (probably won't work over XFS
103                  */
104                 if (!iattr->ia_valid & ATTR_MODE) {
105                         iattr->ia_valid |= ATTR_MODE;
106                         iattr->ia_mode = inode->i_mode;
107                 }
108         }
109
110         /* We set these flags on the client, but have already checked perms
111          * so don't confuse inode_change_ok. */
112         iattr->ia_valid &= ~(ATTR_MTIME_SET | ATTR_ATIME_SET);
113
114         if (inode->i_op->setattr) {
115                 rc = inode->i_op->setattr(dentry, iattr);
116         } else {
117                 rc = inode_change_ok(inode, iattr);
118                 if (!rc)
119                         rc = inode_setattr(inode, iattr);
120         }
121
122         unlock_kernel();
123
124         return rc;
125 }
126
127 static int fsfilt_reiserfs_set_md(struct inode *inode, void *handle,
128                                   void *lmm, int lmm_size)
129 {
130         /* XXX write stripe data into MDS file itself */
131         CERROR("not implemented yet\n");
132
133         return -ENOSYS;
134 }
135
136 static int fsfilt_reiserfs_get_md(struct inode *inode, void *lmm, int lmm_size)
137 {
138         if (lmm == NULL)
139                 return inode->i_size;
140
141         CERROR("not implemented yet\n");
142         return -ENOSYS;
143 }
144
145 static ssize_t fsfilt_reiserfs_readpage(struct file *file, char *buf, size_t count,
146                                         loff_t *offset)
147 {
148         return file->f_op->read(file, buf, count, offset);
149 }
150
151 static int fsfilt_reiserfs_add_journal_cb(struct obd_device *obd,
152                                           __u64 last_rcvd, void *handle,
153                                           fsfilt_cb_t cb_func, void *cb_data)
154 {
155         static unsigned long next = 0;
156
157         if (time_after(jiffies, next)) {
158                 CERROR("no journal callback kernel patch, faking it...\n");
159                 next = jiffies + 300 * HZ;
160         }
161
162         cb_func(obd, last_rcvd, cb_data, 0);
163
164         return 0;
165 }
166
167 static int fsfilt_reiserfs_statfs(struct super_block *sb,
168                                   struct obd_statfs *osfs)
169 {
170         struct kstatfs sfs;
171         int rc;
172
173         memset(&sfs, 0, sizeof(sfs));
174
175         rc = sb->s_op->statfs(sb, &sfs);
176
177         statfs_pack(osfs, &sfs);
178         return rc;
179 }
180
181 static int fsfilt_reiserfs_sync(struct super_block *sb)
182 {
183         return fsync_dev(sb->s_dev);
184 }
185
186 /* If fso is NULL, op is FSFILT operation, otherwise op is number of fso
187    objects. Logs is number of logfiles to update */
188 static int fsfilt_reiserfs_get_op_len(int op, struct fsfilt_objinfo *fso,
189                                       int logs)
190 {
191         if ( !fso ) {
192                 switch(op) {
193                 case FSFILT_OP_CREATE:
194                                  /* directory leaf, index & indirect & EA*/
195                         return MAX_HEIGHT + logs;
196                 case FSFILT_OP_UNLINK:
197                         return MAX_HEIGHT + logs;
198                 }
199
200         } else {
201                 int i;
202                 int needed = MAX_HEIGHT;
203                 struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
204                 int blockpp = 1 << (PAGE_CACHE_SHIFT - sb->s_blocksize_bits);
205                 for (i = 0; i < op; i++, fso++) {
206                         int nblocks = fso->fso_bufcnt * blockpp;
207
208                         needed += nblocks;
209                 }
210                 return needed + logs;
211         }
212
213         return 0;
214 }
215 static struct fsfilt_operations fsfilt_reiserfs_ops = {
216         .fs_type                = "reiserfs",
217         .fs_owner               = THIS_MODULE,
218         .fs_start               = fsfilt_reiserfs_start,
219         .fs_brw_start           = fsfilt_reiserfs_brw_start,
220         .fs_commit              = fsfilt_reiserfs_commit,
221         .fs_setattr             = fsfilt_reiserfs_setattr,
222         .fs_set_md              = fsfilt_reiserfs_set_md,
223         .fs_get_md              = fsfilt_reiserfs_get_md,
224         .fs_readpage            = fsfilt_reiserfs_readpage,
225         .fs_add_journal_cb      = fsfilt_reiserfs_add_journal_cb,
226         .fs_statfs              = fsfilt_reiserfs_statfs,
227         .fs_sync                = fsfilt_reiserfs_sync,
228         .fs_get_op_len          = fsfilt_reiserfs_get_op_len,
229 };
230
231 static int __init fsfilt_reiserfs_init(void)
232 {
233         return fsfilt_register_ops(&fsfilt_reiserfs_ops);
234 }
235
236 static void __exit fsfilt_reiserfs_exit(void)
237 {
238         fsfilt_unregister_ops(&fsfilt_reiserfs_ops);
239 }
240
241 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
242 MODULE_DESCRIPTION("Lustre reiserfs Filesystem Helper v0.1");
243 MODULE_LICENSE("GPL");
244
245 module_init(fsfilt_reiserfs_init);
246 module_exit(fsfilt_reiserfs_exit);