Skip to contentSkip to conversation

btrfs: update target inode's ctime on unlink

PATCH In review Jeff Layton 4 participants 6 messages Aug 12, 2024 – Aug 13, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: update target inode's ctime on unlink

Unlink changes the link count on the target inode. POSIX mandates that the ctime must also change when this occurs.

---
Found using the nfstest_posix testsuite with knfsd exporting btrfs.

---
 fs/btrfs/inode.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/inode.c +1 -0
index 333b0e8587a2..b1b6564ab68f 100644
@@ -4195,6 +4195,7 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans,
 
 	btrfs_i_size_write(dir, dir->vfs_inode.i_size - name->len * 2);
 	inode_inc_iversion(&inode->vfs_inode);
+	inode_set_ctime_current(&inode->vfs_inode);
 	inode_inc_iversion(&dir->vfs_inode);
  	inode_set_mtime_to_ts(&dir->vfs_inode, inode_set_ctime_current(&dir->vfs_inode));
 	ret = btrfs_update_inode(trans, dir);

---
base-commit: 7c626ce4bae1ac14f60076d00eafe71af30450ba
change-id: 20240812-btrfs-unlink-77293421e416

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Jeff Layton

Unlink changes the link count on the target inode. POSIX mandates that the ctime must also change when this occurs.

Right, thanks. According to https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html:

Upon successful completion, unlink() shall mark for update the last data modification and last file status change timestamps of the parent directory. Also, if the file's link count is not 0, the last file status change timestamp of the file shall be marked for update.

Quoted 1 line
#2 lore raw
Quoted 11 lines · David Sterba
Quoted 2 lines · Jeff Layton

Unlink changes the link count on the target inode. POSIX mandates that the ctime must also change when this occurs.

Right, thanks. According to https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html:

Upon successful completion, unlink() shall mark for update the last data modification and last file status change timestamps of the parent directory. Also, if the file's link count is not 0, the last file status change timestamp of the file shall be marked for update.

Weird way to phrase to that. IMO, we still want to stamp the inode's ctime even if the link count goes to 0. That's what Linux generally does, anyway. Oh well..

Quoted 4 lines
Quoted 2 lines

FWIW, this should probably go in via the btrfs tree.

Signature · 1 line
Jeff Layton <[email protected]>
#3 lore raw
Quoted 18 lines · Jeff Layton
Quoted 11 lines · David Sterba
Quoted 2 lines · Jeff Layton

Unlink changes the link count on the target inode. POSIX mandates that the ctime must also change when this occurs.

Right, thanks. According to https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html:

Upon successful completion, unlink() shall mark for update the last data modification and last file status change timestamps of the parent directory. Also, if the file's link count is not 0, the last file status change timestamp of the file shall be marked for update.

Weird way to phrase to that. IMO, we still want to stamp the inode's ctime even if the link count goes to 0. That's what Linux generally does, anyway. Oh well..

Quoted 1 line
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

FWIW, this should probably go in via the btrfs tree.

Yes, we'll take it.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Jeff Layton
Quoted 4 lines · Jeff Layton

Unlink changes the link count on the target inode. POSIX mandates that the ctime must also change when this occurs.

And since we decreased the nlink of the target inode already, updating the timestamp will not cause extra COW overhead.

So this won't cause any extra performance penalty.

Thanks,
Qu

Quoted 24 lines

---
Found using the nfstest_posix testsuite with knfsd exporting btrfs.

---
  fs/btrfs/inode.c | 1 +
  1 file changed, 1 insertion(+)
fs/btrfs/inode.c +1 -1
index 333b0e8587a2..b1b6564ab68f 100644
@@ -4195,6 +4195,7 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans,
 
  	btrfs_i_size_write(dir, dir->vfs_inode.i_size - name->len * 2);
  	inode_inc_iversion(&inode->vfs_inode);
+	inode_set_ctime_current(&inode->vfs_inode);
  	inode_inc_iversion(&dir->vfs_inode);
   	inode_set_mtime_to_ts(&dir->vfs_inode, inode_set_ctime_current(&dir->vfs_inode));
  	ret = btrfs_update_inode(trans, dir);
 
---

base-commit: 7c626ce4bae1ac14f60076d00eafe71af30450ba
change-id: 20240812-btrfs-unlink-77293421e416

Best regards,

#5 lore raw
In reply to Jeff Layton
Quoted 6 lines · Jeff Layton

Unlink changes the link count on the target inode. POSIX mandates that the ctime must also change when this occurs.

---
Found using the nfstest_posix testsuite with knfsd exporting btrfs.

Can you also wire this up for xfstests? I suspect other file systems might have similar issues, so running this as part of normal file system QA would be helpful.