btrfs: set inode flag BTRFS_INODE_COPY_EVERYTHING when logging new name
PATCH 1/1 btrfs: set inode flag BTRFS_INODE_COPY_EVERYTHING when logging new name
From: Filipe Manana <[email protected]>
If we are logging a new name make sure our inode has the runtime flag BTRFS_INODE_COPY_EVERYTHING set so that at btrfs_log_inode() we will find new inode refs/extrefs in the subvolume tree and copy them into the log tree.
We are currently doing it when adding a new link but we are missing it when renaming.
An example where this makes a new name not persisted:
1) create symlink with name foo in directory A
2) fsync directory A, which persists the symlink
3) rename the symlink from foo to bar
4) fsync directory A to persist the new symlink name
Step 4 isn't working correctly as it's not logging the new name and also leaving the old inode ref in the log tree, so after a power failure the symlink still has the old name of "foo". This is because when we first fsync directoy A we log the symlink's inode (as it's a new entry) and at btrfs_log_inode() we set the log mode to LOG_INODE_ALL and then because we are using that mode and the inode has the runtime flag BTRFS_INODE_NEEDS_FULL_SYNC set, we clear that flag as well as the flag BTRFS_INODE_COPY_EVERYTHING. That means the next time we log the inode, during the rename through the call to btrfs_log_new_name() (calling btrfs_log_inode_parent() and then btrfs_log_inode()), we will not search the subvolume tree for new refs/extrefs and jump directory to the 'log_extents' label.
Fix this by making sure we set BTRFS_INODE_COPY_EVERYTHING on an inode when we are about to log a new name. A test case for fstests will follow soon.
--- fs/btrfs/inode.c | 1 - fs/btrfs/tree-log.c | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +0 -1
@@ -6885,7 +6885,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,BTRFS_I (inode)->dir_index =0ULL ;inode_inc_iversion (inode);inode_set_ctime_current (inode); -set_bit (BTRFS_INODE_COPY_EVERYTHING , &BTRFS_I (inode)->runtime_flags); ret =btrfs_add_link (trans,BTRFS_I (dir),BTRFS_I (inode), &fname.disk_name,1 , index);
fs/btrfs/tree-log.c +3 -0
@@ -7905,6 +7905,9 @@ void btrfs_log_new_name(struct btrfs_trans_handle *trans,bool log_pinned = false;int ret; +/* The inode has a new name (ref/extref), so make sure we log it. */ +set_bit (BTRFS_INODE_COPY_EVERYTHING , &inode->runtime_flags); +btrfs_init_log_ctx (&ctx, inode); ctx.logging_new_name = true;
Signature · 1 line
2.47.2
Quoted 30 lines · On Fri, Oct 24, 2025 at 12:52:02PM +0100, [email protected] wrote:
From: Filipe Manana <[email protected]>
If we are logging a new name make sure our inode has the runtime flag
BTRFS_INODE_COPY_EVERYTHINGset so that atbtrfs_log_inode()we will find new inode refs/extrefs in the subvolume tree and copy them into the log tree.We are currently doing it when adding a new link but we are missing it when renaming.
An example where this makes a new name not persisted:
1) create symlink with name foo in directory A
2) fsync directory A, which persists the symlink
3) rename the symlink from foo to bar
4) fsync directory A to persist the new symlink nameStep 4 isn't working correctly as it's not logging the new name and also leaving the old inode ref in the log tree, so after a power failure the symlink still has the old name of "foo". This is because when we first fsync directoy A we log the symlink's inode (as it's a new entry) and at
btrfs_log_inode()we set the log mode toLOG_INODE_ALLand then because we are using that mode and the inode has the runtime flagBTRFS_INODE_NEEDS_FULL_SYNCset, we clear that flag as well as the flagBTRFS_INODE_COPY_EVERYTHING. That means the next time we log the inode, during the rename through the call tobtrfs_log_new_name()(callingbtrfs_log_inode_parent()and thenbtrfs_log_inode()), we will not search the subvolume tree for new refs/extrefs and jump directory to the 'log_extents' label.
Quoted 7 lines
Fix this by making sure we set
BTRFS_INODE_COPY_EVERYTHINGon an inode when we are about to log a new name. A test case for fstests will follow soon.
Quoted 34 lines
--- fs/btrfs/inode.c | 1 - fs/btrfs/tree-log.c | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-)fs/btrfs/inode.c +0
-1@@ -6885,7 +6885,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,BTRFS_I (inode)->dir_index =0ULL ;inode_inc_iversion (inode);inode_set_ctime_current (inode); -set_bit (BTRFS_INODE_COPY_EVERYTHING , &BTRFS_I (inode)->runtime_flags); ret =btrfs_add_link (trans,BTRFS_I (dir),BTRFS_I (inode), &fname.disk_name,1 , index);fs/btrfs/tree-log.c +3
-0@@ -7905,6 +7905,9 @@ void btrfs_log_new_name(struct btrfs_trans_handle *trans,bool log_pinned = false;int ret; +/* The inode has a new name (ref/extref), so make sure we log it. */ +set_bit (BTRFS_INODE_COPY_EVERYTHING , &inode->runtime_flags); +btrfs_init_log_ctx (&ctx, inode); ctx.logging_new_name = true;Signature · 1 line
2.47.2
Quoted 30 lines · 在 2025/10/24 22:22, [email protected] 写道:
From: Filipe Manana <[email protected]>
If we are logging a new name make sure our inode has the runtime flag
BTRFS_INODE_COPY_EVERYTHINGset so that atbtrfs_log_inode()we will find new inode refs/extrefs in the subvolume tree and copy them into the log tree.We are currently doing it when adding a new link but we are missing it when renaming.
An example where this makes a new name not persisted:
1) create symlink with name foo in directory A
2) fsync directory A, which persists the symlink
3) rename the symlink from foo to bar
4) fsync directory A to persist the new symlink nameStep 4 isn't working correctly as it's not logging the new name and also leaving the old inode ref in the log tree, so after a power failure the symlink still has the old name of "foo". This is because when we first fsync directoy A we log the symlink's inode (as it's a new entry) and at
btrfs_log_inode()we set the log mode toLOG_INODE_ALLand then because we are using that mode and the inode has the runtime flagBTRFS_INODE_NEEDS_FULL_SYNCset, we clear that flag as well as the flagBTRFS_INODE_COPY_EVERYTHING. That means the next time we log the inode, during the rename through the call tobtrfs_log_new_name()(callingbtrfs_log_inode_parent()and thenbtrfs_log_inode()), we will not search the subvolume tree for new refs/extrefs and jump directory to the 'log_extents' label.
Quoted 7 lines
Fix this by making sure we set
BTRFS_INODE_COPY_EVERYTHINGon an inode when we are about to log a new name. A test case for fstests will follow soon.
Thanks,
Qu
Quoted 31 lines
--- fs/btrfs/inode.c | 1 - fs/btrfs/tree-log.c | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-)fs/btrfs/inode.c +0
-1@@ -6885,7 +6885,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,BTRFS_I (inode)->dir_index =0ULL ;inode_inc_iversion (inode);inode_set_ctime_current (inode); -set_bit (BTRFS_INODE_COPY_EVERYTHING , &BTRFS_I (inode)->runtime_flags); ret =btrfs_add_link (trans,BTRFS_I (dir),BTRFS_I (inode), &fname.disk_name,1 , index);fs/btrfs/tree-log.c +3
-0@@ -7905,6 +7905,9 @@ void btrfs_log_new_name(struct btrfs_trans_handle *trans,bool log_pinned = false;int ret; +/* The inode has a new name (ref/extref), so make sure we log it. */ +set_bit (BTRFS_INODE_COPY_EVERYTHING , &inode->runtime_flags); +btrfs_init_log_ctx (&ctx, inode); ctx.logging_new_name = true;