<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <pre>Under some conditions, the directory cannot be deleted.
The specific scenarios are as follows: (for example,
/mnt/ocfs2 is the mount point)

1. Create the /mnt/ocfs2/p_dir directory. At this time,
the i_nlink corresponding to the inode of
the /mnt/ocfs2/p_dir directory is equal to 2.

2. During the process of creating the
/mnt/ocfs2/p_dir/s_dir directory, if the call to the inc_nlink
function in ocfs2_mknod succeeds, the functions such as
ocfs2_init_acl, ocfs2_init_security_set, and ocfs2_dentry_attach_lock fail.
At this time, the i_nlink corresponding to the inode of the
/mnt/ocfs2/p_dir directory is equal to 3, but /mnt/ocfs2/p_dir/s_dir
is not added to the /mnt/ocfs2/p_dir directory entry.

3. Delete the /mnt/ocfs2/p_dir directory (rm -rf /mnt/ocfs2/p_dir).
At this time, it is found that the i_nlink corresponding to
the inode corresponding to the /mnt/ocfs2/p_dir directory is equal to 3.
Therefore, the /mnt/ocfs2/p_dir directory cannot be deleted.

Signed-off-by: Jian wang <a class="moz-txt-link-rfc2396E" href="mailto:wangjian161@huawei.com">&lt;wangjian161@huawei.com&gt;</a>
---
 ocfs2/namei.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/ocfs2/namei.c b/ocfs2/namei.c
index 8ea51cf..19543b4 100644
--- a/ocfs2/namei.c
+++ b/ocfs2/namei.c
@@ -388,17 +388,6 @@ static int ocfs2_mknod(struct inode *dir,
                         mlog_errno(status);
                         goto leave;
                 }
-
-                status = ocfs2_journal_access_di(handle, INODE_CACHE(dir),
-                                                 parent_fe_bh,
-                                                 OCFS2_JOURNAL_ACCESS_WRITE);
-                if (status &lt; 0) {
-                        mlog_errno(status);
-                        goto leave;
-                }
-                ocfs2_add_links_count(dirfe, 1);
-                ocfs2_journal_dirty(handle, parent_fe_bh);
-                inc_nlink(dir);
         }
 
         status = ocfs2_init_acl(handle, inode, dir, new_fe_bh, parent_fe_bh,
@@ -440,6 +429,19 @@ static int ocfs2_mknod(struct inode *dir,
                 goto leave;
         }
 
+        if (S_ISDIR(mode)) {
+                status = ocfs2_journal_access_di(handle, INODE_CACHE(dir),
+                                                 parent_fe_bh,
+                                                 OCFS2_JOURNAL_ACCESS_WRITE);
+                if (status &lt; 0) {
+                        mlog_errno(status);
+                        goto leave;
+                }
+                ocfs2_add_links_count(dirfe, 1);
+                ocfs2_journal_dirty(handle, parent_fe_bh);
+                inc_nlink(dir);
+        }
+
         insert_inode_hash(inode);
         d_instantiate(dentry, inode);
         status = 0;
-- 
1.8.3.1
</pre>
  </body>
</html>