Whamcloud - gitweb
1)cleanup smfs for build in 2.6
[fs/lustre-release.git] / lustre / smfs / dir.c
index 89acd05..f954063 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/lustre_idl.h>
 #include <linux/lustre_fsfilt.h>
 #include <linux/lustre_smfs.h>
+#include <linux/lustre_snap.h>
 
 #include "smfs_internal.h"
 
@@ -64,18 +65,17 @@ static int smfs_create(struct inode *dir, struct dentry *dentry,
         handle = smfs_trans_start(dir, FSFILT_OP_CREATE, NULL);
         if (IS_ERR(handle))
                        RETURN(-ENOSPC);
-
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_CREATE, handle, dir);
-
-         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
-        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
-
+        
         lock_kernel();
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_CREATE, handle, PRE_HOOK, rc, 
+                  exit); 
+        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry, NULL);
+        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry, NULL);
+
         if (!cache_dentry || !cache_parent)
                 GOTO(exit, rc = -ENOMEM);
-
+       
         pre_smfs_inode(dir, cache_dir);
-
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
         if (cache_dir && cache_dir->i_op->create)
                 rc = cache_dir->i_op->create(cache_dir, cache_dentry,
@@ -87,21 +87,16 @@ static int smfs_create(struct inode *dir, struct dentry *dentry,
 #endif
         if (rc)
                 GOTO(exit, rc);
-
-        inode = iget4(dir->i_sb, cache_dentry->d_inode->i_ino, NULL,
-                      &I2SMI(dir)->smi_flags);
+        
+        inode = smfs_get_inode(dir->i_sb, cache_dentry->d_inode->i_ino, dir, 0);
         if (!inode)
                 GOTO(exit, rc = -ENOMEM);
 
         d_instantiate(dentry, inode);
         sm_set_inode_ops(cache_dentry->d_inode, inode);
         post_smfs_inode(dir, cache_dir);
-
-        /*Do KML post hook*/
-        SMFS_KML_POST(dir, dentry, NULL, NULL, REINT_CREATE,
-                      "create", rc, exit);
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_CREATE, handle, dir, dentry,
-                             NULL, NULL, rc, exit);
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_CREATE, handle, POST_HOOK, rc, 
+                  exit); 
 exit:
         unlock_kernel();
         post_smfs_dentry(cache_dentry);
@@ -124,22 +119,16 @@ static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry,
         struct dentry *cache_parent = NULL;
         struct dentry *rc = NULL;
         void *handle = NULL;
-        int rc2 = 0;
+        int rc2 = 0, index = 0;
 
         ENTRY;
 
         if (!(cache_dir = I2CI(dir)))
                 RETURN(ERR_PTR(-ENOENT));
 
-        handle = smfs_trans_start(dir, KML_CACHE_NOOP, NULL);
-        if (IS_ERR(handle))
-                       RETURN(ERR_PTR(-ENOSPC));
-
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_LOOKUP, handle, dir);
-
         /* preparing artificial backing fs dentries. */
-        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
-        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
+        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent, NULL);
+        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry, &index);
 
         if (!cache_dentry || !cache_parent)
                 GOTO(exit, rc = ERR_PTR(-ENOMEM));
@@ -147,23 +136,24 @@ static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry,
         if (!cache_dir && cache_dir->i_op->lookup)
                 GOTO(exit, rc = ERR_PTR(-ENOENT));
 
+        SMFS_HOOK(dir, dentry, &index, NULL, HOOK_LOOKUP, handle, 
+                  PRE_HOOK, rc2, exit); 
+
         /* perform lookup in backing fs. */
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
         rc = cache_dir->i_op->lookup(cache_dir, cache_dentry);
 #else
         rc = cache_dir->i_op->lookup(cache_dir, cache_dentry, nd);
 #endif
-
         if (rc && IS_ERR(rc))
                 GOTO(exit, rc);
