Whamcloud - gitweb
Add module refcounts for filesystem interface modules.
[fs/lustre-release.git] / lustre / mds / mds_ext2.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/mds/mds_null.c
5  *
6  *  Lustre Metadata Server (mds) journal abstraction routines
7  *
8  *  Copyright (C) 2002  Cluster File Systems, Inc.
9  *  author: Andreas Dilger <adilger@clusterfs.com>
10  *
11  *  This code is issued under the GNU General Public License.
12  *  See the file COPYING in this distribution
13  *
14  */
15
16 #define DEBUG_SUBSYSTEM S_MDS
17
18 #include <linux/fs.h>
19 #include <linux/ext2_fs.h>
20 #include <linux/lustre_mds.h>
21 #include <linux/module.h>
22
23 static void *mds_ext2_start(struct inode *inode, int nblocks)
24 {
25         return (void *)1;
26 }
27
28 static int mds_ext2_stop(struct inode *inode, void *handle)
29 {
30         return 0;
31 }
32
33 static int mds_ext2_setattr(struct dentry *dentry, void *handle,
34                             struct iattr *iattr)
35 {
36         struct inode *inode = dentry->d_inode;
37
38         /* a _really_ horrible hack to avoid removing the data stored
39            in the block pointers; this data is the object id
40            this will go into an extended attribute at some point.
41         */
42         if (iattr->ia_valid & ATTR_SIZE) {
43                 /* ATTR_SIZE would invoke truncate: clear it */
44                 iattr->ia_valid &= ~ATTR_SIZE;
45                 inode->i_size = iattr->ia_size;
46
47                 /* make sure _something_ gets set - so new inode
48                    goes to disk (probably won't work over XFS */
49                 if (!iattr->ia_valid & ATTR_MODE) {
50                         iattr->ia_valid |= ATTR_MODE;
51                         iattr->ia_mode = inode->i_mode;
52                 }
53         }
54
55         if (inode->i_op->setattr)
56                 return inode->i_op->setattr(dentry, iattr);
57         else
58                 return inode_setattr(inode, iattr);
59 }
60
61 /*
62  * FIXME: nasty hack - store the object id in the first two
63  *        direct block spots.  This should be done with EAs...
64  */
65 static int mds_ext2_set_objid(struct inode *inode, void *handle, obd_id id)
66 {
67         (__u64)(inode->u.ext2_i.i_data[0]) = cpu_to_le64(id);
68         return 0;
69 }
70
71 static int mds_ext2_get_objid(struct inode *inode, obd_id *id)
72 {
73         *id = le64_to_cpu(inode->u.ext2_i.i_data[0]);
74
75         return 0;
76 }
77
78 static ssize_t mds_ext2_readpage(struct file *file, char *buf, size_t count,
79                                  loff_t *offset)
80 {
81         if (S_ISREG(file->f_dentry->d_inode->i_mode))
82                 return file->f_op->read(file, buf, count, offset);
83         else
84                 return generic_file_read(file, buf, count, offset);
85 }
86
87 static struct mds_fs_operations mds_ext2_fs_ops;
88
89 static void mds_ext2_delete_inode(struct inode *inode)
90 {
91         if (S_ISREG(inode->i_mode))
92                 mds_ext2_set_objid(inode, NULL, 0);
93
94         mds_ext2_fs_ops.cl_delete_inode(inode);
95 }
96
97 static int mds_ext2_set_last_rcvd(struct mds_obd *mds, void *handle)
98 {
99         /* Bail for ext2 - can't tell when it is on disk anyways, sync? */
100         mds->mds_last_committed = mds->mds_last_rcvd;
101
102         return 0;
103 }
104
105 static int mds_ext2_journal_data(struct file *filp)
106 {
107         return 0;
108 }
109
110 static struct mds_fs_operations mds_ext2_fs_ops = {
111         fs_owner:               THIS_MODULE,
112         fs_start:               mds_ext2_start,
113         fs_commit:              mds_ext2_stop,
114         fs_setattr:             mds_ext2_setattr,
115         fs_set_objid:           mds_ext2_set_objid,
116         fs_get_objid:           mds_ext2_get_objid,
117         fs_readpage:            mds_ext2_readpage,
118         fs_delete_inode:        mds_ext2_delete_inode,
119         cl_delete_inode:        clear_inode,
120         fs_journal_data:        mds_ext2_journal_data,
121         fs_set_last_rcvd:       mds_ext2_set_last_rcvd,
122 };
123
124 static int __init mds_ext2_init(void)
125 {
126         return mds_register_fs_type(&mds_ext2_fs_ops, "ext2");
127 }
128
129 static void __exit mds_ext2_exit(void)
130 {
131         mds_unregister_fs_type("ext2");
132 }
133
134 MODULE_AUTHOR("Cluster File Systems, Inc. <adilger@clusterfs.com>");
135 MODULE_DESCRIPTION("Lustre MDS ext2 Filesystem Helper v0.1");
136 MODULE_LICENSE("GPL");
137
138 module_init(mds_ext2_init);
139 module_exit(mds_ext2_exit);