1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/mds/mds_extN.c
5 * Lustre Metadata Server (mds) journal abstraction routines
7 * Copyright (c) 2002 Cluster File Systems, Inc.
8 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
12 * Lustre is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * Lustre is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Lustre; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define DEBUG_SUBSYSTEM S_MDS
29 #include <linux/jbd.h>
30 #include <linux/slab.h>
31 #include <linux/extN_fs.h>
32 #include <linux/extN_jbd.h>
33 #include <linux/extN_xattr.h>
34 #include <linux/kp30.h>
35 #include <linux/lustre_mds.h>
36 #include <linux/obd.h>
37 #include <linux/module.h>
38 #include <linux/obd_lov.h>
40 static struct mds_fs_operations mds_extN_fs_ops;
41 static kmem_cache_t *jcb_cache;
42 static int jcb_cache_count;
45 struct journal_callback cb_jcb;
46 struct mds_obd *cb_mds;
50 #define EXTN_XATTR_INDEX_LUSTRE 5
51 #define XATTR_LUSTRE_MDS_OBJID "system.lustre_mds_objid"
53 #define XATTR_MDS_MO_MAGIC 0xEA0BD047
56 * We don't currently need any additional blocks for rmdir and
57 * unlink transactions because we are storing the OST oa_id inside
58 * the inode (which we will be changing anyways as part of this
61 static void *mds_extN_start(struct inode *inode, int op)
63 /* For updates to the last recieved file */
64 int nblocks = EXTN_DATA_TRANS_BLOCKS;
69 nblocks += EXTN_DELETE_TRANS_BLOCKS;
72 /* We may be modifying two directories */
73 nblocks += EXTN_DATA_TRANS_BLOCKS;
74 case MDS_FSOP_SYMLINK:
75 /* Possible new block + block bitmap + GDT for long symlink */
80 /* New inode + block bitmap + GDT for new file */
83 /* Change parent directory */
84 nblocks += EXTN_INDEX_EXTRA_TRANS_BLOCKS+EXTN_DATA_TRANS_BLOCKS;
86 case MDS_FSOP_SETATTR:
87 /* Setattr on inode */
90 default: CERROR("unknown transaction start op %d\n", op);
94 return journal_start(EXTN_JOURNAL(inode), nblocks);
97 static int mds_extN_commit(struct inode *inode, void *handle)
99 return journal_stop((handle_t *)handle);
102 /* Assumes BKL is held */
103 static int mds_extN_setattr(struct dentry *dentry, void *handle,
106 struct inode *inode = dentry->d_inode;
108 if (inode->i_op->setattr)
109 return inode->i_op->setattr(dentry, iattr);
111 return inode_setattr(inode, iattr);
114 static int mds_extN_set_md(struct inode *inode, void *handle,
115 struct lov_mds_md *md)
122 rc = extN_xattr_set(handle, inode, EXTN_XATTR_INDEX_LUSTRE,
123 XATTR_LUSTRE_MDS_OBJID, NULL, 0, 0);
125 md->lmd_magic = cpu_to_le32(XATTR_MDS_MO_MAGIC);
126 rc = extN_xattr_set(handle, inode, EXTN_XATTR_INDEX_LUSTRE,
127 XATTR_LUSTRE_MDS_OBJID, md,
128 md->lmd_easize, XATTR_CREATE);
134 CERROR("error adding objectid %Ld to inode %ld: %d\n",
135 (unsigned long long)md->lmd_object_id, inode->i_ino, rc);
141 static int mds_extN_get_md(struct inode *inode, struct lov_mds_md *md)
144 int size = md->lmd_easize;
148 rc = extN_xattr_get(inode, EXTN_XATTR_INDEX_LUSTRE,
149 XATTR_LUSTRE_MDS_OBJID, md, size);
154 CDEBUG(D_INFO, "error getting EA %s from MDS inode %ld: "
155 "rc = %d\n", XATTR_LUSTRE_MDS_OBJID, inode->i_ino, rc);
158 } else if (md == NULL)
161 if (md->lmd_magic != cpu_to_le32(XATTR_MDS_MO_MAGIC)) {
162 CERROR("MDS striping md for ino %ld has bad magic\n",
166 /* This field is byteswapped because it appears in the
167 * catalogue. All others are opaque to the MDS */
168 md->lmd_object_id = le64_to_cpu(md->lmd_object_id);
174 static ssize_t mds_extN_readpage(struct file *file, char *buf, size_t count,
177 struct inode *inode = file->f_dentry->d_inode;
180 if (S_ISREG(inode->i_mode))
181 rc = file->f_op->read(file, buf, count, offset);
183 struct buffer_head *bh;
185 /* FIXME: this assumes the blocksize == count, but the calling
186 * function will detect this as an error for now */
187 bh = extN_bread(NULL, inode,
188 *offset >> inode->i_sb->s_blocksize_bits,
192 memcpy(buf, bh->b_data, inode->i_blksize);
194 rc = inode->i_blksize;
201 static void mds_extN_delete_inode(struct inode *inode)
203 if (S_ISREG(inode->i_mode)) {
204 void *handle = mds_extN_start(inode, MDS_FSOP_UNLINK);
206 if (IS_ERR(handle)) {
207 CERROR("unable to start transaction");
211 if (mds_extN_set_md(inode, handle, NULL))
212 CERROR("error clearing obdo on %ld\n", inode->i_ino);
214 if (mds_extN_fs_ops.cl_delete_inode)
215 mds_extN_fs_ops.cl_delete_inode(inode);
217 if (mds_extN_commit(inode, handle))
218 CERROR("error closing handle on %ld\n", inode->i_ino);
220 mds_extN_fs_ops.cl_delete_inode(inode);
223 static void mds_extN_callback_status(void *jcb, int error)
225 struct mds_cb_data *mcb = (struct mds_cb_data *)jcb;
227 CDEBUG(D_EXT2, "got callback for last_rcvd "LPD64": rc = %d\n",
228 mcb->cb_last_rcvd, error);
229 if (!error && mcb->cb_last_rcvd > mcb->cb_mds->mds_last_committed)
230 mcb->cb_mds->mds_last_committed = mcb->cb_last_rcvd;
232 kmem_cache_free(jcb_cache, jcb);
236 static int mds_extN_set_last_rcvd(struct mds_obd *mds, void *handle)
238 struct mds_cb_data *mcb;
240 mcb = kmem_cache_alloc(jcb_cache, GFP_NOFS);
246 mcb->cb_last_rcvd = mds->mds_last_rcvd;
248 #ifdef HAVE_JOURNAL_CALLBACK_STATUS
249 CDEBUG(D_EXT2, "set callback for last_rcvd: %Ld\n",
250 (unsigned long long)mcb->cb_last_rcvd);
251 journal_callback_set(handle, mds_extN_callback_status,
254 #warning "no journal callback kernel patch, faking it..."
256 static long next = 0;
258 if (time_after(jiffies, next)) {
259 CERROR("no journal callback kernel patch, faking it...\n");
260 next = jiffies + 300 * HZ;
263 mds_extN_callback_status((struct journal_callback *)mcb, 0);
269 static int mds_extN_journal_data(struct file *filp)
271 struct inode *inode = filp->f_dentry->d_inode;
273 EXTN_I(inode)->i_flags |= EXTN_JOURNAL_DATA_FL;
279 * We need to hack the return value for the free inode counts because
280 * the current EA code requires one filesystem block per inode with EAs,
281 * so it is possible to run out of blocks before we run out of inodes.
283 * This can be removed when the extN EA code is fixed.
285 static int mds_extN_statfs(struct super_block *sb, struct statfs *sfs)
287 int rc = vfs_statfs(sb, sfs);
289 if (!rc && sfs->f_bfree < sfs->f_ffree)
290 sfs->f_ffree = sfs->f_bfree;
295 static struct mds_fs_operations mds_extN_fs_ops = {
296 fs_owner: THIS_MODULE,
297 fs_start: mds_extN_start,
298 fs_commit: mds_extN_commit,
299 fs_setattr: mds_extN_setattr,
300 fs_set_md: mds_extN_set_md,
301 fs_get_md: mds_extN_get_md,
302 fs_readpage: mds_extN_readpage,
303 fs_delete_inode: mds_extN_delete_inode,
304 cl_delete_inode: clear_inode,
305 fs_journal_data: mds_extN_journal_data,
306 fs_set_last_rcvd: mds_extN_set_last_rcvd,
307 fs_statfs: mds_extN_statfs,
310 static int __init mds_extN_init(void)
314 //rc = extN_xattr_register();
315 jcb_cache = kmem_cache_create("mds_extN_jcb",
316 sizeof(struct mds_cb_data), 0,
319 CERROR("error allocating MDS journal callback cache\n");
320 GOTO(out, rc = -ENOMEM);
322 rc = mds_register_fs_type(&mds_extN_fs_ops, "extN");
325 kmem_cache_destroy(jcb_cache);
330 static void __exit mds_extN_exit(void)
334 mds_unregister_fs_type("extN");
335 rc = kmem_cache_destroy(jcb_cache);
337 if (rc || jcb_cache_count) {
338 CERROR("can't free MDS callback cache: count %d, rc = %d\n",
339 jcb_cache_count, rc);
342 //rc = extN_xattr_unregister();
345 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
346 MODULE_DESCRIPTION("Lustre MDS extN Filesystem Helper v0.1");
347 MODULE_LICENSE("GPL");
349 module_init(mds_extN_init);
350 module_exit(mds_extN_exit);