X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fsmfs%2Fdir.c;h=f9540638ec40dcae670e4ed15221cea867b10981;hb=b3d839c2925f4e7f19fd06841b7302bc827956f3;hp=4a3c943f85aa8bcaebb059efee15ed048469b67d;hpb=1675d042a7cbc25c2b2dc8e6e790006a95114ad5;p=fs%2Flustre-release.git diff --git a/lustre/smfs/dir.c b/lustre/smfs/dir.c index 4a3c943..f954063 100644 --- a/lustre/smfs/dir.c +++ b/lustre/smfs/dir.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "smfs_internal.h" @@ -64,20 +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); - - 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 +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); @@ -127,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)); @@ -150,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); @@ -175,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); @@ -204,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); @@ -234,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); @@ -266,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); @@ -282,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); @@ -307,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); @@ -333,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); @@ -363,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); @@ -379,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); @@ -419,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(); + + 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); + 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); @@ -437,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); @@ -472,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); @@ -490,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); @@ -537,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); @@ -557,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);