Whamcloud - gitweb
exp might be NULL
[fs/lustre-release.git] / lustre / smfs / dir.c
index 02e23ba..685d6ff 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,20 +65,19 @@ 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, rc);
-
+        
+        lock_kernel();
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_CREATE, handle,
+                  PRE_HOOK, rc, exit);
+        
         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
 
-        lock_kernel();
         if (!cache_dentry || !cache_parent)
                 GOTO(exit, rc = -ENOMEM);
-
+       
         pre_smfs_inode(dir, cache_dir);
-
-        SMFS_PRE_COW(dir, dentry, REINT_CREATE, "create", rc, exit);
-
+        
 #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,
@@ -89,22 +89,15 @@ 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);
-        if (!inode)
-                GOTO(exit, rc = -ENOMEM);
+        
+        SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode,
+                       rc, exit); 
 
         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);
@@ -134,11 +127,6 @@ static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry,
         if (!(cache_dir = I2CI(dir)))
                 RETURN(ERR_PTR(-ENOENT));
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_LOOKUP, handle, dir, rc2);
-        
-        if (rc2)
-                RETURN(ERR_PTR(rc2));
-
         /* 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);
@@ -149,35 +137,33 @@ 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, NULL, 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);
-        } else {
-                d_add(dentry, NULL);
-                GOTO(exit, rc);
+                SMFS_GET_INODE(dir->i_sb, cache_inode, dir, inode, rc2, exit);
         }
 
         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);
@@ -185,32 +171,32 @@ exit:
         RETURN(rc);
 }
 
-static int smfs_link(struct dentry * old_dentry,
-                     struct inode * dir, struct dentry *dentry)
+static int smfs_link(struct dentry *old_dentry,
+                     struct inode *dir, struct dentry *dentry)
 {
-        struct        inode *cache_old_inode = NULL;
-        struct        inode *cache_dir = I2CI(dir);
-        struct        inode *inode = NULL;
-        struct  dentry *cache_dentry = NULL;
-        struct  dentry *cache_old_dentry = NULL;
-        struct  dentry *cache_parent = NULL;
-        void        *handle = NULL;
-        int        rc = 0;
+        struct inode *cache_old_inode = NULL;
+        struct inode *cache_dir = I2CI(dir);
+        struct inode *inode = NULL;
+        struct dentry *cache_dentry = NULL;
+        struct dentry *cache_old_dentry = NULL;
+        struct dentry *cache_parent = NULL;
+        void *handle = NULL;
+        int rc = 0;
 
         inode = old_dentry->d_inode;
-
         cache_old_inode = I2CI(inode);
 
         handle = smfs_trans_start(dir, FSFILT_OP_LINK, NULL);
         if (IS_ERR(handle))
                  RETURN(-ENOSPC);
-
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_LINK, handle, dir, rc);
-              
+        
+        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);
         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
 
-        lock_kernel();
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -233,11 +219,8 @@ 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);
@@ -265,8 +248,9 @@ static int smfs_unlink(struct inode * dir,
         if (IS_ERR(handle))
                 RETURN(-ENOSPC);
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_UNLINK, handle, dir, rc);
-
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_UNLINK, handle, PRE_HOOK, rc, 
+                  exit); 
+        
         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
         cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
 
@@ -281,11 +265,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);
@@ -306,37 +288,36 @@ 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, rc);
+        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);
+       
         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);
         post_smfs_inode(dir, cache_dir);
+        
+        SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
         if (inode)
                 d_instantiate(dentry, inode);
         else
                 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);
@@ -362,12 +343,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, rc);
-
+        lock_kernel();
+        
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKDIR, handle, PRE_HOOK, rc, 
+                  exit); 
+        
         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
 
-        lock_kernel();
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -378,20 +361,13 @@ static int smfs_mkdir(struct inode *dir, struct dentry *dentry,
 
         if (rc)
                 GOTO(exit, rc);
-
-        inode = iget4(dir->i_sb, cache_dentry->d_inode->i_ino, NULL,
-                      &I2SMI(dir)->smi_flags);
-        if (!inode)
-                GOTO(exit, rc = -ENOENT);
-
+  
+        SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
         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);
@@ -418,12 +394,14 @@ static int smfs_rmdir(struct inode *dir, struct dentry *dentry)
                 RETURN(-ENOSPC);
         }
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_RMDIR, handle, dir, rc);
+        lock_kernel();
+
+        SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_RMDIR, handle, PRE_HOOK, rc, 
+                  exit); 
 
         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
         cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
 
-        lock_kernel();
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -436,11 +414,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);
@@ -471,11 +446,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, rc);
 
+        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);
         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
-        lock_kernel();
         if (!cache_parent || !cache_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -489,18 +466,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);
+        SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
+
         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);
@@ -509,8 +484,8 @@ exit:
         RETURN(rc);
 }
 
-static int smfs_rename(struct inode * old_dir, struct dentry *old_dentry,
-                       struct inode * new_dir,struct dentry *new_dentry)
+static int smfs_rename(struct inode *old_dir, struct dentry *old_dentry,
+                       struct inode *new_dir,struct dentry *new_dentry)
 {
         struct inode *cache_old_dir = I2CI(old_dir);
         struct inode *cache_new_dir = I2CI(new_dir);
@@ -536,17 +511,23 @@ static int smfs_rename(struct inode * old_dir, struct dentry *old_dentry,
         }
         lock_kernel();
 
-        SMFS_CACHE_HOOK_PRE(CACHE_HOOK_RENAME, handle, old_dir, rc);
-
+        
+        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);
+
         cache_old_dentry = pre_smfs_dentry(cache_old_parent, cache_old_inode,
                                            old_dentry);
+        
         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_dentry = pre_smfs_dentry(cache_new_parent, cache_new_inode,
                                            new_dentry);
+
         if (!cache_new_parent || !cache_new_dentry)
                 GOTO(exit, rc = -ENOMEM);
 
@@ -556,17 +537,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);
@@ -620,7 +599,6 @@ static ssize_t smfs_read_dir(struct file *filp, char *buf,
         if (cache_inode->i_fop->read)
                 rc = cache_inode->i_fop->read(sfi->c_file, buf, size,
                                               cache_ppos);
-
         *ppos = *cache_ppos;
         duplicate_file(filp, sfi->c_file);
         RETURN(rc);
@@ -640,18 +618,27 @@ static int smfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
         sfi = F2SMFI(filp);
         if (sfi->magic != SMFS_FILE_MAGIC) BUG();
 
+        SMFS_HOOK(dentry->d_inode, filp, dirent, filldir, HOOK_READDIR, NULL, 
+                  PRE_HOOK, rc, exit); 
+        
         if (cache_inode->i_fop->readdir)
                 rc = cache_inode->i_fop->readdir(sfi->c_file, dirent, filldir);
 
+        SMFS_HOOK(dentry->d_inode, filp, dirent, filldir, HOOK_READDIR, NULL, 
+                  POST_HOOK, rc, exit);
+        
         duplicate_file(filp, sfi->c_file);
+exit:
+        if (rc > 0)
+                rc = 0;
         RETURN(rc);
 }
 
 struct file_operations smfs_dir_fops = {
-        read:           smfs_read_dir,
-        readdir:        smfs_readdir,           /* BKL held */
-        ioctl:          smfs_ioctl,             /* BKL held */
-        fsync:          smfs_fsync,         /* BKL held */
-        open:           smfs_open,
-        release:        smfs_release,
+        .read           = smfs_read_dir,
+        .readdir        = smfs_readdir,       /* BKL held */
+        .ioctl          = smfs_ioctl,         /* BKL held */
+        .fsync          = smfs_fsync,         /* BKL held */
+        .open           = smfs_open,
+        .release        = smfs_release,
 };