|
Kmods SIG |
9e3ffb |
From 5c2d728507299f84631ab8020d6f0f98f2cb8fc2 Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
9e3ffb |
From: Hyeongseok Kim <hyeongseok@gmail.com>
|
|
Kmods SIG |
9e3ffb |
Date: Tue, 2 Mar 2021 14:05:20 +0900
|
|
Kmods SIG |
9e3ffb |
Subject: [Backport 5c2d72850729] exfat: introduce bitmap_lock for cluster
|
|
Kmods SIG |
9e3ffb |
bitmap access
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
s_lock which is for protecting concurrent access of file operations is
|
|
Kmods SIG |
9e3ffb |
too huge for cluster bitmap protection, so introduce a new bitmap_lock
|
|
Kmods SIG |
9e3ffb |
to narrow the lock range if only need to access cluster bitmap.
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
Signed-off-by: Hyeongseok Kim <hyeongseok@gmail.com>
|
|
Kmods SIG |
9e3ffb |
Acked-by: Sungjong Seo <sj1557.seo@samsung.com>
|
|
Kmods SIG |
9e3ffb |
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
|
|
Kmods SIG |
9e3ffb |
---
|
|
Kmods SIG |
9e3ffb |
src/exfat_fs.h | 1 +
|
|
Kmods SIG |
9e3ffb |
src/fatent.c | 37 +++++++++++++++++++++++++++++--------
|
|
Kmods SIG |
9e3ffb |
src/super.c | 1 +
|
|
Kmods SIG |
9e3ffb |
3 files changed, 31 insertions(+), 8 deletions(-)
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
diff --git a/src/exfat_fs.h b/src/exfat_fs.h
|
|
Kmods SIG |
9e3ffb |
index fa21421a14d9e047add5b9b03c0970b4fd4d7522..e05e0a3152c0e5c415bd042e40d680194f02b49e 100644
|
|
Kmods SIG |
9e3ffb |
--- a/src/exfat_fs.h
|
|
Kmods SIG |
9e3ffb |
+++ b/src/exfat_fs.h
|
|
Kmods SIG |
9e3ffb |
@@ -238,6 +238,7 @@ struct exfat_sb_info {
|
|
Kmods SIG |
9e3ffb |
unsigned int used_clusters; /* number of used clusters */
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
struct mutex s_lock; /* superblock lock */
|
|
Kmods SIG |
9e3ffb |
+ struct mutex bitmap_lock; /* bitmap lock */
|
|
Kmods SIG |
9e3ffb |
struct exfat_mount_options options;
|
|
Kmods SIG |
9e3ffb |
struct nls_table *nls_io; /* Charset used for input and display */
|
|
Kmods SIG |
9e3ffb |
struct ratelimit_state ratelimit;
|
|
Kmods SIG |
9e3ffb |
diff --git a/src/fatent.c b/src/fatent.c
|
|
Kmods SIG |
9e3ffb |
index 7b2e8af17193bfffe00b4e0b8b88cccb34b1970a..fd6c7fd127620fc405cff2b5ae2d6fae5be25422 100644
|
|
Kmods SIG |
9e3ffb |
--- a/src/fatent.c
|
|
Kmods SIG |
9e3ffb |
+++ b/src/fatent.c
|
|
Kmods SIG |
9e3ffb |
@@ -151,13 +151,14 @@ int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain,
|
|
Kmods SIG |
9e3ffb |
return 0;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
-int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
|
Kmods SIG |
9e3ffb |
+/* This function must be called with bitmap_lock held */
|
|
Kmods SIG |
9e3ffb |
+static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
|
Kmods SIG |
9e3ffb |
{
|
|
Kmods SIG |
9e3ffb |
- unsigned int num_clusters = 0;
|
|
Kmods SIG |
9e3ffb |
- unsigned int clu;
|
|
Kmods SIG |
9e3ffb |
struct super_block *sb = inode->i_sb;
|
|
Kmods SIG |
9e3ffb |
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
9e3ffb |
int cur_cmap_i, next_cmap_i;
|
|
Kmods SIG |
9e3ffb |
+ unsigned int num_clusters = 0;
|
|
Kmods SIG |
9e3ffb |
+ unsigned int clu;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
/* invalid cluster number */
|
|
Kmods SIG |
9e3ffb |
if (p_chain->dir == EXFAT_FREE_CLUSTER ||
|
|
Kmods SIG |
9e3ffb |
@@ -230,6 +231,17 @@ int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
|
Kmods SIG |
9e3ffb |
return 0;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
+int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
|
Kmods SIG |
9e3ffb |
+{
|
|
Kmods SIG |
9e3ffb |
+ int ret = 0;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ mutex_lock(&EXFAT_SB(inode->i_sb)->bitmap_lock);
|
|
Kmods SIG |
9e3ffb |
+ ret = __exfat_free_cluster(inode, p_chain);
|
|
Kmods SIG |
9e3ffb |
+ mutex_unlock(&EXFAT_SB(inode->i_sb)->bitmap_lock);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ return ret;
|
|
Kmods SIG |
9e3ffb |
+}
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
|
|
Kmods SIG |
9e3ffb |
unsigned int *ret_clu)
|
|
Kmods SIG |
9e3ffb |
{
|
|
Kmods SIG |
9e3ffb |
@@ -328,6 +340,8 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|
Kmods SIG |
9e3ffb |
if (num_alloc > total_cnt - sbi->used_clusters)
|
|
Kmods SIG |
9e3ffb |
return -ENOSPC;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
+ mutex_lock(&sbi->bitmap_lock);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
hint_clu = p_chain->dir;
|
|
Kmods SIG |
9e3ffb |
/* find new cluster */
|
|
Kmods SIG |
9e3ffb |
if (hint_clu == EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
9e3ffb |
@@ -338,8 +352,10 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
hint_clu = exfat_find_free_bitmap(sb, sbi->clu_srch_ptr);
|
|
Kmods SIG |
9e3ffb |
- if (hint_clu == EXFAT_EOF_CLUSTER)
|
|
Kmods SIG |
9e3ffb |
- return -ENOSPC;
|
|
Kmods SIG |
9e3ffb |
+ if (hint_clu == EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
9e3ffb |
+ ret = -ENOSPC;
|
|
Kmods SIG |
9e3ffb |
+ goto unlock;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
/* check cluster validation */
|
|
Kmods SIG |
9e3ffb |
@@ -349,8 +365,10 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|
Kmods SIG |
9e3ffb |
hint_clu = EXFAT_FIRST_CLUSTER;
|
|
Kmods SIG |
9e3ffb |
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
|
Kmods SIG |
9e3ffb |
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
|
Kmods SIG |
9e3ffb |
- num_clusters))
|
|
Kmods SIG |
9e3ffb |
- return -EIO;
|
|
Kmods SIG |
9e3ffb |
+ num_clusters)) {
|
|
Kmods SIG |
9e3ffb |
+ ret = -EIO;
|
|
Kmods SIG |
9e3ffb |
+ goto unlock;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
p_chain->flags = ALLOC_FAT_CHAIN;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
@@ -400,6 +418,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|
Kmods SIG |
9e3ffb |
sbi->used_clusters += num_clusters;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
p_chain->size += num_clusters;
|
|
Kmods SIG |
9e3ffb |
+ mutex_unlock(&sbi->bitmap_lock);
|
|
Kmods SIG |
9e3ffb |
return 0;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
@@ -419,7 +438,9 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
free_cluster:
|
|
Kmods SIG |
9e3ffb |
if (num_clusters)
|
|
Kmods SIG |
9e3ffb |
- exfat_free_cluster(inode, p_chain);
|
|
Kmods SIG |
9e3ffb |
+ __exfat_free_cluster(inode, p_chain);
|
|
Kmods SIG |
9e3ffb |
+unlock:
|
|
Kmods SIG |
9e3ffb |
+ mutex_unlock(&sbi->bitmap_lock);
|
|
Kmods SIG |
9e3ffb |
return ret;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
diff --git a/src/super.c b/src/super.c
|
|
Kmods SIG |
9e3ffb |
index c6d8d2e534865236d16386575627e0a442a8db52..d38d17a77e76c45a006abeae532a6ae3170529d7 100644
|
|
Kmods SIG |
9e3ffb |
--- a/src/super.c
|
|
Kmods SIG |
9e3ffb |
+++ b/src/super.c
|
|
Kmods SIG |
9e3ffb |
@@ -752,6 +752,7 @@ static int exfat_init_fs_context(struct fs_context *fc)
|
|
Kmods SIG |
9e3ffb |
return -ENOMEM;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
mutex_init(&sbi->s_lock);
|
|
Kmods SIG |
9e3ffb |
+ mutex_init(&sbi->bitmap_lock);
|
|
Kmods SIG |
9e3ffb |
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
|
|
Kmods SIG |
9e3ffb |
DEFAULT_RATELIMIT_BURST);
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
--
|
|
Kmods SIG |
9e3ffb |
2.31.1
|
|
Kmods SIG |
9e3ffb |
|