Skip to content

Commit 5fbfb3f

Browse files
fdmananakdave
authored andcommitted
btrfs: use variables to store extent buffer and slot at overwrite_item()
Instead of referring to path->nodes[0] and path->slots[0] multiple times, which is verbose and confusing since we have an 'eb' and 'slot' variables as well, introduce local variables 'dst_eb' to point to path->nodes[0] and 'dst_slot' to have path->slots[0], reducing verbosity and making it more obvious about which extent buffer and slot we are referring to. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent e48264e commit 5fbfb3f

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

fs/btrfs/tree-log.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
401401
int save_old_i_size = 0;
402402
unsigned long src_ptr;
403403
unsigned long dst_ptr;
404+
struct extent_buffer *dst_eb;
405+
int dst_slot;
404406
bool inode_item = key->type == BTRFS_INODE_ITEM_KEY;
405407

406408
/*
@@ -420,10 +422,13 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
420422
if (ret < 0)
421423
return ret;
422424

425+
dst_eb = path->nodes[0];
426+
dst_slot = path->slots[0];
427+
423428
if (ret == 0) {
424429
char *src_copy;
425-
u32 dst_size = btrfs_item_size(path->nodes[0],
426-
path->slots[0]);
430+
const u32 dst_size = btrfs_item_size(dst_eb, dst_slot);
431+
427432
if (dst_size != item_size)
428433
goto insert;
429434

@@ -438,8 +443,8 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
438443
}
439444

440445
read_extent_buffer(eb, src_copy, src_ptr, item_size);
441-
dst_ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]);
442-
ret = memcmp_extent_buffer(path->nodes[0], src_copy, dst_ptr, item_size);
446+
dst_ptr = btrfs_item_ptr_offset(dst_eb, dst_slot);
447+
ret = memcmp_extent_buffer(dst_eb, src_copy, dst_ptr, item_size);
443448

444449
kfree(src_copy);
445450
/*
@@ -462,9 +467,9 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
462467
u64 nbytes;
463468
u32 mode;
464469

465-
item = btrfs_item_ptr(path->nodes[0], path->slots[0],
470+
item = btrfs_item_ptr(dst_eb, dst_slot,
466471
struct btrfs_inode_item);
467-
nbytes = btrfs_inode_nbytes(path->nodes[0], item);
472+
nbytes = btrfs_inode_nbytes(dst_eb, item);
468473
item = btrfs_item_ptr(eb, slot,
469474
struct btrfs_inode_item);
470475
btrfs_set_inode_nbytes(eb, item, nbytes);
@@ -506,20 +511,21 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
506511
key, item_size);
507512
path->skip_release_on_error = 0;
508513

514+
dst_eb = path->nodes[0];
515+
dst_slot = path->slots[0];
516+
509517
/* make sure any existing item is the correct size */
510518
if (ret == -EEXIST || ret == -EOVERFLOW) {
511-
u32 found_size;
512-
found_size = btrfs_item_size(path->nodes[0],
513-
path->slots[0]);
519+
const u32 found_size = btrfs_item_size(dst_eb, dst_slot);
520+
514521
if (found_size > item_size)
515522
btrfs_truncate_item(trans, path, item_size, 1);
516523
else if (found_size < item_size)
517524
btrfs_extend_item(trans, path, item_size - found_size);
518525
} else if (ret) {
519526
return ret;
520527
}
521-
dst_ptr = btrfs_item_ptr_offset(path->nodes[0],
522-
path->slots[0]);
528+
dst_ptr = btrfs_item_ptr_offset(dst_eb, dst_slot);
523529

524530
/* don't overwrite an existing inode if the generation number
525531
* was logged as zero. This is done when the tree logging code
@@ -538,7 +544,6 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
538544
dst_item = (struct btrfs_inode_item *)dst_ptr;
539545

540546
if (btrfs_inode_generation(eb, src_item) == 0) {
541-
struct extent_buffer *dst_eb = path->nodes[0];
542547
const u64 ino_size = btrfs_inode_size(eb, src_item);
543548

544549
/*
@@ -556,30 +561,28 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
556561
}
557562

558563
if (S_ISDIR(btrfs_inode_mode(eb, src_item)) &&
559-
S_ISDIR(btrfs_inode_mode(path->nodes[0], dst_item))) {
564+
S_ISDIR(btrfs_inode_mode(dst_eb, dst_item))) {
560565
save_old_i_size = 1;
561-
saved_i_size = btrfs_inode_size(path->nodes[0],
562-
dst_item);
566+
saved_i_size = btrfs_inode_size(dst_eb, dst_item);
563567
}
564568
}
565569

566-
copy_extent_buffer(path->nodes[0], eb, dst_ptr,
567-
src_ptr, item_size);
570+
copy_extent_buffer(dst_eb, eb, dst_ptr, src_ptr, item_size);
568571

569572
if (save_old_i_size) {
570573
struct btrfs_inode_item *dst_item;
574+
571575
dst_item = (struct btrfs_inode_item *)dst_ptr;
572-
btrfs_set_inode_size(path->nodes[0], dst_item, saved_i_size);
576+
btrfs_set_inode_size(dst_eb, dst_item, saved_i_size);
573577
}
574578

575579
/* make sure the generation is filled in */
576580
if (key->type == BTRFS_INODE_ITEM_KEY) {
577581
struct btrfs_inode_item *dst_item;
582+
578583
dst_item = (struct btrfs_inode_item *)dst_ptr;
579-
if (btrfs_inode_generation(path->nodes[0], dst_item) == 0) {
580-
btrfs_set_inode_generation(path->nodes[0], dst_item,
581-
trans->transid);
582-
}
584+
if (btrfs_inode_generation(dst_eb, dst_item) == 0)
585+
btrfs_set_inode_generation(dst_eb, dst_item, trans->transid);
583586
}
584587
no_copy:
585588
btrfs_release_path(path);

0 commit comments

Comments
 (0)