Skip to content

Commit 8341374

Browse files
committed
Merge tag 'for-6.18-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - fix new inode name tracking in tree-log - fix conventional zone and stripe calculations in zoned mode - fix bio reference counts on error paths in relocation and scrub * tag 'for-6.18-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: release root after error in data_reloc_print_warning_inode() btrfs: scrub: put bio after errors in scrub_raid56_parity_stripe() btrfs: do not update last_log_commit when logging inode due to a new name btrfs: zoned: fix stripe width calculation btrfs: zoned: fix conventional zone capacity calculation
2 parents 537d196 + c367af4 commit 8341374

4 files changed

Lines changed: 34 additions & 34 deletions

File tree

fs/btrfs/inode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
177177
return ret;
178178
}
179179
ret = paths_from_inode(inum, ipath);
180-
if (ret < 0)
180+
if (ret < 0) {
181+
btrfs_put_root(local_root);
181182
goto err;
183+
}
182184

183185
/*
184186
* We deliberately ignore the bit ipath might have been too small to

fs/btrfs/scrub.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
22032203
ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, full_stripe_start,
22042204
&length, &bioc, NULL, NULL);
22052205
if (ret < 0) {
2206+
bio_put(bio);
22062207
btrfs_put_bioc(bioc);
22072208
btrfs_bio_counter_dec(fs_info);
22082209
goto out;
@@ -2212,6 +2213,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
22122213
btrfs_put_bioc(bioc);
22132214
if (!rbio) {
22142215
ret = -ENOMEM;
2216+
bio_put(bio);
22152217
btrfs_bio_counter_dec(fs_info);
22162218
goto out;
22172219
}

fs/btrfs/tree-log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7122,7 +7122,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
71227122
* a power failure unless the log was synced as part of an fsync
71237123
* against any other unrelated inode.
71247124
*/
7125-
if (inode_only != LOG_INODE_EXISTS)
7125+
if (!ctx->logging_new_name && inode_only != LOG_INODE_EXISTS)
71267126
inode->last_log_commit = inode->last_sub_trans;
71277127
spin_unlock(&inode->lock);
71287128

fs/btrfs/zoned.c

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,
13171317
if (!btrfs_dev_is_sequential(device, info->physical)) {
13181318
up_read(&dev_replace->rwsem);
13191319
info->alloc_offset = WP_CONVENTIONAL;
1320+
info->capacity = device->zone_info->zone_size;
13201321
return 0;
13211322
}
13221323

@@ -1522,35 +1523,35 @@ static int btrfs_load_block_group_raid0(struct btrfs_block_group *bg,
15221523
u64 last_alloc)
15231524
{
15241525
struct btrfs_fs_info *fs_info = bg->fs_info;
1526+
u64 stripe_nr = 0, stripe_offset = 0;
1527+
u32 stripe_index = 0;
15251528

15261529
if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) {
15271530
btrfs_err(fs_info, "zoned: data %s needs raid-stripe-tree",
15281531
btrfs_bg_type_to_raid_name(map->type));
15291532
return -EINVAL;
15301533
}
15311534

