[v2,3/4] erofs: relinquish volume with mutex held

Message ID 20230209051838.33297-4-jefflexu@linux.alibaba.com
State New
Headers
Series erofs: cleanup for fscache share domain mode |

Commit Message

Jingbo Xu Feb. 9, 2023, 5:18 a.m. UTC
  Relinquish fscache volume with mutex held.  Otherwise if a new domain is
registered when the old domain with the same name gets removed from the
list but not relinquished yet, fscache may complain the collision.

Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Jia Zhu <zhujia.zj@bytedance.com>
---
 fs/erofs/fscache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Gao Xiang Feb. 9, 2023, 6:06 a.m. UTC | #1
On 2023/2/9 13:18, Jingbo Xu wrote:
> Relinquish fscache volume with mutex held.  Otherwise if a new domain is
> registered when the old domain with the same name gets removed from the
> list but not relinquished yet, fscache may complain the collision.
> 
> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
> Reviewed-by: Jia Zhu <zhujia.zj@bytedance.com>

Do we need to backport this to old kernels?
IOWs, whether "Fixes:" tag is needed?

Thanks,
Gao Xiang

> ---
>   fs/erofs/fscache.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
> index 2f5930e177cc..a6f030966147 100644
> --- a/fs/erofs/fscache.c
> +++ b/fs/erofs/fscache.c
> @@ -328,8 +328,8 @@ static void erofs_fscache_domain_put(struct erofs_domain *domain)
>   			kern_unmount(erofs_pseudo_mnt);
>   			erofs_pseudo_mnt = NULL;
>   		}
> -		mutex_unlock(&erofs_domain_list_lock);
>   		fscache_relinquish_volume(domain->volume, NULL, false);
> +		mutex_unlock(&erofs_domain_list_lock);
>   		kfree(domain->domain_id);
>   		kfree(domain);
>   		return;
  
Jingbo Xu Feb. 9, 2023, 6:14 a.m. UTC | #2
On 2/9/23 2:06 PM, Gao Xiang wrote:
> 
> 
> On 2023/2/9 13:18, Jingbo Xu wrote:
>> Relinquish fscache volume with mutex held.  Otherwise if a new domain is
>> registered when the old domain with the same name gets removed from the
>> list but not relinquished yet, fscache may complain the collision.
>>
>> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
>> Reviewed-by: Jia Zhu <zhujia.zj@bytedance.com>
> 
> Do we need to backport this to old kernels?
> IOWs, whether "Fixes:" tag is needed?

Yeah the small fix is appropriate for being backported.

Fixes: 8b7adf1dff3d ("erofs: introduce fscache-based domain")

I will add the "Fixes" tag in the next version.
  

Patch

diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index 2f5930e177cc..a6f030966147 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -328,8 +328,8 @@  static void erofs_fscache_domain_put(struct erofs_domain *domain)
 			kern_unmount(erofs_pseudo_mnt);
 			erofs_pseudo_mnt = NULL;
 		}
-		mutex_unlock(&erofs_domain_list_lock);
 		fscache_relinquish_volume(domain->volume, NULL, false);
+		mutex_unlock(&erofs_domain_list_lock);
 		kfree(domain->domain_id);
 		kfree(domain);
 		return;