[v2,1/2] exfat: simplify empty entry hint

Message ID PUZPR04MB6316C6A981A51EA6C079455D81399@PUZPR04MB6316.apcprd04.prod.outlook.com
State New
Headers
Series [v2,1/2] exfat: simplify empty entry hint |

Commit Message

Yuezhang.Mo@sony.com Nov. 2, 2022, 7:11 a.m. UTC
  This commit adds exfat_set_empty_hint()/exfat_reset_empty_hint()
to reduce code complexity and make code more readable.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
---
 fs/exfat/dir.c | 58 +++++++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 27 deletions(-)

-- 
2.25.1
  

Comments

Sungjong Seo Nov. 3, 2022, 12:49 p.m. UTC | #1
> This commit adds exfat_set_empty_hint()/exfat_reset_empty_hint()
> to reduce code complexity and make code more readable.
> 
> Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
> Reviewed-by: Andy Wu <Andy.Wu@sony.com>
> Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>

Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>

Looks good. Thanks!

> ---
>  fs/exfat/dir.c | 58 +++++++++++++++++++++++++++-----------------------
>  1 file changed, 31 insertions(+), 27 deletions(-)
> 
> diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index
> a27b55ec060a..9f9b8435baca 100644
> --- a/fs/exfat/dir.c
> +++ b/fs/exfat/dir.c
> @@ -897,6 +897,29 @@ struct exfat_entry_set_cache
> *exfat_get_dentry_set(struct super_block *sb,
>  	return NULL;
>  }
> 
> +static inline void exfat_reset_empty_hint(struct exfat_hint_femp
> +*hint_femp) {
> +	hint_femp->eidx = EXFAT_HINT_NONE;
> +	hint_femp->count = 0;
> +}
> +
> +static inline void exfat_set_empty_hint(struct exfat_inode_info *ei,
> +		struct exfat_hint_femp *candi_empty, struct exfat_chain *clu,
> +		int dentry, int num_entries)
> +{
> +	if (ei->hint_femp.eidx == EXFAT_HINT_NONE ||
> +	    ei->hint_femp.eidx > dentry) {
> +		if (candi_empty->count == 0) {
> +			candi_empty->cur = *clu;
> +			candi_empty->eidx = dentry;
> +		}
> +
> +		candi_empty->count++;
> +		if (candi_empty->count == num_entries)
> +			ei->hint_femp = *candi_empty;
> +	}
> +}
> +
>  enum {
>  	DIRENT_STEP_FILE,
>  	DIRENT_STEP_STRM,
> @@ -921,7 +944,7 @@ int exfat_find_dir_entry(struct super_block *sb,
> struct exfat_inode_info *ei,  {
>  	int i, rewind = 0, dentry = 0, end_eidx = 0, num_ext = 0, len;
>  	int order, step, name_len = 0;
> -	int dentries_per_clu, num_empty = 0;
> +	int dentries_per_clu;
>  	unsigned int entry_type;
>  	unsigned short *uniname = NULL;
>  	struct exfat_chain clu;
> @@ -939,10 +962,13 @@ int exfat_find_dir_entry(struct super_block *sb,
> struct exfat_inode_info *ei,
>  		end_eidx = dentry;
>  	}
> 
> -	candi_empty.eidx = EXFAT_HINT_NONE;
> +	exfat_reset_empty_hint(&ei->hint_femp);
> +
>  rewind:
>  	order = 0;
>  	step = DIRENT_STEP_FILE;
> +	exfat_reset_empty_hint(&candi_empty);
> +
>  	while (clu.dir != EXFAT_EOF_CLUSTER) {
>  		i = dentry & (dentries_per_clu - 1);
>  		for (; i < dentries_per_clu; i++, dentry++) { @@ -962,26
> +988,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct
> exfat_inode_info *ei,
>  			    entry_type == TYPE_DELETED) {
>  				step = DIRENT_STEP_FILE;
> 
> -				num_empty++;
> -				if (candi_empty.eidx == EXFAT_HINT_NONE &&
> -						num_empty == 1) {
> -					exfat_chain_set(&candi_empty.cur,
> -						clu.dir, clu.size, clu.flags);
> -				}
> -
> -				if (candi_empty.eidx == EXFAT_HINT_NONE &&
> -						num_empty >= num_entries) {
> -					candi_empty.eidx =
> -						dentry - (num_empty - 1);
> -					WARN_ON(candi_empty.eidx < 0);
> -					candi_empty.count = num_empty;
> -
> -					if (ei->hint_femp.eidx ==
> -							EXFAT_HINT_NONE ||
> -						candi_empty.eidx <=
> -							 ei->hint_femp.eidx)
> -						ei->hint_femp = candi_empty;
> -				}
> +				exfat_set_empty_hint(ei, &candi_empty, &clu,
> +						dentry, num_entries);
> 
>  				brelse(bh);
>  				if (entry_type == TYPE_UNUSED)
> @@ -989,8 +997,7 @@ int exfat_find_dir_entry(struct super_block *sb,
> struct exfat_inode_info *ei,
>  				continue;
>  			}
> 
> -			num_empty = 0;
> -			candi_empty.eidx = EXFAT_HINT_NONE;
> +			exfat_reset_empty_hint(&candi_empty);
> 
>  			if (entry_type == TYPE_FILE || entry_type == TYPE_DIR)
> {
>  				step = DIRENT_STEP_FILE;
> @@ -1090,9 +1097,6 @@ int exfat_find_dir_entry(struct super_block *sb,
> struct exfat_inode_info *ei,
>  		rewind = 1;
>  		dentry = 0;
>  		clu.dir = p_dir->dir;
> -		/* reset empty hint */
> -		num_empty = 0;
> -		candi_empty.eidx = EXFAT_HINT_NONE;
>  		goto rewind;
>  	}
> 
> --
> 2.25.1
  
Namjae Jeon Nov. 8, 2022, 8 a.m. UTC | #2
2022-11-02 16:11 GMT+09:00, Yuezhang.Mo@sony.com <Yuezhang.Mo@sony.com>:
> This commit adds exfat_set_empty_hint()/exfat_reset_empty_hint()
> to reduce code complexity and make code more readable.
>
> Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
> Reviewed-by: Andy Wu <Andy.Wu@sony.com>
> Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Applied. Thanks for your patch!
  

Patch

diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index a27b55ec060a..9f9b8435baca 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -897,6 +897,29 @@  struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
 	return NULL;
 }
 
+static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp)
+{
+	hint_femp->eidx = EXFAT_HINT_NONE;
+	hint_femp->count = 0;
+}
+
+static inline void exfat_set_empty_hint(struct exfat_inode_info *ei,
+		struct exfat_hint_femp *candi_empty, struct exfat_chain *clu,
+		int dentry, int num_entries)
+{
+	if (ei->hint_femp.eidx == EXFAT_HINT_NONE ||
+	    ei->hint_femp.eidx > dentry) {
+		if (candi_empty->count == 0) {
+			candi_empty->cur = *clu;
+			candi_empty->eidx = dentry;
+		}
+
+		candi_empty->count++;
+		if (candi_empty->count == num_entries)
+			ei->hint_femp = *candi_empty;
+	}
+}
+
 enum {
 	DIRENT_STEP_FILE,
 	DIRENT_STEP_STRM,
@@ -921,7 +944,7 @@  int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
 {
 	int i, rewind = 0, dentry = 0, end_eidx = 0, num_ext = 0, len;
 	int order, step, name_len = 0;
-	int dentries_per_clu, num_empty = 0;
+	int dentries_per_clu;
 	unsigned int entry_type;
 	unsigned short *uniname = NULL;
 	struct exfat_chain clu;
@@ -939,10 +962,13 @@  int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
 		end_eidx = dentry;
 	}
 
-	candi_empty.eidx = EXFAT_HINT_NONE;
+	exfat_reset_empty_hint(&ei->hint_femp);
+
 rewind:
 	order = 0;
 	step = DIRENT_STEP_FILE;
+	exfat_reset_empty_hint(&candi_empty);
+
 	while (clu.dir != EXFAT_EOF_CLUSTER) {
 		i = dentry & (dentries_per_clu - 1);
 		for (; i < dentries_per_clu; i++, dentry++) {
@@ -962,26 +988,8 @@  int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
 			    entry_type == TYPE_DELETED) {
 				step = DIRENT_STEP_FILE;
 
-				num_empty++;
-				if (candi_empty.eidx == EXFAT_HINT_NONE &&
-						num_empty == 1) {
-					exfat_chain_set(&candi_empty.cur,
-						clu.dir, clu.size, clu.flags);
-				}
-
-				if (candi_empty.eidx == EXFAT_HINT_NONE &&
-						num_empty >= num_entries) {
-					candi_empty.eidx =
-						dentry - (num_empty - 1);
-					WARN_ON(candi_empty.eidx < 0);
-					candi_empty.count = num_empty;
-
-					if (ei->hint_femp.eidx ==
-							EXFAT_HINT_NONE ||
-						candi_empty.eidx <=
-							 ei->hint_femp.eidx)
-						ei->hint_femp = candi_empty;
-				}
+				exfat_set_empty_hint(ei, &candi_empty, &clu,
+						dentry, num_entries);
 
 				brelse(bh);
 				if (entry_type == TYPE_UNUSED)
@@ -989,8 +997,7 @@  int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
 				continue;
 			}
 
-			num_empty = 0;
-			candi_empty.eidx = EXFAT_HINT_NONE;
+			exfat_reset_empty_hint(&candi_empty);
 
 			if (entry_type == TYPE_FILE || entry_type == TYPE_DIR) {
 				step = DIRENT_STEP_FILE;
@@ -1090,9 +1097,6 @@  int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
 		rewind = 1;
 		dentry = 0;
 		clu.dir = p_dir->dir;
-		/* reset empty hint */
-		num_empty = 0;
-		candi_empty.eidx = EXFAT_HINT_NONE;
 		goto rewind;
 	}