1535+
if (last_alloc) {
1536+
u32 factor = map->num_stripes;
1537+
1538+
stripe_nr = last_alloc >> BTRFS_STRIPE_LEN_SHIFT;
1539+
stripe_offset = last_alloc & BTRFS_STRIPE_LEN_MASK;
1540+
stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
1541+
}
1542+
15321543
for (int i = 0; i < map->num_stripes; i++) {
15331544
if (zone_info[i].alloc_offset == WP_MISSING_DEV)
15341545
continue;
15351546

15361547
if (zone_info[i].alloc_offset == WP_CONVENTIONAL) {
1537-
u64 stripe_nr, full_stripe_nr;
1538-
u64 stripe_offset;
1539-
int stripe_index;
15401548

1541-
stripe_nr = div64_u64(last_alloc, map->stripe_size);
1542-
stripe_offset = stripe_nr * map->stripe_size;
1543-
full_stripe_nr = div_u64(stripe_nr, map->num_stripes);
1544-
div_u64_rem(stripe_nr, map->num_stripes, &stripe_index);
1545-
1546-
zone_info[i].alloc_offset =
1547-
full_stripe_nr * map->stripe_size;
1549+
zone_info[i].alloc_offset = btrfs_stripe_nr_to_offset(stripe_nr);
15481550

15491551
if (stripe_index > i)
1550-
zone_info[i].alloc_offset += map->stripe_size;
1552+
zone_info[i].alloc_offset += BTRFS_STRIPE_LEN;
15511553
else if (stripe_index == i)
1552-
zone_info[i].alloc_offset +=
1553-
(last_alloc - stripe_offset);
1554+
zone_info[i].alloc_offset += stripe_offset;
15541555
}
15551556

15561557
if (test_bit(0, active) != test_bit(i, active)) {
@@ -1574,13 +1575,23 @@ static int btrfs_load_block_group_raid10(struct btrfs_block_group *bg,
15741575
u64 last_alloc)
15751576
{
15761577
struct btrfs_fs_info *fs_info = bg->fs_info;
1578+
u64 stripe_nr = 0, stripe_offset = 0;
1579+
u32 stripe_index = 0;
15771580

15781581
if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) {
15791582
btrfs_err(fs_info, "zoned: data %s needs raid-stripe-tree",
15801583
btrfs_bg_type_to_raid_name(map->type));
15811584
return -EINVAL;
15821585
}
15831586

1587+
if (last_alloc) {
1588+
u32 factor = map->num_stripes / map->sub_stripes;
1589+
1590+
stripe_nr = last_alloc >> BTRFS_STRIPE_LEN_SHIFT;
1591+
stripe_offset = last_alloc & BTRFS_STRIPE_LEN_MASK;
1592+
stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
1593+
}
1594+
15841595
for (int i = 0; i < map->num_stripes; i++) {
15851596
if (zone_info[i].alloc_offset == WP_MISSING_DEV)
15861597
continue;
@@ -1594,26 +1605,12 @@ static int btrfs_load_block_group_raid10(struct btrfs_block_group *bg,
15941605
}
15951606

15961607
if (zone_info[i].alloc_offset == WP_CONVENTIONAL) {
1597-
u64 stripe_nr, full_stripe_nr;
1598-
u64 stripe_offset;
1599-
int stripe_index;
1600-
1601-
stripe_nr = div64_u64(last_alloc, map->stripe_size);
1602-
stripe_offset = stripe_nr * map->stripe_size;
1603-
full_stripe_nr = div_u64(stripe_nr,
1604-
map->num_stripes / map->sub_stripes);
1605-
div_u64_rem(stripe_nr,
1606-
(map->num_stripes / map->sub_stripes),
1607-
&stripe_index);
1608-
1609-
zone_info[i].alloc_offset =
1610-
full_stripe_nr * map->stripe_size;
1608+
zone_info[i].alloc_offset = btrfs_stripe_nr_to_offset(stripe_nr);
16111609

16121610
if (stripe_index > (i / map->sub_stripes))
1613-
zone_info[i].alloc_offset += map->stripe_size;
1611+
zone_info[i].alloc_offset += BTRFS_STRIPE_LEN;
16141612
else if (stripe_index == (i / map->sub_stripes))
1615-
zone_info[i].alloc_offset +=
1616-
(last_alloc - stripe_offset);
1613+
zone_info[i].alloc_offset += stripe_offset;
16171614
}
16181615

16191616
if ((i % map->sub_stripes) == 0) {
@@ -1683,8 +1680,6 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
16831680
set_bit(BLOCK_GROUP_FLAG_SEQUENTIAL_ZONE, &cache->runtime_flags);
16841681

16851682
if (num_conventional > 0) {
1686-
/* Zone capacity is always zone size in emulation */
1687-
cache->zone_capacity = cache->length;
16881683
ret = calculate_alloc_pointer(cache, &last_alloc, new);
16891684
if (ret) {
16901685
btrfs_err(fs_info,
@@ -1693,6 +1688,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
16931688
goto out;
16941689
} else if (map->num_stripes == num_conventional) {
16951690
cache->alloc_offset = last_alloc;
1691+
cache->zone_capacity = cache->length;
16961692
set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &cache->runtime_flags);
16971693
goto out;
16981694
}

0 commit comments

Comments
 (0)