Whamcloud - gitweb
- this time added with -ko
[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         lock_kernel();
39
40         /* a _really_ horrible hack to avoid removing the data stored
41            in the block pointers; this data is the object id
42            this will go into an extended attribute at some point.
43         */
44         if (iattr->ia_valid & ATTR_SIZE) {
45                 /* ATTR_SIZE would invoke truncate: clear it */
46                 iattr->ia_valid &= ~ATTR_SIZE;
47                 inode->i_size = iattr->ia_size;
48
49                 /* make sure _something_ gets set - so new inode
50                    goes to disk (probably won't work over XFS */
51                 if (!iattr->ia_valid & ATTR_MODE) {
52                         iattr->ia_valid |= ATTR_MODE;
53                         iattr->ia_mode = inode->i_mode;
54                 }
55         }
56
57         if (inode->i_op->setattr)
58                 rc = inode->i_op->setattr(dentry, iattr);
59         else
60                 rc = inode_setattr(inode, iattr);
61
62         unlock_kernel();
63
64         return rc;
65 }
66
67 /*
68  * FIXME: nasty hack - store the object id in the first two
69  *        direct block spots.  This should be done with EAs...
70  */
71 static int mds_ext2_set_objid(struct inode *inode, void *handle, obd_id id)
72 {
73         (__u64)(inode->u.ext2_i.i_data[0]) = cpu_to_le64(id);
74         return 0;
75 }
76
77 static int mds_ext2_get_objid(struct inode *inode, obd_id *id)
78 {
79         *id = le64_to_cpu(inode->u.ext2_i.i_data[0]);
80
81         return 0;
82 }
83
84 static ssize_t mds_ext2_readpage(struct file *file, char *buf, size_t count,
85                                  loff_t *offset)
86 {
87         if (S_ISREG(file->f_dentry->d_inode->i_mode))
88                 return file->f_op->read(file, buf, count, offset);
89         else
90                 return generic_file_read(file, buf, count, offset);
91 }
92
93 static struct mds_fs_operations mds_ext2_fs_ops;
94
95 static void mds_ext2_delete_inode(struct inode *inode)
96 {
97         if (S_ISREG(inode->i_mode))
98                 mds_ext2_set_objid(inode, NULL, 0);
99
100         mds_ext2_fs_ops.cl_delete_inode(inode);
101 }
102
103 static int mds_ext2_set_last_rcvd(struct mds_obd *mds, void *handle)
104 {
105         /* Bail for ext2 - can't tell when it is on disk anyways, sync? */
106         mds->mds_last_committed = mds->mds_last_rcvd;
107
108         return 0;
109 }
110
111 static int mds_ext2_journal_data(struct file *filp)
112 {
113         return 0;
114 }
115
116 static struct mds_fs_operations mds_ext2_fs_ops = {
117         fs_owner:               THIS_MODULE,
118         fs_start:               mds_ext2_start,
119         fs_commit:              mds_ext2_stop,
120         fs_setattr:             mds_ext2_setattr,
121         fs_set_objid:           mds_ext2_set_objid,
122         fs_get_objid:           mds_ext2_get_objid,
123         fs_readpage:            mds_ext2_readpage,
124         fs_delete_inode:        mds_ext2_delete_inode,
125         cl_delete_inode:        clear_inode,
126         fs_journal_data:        mds_ext2_journal_data,
127         fs_set_last_rcvd:       mds_ext2_set_last_rcvd,
128 };
129
130 static int __init mds_ext2_init(void)
131 {
132         return mds_register_fs_type(&mds_ext2_fs_ops, "ext2");
133 }
134
135 static void __exit mds_ext2_exit(void)
136 {
137         mds_unregister_fs_type("ext2");
138 }
139
140 MODULE_AUTHOR("Cluster File Systems, Inc. <adilger@clusterfs.com>");
141 MODULE_DESCRIPTION("Lustre MDS ext2 Filesystem Helper v0.1");
142 MODULE_LICENSE("GPL");
143
144 module_init(mds_ext2_init);
145 module_exit(mds_ext2_exit);