unlink: don't do unlink with inode_semtake

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd
2022-07-08 12:25:58 +08:00
committed by Xiang Xiao
parent 30f8d33bca
commit cda9cfbc80
+10 -14
View File
@@ -108,12 +108,6 @@ int nx_unlink(FAR const char *pathname)
{ {
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS #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 /* Refuse to unlink the inode if it has children. I.e., if it is
* functioning as a directory and the directory is not empty. * 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) if (inode->i_child != NULL)
{ {
ret = -ENOTEMPTY; ret = -ENOTEMPTY;
goto errout_with_sem; goto errout_with_inode;
} }
/* Notify the driver that it has been unlinked. If there are no /* 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); ret = inode->u.i_ops->unlink(inode);
if (ret < 0) if (ret < 0)
{ {
goto errout_with_sem; goto errout_with_inode;
} }
} }
#ifndef CONFIG_DISABLE_MOUNTPOINT #ifndef CONFIG_DISABLE_MOUNTPOINT
@@ -147,7 +141,7 @@ int nx_unlink(FAR const char *pathname)
ret = inode->u.i_bops->unlink(inode); ret = inode->u.i_bops->unlink(inode);
if (ret < 0) if (ret < 0)
{ {
goto errout_with_sem; goto errout_with_inode;
} }
} }
#endif #endif
@@ -165,7 +159,7 @@ int nx_unlink(FAR const char *pathname)
else else
{ {
ret = -ENXIO; ret = -ENXIO;
goto errout_with_sem; goto errout_with_inode;
} }
/* Remove the old inode. Because we hold a reference count on the /* 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. * 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); ret = inode_remove(pathname);
inode_semgive(); inode_semgive();
@@ -191,10 +191,6 @@ int nx_unlink(FAR const char *pathname)
RELEASE_SEARCH(&desc); RELEASE_SEARCH(&desc);
return OK; return OK;
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
errout_with_sem:
inode_semgive();
#endif
#if !defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) #if !defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
errout_with_inode: errout_with_inode:
inode_release(inode); inode_release(inode);