1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/lvfs/fsfilt_reiserfs.c
38 * Author: Andreas Dilger <adilger@clusterfs.com>
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).
48 #define DEBUG_SUBSYSTEM S_FILTER
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>
60 #include <linux/module.h>
61 #include <linux/init.h>
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>
67 #define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without
68 changing JOURNAL_PER_BALANCE_CNT */
70 static void *fsfilt_reiserfs_start(struct inode *inode, int op,
71 void *desc_private, int logs)
73 return (void *)0xf00f00be;
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)
80 return (void *)0xf00f00be;
83 static int fsfilt_reiserfs_commit(struct inode *inode, void *handle,
86 if (handle != (void *)0xf00f00be) {
87 CERROR("bad handle %p", handle);
94 static int fsfilt_reiserfs_setattr(struct dentry *dentry, void *handle,
95 struct iattr *iattr, int do_trunc)
97 struct inode *inode = dentry->d_inode;
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.
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);
113 /* make sure _something_ gets set - so new inode
114 * goes to disk (probably won't work over XFS
116 if (!iattr->ia_valid & ATTR_MODE) {
117 iattr->ia_valid |= ATTR_MODE;
118 iattr->ia_mode = inode->i_mode;
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);
126 if (inode->i_op->setattr) {
127 rc = inode->i_op->setattr(dentry, iattr);
129 rc = inode_change_ok(inode, iattr);
131 rc = inode_setattr(inode, iattr);
139 static int fsfilt_reiserfs_set_md(struct inode *inode, void *handle,
140 void *lmm, int lmm_size, const char *name)
142 /* XXX write stripe data into MDS file itself */
143 CERROR("not implemented yet\n");
148 static int fsfilt_reiserfs_get_md(struct inode *inode, void *lmm, int lmm_size,
152 return i_size_read(inode);
154 CERROR("not implemented yet\n");
158 static ssize_t fsfilt_reiserfs_readpage(struct file *file, char *buf, size_t count,
161 return file->f_op->read(file, buf, count, offset);
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)
168 static unsigned long next = 0;
170 if (time_after(jiffies, next)) {
171 CERROR("no journal callback kernel patch, faking it...\n");
172 next = jiffies + 300 * HZ;
175 cb_func(obd, last_rcvd, cb_data, 0);
180 static int fsfilt_reiserfs_statfs(struct super_block *sb,
181 struct obd_statfs *osfs)
186 memset(&sfs, 0, sizeof(sfs));
187 rc = ll_do_statfs(sb, &sfs);
188 statfs_pack(osfs, &sfs);
192 static int fsfilt_reiserfs_sync(struct super_block *sb)
194 return fsync_dev(sb->s_dev);
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,
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;
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;
221 return needed + logs;
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,
242 static int __init fsfilt_reiserfs_init(void)
244 return fsfilt_register_ops(&fsfilt_reiserfs_ops);
247 static void __exit fsfilt_reiserfs_exit(void)
249 fsfilt_unregister_ops(&fsfilt_reiserfs_ops);
252 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
253 MODULE_DESCRIPTION("Lustre reiserfs Filesystem Helper v0.1");
254 MODULE_LICENSE("GPL");
256 module_init(fsfilt_reiserfs_init);
257 module_exit(fsfilt_reiserfs_exit);