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