Skip to contentSkip to conversation

exfat: add exfat_update_inode()

PATCH Superseded Tetsuhiro Kohada 2 participants 3 messages Oct 2, 2020 – Oct 7, 2020

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 exfat: add exfat_update_inode()

Integrate exfat_sync_inode() and mark_inode_dirty() as exfat_update_inode() Also, return the result of _exfat_write_inode () when sync is specified.

---
Changes in v3
- no change
Changes in v2
- no change

 fs/exfat/exfat_fs.h |  2 +-
 fs/exfat/file.c     |  5 +----
 fs/exfat/inode.c    |  9 +++++++--
 fs/exfat/namei.c    | 35 +++++++----------------------------
 4 files changed, 16 insertions(+), 35 deletions(-)
fs/exfat/exfat_fs.h +1 -1
index b8f0e829ecbd..ec0ee516aee2 100644
@@ -466,7 +466,7 @@ int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);
 
 /* inode.c */
 extern const struct inode_operations exfat_file_inode_operations;
-void exfat_sync_inode(struct inode *inode);
+int exfat_update_inode(struct inode *inode);
 struct inode *exfat_build_inode(struct super_block *sb,
 		struct exfat_dir_entry *info, loff_t i_pos);
 void exfat_hash_inode(struct inode *inode, loff_t i_pos);
fs/exfat/file.c +1 -4
index a92478eabfa4..e510b95dbf77 100644
@@ -245,10 +245,7 @@ void exfat_truncate(struct inode *inode, loff_t size)
 		goto write_size;
 
 	inode->i_ctime = inode->i_mtime = current_time(inode);
-	if (IS_DIRSYNC(inode))
-		exfat_sync_inode(inode);
-	else
-		mark_inode_dirty(inode);
+	exfat_update_inode(inode);
 
 	inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1)) &
 			~(sbi->cluster_size - 1)) >> inode->i_blkbits;
fs/exfat/inode.c +7 -2
index 730373e0965a..5a55303e1f65 100644
@@ -91,10 +91,15 @@ int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
 	return ret;
 }
 
