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>
25 #include <linux/obd_lov.h>
27 static struct mds_fs_operations mds_extN_fs_ops;
28 static kmem_cache_t *jcb_cache;
29 static int jcb_cache_count;
32 struct journal_callback cb_jcb;
33 struct mds_obd *cb_mds;
37 #define EXTN_XATTR_INDEX_LUSTRE 5
38 #define XATTR_LUSTRE_MDS_OBJID "system.lustre_mds_objid"
40 #define XATTR_MDS_MO_MAGIC 0x4711
43 * We don't currently need any additional blocks for rmdir and
44 * unlink transactions because we are storing the OST oa_id inside
45 * the inode (which we will be changing anyways as part of this
48 static void *mds_extN_start(struct inode *inode, int op)
50 /* For updates to the last recieved file */
51 int nblocks = EXTN_DATA_TRANS_BLOCKS;
56 nblocks += EXTN_DELETE_TRANS_BLOCKS;
59 /* We may be modifying two directories */
60 nblocks += EXTN_DATA_TRANS_BLOCKS;
61 case MDS_FSOP_SYMLINK:
62 /* Possible new block + block bitmap + GDT for long symlink */
67 /* New inode + block bitmap + GDT for new file */
70 /* Change parent directory */
71 nblocks += EXTN_INDEX_EXTRA_TRANS_BLOCKS+EXTN_DATA_TRANS_BLOCKS;
73 case MDS_FSOP_SETATTR:
74 /* Setattr on inode */
77 default: CERROR("unknown transaction start op %d\n", op);
81 return journal_start(EXTN_JOURNAL(inode), nblocks);
84 static int mds_extN_commit(struct inode *inode, void *handle)
86 return journal_stop((handle_t *)handle);
89 static int mds_extN_setattr(struct dentry *dentry, void *handle,
92 struct inode *inode = dentry->d_inode;
94 if (inode->i_op->setattr)
95 return inode->i_op->setattr(dentry, iattr);
97 return inode_setattr(inode, iattr);
100 static int mds_extN_set_obdo(struct inode *inode, void *handle,
103 struct mds_objid *data;
111 rc = extN_xattr_set(handle, inode, EXTN_XATTR_INDEX_LUSTRE,
112 XATTR_LUSTRE_MDS_OBJID, NULL, 0, 0);
114 data = (struct mds_objid *)obdo->o_inline;
115 data->mo_magic = cpu_to_le64(XATTR_MDS_MO_MAGIC);
116 rc = extN_xattr_set(handle, inode, EXTN_XATTR_INDEX_LUSTRE,
117 XATTR_LUSTRE_MDS_OBJID, obdo->o_inline,
118 OBD_INLINESZ, XATTR_CREATE);
124 CERROR("error adding objectid %Ld to inode %ld\n",
125 (unsigned long long)obdo->o_id, inode->i_ino);
129 static int mds_extN_get_obdo(struct inode *inode, struct obdo *obdo)
131 struct mds_objid *data;
136 rc = extN_xattr_get(inode, EXTN_XATTR_INDEX_LUSTRE,
137 XATTR_LUSTRE_MDS_OBJID, obdo->o_inline,
139 data = (struct mds_objid *)obdo->o_inline;
145 CDEBUG(D_INFO, "error getting EA %s from MDS inode %ld: "
146 "rc = %d\n", XATTR_LUSTRE_MDS_OBJID, inode->i_ino, rc);
148 } else if (data->mo_magic != cpu_to_le64(XATTR_MDS_MO_MAGIC)) {
149 CERROR("MDS object id %Ld has bad magic %Lx\n",
150 (unsigned long long)obdo->o_id,
151 (unsigned long long)le64_to_cpu(data->mo_magic));
154 /* This field is byteswapped because it appears in the
155 * catalogue. All others are opaque to the MDS */
156 obdo->o_id = le64_to_cpu(data->mo_lov_md.lmd_object_id);
157 obdo->o_mode = S_IFREG;
158 obdo->o_valid |= OBD_MD_FLID | OBD_MD_FLINLINE | OBD_MD_FLMODE;
161 #warning FIXME: pass this buffer to caller for transmission when size exceeds OBD_INLINESZ
165 static ssize_t mds_extN_readpage(struct file *file, char *buf, size_t count,
168 struct inode *inode = file->f_dentry->d_inode;
171 if (S_ISREG(inode->i_mode))
172 rc = file->f_op->read(file, buf, count, offset);
174 struct buffer_head *bh;
176 /* FIXME: this assumes the blocksize == count, but the calling
177 * function will detect this as an error for now */
178 bh = extN_bread(NULL, inode,
179 *offset >> inode->i_sb->s_blocksize_bits,
183 memcpy(buf, bh->b_data, inode->i_blksize);
185 rc = inode->i_blksize;
192 static void mds_extN_delete_inode(struct inode *inode)
194 if (S_ISREG(inode->i_mode)) {
195 void *handle = mds_extN_start(inode, MDS_FSOP_UNLINK);
197 if (IS_ERR(handle)) {
198 CERROR("unable to start transaction");
202 if (mds_extN_set_obdo(inode, handle, NULL))
203 CERROR("error clearing obdo on %ld\n", inode->i_ino);
205 if (mds_extN_fs_ops.cl_delete_inode)
206 mds_extN_fs_ops.cl_delete_inode(inode);
208 if (mds_extN_commit(inode, handle))
209 CERROR("error closing handle on %ld\n", inode->i_ino);
211 mds_extN_fs_ops.cl_delete_inode(inode);
214 static void mds_extN_callback_status(void *jcb, int error)
216 struct mds_cb_data *mcb = (struct mds_cb_data *)jcb;
218 CDEBUG(D_EXT2, "got callback for last_rcvd %Ld: rc = %d\n",
219 mcb->cb_last_rcvd, error);
220 if (!error && mcb->cb_last_rcvd > mcb->cb_mds->mds_last_committed)
221 mcb->cb_mds->mds_last_committed = mcb->cb_last_rcvd;
223 kmem_cache_free(jcb_cache, jcb);
227 #ifdef HAVE_JOURNAL_CALLBACK
228 static void mds_extN_callback_func(void *cb_data)
230 mds_extN_callback_status(cb_data, 0);
234 static int mds_extN_set_last_rcvd(struct mds_obd *mds, void *handle)
236 struct mds_cb_data *mcb;
238 mcb = kmem_cache_alloc(jcb_cache, GFP_NOFS);
244 mcb->cb_last_rcvd = mds->mds_last_rcvd;
246 #ifdef HAVE_JOURNAL_CALLBACK_STATUS
247 CDEBUG(D_EXT2, "set callback for last_rcvd: %Ld\n",
248 (unsigned long long)mcb->cb_last_rcvd);
249 journal_callback_set(handle, mds_extN_callback_status,
251 #elif defined(HAVE_JOURNAL_CALLBACK)
252 /* XXX original patch version - remove soon */
253 #warning "using old journal callback kernel patch, please update"
254 CDEBUG(D_EXT2, "set callback for last_rcvd: %Ld\n",
255 (unsigned long long)mcb->cb_last_rcvd);
256 journal_callback_set(handle, mds_extN_callback_func, mcb);
258 #warning "no journal callback kernel patch, faking it..."
260 static long next = 0;
262 if (time_after(jiffies, next)) {
263 CERROR("no journal callback kernel patch, faking it...\n");
264 next = jiffies + 300 * HZ;
267 mds_extN_callback_status((struct journal_callback *)mcb, 0);
273 static int mds_extN_journal_data(struct file *filp)
275 struct inode *inode = filp->f_dentry->d_inode;
277 EXTN_I(inode)->i_flags |= EXTN_JOURNAL_DATA_FL;
282 static struct mds_fs_operations mds_extN_fs_ops = {
283 fs_start: mds_extN_start,
284 fs_commit: mds_extN_commit,
285 fs_setattr: mds_extN_setattr,
286 fs_set_obdo: mds_extN_set_obdo,
287 fs_get_obdo: mds_extN_get_obdo,
288 fs_readpage: mds_extN_readpage,
289 fs_delete_inode: mds_extN_delete_inode,
290 cl_delete_inode: clear_inode,
291 fs_journal_data: mds_extN_journal_data,
292 fs_set_last_rcvd: mds_extN_set_last_rcvd,
295 static int __init mds_extN_init(void)
299 //rc = extN_xattr_register();
300 jcb_cache = kmem_cache_create("mds_extN_jcb",
301 sizeof(struct mds_cb_data), 0,
304 CERROR("error allocating MDS journal callback cache\n");
305 GOTO(out, rc = -ENOMEM);
307 rc = mds_register_fs_type(&mds_extN_fs_ops, "extN");
310 kmem_cache_destroy(jcb_cache);
315 static void __exit mds_extN_exit(void)
319 mds_unregister_fs_type("extN");
320 rc = kmem_cache_destroy(jcb_cache);
322 if (rc || jcb_cache_count) {
323 CERROR("can't free MDS callback cache: count %d, rc = %d\n",
324 jcb_cache_count, rc);
327 //rc = extN_xattr_unregister();
330 MODULE_AUTHOR("Cluster File Systems, Inc. <adilger@clusterfs.com>");
331 MODULE_DESCRIPTION("Lustre MDS extN Filesystem Helper v0.1");
332 MODULE_LICENSE("GPL");
334 module_init(mds_extN_init);
335 module_exit(mds_extN_exit);