Whamcloud - gitweb
Remove use of ext2-specific inode flags to signal objid-in-i_data. Just
[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
22 static void *mds_ext2_start(struct inode *inode, int nblocks)
23 {
24         return (void *)1;
25 }
26
27 static int mds_ext2_stop(struct inode *inode, void *handle)
28 {
29         return 0;
30 }
31
32 static int mds_ext2_setattr(struct dentry *dentry, void *handle,
33                             struct iattr *iattr)
34 {
35         struct inode *inode = dentry->d_inode;
36
37         /* a _really_ horrible hack to avoid removing the data stored
38            in the block pointers; this data is the object id
39            this will go into an extended attribute at some point.
40         */
41         if (iattr->ia_valid & ATTR_SIZE ) {
42                 /* ATTR_SIZE would invoke truncate: clear it */
43                 iattr->ia_valid &= ~ATTR_SIZE;
44                 inode->i_size = iattr->ia_size;
45
46                 /* make sure _something_ gets set - so new inode
47                    goes to disk (probably won't work over XFS */
48                 if (!iattr->ia_valid & ATTR_MODE) {
49                         iattr->ia_valid |= ATTR_MODE;
50                         iattr->ia_mode = inode->i_mode;
51                 }
52         }
53
54         if (inode->i_op->setattr)
55                 return inode->i_op->setattr(dentry, iattr);
56         else
57                 return inode_setattr(inode, iattr);
58 }
59
60 /*
61  * FIXME: nasty hack - store the object id in the first two
62  *        direct block spots.  This should be done with EAs...
63  */
64 static int mds_ext2_set_objid(struct inode *inode, void *handle, obd_id id)
65 {
66         (__u64)(inode->u.ext2_i.i_data[0]) = cpu_to_le64(id);
67         return 0;
68 }
69
70 static void mds_ext2_get_objid(struct inode *inode, obd_id *id)
71 {
72         *id = le64_to_cpu(inode->u.ext2_i.i_data[0]);
73 }
74
75 static ssize_t mds_ext2_readpage(struct file *file, char *buf, size_t count,
76                                  loff_t *offset)
77 {
78         if (S_ISREG(file->f_dentry->d_inode->i_mode))
79                 return file->f_op->read(file, buf, count, offset);
80         else
81                 return generic_file_read(file, buf, count, offset);
82 }
83
84 struct mds_fs_operations mds_ext2_fs_ops;
85
86 void mds_ext2_delete_inode(struct inode *inode)
87 {
88         if (S_ISREG(inode->i_mode))
89                 mds_ext2_set_objid(inode, NULL, 0);
90
91         mds_ext2_fs_ops.cl_delete_inode(inode);
92 }
93
94 struct mds_fs_operations mds_ext2_fs_ops = {
95         fs_start:       mds_ext2_start,
96         fs_commit:      mds_ext2_stop,
97         fs_setattr:     mds_ext2_setattr,
98         fs_set_objid:   mds_ext2_set_objid,
99         fs_get_objid:   mds_ext2_get_objid,
100         fs_readpage:    mds_ext2_readpage,
101         fs_delete_inode:mds_ext2_delete_inode,
102         cl_delete_inode:clear_inode,
103 };