Whamcloud - gitweb
Added some debugging support on the server side of the LDLM`
[fs/lustre-release.git] / lustre / mds / mds_ext3.c
index 5ff07a7..8c5d9bf 100644 (file)
 #include <linux/ext3_fs.h>
 #include <linux/ext3_jbd.h>
 #include <linux/lustre_mds.h>
+#include <linux/module.h>
+
+static struct mds_fs_operations mds_ext3_fs_ops;
+static kmem_cache_t *jcb_cache;
+static int jcb_cache_count;
+
+struct mds_cb_data {
+        struct journal_callback cb_jcb;
+        struct mds_obd *cb_mds;
+        __u64 cb_last_rcvd;
+};
 
 /*
  * We don't currently need any additional blocks for rmdir and
@@ -35,19 +46,29 @@ static void *mds_ext3_start(struct inode *inode, int op)
         switch(op) {
         case MDS_FSOP_RMDIR:
         case MDS_FSOP_UNLINK:
-                nblocks += EXT3_DELETE_TRANS_BLOCKS; break;
+                nblocks += EXT3_DELETE_TRANS_BLOCKS;
+                break;
         case MDS_FSOP_RENAME:
+                /* We may be modifying two directories */
                 nblocks += EXT3_DATA_TRANS_BLOCKS;
+        case MDS_FSOP_SYMLINK:
+                /* Possible new block + block bitmap + GDT for long symlink */
+                nblocks += 3;
         case MDS_FSOP_CREATE:
-                // FIXME: when we store oa_id in an EA we need more blocks
-                // nblocks += 0;
         case MDS_FSOP_MKDIR:
-        case MDS_FSOP_SYMLINK:
-                /* Create new directory or symlink (more data blocks) */
-                nblocks += 2;
         case MDS_FSOP_MKNOD:
-                /* Change parent directory + setattr on new inode */
-                nblocks += EXT3_DATA_TRANS_BLOCKS + 3;
+                /* New inode + block bitmap + GDT for new file */
+                nblocks += 3;
+        case MDS_FSOP_LINK:
+                /* Change parent directory */
+                nblocks += EXT3_DATA_TRANS_BLOCKS;
+                break;
+        case MDS_FSOP_SETATTR:
+                /* Setattr on inode */
+                nblocks += 1;
+                break;
+        default: CERROR("unknown transaction start op %d\n", op);
+                 LBUG();
         }
 
         return journal_start(EXT3_JOURNAL(inode), nblocks);
@@ -102,13 +123,15 @@ static int mds_ext3_setattr(struct dentry *dentry, void *handle,
  */
 static int mds_ext3_set_objid(struct inode *inode, void *handle, obd_id id)
 {
-        (__u64)EXT3_I(inode)->i_data[0] = cpu_to_le64(id);
+        *((__u64 *)EXT3_I(inode)->i_data) = cpu_to_le64(id);
         return 0;
 }
 
-static void mds_ext3_get_objid(struct inode *inode, obd_id *id)
+static int mds_ext3_get_objid(struct inode *inode, obd_id *id)
 {
-        *id = le64_to_cpu(EXT3_I(inode)->i_data[0]);
+        *id = le64_to_cpu(*((__u64 *)EXT3_I(inode)->i_data));
+
+        return 0;
 }
 
 static ssize_t mds_ext3_readpage(struct file *file, char *buf, size_t count,
@@ -138,14 +161,10 @@ static ssize_t mds_ext3_readpage(struct file *file, char *buf, size_t count,
         return rc;
 }
 
-struct mds_fs_operations mds_ext3_fs_ops;
-
-void mds_ext3_delete_inode(struct inode *inode)
+static void mds_ext3_delete_inode(struct inode *inode)
 {
-        void *handle;
-
         if (S_ISREG(inode->i_mode)) {
-                handle = mds_ext3_start(inode, MDS_FSOP_UNLINK);
+                void *handle = mds_ext3_start(inode, MDS_FSOP_UNLINK);
 
                 if (IS_ERR(handle)) {
                         CERROR("unable to start transaction");
@@ -164,14 +183,76 @@ void mds_ext3_delete_inode(struct inode *inode)
                 mds_ext3_fs_ops.cl_delete_inode(inode);
 }
 
-int mds_ext3_journal_data(struct inode *inode, struct file *filp)
+
+static void mds_ext3_callback_status(void *jcb, int error)
+{
+        struct mds_cb_data *mcb = (struct mds_cb_data *)jcb;
+
+        CDEBUG(D_EXT2, "got callback for last_rcvd %Ld: rc = %d\n",
+               mcb->cb_last_rcvd, error);
+        if (!error && mcb->cb_last_rcvd > mcb->cb_mds->mds_last_committed)
+                mcb->cb_mds->mds_last_committed = mcb->cb_last_rcvd;
+
+        kmem_cache_free(jcb_cache, mcb);
+        --jcb_cache_count;
+}
+
+#ifdef HAVE_JOURNAL_CALLBACK
+static void mds_ext3_callback_func(void *cb_data)
+{
+        mds_ext3_callback_status(cb_data, 0);
+}
+#endif
+
+static int mds_ext3_set_last_rcvd(struct mds_obd *mds, void *handle)
+{
+        struct mds_cb_data *mcb;
+
+        mcb = kmem_cache_alloc(jcb_cache, GFP_NOFS);
+        if (!mcb)
+                RETURN(-ENOMEM);
+
+        ++jcb_cache_count;
+        mcb->cb_mds = mds;
+        mcb->cb_last_rcvd = mds->mds_last_rcvd;
+
+#ifdef HAVE_JOURNAL_CALLBACK_STATUS
+        CDEBUG(D_EXT2, "set callback for last_rcvd: %Ld\n",
+               (unsigned long long)mcb->cb_last_rcvd);
+        journal_callback_set(handle, mds_ext3_callback_status,
+                             (void *)mcb);
+#elif defined(HAVE_JOURNAL_CALLBACK)
+        /* XXX original patch version - remove soon */
+#warning "using old journal callback kernel patch, please update"
+        CDEBUG(D_EXT2, "set callback for last_rcvd: %Ld\n",
+               (unsigned long long)mcb->cb_last_rcvd);
+        journal_callback_set(handle, mds_ext3_callback_func, mcb);
+#else
+#warning "no journal callback kernel patch, faking it..."
+        {
+        static long next = 0;
+
+        if (time_after(jiffies, next)) {
+                CERROR("no journal callback kernel patch, faking it...\n");
+                next = jiffies + 300 * HZ;
+        }
+        }
+        mds_ext3_callback_status((struct journal_callback *)mcb, 0);
+#endif
+
+        return 0;
+}
+
+static int mds_ext3_journal_data(struct file *filp)
 {
+        struct inode *inode = filp->f_dentry->d_inode;
+
         EXT3_I(inode)->i_flags |= EXT3_JOURNAL_DATA_FL;
 
         return 0;
 }
 
-struct mds_fs_operations mds_ext3_fs_ops = {
+static struct mds_fs_operations mds_ext3_fs_ops = {
         fs_start:       mds_ext3_start,
         fs_commit:      mds_ext3_commit,
         fs_setattr:     mds_ext3_setattr,
@@ -181,4 +262,45 @@ struct mds_fs_operations mds_ext3_fs_ops = {
         fs_delete_inode:mds_ext3_delete_inode,
         cl_delete_inode:clear_inode,
         fs_journal_data:mds_ext3_journal_data,
+        fs_set_last_rcvd:mds_ext3_set_last_rcvd,
 };
+
+static int __init mds_ext3_init(void)
+{
+        int rc;
+
+        jcb_cache = kmem_cache_create("mds_ext3_jcb",
+                                      sizeof(struct mds_cb_data), 0,
+                                      0, NULL, NULL);
+        if (!jcb_cache) {
+                CERROR("error allocating MDS journal callback cache\n");
+                GOTO(out, rc = -ENOMEM);
+        }
+
+        rc = mds_register_fs_type(&mds_ext3_fs_ops, "ext3");
+
+        if (rc)
+                kmem_cache_destroy(jcb_cache);
+out:
+        return rc;
+}
+
+static void __exit mds_ext3_exit(void)
+{
+        int rc = 0;
+
+        mds_unregister_fs_type("ext3");
+        rc = kmem_cache_destroy(jcb_cache);
+
+        if (rc || jcb_cache_count) {
+                CERROR("can't free MDS callback cache: count %d, rc = %d\n",
+                       jcb_cache_count, rc);
+        }
+}
+
+MODULE_AUTHOR("Cluster File Systems, Inc. <adilger@clusterfs.com>");
+MODULE_DESCRIPTION("Lustre MDS ext3 Filesystem Helper v0.1");
+MODULE_LICENSE("GPL");
+
+module_init(mds_ext3_init);
+module_exit(mds_ext3_exit);