Skip to content

Commit 45af60e

Browse files
committed
Merge tag 'for-5.13-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "A few more fixes: - fix unaligned compressed writes in zoned mode - fix false positive lockdep warning when cloning inline extent - remove wrong BUG_ON in tree-log error handling" * tag 'for-5.13-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: zoned: fix parallel compressed writes btrfs: zoned: pass start block to btrfs_use_zone_append btrfs: do not BUG_ON in link_to_fixup_dir btrfs: release path before starting transaction when cloning inline extent
2 parents 8bb14ca + 764c7c9 commit 45af60e

7 files changed

Lines changed: 49 additions & 13 deletions

File tree

fs/btrfs/compression.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "compression.h"
2929
#include "extent_io.h"
3030
#include "extent_map.h"
31+
#include "zoned.h"
3132

3233
static const char* const btrfs_compress_types[] = { "", "zlib", "lzo", "zstd" };
3334

@@ -349,6 +350,7 @@ static void end_compressed_bio_write(struct bio *bio)
349350
*/
350351
inode = cb->inode;
351352
cb->compressed_pages[0]->mapping = cb->inode->i_mapping;
353+
btrfs_record_physical_zoned(inode, cb->start, bio);
352354
btrfs_writepage_endio_finish_ordered(cb->compressed_pages[0],
353355
cb->start, cb->start + cb->len - 1,
354356
bio->bi_status == BLK_STS_OK);
@@ -401,6 +403,8 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
401403
u64 first_byte = disk_start;
402404
blk_status_t ret;
403405
int skip_sum = inode->flags & BTRFS_INODE_NODATASUM;
406+
const bool use_append = btrfs_use_zone_append(inode, disk_start);
407+
const unsigned int bio_op = use_append ? REQ_OP_ZONE_APPEND : REQ_OP_WRITE;
404408

405409
WARN_ON(!PAGE_ALIGNED(start));
406410
cb = kmalloc(compressed_bio_size(fs_info, compressed_len), GFP_NOFS);
@@ -418,10 +422,31 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
418422
cb->nr_pages = nr_pages;
419423

420424
bio = btrfs_bio_alloc(first_byte);
421-
bio->bi_opf = REQ_OP_WRITE | write_flags;
425+
bio->bi_opf = bio_op | write_flags;
422426
bio->bi_private = cb;
423427
bio->bi_end_io = end_compressed_bio_write;
424428

