Skip to content

Commit bff4d06

Browse files
fdmananagregkh
authored andcommitted
btrfs: add helper to truncate inode items when logging inode
commit 8a2b3da upstream. Move the call to btrfs_truncate_inode_items(), and the surrounding retry loop, into a local helper function. This avoids some repetition and avoids making the next change a bit awkward due to a bit of too much indentation. This patch is part of a patch set comprised of the following patches: btrfs: check if a log tree exists at inode_logged() btrfs: remove no longer needed checks for NULL log context btrfs: do not log new dentries when logging that a new name exists btrfs: always update the logged transaction when logging new names btrfs: avoid expensive search when dropping inode items from log btrfs: add helper to truncate inode items when logging inode btrfs: avoid expensive search when truncating inode items from the log btrfs: avoid search for logged i_size when logging inode if possible btrfs: avoid attempt to drop extents when logging inode for the first time btrfs: do not commit delayed inode when logging a file in full sync mode This is patch 6/10 and test results are listed in the change log of the last patch in the set. Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Harshvardhan Jha <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 707d49d commit bff4d06

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

fs/btrfs/tree-log.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,6 +3955,21 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans,
39553955
return ret;
39563956
}
39573957

3958+
static int truncate_inode_items(struct btrfs_trans_handle *trans,
3959+
struct btrfs_root *log_root,
3960+
struct btrfs_inode *inode,
3961+
u64 new_size, u32 min_type)
3962+
{
3963+
int ret;
3964+
3965+
do {
3966+
ret = btrfs_truncate_inode_items(trans, log_root, inode,
3967+
new_size, min_type, NULL);
3968+
} while (ret == -EAGAIN);
3969+
3970+
return ret;
3971+
}
3972+
39583973
static void fill_inode_item(struct btrfs_trans_handle *trans,
39593974
struct extent_buffer *leaf,
39603975
struct btrfs_inode_item *item,
@@ -4548,13 +4563,9 @@ static int btrfs_log_prealloc_extents(struct btrfs_trans_handle *trans,
45484563
* Avoid logging extent items logged in past fsync calls
45494564
* and leading to duplicate keys in the log tree.
45504565
*/
4551-
do {
4552-
ret = btrfs_truncate_inode_items(trans,
4553-
root->log_root,
4554-
inode, truncate_offset,
4555-
BTRFS_EXTENT_DATA_KEY,
4556-
NULL);
4557-
} while (ret == -EAGAIN);
4566+
ret = truncate_inode_items(trans, root->log_root, inode,
4567+
truncate_offset,
4568+
BTRFS_EXTENT_DATA_KEY);
45584569
if (ret)
45594570
goto out;
45604571
dropped_extents = true;
@@ -5531,12 +5542,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
55315542
&inode->runtime_flags);
55325543
clear_bit(BTRFS_INODE_COPY_EVERYTHING,
55335544
&inode->runtime_flags);
5534-
while(1) {
5535-
ret = btrfs_truncate_inode_items(trans,
5536-
log, inode, 0, 0, NULL);
5537-
if (ret != -EAGAIN)
5538-
break;
5539-
}
5545+
ret = truncate_inode_items(trans, log, inode, 0, 0);
55405546
}
55415547
} else if (test_and_clear_bit(BTRFS_INODE_COPY_EVERYTHING,
55425548
&inode->runtime_flags) ||

0 commit comments

Comments
 (0)