1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Lustre Metadata Server (mds) journal abstraction routines
8 * Copyright (C) 2002 Cluster File Systems, Inc.
9 * author: Andreas Dilger <adilger@clusterfs.com>
11 * This code is issued under the GNU General Public License.
12 * See the file COPYING in this distribution
16 #define DEBUG_SUBSYSTEM S_MDS
19 #include <linux/jbd.h>
20 #include <linux/ext3_fs.h>
21 #include <linux/ext3_jbd.h>
22 #include <linux/lustre_mds.h>
25 * We don't currently need any additional blocks for rmdir and
26 * unlink transactions because we are storing the OST oa_id inside
27 * the inode (which we will be changing anyways as part of this
28 * transaction). When we store the oa_id in an EA (which may be
29 * in an external block) we need to increase nblocks by 1.
31 static void *mds_ext3_start(struct inode *inode, int op)
37 case MDS_FSOP_UNLINK: nblocks = EXT3_DELETE_TRANS_BLOCKS; break;
40 return journal_start(EXT3_JOURNAL(inode), nblocks);
43 static int mds_ext3_commit(struct inode *inode, void *handle)
45 return journal_stop((handle_t *)handle);
48 static int mds_ext3_setattr(struct inode *inode, void *handle,
51 /* a _really_ horrible hack to avoid removing the data stored
52 in the block pointers; this data is the object id
53 this will go into an extended attribute at some point.
55 if ( iattr->ia_valid & ATTR_SIZE ) {
56 /* ATTR_SIZE would invoke truncate: clear it */
57 iattr->ia_valid &= ~ATTR_SIZE;
58 inode->i_size = iattr->ia_size;
60 /* an _even_more_ horrible hack to make this hack work with
61 * ext3. This is because ext3 keeps a separate inode size
62 * until the inode is committed to ensure consistency. This
63 * will also go away with the move to EAs.
65 EXT3_I(inode)->i_disksize = inode->i_size;
67 /* make sure _something_ gets set - so new inode
68 goes to disk (probably won't work over XFS */
69 if (!iattr->ia_valid & ATTR_MODE) {
70 iattr->ia_valid |= ATTR_MODE;
71 iattr->ia_mode = inode->i_mode;
79 * FIXME: nasty hack - store the object id in the first two
80 * direct block spots. This should be done with EAs...
82 static int mds_ext3_set_objid(struct inode *inode, void *handle, obd_id id)
84 memcpy(&EXT3_I(inode)->i_data, &id, sizeof(id));
89 static void mds_ext3_get_objid(struct inode *inode, obd_id *id)
91 memcpy(id, &EXT3_I(inode)->i_data, sizeof(*id));
94 static ssize_t mds_ext3_readpage(struct file *file, char *buf, size_t count,
97 struct inode *inode = file->f_dentry->d_inode;
100 if (S_ISREG(inode->i_mode))
101 rc = file->f_op->read(file, buf, count, offset);
103 struct buffer_head *bh;
105 /* FIXME: this assumes the blocksize == count, but the calling
106 * function will detect this as an error for now */
107 bh = ext3_bread(NULL, inode,
108 *offset >> inode->i_sb->s_blocksize_bits,
112 memcpy(buf, bh->b_data, inode->i_blksize);
114 rc = inode->i_blksize;
121 struct mds_fs_operations mds_ext3_fs_ops;
123 void mds_ext3_delete_inode(struct inode * inode)
127 if (!S_ISDIR(inode->i_mode)) {
128 handle = mds_ext3_start(inode, MDS_FSOP_UNLINK);
130 if (!IS_ERR(handle)) {
131 CERROR("unable to start transaction");
135 if (mds_ext3_set_objid(inode, handle, 0))
136 CERROR("error clearing objid on %ld\n", inode->i_ino);
138 if (mds_ext3_fs_ops.cl_delete_inode)
139 mds_ext3_fs_ops.cl_delete_inode(inode);
141 if (mds_ext3_commit(inode, handle))
142 CERROR("error closing handle on %ld\n", inode->i_ino);
143 } else if (mds_ext3_fs_ops.cl_delete_inode)
144 mds_ext3_fs_ops.cl_delete_inode(inode);
147 struct mds_fs_operations mds_ext3_fs_ops = {
148 fs_start: mds_ext3_start,
149 fs_commit: mds_ext3_commit,
150 fs_setattr: mds_ext3_setattr,
151 fs_set_objid: mds_ext3_set_objid,
152 fs_get_objid: mds_ext3_get_objid,
153 fs_readpage: mds_ext3_readpage,
154 fs_delete_inode:mds_ext3_delete_inode,
155 cl_delete_inode:NULL,