public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 2/6] exfat: add exfat_get_dentry_set_by_inode() helper
@ 2024-10-30  6:12 Yuezhang.Mo
  2024-11-13  5:48 ` Namjae Jeon
  0 siblings, 1 reply; 3+ messages in thread
From: Yuezhang.Mo @ 2024-10-30  6:12 UTC (permalink / raw)
  To: linkinjeon@kernel.org, sj1557.seo@samsung.com
  Cc: linux-fsdevel@vger.kernel.org, Wataru.Aoyama@sony.com

This helper gets the directory entry set of the file for the inode
which has been created.

It's used to remove all the instances of the pattern it replaces
making the code cleaner, it's also a preparation for changing ->dir
to record the cluster where the directory entry set is located and
changing ->entry to record the index of the directory entry within
the cluster.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Reviewed-by: Daniel Palmer <daniel.palmer@sony.com>
---
 fs/exfat/dir.c      |  9 +++++++++
 fs/exfat/exfat_fs.h |  2 ++
 fs/exfat/inode.c    |  2 +-
 fs/exfat/namei.c    | 48 +++++++++++++--------------------------------
 4 files changed, 26 insertions(+), 35 deletions(-)

diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 7446bf09a04a..61221c59547d 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -873,6 +873,15 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
 	return -EIO;
 }
 
+int exfat_get_dentry_set_by_inode(struct exfat_entry_set_cache *es,
+		struct inode *inode)
+{
+	struct exfat_inode_info *ei = EXFAT_I(inode);
+
+	return exfat_get_dentry_set(es, inode->i_sb, &ei->dir, ei->entry,
+			ES_ALL_ENTRIES);
+}
+
 static int exfat_validate_empty_dentry_set(struct exfat_entry_set_cache *es)
 {
 	struct exfat_dentry *ep;
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index 3cdc1de362a9..7b5f962f074d 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -508,6 +508,8 @@ struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
 int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
 		struct super_block *sb, struct exfat_chain *p_dir, int entry,
 		unsigned int num_entries);
+int exfat_get_dentry_set_by_inode(struct exfat_entry_set_cache *es,
+		struct inode *inode);
 int exfat_get_empty_dentry_set(struct exfat_entry_set_cache *es,
 		struct super_block *sb, struct exfat_chain *p_dir, int entry,
 		unsigned int num_entries);
diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c
index d724de8f57bf..d338a59c27f7 100644
--- a/fs/exfat/inode.c
+++ b/fs/exfat/inode.c
@@ -43,7 +43,7 @@ int __exfat_write_inode(struct inode *inode, int sync)
 	exfat_set_volume_dirty(sb);
 
 	/* get the directory entry of given file or directory */
-	if (exfat_get_dentry_set(&es, sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES))
+	if (exfat_get_dentry_set_by_inode(&es, inode))
 		return -EIO;
 	ep = exfat_get_dentry_cached(&es, ES_IDX_FILE);
 	ep2 = exfat_get_dentry_cached(&es, ES_IDX_STREAM);
diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 6723396deae8..050a936efbcb 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -766,26 +766,23 @@ static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry,
 /* remove an entry, BUT don't truncate */
 static int exfat_unlink(struct inode *dir, struct dentry *dentry)
 {
-	struct exfat_chain cdir;
 	struct super_block *sb = dir->i_sb;
 	struct inode *inode = dentry->d_inode;
 	struct exfat_inode_info *ei = EXFAT_I(inode);
 	struct exfat_entry_set_cache es;
-	int entry, err = 0;
+	int err = 0;
 
 	if (unlikely(exfat_forced_shutdown(sb)))
 		return -EIO;
 
 	mutex_lock(&EXFAT_SB(sb)->s_lock);
-	exfat_chain_dup(&cdir, &ei->dir);
-	entry = ei->entry;
 	if (ei->dir.dir == DIR_DELETED) {
 		exfat_err(sb, "abnormal access to deleted dentry");
 		err = -ENOENT;
 		goto unlock;
 	}
 
-	err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES);
+	err = exfat_get_dentry_set_by_inode(&es, inode);
 	if (err) {
 		err = -EIO;
 		goto unlock;
@@ -915,21 +912,18 @@ static int exfat_check_dir_empty(struct super_block *sb,
 static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
 {
 	struct inode *inode = dentry->d_inode;
-	struct exfat_chain cdir, clu_to_free;
+	struct exfat_chain clu_to_free;
 	struct super_block *sb = inode->i_sb;
 	struct exfat_sb_info *sbi = EXFAT_SB(sb);
 	struct exfat_inode_info *ei = EXFAT_I(inode);
 	struct exfat_entry_set_cache es;
-	int entry, err;
+	int err;
 
 	if (unlikely(exfat_forced_shutdown(sb)))
 		return -EIO;
 
 	mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock);
 
-	exfat_chain_dup(&cdir, &ei->dir);
-	entry = ei->entry;
-
 	if (ei->dir.dir == DIR_DELETED) {
 		exfat_err(sb, "abnormal access to deleted dentry");
 		err = -ENOENT;
@@ -947,7 +941,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
 		goto unlock;
 	}
 
-	err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES);
+	err = exfat_get_dentry_set_by_inode(&es, inode);
 	if (err) {
 		err = -EIO;
 		goto unlock;
@@ -983,8 +977,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
 }
 
 static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
-		int oldentry, struct exfat_uni_name *p_uniname,
-		struct exfat_inode_info *ei)
+		struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
 {
 	int ret, num_new_entries;
 	struct exfat_dentry *epold, *epnew;
@@ -999,7 +992,7 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
 	if (num_new_entries < 0)
 		return num_new_entries;
 
-	ret = exfat_get_dentry_set(&old_es, sb, p_dir, oldentry, ES_ALL_ENTRIES);
+	ret = exfat_get_dentry_set_by_inode(&old_es, &ei->vfs_inode);
 	if (ret) {
 		ret = -EIO;
 		return ret;
@@ -1053,21 +1046,18 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
 	return ret;
 }
 
-static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,
-		int oldentry, struct exfat_chain *p_newdir,
+static int exfat_move_file(struct inode *inode, struct exfat_chain *p_newdir,
 		struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
 {
 	int ret, newentry, num_new_entries;
 	struct exfat_dentry *epmov, *epnew;
-	struct super_block *sb = inode->i_sb;
 	struct exfat_entry_set_cache mov_es, new_es;
 
 	num_new_entries = exfat_calc_num_entries(p_uniname);
 	if (num_new_entries < 0)
 		return num_new_entries;
 
-	ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry,
-			ES_ALL_ENTRIES);
+	ret = exfat_get_dentry_set_by_inode(&mov_es, &ei->vfs_inode);
 	if (ret)
 		return -EIO;
 
@@ -1116,8 +1106,7 @@ static int __exfat_rename(struct inode *old_parent_inode,
 		struct dentry *new_dentry)
 {
 	int ret;
-	int dentry;
-	struct exfat_chain olddir, newdir;
+	struct exfat_chain newdir;
 	struct exfat_uni_name uni_name;
 	struct super_block *sb = old_parent_inode->i_sb;
 	struct exfat_sb_info *sbi = EXFAT_SB(sb);
@@ -1134,11 +1123,6 @@ static int __exfat_rename(struct inode *old_parent_inode,
 		return -ENOENT;
 	}
 
-	exfat_chain_set(&olddir, EXFAT_I(old_parent_inode)->start_clu,
-		EXFAT_B_TO_CLU_ROUND_UP(i_size_read(old_parent_inode), sbi),
-		EXFAT_I(old_parent_inode)->flags);
-	dentry = ei->entry;
-
 	/* check whether new dir is existing directory and empty */
 	if (new_inode) {
 		ret = -EIO;
@@ -1173,21 +1157,17 @@ static int __exfat_rename(struct inode *old_parent_inode,
 
 	exfat_set_volume_dirty(sb);
 
-	if (olddir.dir == newdir.dir)
-		ret = exfat_rename_file(new_parent_inode, &olddir, dentry,
+	if (new_parent_inode == old_parent_inode)
+		ret = exfat_rename_file(new_parent_inode, &newdir,
 				&uni_name, ei);
 	else
-		ret = exfat_move_file(new_parent_inode, &olddir, dentry,
-				&newdir, &uni_name, ei);
+		ret = exfat_move_file(new_parent_inode, &newdir, &uni_name, ei);
 
 	if (!ret && new_inode) {
 		struct exfat_entry_set_cache es;
-		struct exfat_chain *p_dir = &(new_ei->dir);
-		int new_entry = new_ei->entry;
 
 		/* delete entries of new_dir */
-		ret = exfat_get_dentry_set(&es, sb, p_dir, new_entry,
-				ES_ALL_ENTRIES);
+		ret = exfat_get_dentry_set_by_inode(&es, new_inode);
 		if (ret) {
 			ret = -EIO;
 			goto del_out;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1 2/6] exfat: add exfat_get_dentry_set_by_inode() helper
  2024-10-30  6:12 [PATCH v1 2/6] exfat: add exfat_get_dentry_set_by_inode() helper Yuezhang.Mo
@ 2024-11-13  5:48 ` Namjae Jeon
  2024-11-14  5:09   ` Yuezhang.Mo
  0 siblings, 1 reply; 3+ messages in thread
From: Namjae Jeon @ 2024-11-13  5:48 UTC (permalink / raw)
  To: Yuezhang.Mo@sony.com
  Cc: sj1557.seo@samsung.com, linux-fsdevel@vger.kernel.org,
	Wataru.Aoyama@sony.com

[snip]
>  static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
> -               int oldentry, struct exfat_uni_name *p_uniname,
> -               struct exfat_inode_info *ei)
> +               struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
>  {
>         int ret, num_new_entries;
>         struct exfat_dentry *epold, *epnew;
> @@ -999,7 +992,7 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
>         if (num_new_entries < 0)
>                 return num_new_entries;
>
> -       ret = exfat_get_dentry_set(&old_es, sb, p_dir, oldentry, ES_ALL_ENTRIES);
> +       ret = exfat_get_dentry_set_by_inode(&old_es, &ei->vfs_inode);
It is better to just use exfat_get_dentry_set rather than
exfat_get_dentry_set_by_inode here.

>         if (ret) {
>                 ret = -EIO;
>                 return ret;
> @@ -1053,21 +1046,18 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
>         return ret;
>  }
>
> -static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,
> -               int oldentry, struct exfat_chain *p_newdir,
> +static int exfat_move_file(struct inode *inode, struct exfat_chain *p_newdir,
>                 struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
>  {
>         int ret, newentry, num_new_entries;
>         struct exfat_dentry *epmov, *epnew;
> -       struct super_block *sb = inode->i_sb;
>         struct exfat_entry_set_cache mov_es, new_es;
>
>         num_new_entries = exfat_calc_num_entries(p_uniname);
>         if (num_new_entries < 0)
>                 return num_new_entries;
>
> -       ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry,
> -                       ES_ALL_ENTRIES);
> +       ret = exfat_get_dentry_set_by_inode(&mov_es, &ei->vfs_inode);
It's the same here. It is better to just use exfat_get_dentry_set().
Thanks.
>         if (ret)
>                 return -EIO;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1 2/6] exfat: add exfat_get_dentry_set_by_inode() helper
  2024-11-13  5:48 ` Namjae Jeon
