From 9effeba2fb589497a22f3ac2b93b0bf2d361d556 Mon Sep 17 00:00:00 2001 From: Erez Zadok Date: Thu, 10 Jan 2008 07:11:04 -0500 Subject: [PATCH] Unionfs: minor code rearrangement in rename To avoid too much code nesting. Signed-off-by: Erez Zadok --- fs/unionfs/rename.c | 91 ++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/fs/unionfs/rename.c b/fs/unionfs/rename.c index 0b3d94df4b..05867f4bea 100644 --- a/fs/unionfs/rename.c +++ b/fs/unionfs/rename.c @@ -415,57 +415,54 @@ int unionfs_rename(struct inode *old_dir, struct dentry *old_dentry, goto out; } } + err = do_unionfs_rename(old_dir, old_dentry, new_dir, new_dentry); -out: - if (err) { - /* clear the new_dentry stuff created */ - d_drop(new_dentry); - } else { - /* - * force re-lookup since the dir on ro branch is not renamed, - * and lower dentries still indicate the un-renamed ones. - */ - if (S_ISDIR(old_dentry->d_inode->i_mode)) - atomic_dec(&UNIONFS_D(old_dentry)->generation); - else - unionfs_postcopyup_release(old_dentry); - - /* - * If the dentry already existed before the rename and is - * not used by anyone else, we must purge its lower - * pointers, since it might remain in the cache for a while - * and the odf might give the same inode number to a new - * inode, so we don't want the new inode to have the old - * inode's pointers. - * - * If its i_count >= 2 we must not modify its lower - * pointers. The odf will silly rename this inode so it - * doesn't give it to another inode - */ - if (new_dentry->d_inode && - atomic_read(&new_dentry->d_inode->i_count) < 2) { - int bindex; - struct inode *i = new_dentry->d_inode; - for (bindex = ibstart(i); - bindex <= ibend(i); - bindex++) { - if (unionfs_lower_inode_idx(i, bindex)) - iput(unionfs_lower_inode_idx(i, - bindex)); - unionfs_set_lower_inode_idx(i, bindex, NULL); - } - } + if (err) + goto out; + /* + * force re-lookup since the dir on ro branch is not renamed, and + * lower dentries still indicate the un-renamed ones. + */ + if (S_ISDIR(old_dentry->d_inode->i_mode)) + atomic_dec(&UNIONFS_D(old_dentry)->generation); + else + unionfs_postcopyup_release(old_dentry); - /* if all of this renaming succeeded, update our times */ - unionfs_copy_attr_times(old_dir); - unionfs_copy_attr_times(new_dir); - unionfs_copy_attr_times(old_dentry->d_inode); - unionfs_copy_attr_times(new_dentry->d_inode); - unionfs_check_inode(old_dir); - unionfs_check_inode(new_dir); - unionfs_check_dentry(old_dentry); + /* + * If the dentry already existed before the rename and is not used + * by anyone else, we must purge its lower pointers, since it might + * remain in the cache for a while and the odf might give the same + * inode number to a new inode, so we don't want the new inode to + * have the old inode's pointers. + * + * If its i_count >= 2 we must not modify its lower pointers. + * The odf will silly rename this inode so it doesn't give it to + * another inode + */ + if (new_dentry->d_inode && + atomic_read(&new_dentry->d_inode->i_count) < 2) { + int bindex; + struct inode *i = new_dentry->d_inode; + for (bindex = ibstart(i); bindex <= ibend(i); bindex++) { + if (unionfs_lower_inode_idx(i, bindex)) + iput(unionfs_lower_inode_idx(i, bindex)); + unionfs_set_lower_inode_idx(i, bindex, NULL); + } } + /* if all of this renaming succeeded, update our times */ + unionfs_copy_attr_times(old_dir); + unionfs_copy_attr_times(new_dir); + unionfs_copy_attr_times(old_dentry->d_inode); + unionfs_copy_attr_times(new_dentry->d_inode); + unionfs_check_inode(old_dir); + unionfs_check_inode(new_dir); + unionfs_check_dentry(old_dentry); + unionfs_check_dentry(new_dentry); + +out: + if (err) /* clear the new_dentry stuff created */ + d_drop(new_dentry); unionfs_unlock_dentry(new_dentry); unionfs_unlock_dentry(old_dentry); unionfs_read_unlock(old_dentry->d_sb); -- 2.34.1