-
+        
         if ((cache_inode = rc ? rc->d_inode : cache_dentry->d_inode)) {
                 if (IS_ERR(cache_inode)) {
                         dentry->d_inode = cache_inode;
                         GOTO(exit, rc = NULL);
                 }
-                inode = iget4(dir->i_sb, cache_inode->i_ino, NULL,
-                                    &I2SMI(dir)->smi_flags);
+                inode = smfs_get_inode(dir->i_sb, cache_inode->i_ino, dir, index);
         } else {
                 d_add(dentry, NULL);
                 GOTO(exit, rc);
@@ -172,10 +162,10 @@ static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry,
         d_add(dentry, inode);
         rc = NULL;
 
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_LOOKUP, handle, dir, dentry,
-                             NULL, NULL, rc2, exit);
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_LOOKUP, handle, POST_HOOK, rc2, 
+                  exit); 
 exit:
-        if (rc2)
+        if (rc2 < 0)
                 rc = ERR_PTR(rc2);
         post_smfs_dentry(cache_dentry);
         post_smfs_dentry(cache_parent);
@@ -201,19 +191,20 @@ static int smfs_link(struct dentry * old_dentry,
 
         handle = smfs_trans_start(dir, FSFILT_OP_LINK, NULL);
         if (IS_ERR(handle))
-                       RETURN(-ENOSPC);
-
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_LINK, handle, dir);
-
-        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
-        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
-
+                 RETURN(-ENOSPC);
+        
         lock_kernel();
+        SMFS_HOOK(dir, old_dentry, NULL, NULL, HOOK_LINK, handle, PRE_HOOK, rc, 
+                  exit); 
+        
+        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry, NULL);
+        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry, NULL);
+
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
         cache_old_dentry = pre_smfs_dentry(NULL, cache_old_inode,
-                                           old_dentry);
+                                           old_dentry, NULL);
         if (!cache_old_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -231,11 +222,9 @@ static int smfs_link(struct dentry * old_dentry,
         d_instantiate(dentry, inode);
         post_smfs_inode(dir, cache_dir);
 
-        SMFS_KML_POST(dir, old_dentry, dentry, NULL,
-                      REINT_LINK, "link", rc, exit);
-
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_LINK, handle,
-                             dir, old_dentry, NULL, NULL, rc, exit);
+        SMFS_HOOK(dir, old_dentry, dentry, NULL, HOOK_LINK, handle, POST_HOOK, 
+                  rc, exit); 
+        
 exit:
         unlock_kernel();
         post_smfs_dentry(cache_dentry);
@@ -263,10 +252,11 @@ static int smfs_unlink(struct inode * dir,
         if (IS_ERR(handle))
                 RETURN(-ENOSPC);
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_UNLINK, handle, dir);
-
-        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
-        cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_UNLINK, handle, PRE_HOOK, rc, 
+                  exit); 
+        
+        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry, NULL);
+        cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry, NULL);
 
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
@@ -279,11 +269,9 @@ static int smfs_unlink(struct inode * dir,
         post_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
         post_smfs_inode(dir, cache_dir);
         unlock_kernel();
-        SMFS_KML_POST(dir, dentry, &mode, NULL, REINT_UNLINK,
-                      "unlink", rc, exit);
-
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_UNLINK, handle, dir, dentry,
-                             NULL, NULL, rc, exit);
+        
+        SMFS_HOOK(dir, dentry, &mode, NULL, HOOK_UNLINK, handle, POST_HOOK, 
+                  rc, exit); 
 exit:
         post_smfs_dentry(cache_dentry);
         post_smfs_dentry(cache_parent);
@@ -304,25 +292,26 @@ static int smfs_symlink(struct inode *dir, struct dentry *dentry,
         if (!cache_dir)
                 RETURN(-ENOENT);
 
-        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
-        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
-
-        if (!cache_parent || !cache_dentry)
-                GOTO(exit, rc = -ENOMEM);
-
         handle = smfs_trans_start(dir, FSFILT_OP_SYMLINK, NULL);
         if (IS_ERR(handle))
                 RETURN(-ENOSPC);
+        
+        lock_kernel();
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_SYMLINK, handle, PRE_HOOK, rc, 
+                  exit); 
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_SYMLINK, handle, dir);
+        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry, NULL);
+        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry, NULL);
 
