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/extN_fs.h>
21 #include <linux/extN_jbd.h>
22 #include <linux/extN_xattr.h>
23 #include <linux/lustre_mds.h>
24 #include <linux/module.h>
26 static struct mds_fs_operations mds_extN_fs_ops;
27 static kmem_cache_t *jcb_cache;
28 static int jcb_cache_count;
31 struct journal_callback cb_jcb;
32 struct mds_obd *cb_mds;
43 #define EXTN_XATTR_INDEX_LUSTRE 5
44 #define XATTR_LUSTRE_MDS_OBJID "system.lustre_mds_objid"
46 #define XATTR_MDS_MO_MAGIC 0x4711
49 * We don't currently need any additional blocks for rmdir and
50 * unlink transactions because we are storing the OST oa_id inside
51 * the inode (which we will be changing anyways as part of this
54 static void *mds_extN_start(struct inode *inode, int op)
56 /* For updates to the last recieved file */
57 int nblocks = EXTN_DATA_TRANS_BLOCKS;
62 nblocks += EXTN_DELETE_TRANS_BLOCKS;
65 /* We may be modifying two directories */
66 nblocks += EXTN_DATA_TRANS_BLOCKS;
67 case MDS_FSOP_SYMLINK:
68 /* Possible new block + block bitmap + GDT for long symlink */
73 /* New inode + block bitmap + GDT for new file */
76 /* Change parent directory */
77 nblocks += EXTN_INDEX_EXTRA_TRANS_BLOCKS+EXTN_DATA_TRANS_BLOCKS;
79 case MDS_FSOP_SETATTR:
80 /* Setattr on inode */
83 default: CERROR("unknown transaction start op %d\n", op);
87 return journal_start(EXTN_JOURNAL(inode), nblocks);
90 static int mds_extN_commit(struct inode *inode, void *handle)
92 return journal_stop((handle_t *)handle);
95 static int mds_extN_setattr(struct dentry *dentry, void *handle,
98 struct inode *inode = dentry->d_inode;
100 if (inode->i_op->setattr)
101 return inode->i_op->setattr(dentry, iattr);
103 return inode_setattr(inode, iattr);
106 static int mds_extN_set_objid(struct inode *inode, void *handle, obd_id id)
108 struct mds_objid data;
111 data.mo_magic = cpu_to_le16(XATTR_MDS_MO_MAGIC);
113 data.mo_ost = 0; /* FIXME: store OST index here */
114 data.mo_id = cpu_to_le64(id);
119 rc = extN_xattr_set(handle, inode, EXTN_XATTR_INDEX_LUSTRE,
120 XATTR_LUSTRE_MDS_OBJID, NULL, 0, 0);
122 rc = extN_xattr_set(handle, inode, EXTN_XATTR_INDEX_LUSTRE,
123 XATTR_LUSTRE_MDS_OBJID, &data,
124 sizeof(struct mds_objid), XATTR_CREATE);
130 CERROR("error adding objectid %Ld to inode %ld\n",
131 (unsigned long long)id, inode->i_ino);
135 static int mds_extN_get_objid(struct inode *inode, obd_id *id)
137 struct mds_objid data;
142 rc = extN_xattr_get(inode, EXTN_XATTR_INDEX_LUSTRE,
143 XATTR_LUSTRE_MDS_OBJID, &data,
144 sizeof(struct mds_objid));
149 CERROR("error getting EA %s from MDS inode %ld: rc = %d\n",
150 XATTR_LUSTRE_MDS_OBJID, inode->i_ino, rc);
152 } else if (data.mo_magic != cpu_to_le16(XATTR_MDS_MO_MAGIC)) {
153 CERROR("MDS object id %Ld has bad magic %x\n",
154 (unsigned long long)le64_to_cpu(data.mo_id),
155 le16_to_cpu(data.mo_magic));
158 *id = le64_to_cpu(data.mo_id);
159 /* FIXME: will actually use data.mo_ost at some point */
161 CERROR("MDS objid %Ld with ost index %d!\n",
168 static ssize_t mds_extN_readpage(struct file *file, char *buf, size_t count,
171 struct inode *inode = file->f_dentry->d_inode;
174 if (S_ISREG(inode->i_mode))
175 rc = file->f_op->read(file, buf, count, offset);
177 struct buffer_head *bh;
179 /* FIXME: this assumes the blocksize == count, but the calling
180 * function will detect this as an error for now */
181 bh = extN_bread(NULL, inode,
182 *offset >> inode->i_sb->s_blocksize_bits,
186 memcpy(buf, bh->b_data, inode->i_blksize);
188 rc = inode->i_blksize;
195 static void mds_extN_delete_inode(struct inode *inode)
197 if (S_ISREG(inode->i_mode)) {
198 void *handle = mds_extN_start(inode, MDS_FSOP_UNLINK);
200 if (IS_ERR(handle)) {
201 CERROR("unable to start transaction");
205 if (mds_extN_set_objid(inode, handle, 0))
206 CERROR("error clearing objid on %ld\n", inode->i_ino);
208 if (mds_extN_fs_ops.cl_delete_inode)
209 mds_extN_fs_ops.cl_delete_inode(inode);
211 if (mds_extN_commit(inode, handle))
212 CERROR("error closing handle on %ld\n", inode->i_ino);
214 mds_extN_fs_ops.cl_delete_inode(inode);
217 static void mds_extN_callback_status(struct journal_callback *jcb, int error)
219 struct mds_cb_data *mcb = (struct mds_cb_data *)jcb;
221 CDEBUG(D_EXT2, "got callback for last_rcvd %Ld: rc = %d\n",
222 mcb->cb_last_rcvd, error);
223 if (!error && mcb->cb_last_rcvd > mcb->cb_mds->mds_last_committed)
224 mcb->cb_mds->mds_last_committed = mcb->cb_last_rcvd;
226 kmem_cache_free(jcb_cache, jcb);
230 #ifdef HAVE_JOURNAL_CALLBACK
231 static void mds_extN_callback_func(void *cb_data)
233 mds_extN_callback_status(cb_data, 0);
237 static int mds_extN_set_last_rcvd(struct mds_obd *mds, void *handle)
239 struct mds_cb_data *mcb;
241 mcb = kmem_cache_alloc(jcb_cache, GFP_NOFS);
247 mcb->cb_last_rcvd = mds->mds_last_rcvd;
249 #ifdef HAVE_JOURNAL_CALLBACK_STATUS
250 CDEBUG(D_EXT2, "set callback for last_rcvd: %Ld\n",
251 (unsigned long long)mcb->cb_last_rcvd);
252 journal_callback_set(handle, mds_extN_callback_status,
253 (struct journal_callback *)mcb);
254 #elif HAVE_JOURNAL_CALLBACK /* XXX original patch version - remove soon */
255 #warning "using old journal callback kernel patch, please update"
256 CDEBUG(D_EXT2, "set callback for last_rcvd: %Ld\n",
257 (unsigned long long)mcb->cb_last_rcvd);
258 journal_callback_set(handle, mds_extN_callback_func, mcb);
260 #warning "no journal callback kernel patch, faking it..."
262 static long next = 0;
264 if (time_after(jiffies, next)) {
265 CERROR("no journal callback kernel patch, faking it...\n");
266 next = jiffies + 300 * HZ;
269 mds_extN_callback_status((struct journal_callback *)mcb, 0);
275 static int mds_extN_journal_data(struct file *filp)
277 struct inode *inode = filp->f_dentry->d_inode;
279 EXTN_I(inode)->i_flags |= EXTN_JOURNAL_DATA_FL;
284 static struct mds_fs_operations mds_extN_fs_ops = {
285 fs_start: mds_extN_start,
286 fs_commit: mds_extN_commit,
287 fs_setattr: mds_extN_setattr,
288 fs_set_objid: mds_extN_set_objid,
289 fs_get_objid: mds_extN_get_objid,
290 fs_readpage: mds_extN_readpage,
291 fs_delete_inode: mds_extN_delete_inode,
292 cl_delete_inode: clear_inode,
293 fs_journal_data: mds_extN_journal_data,
294 fs_set_last_rcvd: mds_extN_set_last_rcvd,
297 static int __init mds_extN_init(void)
301 //rc = extN_xattr_register();
302 jcb_cache = kmem_cache_create("mds_extN_jcb",
303 sizeof(struct mds_cb_data), 0,
304 SLAB_POISON, NULL, NULL);
306 CERROR("error allocating MDS journal callback cache\n");
307 GOTO(out, rc = -ENOMEM);
309 rc = mds_register_fs_type(&mds_extN_fs_ops, "extN");
312 kmem_cache_destroy(jcb_cache);
317 static void __exit mds_extN_exit(void)
321 mds_unregister_fs_type("extN");
322 rc = kmem_cache_destroy(jcb_cache);
324 if (rc || jcb_cache_count) {
325 CERROR("can't free MDS callback cache: count %d, rc = %d\n",
326 jcb_cache_count, rc);
329 //rc = extN_xattr_unregister();
332 MODULE_AUTHOR("Cluster File Systems, Inc. <adilger@clusterfs.com>");
333 MODULE_DESCRIPTION("Lustre MDS extN Filesystem Helper v0.1");
334 MODULE_LICENSE("GPL");
336 module_init(mds_extN_init);
337 module_exit(mds_extN_exit);