You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/07/22 03:00:31 UTC

[incubator-nuttx] branch master updated: unlink: don't do unlink with inode_semtake

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new cda9cfbc80 unlink: don't do unlink with inode_semtake
cda9cfbc80 is described below

commit cda9cfbc800f9c4084f9a61224d5114631f1e359
Author: ligd <li...@xiaomi.com>
AuthorDate: Fri Jul 8 12:25:58 2022 +0800

    unlink: don't do unlink with inode_semtake
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 fs/vfs/fs_unlink.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/fs/vfs/fs_unlink.c b/fs/vfs/fs_unlink.c
index 5efdce5712..8600572d81 100644
--- a/fs/vfs/fs_unlink.c
+++ b/fs/vfs/fs_unlink.c
@@ -108,12 +108,6 @@ int nx_unlink(FAR const char *pathname)
 
     {
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
-      ret = inode_semtake();
-      if (ret < 0)
-        {
-          goto errout_with_inode;
-        }
-
       /* Refuse to unlink the inode if it has children.  I.e., if it is
        * functioning as a directory and the directory is not empty.
        */
@@ -121,7 +115,7 @@ int nx_unlink(FAR const char *pathname)
       if (inode->i_child != NULL)
         {
           ret = -ENOTEMPTY;
-          goto errout_with_sem;
+          goto errout_with_inode;
         }
 
       /* Notify the driver that it has been unlinked.  If there are no
@@ -136,7 +130,7 @@ int nx_unlink(FAR const char *pathname)
           ret = inode->u.i_ops->unlink(inode);
           if (ret < 0)
             {
-              goto errout_with_sem;
+              goto errout_with_inode;
             }
         }
 #ifndef CONFIG_DISABLE_MOUNTPOINT
@@ -147,7 +141,7 @@ int nx_unlink(FAR const char *pathname)
           ret = inode->u.i_bops->unlink(inode);
           if (ret < 0)
             {
-              goto errout_with_sem;
+              goto errout_with_inode;
             }
         }
 #endif
@@ -165,7 +159,7 @@ int nx_unlink(FAR const char *pathname)
       else
         {
           ret = -ENXIO;
-          goto errout_with_sem;
+          goto errout_with_inode;
         }
 
       /* Remove the old inode.  Because we hold a reference count on the
@@ -175,6 +169,12 @@ int nx_unlink(FAR const char *pathname)
        * return -EBUSY to indicate that the inode was not deleted now.
        */
 
+      ret = inode_semtake();
+      if (ret < 0)
+        {
+          goto errout_with_inode;
+        }
+
       ret = inode_remove(pathname);
       inode_semgive();
 
@@ -191,10 +191,6 @@ int nx_unlink(FAR const char *pathname)
   RELEASE_SEARCH(&desc);
   return OK;
 
-#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
-errout_with_sem:
-  inode_semgive();
-#endif
 #if !defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
 errout_with_inode:
   inode_release(inode);