@ 2024-11-14  5:09   ` Yuezhang.Mo
  0 siblings, 0 replies; 3+ messages in thread
From: Yuezhang.Mo @ 2024-11-14  5:09 UTC (permalink / raw)
  To: Namjae Jeon
  Cc: sj1557.seo@samsung.com, linux-fsdevel@vger.kernel.org,
	Wataru.Aoyama@sony.com

>> @@ -999,7 +992,7 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
>>         if (num_new_entries < 0)
>>                 return num_new_entries;
>>
>> -       ret = exfat_get_dentry_set(&old_es, sb, p_dir, oldentry, ES_ALL_ENTRIES);
>> +       ret = exfat_get_dentry_set_by_inode(&old_es, &ei->vfs_inode);
> It is better to just use exfat_get_dentry_set rather than
> exfat_get_dentry_set_by_inode here.
>
>>         if (ret) {
>>                 ret = -EIO;
>>                 return ret;
>> @@ -1053,21 +1046,18 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
>>         return ret;
>>  }
>>
>> -static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,
>> -               int oldentry, struct exfat_chain *p_newdir,
>> +static int exfat_move_file(struct inode *inode, struct exfat_chain *p_newdir,
>>                 struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
>>  {
>>         int ret, newentry, num_new_entries;
>>         struct exfat_dentry *epmov, *epnew;
>> -       struct super_block *sb = inode->i_sb;
>>         struct exfat_entry_set_cache mov_es, new_es;
>>
>>         num_new_entries = exfat_calc_num_entries(p_uniname);
>>         if (num_new_entries < 0)
>>                 return num_new_entries;
>>
>> -       ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry,
>> -                       ES_ALL_ENTRIES);
>> +       ret = exfat_get_dentry_set_by_inode(&mov_es, &ei->vfs_inode);
> It's the same here. It is better to just use If using exfat_get_dentry_set() like this().
> Thanks.

Thanks for your comment.
These two changes are necessary, do you mean to move these 2 changes to patch [6/6]?

Before applying patch [6/6], if using exfat_get_dentry_set() like this, it can correctly
get dentry set.

struct exfat_inode_info *parent_ei = EXFAT_I(parent_dir);
struct exfat_inode_info *child_ei =  EXFAT_I(child_inode);
exfat_chain_set(&cdir, parent_ei->start_clu, EXFAT_B_TO_CLU(i_size_read(parent_dir), sbi), parent_ei->flags);
exfat_get_dentry_set(&es, sb, &cdir, child_ei->entry, ES_ALL_ENTRIES);

After applying patch [6/6], child_ei->entry may not start from EXFAT_I(parent_dir)->start_clu,
but from child_ei->dir.dir. If using exfat_get_dentry_set() like this, it may not correctly get
dentry set.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-14  5:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-30  6:12 [PATCH v1 2/6] exfat: add exfat_get_dentry_set_by_inode() helper Yuezhang.Mo
2024-11-13  5:48 ` Namjae Jeon
2024-11-14  5:09   ` Yuezhang.Mo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox