ocfs2: re-order ocfs2_empty_dir checks
authorMark Fasheh <mfasheh@suse.com>
Wed, 18 Feb 2009 19:41:38 +0000 (11:41 -0800)
committerMark Fasheh <mfasheh@suse.com>
Fri, 3 Apr 2009 18:39:17 +0000 (11:39 -0700)
ocfs2_empty_dir() is far more expensive than checking link count. Since both
need to be checked at the same time, we can improve performance by checking
link count first.

Signed-off-by: Mark Fasheh <mfasheh@suse.com>
fs/ocfs2/namei.c

index 67113cfddc9ba7be5d981adfa07b84359e3448f4..58c318d2f0615bb4eb9df3c6e5a17dd202df77c3 100644 (file)
@@ -834,10 +834,7 @@ static int ocfs2_unlink(struct inode *dir,
        child_locked = 1;
 
        if (S_ISDIR(inode->i_mode)) {
-               if (!ocfs2_empty_dir(inode)) {
-                       status = -ENOTEMPTY;
-                       goto leave;
-               } else if (inode->i_nlink != 2) {
+               if (inode->i_nlink != 2 || !ocfs2_empty_dir(inode)) {
                        status = -ENOTEMPTY;
                        goto leave;
                }
@@ -1280,8 +1277,8 @@ static int ocfs2_rename(struct inode *old_dir,
 
        if (target_exists) {
                if (S_ISDIR(new_inode->i_mode)) {
-                       if (!ocfs2_empty_dir(new_inode) ||
-                           new_inode->i_nlink != 2) {
+                       if (new_inode->i_nlink != 2 ||
+                           !ocfs2_empty_dir(new_inode)) {
                                status = -ENOTEMPTY;
                                goto bail;
                        }