-void exfat_sync_inode(struct inode *inode)
+int exfat_update_inode(struct inode *inode)
 {
 	lockdep_assert_held(&EXFAT_SB(inode->i_sb)->s_lock);
-	__exfat_write_inode(inode, 1);
+
+	if (IS_DIRSYNC(inode))
+		return __exfat_write_inode(inode, 1);
+
+	mark_inode_dirty(inode);
+	return 0;
 }
 
 /*
fs/exfat/namei.c +7 -28
index 676094f2abe2..4eb7cb528e97 100644
@@ -561,10 +561,7 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
 
 	inode_inc_iversion(dir);
 	dir->i_ctime = dir->i_mtime = current_time(dir);
-	if (IS_DIRSYNC(dir))
-		exfat_sync_inode(dir);
-	else
-		mark_inode_dirty(dir);
+	exfat_update_inode(dir);
 
 	i_pos = exfat_make_i_pos(&info);
 	inode = exfat_build_inode(sb, &info, i_pos);
@@ -812,10 +809,7 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
 	inode_inc_iversion(dir);
 	dir->i_mtime = dir->i_atime = current_time(dir);
 	exfat_truncate_atime(&dir->i_atime);
-	if (IS_DIRSYNC(dir))
-		exfat_sync_inode(dir);
-	else
-		mark_inode_dirty(dir);
+	exfat_update_inode(dir);
 
 	clear_nlink(inode);
 	inode->i_mtime = inode->i_atime = current_time(inode);
@@ -846,10 +840,7 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 
 	inode_inc_iversion(dir);
 	dir->i_ctime = dir->i_mtime = current_time(dir);
-	if (IS_DIRSYNC(dir))
-		exfat_sync_inode(dir);
-	else
-		mark_inode_dirty(dir);
+	exfat_update_inode(dir);
 	inc_nlink(dir);
 
 	i_pos = exfat_make_i_pos(&info);
@@ -976,10 +967,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
 	inode_inc_iversion(dir);
 	dir->i_mtime = dir->i_atime = current_time(dir);
 	exfat_truncate_atime(&dir->i_atime);
-	if (IS_DIRSYNC(dir))
-		exfat_sync_inode(dir);
-	else
-		mark_inode_dirty(dir);
+	exfat_update_inode(dir);
 	drop_nlink(dir);
 
 	clear_nlink(inode);
@@ -1352,19 +1340,13 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
 	new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
 		EXFAT_I(new_dir)->i_crtime = current_time(new_dir);
 	exfat_truncate_atime(&new_dir->i_atime);
-	if (IS_DIRSYNC(new_dir))
-		exfat_sync_inode(new_dir);
-	else
-		mark_inode_dirty(new_dir);
+	exfat_update_inode(new_dir);
 
 	i_pos = ((loff_t)EXFAT_I(old_inode)->dir.dir << 32) |
 		(EXFAT_I(old_inode)->entry & 0xffffffff);
 	exfat_unhash_inode(old_inode);
 	exfat_hash_inode(old_inode, i_pos);
-	if (IS_DIRSYNC(new_dir))
-		exfat_sync_inode(old_inode);
-	else
-		mark_inode_dirty(old_inode);
+	exfat_update_inode(old_inode);
 
 	if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
 		drop_nlink(old_dir);
@@ -1374,10 +1356,7 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
 
 	inode_inc_iversion(old_dir);
 	old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
-	if (IS_DIRSYNC(old_dir))
-		exfat_sync_inode(old_dir);
-	else
-		mark_inode_dirty(old_dir);
+	exfat_update_inode(old_dir);
 
 	if (new_inode) {
 		exfat_unhash_inode(new_inode);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines
fs/exfat/namei.c +1 -4
@@ -1352,19 +1340,13 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
 	new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
 		EXFAT_I(new_dir)->i_crtime = current_time(new_dir);
 	exfat_truncate_atime(&new_dir->i_atime);
-	if (IS_DIRSYNC(new_dir))
-		exfat_sync_inode(new_dir);
-	else
-		mark_inode_dirty(new_dir);
+	exfat_update_inode(new_dir);

fs/exfat/namei.c static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, · line 1349

Quoted 10 lines
fs/exfat/namei.c +1 -4
 
 	i_pos = ((loff_t)EXFAT_I(old_inode)->dir.dir << 32) |
 		(EXFAT_I(old_inode)->entry & 0xffffffff);
 	exfat_unhash_inode(old_inode);
 	exfat_hash_inode(old_inode, i_pos);
-	if (IS_DIRSYNC(new_dir))
-		exfat_sync_inode(old_inode);
-	else
-		mark_inode_dirty(old_inode);
+	exfat_update_inode(old_inode);

This is checking if old_inode is IS_DIRSYNC, not new_dir. Is there any reason ?

#2 lore raw

Thank you for your reply.

Quoted 9 lines
Quoted 9 lines
  	new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
  		EXFAT_I(new_dir)->i_crtime = current_time(new_dir);
  	exfat_truncate_atime(&new_dir->i_atime);
fs/exfat/namei.c +1 -4
-	if (IS_DIRSYNC(new_dir))
-		exfat_sync_inode(new_dir);
-	else
-		mark_inode_dirty(new_dir);
+	exfat_update_inode(new_dir);
Quoted 11 lines

fs/exfat/namei.c static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, · line 1349

Quoted 9 lines
  	i_pos = ((loff_t)EXFAT_I(old_inode)->dir.dir << 32) |
  		(EXFAT_I(old_inode)->entry & 0xffffffff);
  	exfat_unhash_inode(old_inode);
  	exfat_hash_inode(old_inode, i_pos);
fs/exfat/namei.c +1 -4
-	if (IS_DIRSYNC(new_dir))
-		exfat_sync_inode(old_inode);
-	else
-		mark_inode_dirty(old_inode);
+	exfat_update_inode(old_inode);

This is checking if old_inode is IS_DIRSYNC, not new_dir. Is there any reason ?

To eliminate meaningless usage and simplify it.

Th exfat does not have an attribute that indicates whether each file/dir should be synced(such as ext4). Therefore, sync necessity cannot be set for each inode, so sync necessity of the whole FS setting(sb-> s_flags) is inherited. As a result, the following values ​​are all the same.
IS_DIRSYNC (new_dir)
IS_DIRSYNC (old_dir)
IS_DIRSYNC (old_inode)
sb-> s_flags & SB_SYNCHRONOUS | SB_DIRSYNC

In exfat, IS_DIRSYNC only works as a shortcut to sb->s_flags.

Even if S_SYNC or S_DIRSYNC were set to inode->i_flags, the current implementation is inappropriate. Whether to sync or not should be determined by "IS_DIRSYNC(new_dir)||IS_DIRSYNC(old_dir)", I think. (Syncing only old_dir is a high risk of losing file)

Whatever, no one sets S_SYNC and S_DIRSYNC in exfat, so the behavior is no different.

***
Please tell me your opinion about "aggregate dir-entry updates into __exfat_write_inode()"

BR
---
Tetsuhiro Kohada <[email protected]>