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