429+
if (use_append) {
430+
struct extent_map *em;
431+
struct map_lookup *map;
432+
struct block_device *bdev;
433+
434+
em = btrfs_get_chunk_map(fs_info, disk_start, PAGE_SIZE);
435+
if (IS_ERR(em)) {
436+
kfree(cb);
437+
bio_put(bio);
438+
return BLK_STS_NOTSUPP;
439+
}
440+
441+
map = em->map_lookup;
442+
/* We only support single profile for now */
443+
ASSERT(map->num_stripes == 1);
444+
bdev = map->stripes[0].dev->bdev;
445+
446+
bio_set_dev(bio, bdev);
447+
free_extent_map(em);
448+
}
449+
425450
if (blkcg_css) {
426451
bio->bi_opf |= REQ_CGROUP_PUNT;
427452
kthread_associate_blkcg(blkcg_css);
@@ -432,16 +457,21 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
432457
bytes_left = compressed_len;
433458
for (pg_index = 0; pg_index < cb->nr_pages; pg_index++) {
434459
int submit = 0;
460+
int len;
435461

436462
page = compressed_pages[pg_index];
437463
page->mapping = inode->vfs_inode.i_mapping;
438464
if (bio->bi_iter.bi_size)
439465
submit = btrfs_bio_fits_in_stripe(page, PAGE_SIZE, bio,
440466
0);
441467

468+
if (pg_index == 0 && use_append)
469+
len = bio_add_zone_append_page(bio, page, PAGE_SIZE, 0);
470+
else
471+
len = bio_add_page(bio, page, PAGE_SIZE, 0);
472+
442473
page->mapping = NULL;
443-
if (submit || bio_add_page(bio, page, PAGE_SIZE, 0) <
444-
PAGE_SIZE) {
474+
if (submit || len < PAGE_SIZE) {
445475
/*
446476
* inc the count before we submit the bio so
447477
* we know the end IO handler won't happen before
@@ -465,11 +495,15 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
465495
}
466496

467497
bio = btrfs_bio_alloc(first_byte);
468-
bio->bi_opf = REQ_OP_WRITE | write_flags;
498+
bio->bi_opf = bio_op | write_flags;
469499
bio->bi_private = cb;
470500
bio->bi_end_io = end_compressed_bio_write;
471501
if (blkcg_css)
472502
bio->bi_opf |= REQ_CGROUP_PUNT;
503+
/*
504+
* Use bio_add_page() to ensure the bio has at least one
505+
* page.
506+
*/
473507
bio_add_page(bio, page, PAGE_SIZE, 0);
474508
}
475509
if (bytes_left < PAGE_SIZE) {

fs/btrfs/extent_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3753,7 +3753,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
37533753
/* Note that em_end from extent_map_end() is exclusive */
37543754
iosize = min(em_end, end + 1) - cur;
37553755

3756-
if (btrfs_use_zone_append(inode, em))
3756+
if (btrfs_use_zone_append(inode, em->block_start))
37573757
opf = REQ_OP_ZONE_APPEND;
37583758

37593759
free_extent_map(em);

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7786,7 +7786,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
77867786
iomap->bdev = fs_info->fs_devices->latest_bdev;
77877787
iomap->length = len;
77887788

7789-
if (write && btrfs_use_zone_append(BTRFS_I(inode), em))
7789+
if (write && btrfs_use_zone_append(BTRFS_I(inode), em->block_start))
77907790
iomap->flags |= IOMAP_F_ZONE_APPEND;
77917791

77927792
free_extent_map(em);

fs/btrfs/reflink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ static int clone_copy_inline_extent(struct inode *dst,
281281
ret = btrfs_inode_set_file_extent_range(BTRFS_I(dst), 0, aligned_end);
282282
out:
283283
if (!ret && !trans) {
284+
/*
285+
* Release path before starting a new transaction so we don't
286+
* hold locks that would confuse lockdep.
287+
*/
288+
btrfs_release_path(path);
284289
/*
285290
* No transaction here means we copied the inline extent into a
286291
* page of the destination inode.

fs/btrfs/tree-log.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,8 +1858,6 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans,
18581858
ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
18591859
} else if (ret == -EEXIST) {
18601860
ret = 0;
1861-
} else {
1862-
BUG(); /* Logic Error */
18631861
}
18641862
iput(inode);
18651863

fs/btrfs/zoned.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ void btrfs_free_redirty_list(struct btrfs_transaction *trans)
12781278
spin_unlock(&trans->releasing_ebs_lock);
12791279
}
12801280

1281-
bool btrfs_use_zone_append(struct btrfs_inode *inode, struct extent_map *em)
1281+
bool btrfs_use_zone_append(struct btrfs_inode *inode, u64 start)
12821282
{
12831283
struct btrfs_fs_info *fs_info = inode->root->fs_info;
12841284
struct btrfs_block_group *cache;
@@ -1293,7 +1293,7 @@ bool btrfs_use_zone_append(struct btrfs_inode *inode, struct extent_map *em)
12931293
if (!is_data_inode(&inode->vfs_inode))
12941294
return false;
12951295

1296-
cache = btrfs_lookup_block_group(fs_info, em->block_start);
1296+
cache = btrfs_lookup_block_group(fs_info, start);
12971297
ASSERT(cache);
12981298
if (!cache)
12991299
return false;

fs/btrfs/zoned.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache);
5353
void btrfs_redirty_list_add(struct btrfs_transaction *trans,
5454
struct extent_buffer *eb);
5555
void btrfs_free_redirty_list(struct btrfs_transaction *trans);
56-
bool btrfs_use_zone_append(struct btrfs_inode *inode, struct extent_map *em);
56+
bool btrfs_use_zone_append(struct btrfs_inode *inode, u64 start);
5757
void btrfs_record_physical_zoned(struct inode *inode, u64 file_offset,
5858
struct bio *bio);
5959
void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered);
@@ -152,8 +152,7 @@ static inline void btrfs_redirty_list_add(struct btrfs_transaction *trans,
152152
struct extent_buffer *eb) { }
153153
static inline void btrfs_free_redirty_list(struct btrfs_transaction *trans) { }
154154

155-
static inline bool btrfs_use_zone_append(struct btrfs_inode *inode,
156-
struct extent_map *em)
155+
static inline bool btrfs_use_zone_append(struct btrfs_inode *inode, u64 start)
157156
{
158157
return false;
159158
}

0 commit comments

Comments
 (0)