mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-09 13:49:24 -04:00
exfat: introduce bitmap_lock for cluster bitmap access
s_lock which is for protecting concurrent access of file operations is too huge for cluster bitmap protection, so introduce a new bitmap_lock to narrow the lock range if only need to access cluster bitmap. Signed-off-by: Hyeongseok Kim <hyeongseok@gmail.com> Acked-by: Sungjong Seo <sj1557.seo@samsung.com> Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
This commit is contained in:
parent
73138cb2dc
commit
7646a7516d
3 changed files with 32 additions and 8 deletions
|
|
@ -247,6 +247,7 @@ struct exfat_sb_info {
|
|||
unsigned int used_clusters; /* number of used clusters */
|
||||
|
||||
struct mutex s_lock; /* superblock lock */
|
||||
struct mutex bitmap_lock; /* bitmap lock */
|
||||
struct exfat_mount_options options;
|
||||
struct nls_table *nls_io; /* Charset used for input and display */
|
||||
struct ratelimit_state ratelimit;
|
||||
|
|
|
|||
37
fatent.c
37
fatent.c
|
|
@ -159,13 +159,14 @@ int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
||||
/* This function must be called with bitmap_lock held */
|
||||
static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
||||
{
|
||||
unsigned int num_clusters = 0;
|
||||
unsigned int clu;
|
||||
struct super_block *sb = inode->i_sb;
|
||||
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||
int cur_cmap_i, next_cmap_i;
|
||||
unsigned int num_clusters = 0;
|
||||
unsigned int clu;
|
||||
|
||||
/* invalid cluster number */
|
||||
if (p_chain->dir == EXFAT_FREE_CLUSTER ||
|
||||
|
|
@ -238,6 +239,17 @@ dec_used_clus:
|
|||
return 0;
|
||||
}
|
||||
|
||||
int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&EXFAT_SB(inode->i_sb)->bitmap_lock);
|
||||
ret = __exfat_free_cluster(inode, p_chain);
|
||||
mutex_unlock(&EXFAT_SB(inode->i_sb)->bitmap_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
|
||||
unsigned int *ret_clu)
|
||||
{
|
||||
|
|
@ -336,6 +348,8 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||
if (num_alloc > total_cnt - sbi->used_clusters)
|
||||
return -ENOSPC;
|
||||
|
||||
mutex_lock(&sbi->bitmap_lock);
|
||||
|
||||
hint_clu = p_chain->dir;
|
||||
/* find new cluster */
|
||||
if (hint_clu == EXFAT_EOF_CLUSTER) {
|
||||
|
|
@ -346,8 +360,10 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||
}
|
||||
|
||||
hint_clu = exfat_find_free_bitmap(sb, sbi->clu_srch_ptr);
|
||||
if (hint_clu == EXFAT_EOF_CLUSTER)
|
||||
return -ENOSPC;
|
||||
if (hint_clu == EXFAT_EOF_CLUSTER) {
|
||||
ret = -ENOSPC;
|
||||
goto unlock;
|
||||
}
|
||||
}
|
||||
|
||||
/* check cluster validation */
|
||||
|
|
@ -357,8 +373,10 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||
hint_clu = EXFAT_FIRST_CLUSTER;
|
||||
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
||||
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
||||
num_clusters))
|
||||
return -EIO;
|
||||
num_clusters)) {
|
||||
ret = -EIO;
|
||||
goto unlock;
|
||||
}
|
||||
p_chain->flags = ALLOC_FAT_CHAIN;
|
||||
}
|
||||
}
|
||||
|
|
@ -408,6 +426,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||
sbi->used_clusters += num_clusters;
|
||||
|
||||
p_chain->size += num_clusters;
|
||||
mutex_unlock(&sbi->bitmap_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -427,7 +446,9 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|||
}
|
||||
free_cluster:
|
||||
if (num_clusters)
|
||||
exfat_free_cluster(inode, p_chain);
|
||||
__exfat_free_cluster(inode, p_chain);
|
||||
unlock:
|
||||
mutex_unlock(&sbi->bitmap_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
2
super.c
2
super.c
|
|
@ -902,6 +902,7 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent)
|
|||
return -ENOMEM;
|
||||
|
||||
mutex_init(&sbi->s_lock);
|
||||
mutex_init(&sbi->bitmap_lock);
|
||||
sb->s_fs_info = sbi;
|
||||
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
|
||||
DEFAULT_RATELIMIT_BURST);
|
||||
|
|
@ -1046,6 +1047,7 @@ static int exfat_init_fs_context(struct fs_context *fc)
|
|||
return -ENOMEM;
|
||||
|
||||
mutex_init(&sbi->s_lock);
|
||||
mutex_init(&sbi->bitmap_lock);
|
||||
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
|
||||
DEFAULT_RATELIMIT_BURST);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue