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