Whamcloud - gitweb
- fixed stupid bug with locking in MDS. It caused clients do not flush local
[fs/lustre-release.git] / lustre / smfs / smfs_llog.c
index b2efd68..cfecc3e 100644 (file)
@@ -1,6 +1,9 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
+ *  lustre/smfs/smfs_llog.c
+ *  Lustre filesystem abstraction routines
+ *
  *  Copyright (C) 2004 Cluster File Systems, Inc.
  *
  *   This file is part of Lustre, http://www.lustre.org.
@@ -17,7 +20,6 @@
  *   You should have received a copy of the GNU General Public License
  *   along with Lustre; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
  */
 
 #define DEBUG_SUBSYSTEM S_SM
 static int smfs_llog_process_rec_cb(struct llog_handle *handle,
                                     struct llog_rec_hdr *rec, void *data)
 {
-        struct reint_record *reint_rec;
-        char *rec_buf ;
+        char   *rec_buf ;
         struct smfs_proc_args *args = (struct smfs_proc_args *)data;
         struct lvfs_run_ctxt saved;
-        int rc = 0;
-        ENTRY;
+        int    rc = 0;
 
         if (!(le32_to_cpu(handle->lgh_hdr->llh_flags) & LLOG_F_IS_PLAIN)) {
                 CERROR("log is not plain\n");
@@ -59,23 +59,20 @@ static int smfs_llog_process_rec_cb(struct llog_handle *handle,
 
         rec_buf = (char*) (rec + 1);
 
-        OBD_ALLOC(reint_rec, sizeof(struct reint_record));
-        if (!reint_rec)
-                RETURN(-ENOMEM);
-
-        rc = smfs_rec_unpack(args, reint_rec, rec_buf);
-        if (rc)
-                GOTO(exit, rc = -ENOMEM);
-
         if (!S2SMI(args->sr_sb)->smsi_ctxt)
                 GOTO(exit, rc = -ENODEV);
 
         push_ctxt(&saved, S2SMI(args->sr_sb)->smsi_ctxt, NULL);
+#if 0
+        /*FIXME later should first unpack the rec,
+         * then call lvfs_reint or lvfs_undo
+         * kml rec format has changed lvfs_reint lvfs_undo should
+         * be rewrite FIXME later*/
         if (SMFS_DO_REINT_REC(args->sr_flags))
-                rc = lvfs_reint(args->sr_sb, reint_rec);
+                rc = lvfs_reint(args->sr_sb, rec_buf);
         else
-                rc = lvfs_undo(args->sr_sb, reint_rec);
-
+                rc = lvfs_undo(args->sr_sb, rec_buf);
+#endif
         if (!rc && !SMFS_DO_REC_ALL(args->sr_flags)) {
                 args->sr_count --;
                 if (args->sr_count == 0)
@@ -83,67 +80,38 @@ static int smfs_llog_process_rec_cb(struct llog_handle *handle,
         }
         pop_ctxt(&saved, S2SMI(args->sr_sb)->smsi_ctxt, NULL);
 exit:
-        reint_rec_free(reint_rec);
         RETURN(rc);
 }
 
-int smfs_llog_setup(struct super_block *sb)
+int smfs_llog_setup(struct super_block *sb, struct vfsmount *mnt)
 {
         struct llog_ctxt **ctxt = &(S2SMI(sb)->smsi_rec_log);
         struct lvfs_run_ctxt saved;
-        struct lvfs_run_ctxt *current_ctxt = NULL;
-        struct vfsmount *mnt;
         struct dentry *dentry;
         int rc = 0, rc2;
-        ENTRY;
 
         /* create OBJECTS and LOGS for writing logs */
-        S2SMI(sb)->sm_cache_fsfilt->fs_setup(sb);
-
-        OBD_ALLOC(current_ctxt, sizeof(*current_ctxt));
-        if (!current_ctxt)
-                RETURN(-ENOMEM);
-        mnt = get_vfsmount(sb);
-        if (!mnt)
-                GOTO(err_exit, rc = -EINVAL);
-
-        OBD_SET_CTXT_MAGIC(current_ctxt);
-        current_ctxt->pwdmnt = mnt;
-        current_ctxt->pwd = mnt->mnt_root;
-        current_ctxt->fs = get_ds();
-        S2SMI(sb)->smsi_ctxt = current_ctxt;
-
-        push_ctxt(&saved, current_ctxt, NULL);
+        ENTRY;
+
+        LASSERT(mnt);
+
+        push_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
         dentry = simple_mkdir(current->fs->pwd, "LOGS", 0777, 1);
         if (IS_ERR(dentry)) {
                 rc = PTR_ERR(dentry);
                 CERROR("cannot create LOGS directory: rc = %d\n", rc);
-                GOTO(err_exit, rc = -EINVAL);
+                GOTO(exit, rc = -EINVAL);
         }
-        
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-        if (list_empty(&dentry->d_hash))
-                d_rehash(dentry);
-#else
-        /* FIXME-WANGDI: here should be something. */
-#endif
-        
+
         S2SMI(sb)->smsi_logs_dir = dentry;
         dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
         if (IS_ERR(dentry)) {
                 rc = PTR_ERR(dentry);
                 CERROR("cannot create OBJECTS directory: rc = %d\n", rc);
-                GOTO(err_exit, rc = -EINVAL);
+                GOTO(exit, rc = -EINVAL);
         }
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-        if (list_empty(&dentry->d_hash))
-                d_rehash(dentry);
-#else
-        /* FIXME-WANGDI: here should be something. */
-#endif
 
         S2SMI(sb)->smsi_objects_dir = dentry;
-        pop_ctxt(&saved, current_ctxt, NULL);
 
         /* write log will not write to KML, cleanup kml flags */
         SMFS_CLEAN_INODE_REC(S2SMI(sb)->smsi_objects_dir->d_inode);
@@ -154,11 +122,11 @@ int smfs_llog_setup(struct super_block *sb)
         SMFS_CLEAN_INODE_CACHE_HOOK(S2SMI(sb)->smsi_logs_dir->d_inode);
 
         if (SMFS_DO_REC(S2SMI(sb))) {
-                rc = llog_catalog_setup(ctxt, KML_LOG_NAME, current_ctxt,
-                                        S2SMI(sb)->sm_fsfilt,
+                rc = llog_catalog_setup(ctxt, KML_LOG_NAME, S2SMI(sb)->smsi_exp,
+                                        S2SMI(sb)->smsi_ctxt, S2SMI(sb)->sm_fsfilt,
                                         S2SMI(sb)->smsi_logs_dir,
                                         S2SMI(sb)->smsi_objects_dir);
-                (*ctxt)->loc_proc_cb = smfs_llog_process_rec_cb;
+                (*ctxt)->llog_proc_cb = smfs_llog_process_rec_cb;
         }
 
         if (SMFS_CACHE_HOOK(S2SMI(sb))) {
@@ -167,11 +135,8 @@ int smfs_llog_setup(struct super_block *sb)
                         rc = rc2;
         }
 exit:
+        pop_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
         RETURN(rc);
-err_exit:
-        if (current_ctxt)
-                OBD_FREE(current_ctxt, sizeof(*current_ctxt));
-        goto exit;
 }
 
 int smfs_llog_cleanup(struct super_block *sb)
@@ -185,6 +150,7 @@ int smfs_llog_cleanup(struct super_block *sb)
 
         if (SMFS_DO_REC(S2SMI(sb))) {
                 rc2 = llog_catalog_cleanup(ctxt);
+                OBD_FREE(ctxt, sizeof(*ctxt));
                 if (!rc)
                         rc = rc2;
         }
@@ -197,8 +163,6 @@ int smfs_llog_cleanup(struct super_block *sb)
                 l_dput(S2SMI(sb)->smsi_objects_dir);
                 S2SMI(sb)->smsi_objects_dir = NULL;
         }
-
-        OBD_FREE(S2SMI(sb)->smsi_ctxt, sizeof(struct lvfs_run_ctxt));
         RETURN(rc);
 }
 
@@ -210,8 +174,7 @@ int smfs_llog_add_rec(struct smfs_super_info * sinfo, void *data, int data_size)
         rec.lrh_len = size_round(data_size);
         rec.lrh_type = SMFS_UPDATE_REC;
 
-        rc = llog_add(sinfo->smsi_rec_log,
-                      &rec, data, NULL, 0, NULL);
+        rc = llog_add(sinfo->smsi_rec_log, &rec, data, NULL, 0, NULL, NULL, NULL);
         if (rc != 1) {
                 CERROR("error adding kml rec: %d\n", rc);
                 RETURN(-EINVAL);