fs_lock:Reduce stack size
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
parent
a69d3d78fe
commit
0bf2634631
@ -548,15 +548,21 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
|
|||||||
{
|
{
|
||||||
FAR struct file_lock_bucket_s *bucket;
|
FAR struct file_lock_bucket_s *bucket;
|
||||||
FAR struct file_lock_s *file_lock;
|
FAR struct file_lock_s *file_lock;
|
||||||
char path[PATH_MAX];
|
FAR char *path;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* We need to get the unique identifier (Path) via filep */
|
/* We need to get the unique identifier (Path) via filep */
|
||||||
|
|
||||||
|
path = lib_get_pathbuffer();
|
||||||
|
if (path == NULL)
|
||||||
|
{
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
ret = file_lock_get_path(filep, path);
|
ret = file_lock_get_path(filep, path);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
return ret;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert a flock to a posix lock */
|
/* Convert a flock to a posix lock */
|
||||||
@ -564,11 +570,10 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
|
|||||||
ret = file_lock_normalize(filep, flock, flock);
|
ret = file_lock_normalize(filep, flock, flock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
return ret;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxmutex_lock(&g_protect_lock);
|
nxmutex_lock(&g_protect_lock);
|
||||||
|
|
||||||
bucket = file_lock_find_bucket(path);
|
bucket = file_lock_find_bucket(path);
|
||||||
if (bucket != NULL)
|
if (bucket != NULL)
|
||||||
{
|
{
|
||||||
@ -602,6 +607,8 @@ out:
|
|||||||
flock->l_len = flock->l_end - flock->l_start + 1;
|
flock->l_len = flock->l_end - flock->l_start + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_free:
|
||||||
|
lib_put_pathbuffer(path);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,16 +633,22 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
|
|||||||
{
|
{
|
||||||
FAR struct file_lock_bucket_s *bucket;
|
FAR struct file_lock_bucket_s *bucket;
|
||||||
FAR struct file_lock_s *file_lock;
|
FAR struct file_lock_s *file_lock;
|
||||||
|
FAR char *path;
|
||||||
struct flock request;
|
struct flock request;
|
||||||
char path[PATH_MAX];
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
path = lib_get_pathbuffer();
|
||||||
|
if (path == NULL)
|
||||||
|
{
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
/* We need to get the unique identifier (Path) via filep */
|
/* We need to get the unique identifier (Path) via filep */
|
||||||
|
|
||||||
ret = file_lock_get_path(filep, path);
|
ret = file_lock_get_path(filep, path);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
return ret;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert a flock to a posix lock */
|
/* Convert a flock to a posix lock */
|
||||||
@ -643,7 +656,7 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
|
|||||||
ret = file_lock_normalize(filep, flock, &request);
|
ret = file_lock_normalize(filep, flock, &request);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
return ret;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.l_pid = getpid();
|
request.l_pid = getpid();
|
||||||
@ -659,8 +672,8 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
|
|||||||
|
|
||||||
if (request.l_type == F_UNLCK)
|
if (request.l_type == F_UNLCK)
|
||||||
{
|
{
|
||||||
nxmutex_unlock(&g_protect_lock);
|
ret = OK;
|
||||||
return OK;
|
goto out_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* It looks like we didn't find a bucket, let's go create one */
|
/* It looks like we didn't find a bucket, let's go create one */
|
||||||
@ -668,8 +681,8 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
|
|||||||
bucket = file_lock_create_bucket(path);
|
bucket = file_lock_create_bucket(path);
|
||||||
if (bucket == NULL)
|
if (bucket == NULL)
|
||||||
{
|
{
|
||||||
nxmutex_unlock(&g_protect_lock);
|
ret = -ENOMEM;
|
||||||
return -ENOMEM;
|
goto out_lock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (request.l_type != F_UNLCK)
|
else if (request.l_type != F_UNLCK)
|
||||||
@ -711,7 +724,10 @@ retry:
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
file_lock_delete_bucket(bucket, path);
|
file_lock_delete_bucket(bucket, path);
|
||||||
|
out_lock:
|
||||||
nxmutex_unlock(&g_protect_lock);
|
nxmutex_unlock(&g_protect_lock);
|
||||||
|
out_free:
|
||||||
|
lib_put_pathbuffer(path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -731,10 +747,16 @@ void file_closelk(FAR struct file *filep)
|
|||||||
FAR struct file_lock_bucket_s *bucket;
|
FAR struct file_lock_bucket_s *bucket;
|
||||||
FAR struct file_lock_s *file_lock;
|
FAR struct file_lock_s *file_lock;
|
||||||
FAR struct file_lock_s *temp;
|
FAR struct file_lock_s *temp;
|
||||||
char path[PATH_MAX];
|
FAR char *path;
|
||||||
bool deleted = false;
|
bool deleted = false;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
path = lib_get_pathbuffer();
|
||||||
|
if (path == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ret = file_lock_get_path(filep, path);
|
ret = file_lock_get_path(filep, path);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -742,7 +764,7 @@ void file_closelk(FAR struct file *filep)
|
|||||||
* it.
|
* it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bucket = file_lock_find_bucket(path);
|
bucket = file_lock_find_bucket(path);
|
||||||
@ -750,7 +772,7 @@ void file_closelk(FAR struct file *filep)
|
|||||||
{
|
{
|
||||||
/* There is no bucket here, so we don't need to free it. */
|
/* There is no bucket here, so we don't need to free it. */
|
||||||
|
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxmutex_lock(&g_protect_lock);
|
nxmutex_lock(&g_protect_lock);
|
||||||
@ -774,6 +796,8 @@ void file_closelk(FAR struct file *filep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
nxmutex_unlock(&g_protect_lock);
|
nxmutex_unlock(&g_protect_lock);
|
||||||
|
out:
|
||||||
|
lib_put_pathbuffer(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user