+        if (!cache_parent || !cache_dentry)
+                GOTO(exit, rc = -ENOMEM);
+       
         pre_smfs_inode(dir, cache_dir);
-        lock_kernel();
         if (cache_dir->i_op->symlink)
                 rc = cache_dir->i_op->symlink(cache_dir, cache_dentry, symname);
 
-        inode = iget4(dir->i_sb, cache_dentry->d_inode->i_ino, NULL,
-                      &I2SMI(dir)->smi_flags);
+
+        inode = smfs_get_inode(dir->i_sb, cache_dentry->d_inode->i_ino, dir, 0);
         post_smfs_inode(dir, cache_dir);
         if (inode)
                 d_instantiate(dentry, inode);
@@ -330,11 +319,9 @@ static int smfs_symlink(struct inode *dir, struct dentry *dentry,
                 rc = -ENOENT;
 
         tgt_len = strlen(symname) + 1;
-        SMFS_KML_POST(dir, dentry, (char*)symname, &tgt_len, REINT_CREATE,
-                      "symlink", rc, exit);
-
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_SYMLINK, handle, dir, dentry,
-                             NULL, NULL, rc, exit);
+        
+        SMFS_HOOK(dir, dentry, (char *)symname, &tgt_len, HOOK_SYMLINK, handle, 
+                  POST_HOOK, rc, exit); 
 exit:
         unlock_kernel();
         post_smfs_dentry(cache_dentry);
@@ -360,12 +347,14 @@ static int smfs_mkdir(struct inode *dir, struct dentry *dentry,
         if (IS_ERR(handle))
                 RETURN(-ENOSPC);
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_MKDIR, handle, dir);
-
-        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
-        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
-
         lock_kernel();
+        
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKDIR, handle, PRE_HOOK, rc, 
+                  exit); 
+        
+        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry, NULL);
+        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry, NULL);
+
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -376,20 +365,17 @@ static int smfs_mkdir(struct inode *dir, struct dentry *dentry,
 
         if (rc)
                 GOTO(exit, rc);
+  
+        inode = smfs_get_inode(dir->i_sb, cache_dentry->d_inode->i_ino, dir, 0);
 
-        inode = iget4(dir->i_sb, cache_dentry->d_inode->i_ino, NULL,
-                      &I2SMI(dir)->smi_flags);
         if (!inode)
                 GOTO(exit, rc = -ENOENT);
 
         d_instantiate(dentry, inode);
         post_smfs_inode(dir, cache_dir);
 
-        SMFS_KML_POST(dir, dentry, NULL, NULL,
-                      REINT_CREATE, "mkdir", rc, exit);
-
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_MKDIR, handle,
-                             dir, dentry, NULL, NULL, rc, exit);
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKDIR, handle, POST_HOOK, rc,
+                  exit); 
 exit:
         unlock_kernel();
         post_smfs_dentry(cache_dentry);
@@ -416,12 +402,14 @@ static int smfs_rmdir(struct inode *dir, struct dentry *dentry)
                 RETURN(-ENOSPC);
         }
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_RMDIR, handle, dir);
+        lock_kernel();
 
-        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
-        cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_RMDIR, handle, PRE_HOOK, rc, 
+                  exit); 
+
+        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry, NULL);
+        cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry, NULL);
 
-        lock_kernel();
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -434,11 +422,8 @@ static int smfs_rmdir(struct inode *dir, struct dentry *dentry)
         post_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
         unlock_kernel();
         
-        SMFS_KML_POST(dir, dentry, &mode, NULL,
-                      REINT_UNLINK, "rmdir", rc, exit);
-
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_RMDIR, handle, dir, dentry,
-                             NULL, NULL, rc, exit);
+        SMFS_HOOK(dir, dentry, &mode, NULL, HOOK_RMDIR, handle, POST_HOOK, 
+                  rc, exit); 
 exit:
         post_smfs_dentry(cache_dentry);
         post_smfs_dentry(cache_parent);
