Skip to content

Commit 3a8d1db

Browse files
fdmananakdave
authored andcommitted
btrfs: unify overwrite_item() and do_overwrite_item()
After commit 193df62 ("btrfs: search for last logged dir index if it's not cached in the inode"), there are no more callers of do_overwrite_item(), except overwrite_item(). Originally both used to be the same function, but were split in commit 086dcbf ("btrfs: insert items in batches when logging a directory when possible"), as there was the need to execute all logic of overwrite_item() but skip the tree search, since in the context of directory logging we already had a path with a leaf to copy data from. So unify them again as there is no more need to have them split. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 63d5429 commit 3a8d1db

File tree

1 file changed

+24
-52
lines changed

1 file changed

+24
-52
lines changed

fs/btrfs/tree-log.c

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,25 @@ static int process_one_buffer(struct btrfs_root *log,
365365
return ret;
366366
}
367367

368-
static int do_overwrite_item(struct btrfs_trans_handle *trans,
369-
struct btrfs_root *root,
370-
struct btrfs_path *path,
371-
struct extent_buffer *eb, int slot,
372-
struct btrfs_key *key)
368+
/*
369+
* Item overwrite used by replay and tree logging. eb, slot and key all refer
370+
* to the src data we are copying out.
371+
*
372+
* root is the tree we are copying into, and path is a scratch
373+
* path for use in this function (it should be released on entry and
374+
* will be released on exit).
375+
*
376+
* If the key is already in the destination tree the existing item is
377+
* overwritten. If the existing item isn't big enough, it is extended.
378+
* If it is too large, it is truncated.
379+
*
380+
* If the key isn't in the destination yet, a new item is inserted.
381+
*/
382+
static int overwrite_item(struct btrfs_trans_handle *trans,
383+
struct btrfs_root *root,
384+
struct btrfs_path *path,
385+
struct extent_buffer *eb, int slot,
386+
struct btrfs_key *key)
373387
{
374388
int ret;
375389
u32 item_size;
@@ -386,22 +400,10 @@ static int do_overwrite_item(struct btrfs_trans_handle *trans,
386400
item_size = btrfs_item_size(eb, slot);
387401
src_ptr = btrfs_item_ptr_offset(eb, slot);
388402

389-
/* Our caller must have done a search for the key for us. */
390-
ASSERT(path->nodes[0] != NULL);
391-
392-
/*
393-
* And the slot must point to the exact key or the slot where the key
394-
* should be at (the first item with a key greater than 'key')
395-
*/
396-
if (path->slots[0] < btrfs_header_nritems(path->nodes[0])) {
397-
struct btrfs_key found_key;
398-
399-
btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);
400-
ret = btrfs_comp_cpu_keys(&found_key, key);
401-
ASSERT(ret >= 0);
402-
} else {
403-
ret = 1;
404-
}
403+
/* Look for the key in the destination tree. */
404+
ret = btrfs_search_slot(NULL, root, key, path, 0, 0);
405+
if (ret < 0)
406+
return ret;
405407

406408
if (ret == 0) {
407409
char *src_copy;
@@ -579,36 +581,6 @@ static int do_overwrite_item(struct btrfs_trans_handle *trans,
579581
return 0;
580582
}
581583

582-
/*
583-
* Item overwrite used by replay and tree logging. eb, slot and key all refer
584-
* to the src data we are copying out.
585-
*
586-
* root is the tree we are copying into, and path is a scratch
587-
* path for use in this function (it should be released on entry and
588-
* will be released on exit).
589-
*
590-
* If the key is already in the destination tree the existing item is
591-
* overwritten. If the existing item isn't big enough, it is extended.
592-
* If it is too large, it is truncated.
593-
*
594-
* If the key isn't in the destination yet, a new item is inserted.
595-
*/
596-
static int overwrite_item(struct btrfs_trans_handle *trans,
597-
struct btrfs_root *root,
598-
struct btrfs_path *path,
599-
struct extent_buffer *eb, int slot,
600-
struct btrfs_key *key)
601-
{
602-
int ret;
603-
604-
/* Look for the key in the destination tree. */
605-
ret = btrfs_search_slot(NULL, root, key, path, 0, 0);
606-
if (ret < 0)
607-
return ret;
608-
609-
return do_overwrite_item(trans, root, path, eb, slot, key);
610-
}
611-
612584
static int read_alloc_one_name(struct extent_buffer *eb, void *start, int len,
613585
struct fscrypt_str *name)
614586
{
@@ -5406,7 +5378,7 @@ struct btrfs_dir_list {
54065378
* has a size that doesn't match the sum of the lengths of all the logged
54075379
* names - this is ok, not a problem, because at log replay time we set the
54085380
* directory's i_size to the correct value (see replay_one_name() and
5409-
* do_overwrite_item()).
5381+
* overwrite_item()).
54105382
*/
54115383
static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
54125384
struct btrfs_inode *start_inode,

0 commit comments

Comments
 (0)