fs/lock: Limit inode type for file locks

When we close a socket fd, it will call get path on sockets.
`close(socket_fd)` -> `file_closelk(filep)` -> `file_fcntl(F_GETPATH)`
It causes a heavy stack load for each socket close operation.
(We have `GETPATH` for sockets to be used for `fdinfo`)

But the socket fds are not intended to be used for file locks.
And so do some other file types, so we may just limit the usage of flock.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng 2024-01-05 17:07:16 +08:00 committed by Alan Carvalho de Assis
parent 8cdec83adb
commit 14602be4cc

View File

@ -88,6 +88,22 @@ static mutex_t g_protect_lock = NXMUTEX_INITIALIZER;
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: file_lock_get_path
****************************************************************************/
static int file_lock_get_path(FAR struct file *filep, FAR char *path)
{
/* We only apply file lock on mount points (f_inode won't be NULL). */
if (!INODE_IS_MOUNTPT(filep->f_inode))
{
return -EBADF;
}
return file_fcntl(filep, F_GETPATH, path);
}
/****************************************************************************
* Name: file_lock_normalize
****************************************************************************/
@ -534,7 +550,7 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
/* We need to get the unique identifier (Path) via filep */
ret = file_fcntl(filep, F_GETPATH, path);
ret = file_lock_get_path(filep, path);
if (ret < 0)
{
return ret;
@ -613,7 +629,7 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
/* We need to get the unique identifier (Path) via filep */
ret = file_fcntl(filep, F_GETPATH, path);
ret = file_lock_get_path(filep, path);
if (ret < 0)
{
return ret;
@ -716,7 +732,7 @@ void file_closelk(FAR struct file *filep)
bool deleted = false;
int ret;
ret = file_fcntl(filep, F_GETPATH, path);
ret = file_lock_get_path(filep, path);
if (ret < 0)
{
/* It isn't an error if fs doesn't support F_GETPATH, so we just end