@@ -469,11 +454,13 @@ static int smfs_mknod(struct inode *dir, struct dentry *dentry,
                 CERROR("smfs_do_mkdir: no space for transaction\n");
                 RETURN(-ENOSPC);
         }
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_MKNOD, handle, dir);
 
-        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
-        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
         lock_kernel();
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKNOD, handle, PRE_HOOK, rc, 
+                  exit); 
+        
+        cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent, NULL);
+        cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry, NULL);
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -487,18 +474,16 @@ static int smfs_mknod(struct inode *dir, struct dentry *dentry,
                                          mode, rdev)))
                 GOTO(exit, rc);
 
-        inode = iget4(dir->i_sb, cache_dentry->d_inode->i_ino, NULL,
-                      &I2SMI(dir)->smi_flags);
+        inode = smfs_get_inode(dir->i_sb, cache_dentry->d_inode->i_ino, dir, 0);
+
         d_instantiate(dentry, inode);
 
         pre_smfs_inode(dir, cache_dir);
         pre_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
 
-        SMFS_KML_POST(dir, dentry, NULL, NULL,
-                      REINT_CREATE, "mknod", rc, exit);
-
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_MKNOD, handle, dir,
-                             dentry, NULL, NULL, rc, exit);
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKNOD, handle, POST_HOOK, rc, 
+                  exit); 
+        
 exit:
         unlock_kernel();
         post_smfs_dentry(cache_dentry);
@@ -534,17 +519,19 @@ static int smfs_rename(struct inode * old_dir, struct dentry *old_dentry,
         }
         lock_kernel();
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_RENAME, handle, old_dir);
-
-        cache_old_parent = pre_smfs_dentry(NULL, cache_old_dir, old_dentry);
+        
+        SMFS_HOOK(old_dir, old_dentry, new_dir, new_dentry, HOOK_RENAME, handle, 
+                  PRE_HOOK, rc, exit); 
+        
+        cache_old_parent = pre_smfs_dentry(NULL, cache_old_dir, old_dentry, NULL);
         cache_old_dentry = pre_smfs_dentry(cache_old_parent, cache_old_inode,
-                                           old_dentry);
+                                           old_dentry, NULL);
         if (!cache_old_parent || !cache_old_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
-        cache_new_parent = pre_smfs_dentry(NULL, cache_new_dir, new_dentry);
+        cache_new_parent = pre_smfs_dentry(NULL, cache_new_dir, new_dentry, NULL);
         cache_new_dentry = pre_smfs_dentry(cache_new_parent, cache_new_inode,
-                                           new_dentry);
+                                           new_dentry, NULL);
         if (!cache_new_parent || !cache_new_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -554,17 +541,15 @@ static int smfs_rename(struct inode * old_dir, struct dentry *old_dentry,
         if (cache_old_dir->i_op->rename)
                 rc = cache_old_dir->i_op->rename(cache_old_dir, cache_old_dentry,
                                                  cache_new_dir, cache_new_dentry);
-
+        
         post_smfs_inode(old_dir, cache_old_dir);
         post_smfs_inode(new_dir, cache_new_dir);
 
-        SMFS_KML_POST(old_dir, old_dentry, new_dir,
-                      new_dentry, REINT_RENAME, "rename", rc, exit);
+        SMFS_HOOK(old_dir, old_dentry, new_dir, new_dentry, HOOK_RENAME, handle, 
+                  POST_HOOK, rc, exit); 
+        
         if (new_dentry->d_inode)
                 post_smfs_inode(new_dentry->d_inode, cache_new_dentry->d_inode);
-
-        SMFS_CACHE_HOOK_POST(CACHE_HOOK_RENAME, handle, old_dir, old_dentry,
-                             new_dir, new_dentry, rc, exit);
 exit:
         unlock_kernel();
         post_smfs_dentry(cache_old_dentry);