From patchwork Fri Nov 1 05:21:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13858705 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12F5E142624; Fri, 1 Nov 2024 05:22:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730438539; cv=none; b=pMa7KEjGdhEz0Ct5IZgcNCb7a1VFFRd5YgQOICcauBhsFN2FAg4GRkucdzJmco26tf6o6pC1zAnRKwn0cXnUREhmfvb2dj9ISiT7XF59VsptZHvM9WU5znGZcOMP6D5awi/sX20a7xxnVcRDoWh0nDVz78wxywPzx3RQCXTd38M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730438539; c=relaxed/simple; bh=slb+KppCK655pfVwV7e99lPKBdHboIRwq1Bll/HsT1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qPNPgPCkemU7diNLu873EJkXFyYornuvVOF4M6Ju21hPmXuphEieJANi6Es0S9A6piTStM0I+dIrKWUZgRh7EP5mh97dldhLC09gkuyFs9TZ04NSqny7hp7LxNZBEHgWwEkenjhQcjtYnn/0jnxfLgp0qYbEYcZ/YMQbD1A2uWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=GDX2Exju; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GDX2Exju" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=lGZz3Zhi20WXhdaLzZCJgylWTpCpZvB7OeLjk0c/j4I=; b=GDX2ExjuOkHTUQ7ewprh8gD8St iZ4W5jywqde1Qs1EUFw/h+SA4vCrtWnCUhS3zpNhkSU3PQ5b+1J8AgSjpHBannp6TQZeAc/fefpO4 ByOqMTkUNh9e4FUd75fMt4E1sWFcZloUaM/TS2O2qkCM7mPs/u1hisHdf/Ryy6dY51jFiGvnoulpN b7jZVfKRXglcpxkNIOhdvE4Dz4AyDKudqiwxMcpiN28xDuUdWq8FMmkNCGRPi4EsLVjcqTf8ugJIJ nfKe317ISTD8q5sJcmPt+sOijU3QgPgamcgwkqY/FrMcnjlGuU+6eMhkN52ksWYXYw8I4gH412fvh 6ig4/i3Q==; Received: from 2a02-8389-2341-5b80-5ae8-ad80-e9c6-3f1e.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:5ae8:ad80:e9c6:3f1e] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t6k6t-00000005pGr-0nJV; Fri, 01 Nov 2024 05:22:12 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 1/4] block: fix bio_split_rw_at to take zone_write_granularity into account Date: Fri, 1 Nov 2024 06:21:44 +0100 Message-ID: <20241101052206.437530-2-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101052206.437530-1-hch@lst.de> References: <20241101052206.437530-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Otherwise it can create unaligned writes on zoned devices. Fixes: a805a4fa4fa3 ("block: introduce zone_write_granularity limit") Signed-off-by: Christoph Hellwig --- block/blk-merge.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index d813d799cee7..d6895859a2fb 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -358,7 +358,8 @@ int bio_split_rw_at(struct bio *bio, const struct queue_limits *lim, * split size so that each bio is properly block size aligned, even if * we do not use the full hardware limits. */ - bytes = ALIGN_DOWN(bytes, lim->logical_block_size); + bytes = ALIGN_DOWN(bytes, lim->zone_write_granularity ? + lim->zone_write_granularity : lim->logical_block_size); /* * Bio splitting may cause subtle trouble such as hang when doing sync From patchwork Fri Nov 1 05:21:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13858706 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 430C210F4; Fri, 1 Nov 2024 05:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730438540; cv=none; b=u6xLdGstfAzk8KV6iSJKSCW01cHxXB5Wx5L7FH5EqJdD0XPRe/cGQ2eu1o4xW+EfcotD8AkngqxZe3BdnrclwcJUQ/uDcq6Al4pw4tYCIBuf8qYRdniM28dv+5zrt3oB3+GRBY+kvHI24001DaJvMeF7lBWv8z5xVICP7x5HnHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730438540; c=relaxed/simple; bh=ZUkHU54sLpz5za57c2YCZC3gjWNt5WfSHTest/Z7aw4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iq0Za94sxspg2fAWNyR3SxPN5Rie/712bWCrpSjTv7X6eIzVAGjFByE/iggrjDZbfyD6W0KQWkjtlhd7PTrL9GPIgABWNpoJMiRH6AuM7+7IzfTH+Px7sgeIJ2l14SoUsMIX1AIwBgJU44ddlGlByi5UBh340V2+NpFFXisVBMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=1qieJJdO; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="1qieJJdO" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=I56f3/YPgy9WjhPLAy7KWovxKgackQQXlSQlZ3dgc20=; b=1qieJJdOEzQvrxoSDBVxFokRuR mRyFInrcPXfJoW0e4qNImubXASw1v2luCRU/9snhnC/v9jL3HyE+Q4O7TVTeus86FyVm3OeCBtIvz I83y/BMF8hRb9BxKJYrXEpL2YAXEADrx5f6pAGTr1zgQedfTIaoZEjNOzexKu3/9mlyPzdPVKjquj 1TaGr1eW7u0cUJVZNnlcms2MHT7bvevj3KWAvFQFex+XC7KskCSVcTrjy9SquNkghwVdUVqlnH1cL qDQ5PhRxQdZs3D5RbfFrb4Z9upIx3VRgGHCgbHsNIU1jAcPjQVP7SKpK7lkXRYQW6iaWEhPs0NHut dd/arQVg==; Received: from 2a02-8389-2341-5b80-5ae8-ad80-e9c6-3f1e.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:5ae8:ad80:e9c6:3f1e] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t6k6w-00000005pH8-37gt; Fri, 01 Nov 2024 05:22:15 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 2/4] block: lift bio_is_zone_append to bio.h Date: Fri, 1 Nov 2024 06:21:45 +0100 Message-ID: <20241101052206.437530-3-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101052206.437530-1-hch@lst.de> References: <20241101052206.437530-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Make bio_is_zone_append globally available, because file systems need to use to check for a zone append bio in their end_io handlers to deal with the block layer emulation. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Johannes Thumshirn --- block/blk.h | 9 --------- include/linux/bio.h | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/block/blk.h b/block/blk.h index 63d5df0dc29c..6060e1e180a3 100644 --- a/block/blk.h +++ b/block/blk.h @@ -457,11 +457,6 @@ static inline bool bio_zone_write_plugging(struct bio *bio) { return bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING); } -static inline bool bio_is_zone_append(struct bio *bio) -{ - return bio_op(bio) == REQ_OP_ZONE_APPEND || - bio_flagged(bio, BIO_EMULATES_ZONE_APPEND); -} void blk_zone_write_plug_bio_merged(struct bio *bio); void blk_zone_write_plug_init_request(struct request *rq); static inline void blk_zone_update_request_bio(struct request *rq, @@ -510,10 +505,6 @@ static inline bool bio_zone_write_plugging(struct bio *bio) { return false; } -static inline bool bio_is_zone_append(struct bio *bio) -{ - return false; -} static inline void blk_zone_write_plug_bio_merged(struct bio *bio) { } diff --git a/include/linux/bio.h b/include/linux/bio.h index 4a1bf43ca53d..60830a6a5939 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -675,6 +675,23 @@ static inline void bio_clear_polled(struct bio *bio) bio->bi_opf &= ~REQ_POLLED; } +/** + * bio_is_zone_append - is this a zone append bio? + * @bio: bio to check + * + * Check if @bio is a zone append operation. Core block layer code and end_io + * handlers must use this instead of an open coded REQ_OP_ZONE_APPEND check + * because the block layer can rewrite REQ_OP_ZONE_APPEND to REQ_OP_WRITE if + * it is not natively supported. + */ +static inline bool bio_is_zone_append(struct bio *bio) +{ + if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED)) + return false; + return bio_op(bio) == REQ_OP_ZONE_APPEND || + bio_flagged(bio, BIO_EMULATES_ZONE_APPEND); +} + struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev, unsigned int nr_pages, blk_opf_t opf, gfp_t gfp); struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new); From patchwork Fri Nov 1 05:21:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13858707 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BC5C148833; Fri, 1 Nov 2024 05:22:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730438541; cv=none; b=dZpsV3X5o4JB4Ejy5nPa0PssrPNAYFw4S+a+1BRv2hDno+65f+7dSclLiA9aAdSD02GBN9DOCXt9lJPqoo/5UciYDXoOlkUnYDEbzZCBXyI+uQhUKuAbfd+Yk/dcRO9UkJtnHYUzhiGga8aY9jjKRap3Nq+WmS94W4kSI8CLKV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730438541; c=relaxed/simple; bh=z39hrZpi+DFwhXJlNFv4OE3g8fMI19Mu3OuYJ7O2bYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nkiXLAbyzMicoZ7FX84A4GWiBc92RuUpa6FmTYcGqualCxvhAKCO8djR0kbhSHQkLpabiXWgVhV7AJcWC1UAt+rG/Hd2vA0GSVqsOqGOQCrXqB+cY7xd6pB9Q2rLEfjELEbgqpT0ANsexTI2ucLxcT9wVr/2+cM0SdyAVldD4N4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=rqphav1z; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="rqphav1z" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=eQglrKO3cTPUjwY+ITAsHWbCwAas6cfGpEhvnjlZTXk=; b=rqphav1ztRqhjdfzstWbpeo/qw vyAld9K1qTzknBfd6XJAEG9uIIsCRMkUUiB7uay1nQMpWNIHVlNvXou/6murKjXFrSmGjOIj0XK9H 2NMBP4wTcBNzELQoChsPzukZKRCeJHhcd4XZLIwM2a39RzCMBWpUQDG0qg+XC9jeLIPAAJ9MBS5lQ Afx4FMmYk/H/+A5jdhtwhe3emOsnfQY6DaDc2gfyvIKAyD/v9t1e4oNEfQL5Cik57b+MvzbJnI1OZ UqZprdi1qpyFTlNuyAqHACMcxHqV+4Is/zsHoCFFA1x8VGcqthA+2RLbwfGa2V4HwPVcNKIvvDydn SDC8KOgg==; Received: from 2a02-8389-2341-5b80-5ae8-ad80-e9c6-3f1e.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:5ae8:ad80:e9c6:3f1e] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t6k6z-00000005pHO-2vlh; Fri, 01 Nov 2024 05:22:18 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] btrfs: use bio_is_zone_append in the completion handler Date: Fri, 1 Nov 2024 06:21:46 +0100 Message-ID: <20241101052206.437530-4-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101052206.437530-1-hch@lst.de> References: <20241101052206.437530-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Otherwise it won't catch bios turned into regular writes by the block level zone write plugging. Fixes: 9b1ce7f0c6f8 ("block: Implement zone append emulation") Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- fs/btrfs/bio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index fec5c6cde0a7..0f096e226908 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -366,7 +366,7 @@ static void btrfs_simple_end_io(struct bio *bio) INIT_WORK(&bbio->end_io_work, btrfs_end_bio_work); queue_work(btrfs_end_io_wq(fs_info, bio), &bbio->end_io_work); } else { - if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status) + if (bio_is_zone_append(bio) && !bio->bi_status) btrfs_record_physical_zoned(bbio); btrfs_bio_end_io(bbio, bbio->bio.bi_status); } @@ -409,7 +409,7 @@ static void btrfs_orig_write_end_io(struct bio *bio) else bio->bi_status = BLK_STS_OK; - if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status) + if (bio_is_zone_append(bio) && !bio->bi_status) stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT; btrfs_bio_end_io(bbio, bbio->bio.bi_status); @@ -423,7 +423,7 @@ static void btrfs_clone_write_end_io(struct bio *bio) if (bio->bi_status) { atomic_inc(&stripe->bioc->error); btrfs_log_dev_io_error(bio, stripe->dev); - } else if (bio_op(bio) == REQ_OP_ZONE_APPEND) { + } else if (bio_is_zone_append(bio)) { stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT; } From patchwork Fri Nov 1 05:21:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13858708 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78A61148833; Fri, 1 Nov 2024 05:22:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730438544; cv=none; b=VHlPxDeDTrTweYB9zuORSLnxwuplXT4nNpb4hYWhA7u5DuwxooII/BlN/dIwfDUdfH856clwsf9+mgawM8kf33t7UjK639M69f0GqibCHqJjicAbgxqb5VoAx/EpxCW4UQjFX8SRUnXrA0pEYBeBhNRPs6rLyGMAC72i+B2qV9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730438544; c=relaxed/simple; bh=vU82TCo/QxS1LB29en1h62ORa9cEBpHnZIQoL6RsBH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WSBkzr4zXv8hBx9+a70y6OF9Ce46oPyw1Uj5Pi23T/zUURRb0IvTWa98QDHvKqxER1/4VwKkx2yyhq33Zvg7IpuBHBPbCNgZiNHNq3bMths5BcFaDMRkgVbWs02ZnB9s0Mj2OMOPqyF9Es6Qdi75M2o1DOXU3pgVHlD51NREkz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=2vrkgonL; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="2vrkgonL" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=n6iYwR+va9aUImMwmsfXGV0Qu2Qx4DaWLQ9hhemGQHM=; b=2vrkgonL/mCaSodPqL6wZFCgxo MeHw3q4noJJnJQPgYCIFcWDyiGN+wnpeBX57GPJwMSPdfSd2UIr6VGe2PAdtFFZ1V42YPRi3L6LYG C8fJ7kz/LS6GEvWuXmCKtCx4V6dfStMp6Kg3Y8wM+nt9G5VLqVrkkHlqkQBHRyAoqBQEZav3fkTr8 O+KYME1tQ3iM4MW5Z/JtHK+PrPPL8atJ857rD0IBd4kYUVBazJHXr60H6vWJwsRvQ7+5+nBFlV08q /g5T/yYIn8J3tfHrIdBJbfWSKGAAQeONbhSwKYxt5b9vYsRtvzHy+6diFRK0ysdt57Y15++a3jTO/ NzupJAbg==; Received: from 2a02-8389-2341-5b80-5ae8-ad80-e9c6-3f1e.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:5ae8:ad80:e9c6:3f1e] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t6k72-00000005pHe-3cKT; Fri, 01 Nov 2024 05:22:21 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 4/4] btrfs: split bios to the fs sector size boundary Date: Fri, 1 Nov 2024 06:21:47 +0100 Message-ID: <20241101052206.437530-5-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101052206.437530-1-hch@lst.de> References: <20241101052206.437530-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Btrfs like other file systems can't really deal with I/O not aligned to it's internal block size (which strangely is called sector size in btrfs), but the block layer split helper doesn't even know about that. Round down the split boundary so that all I/Os are aligned. Fixes: d5e4377d5051 ("btrfs: split zone append bios in btrfs_submit_bio") Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- fs/btrfs/bio.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 0f096e226908..299b9a0ed68b 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -660,8 +660,15 @@ static u64 btrfs_append_map_length(struct btrfs_bio *bbio, u64 map_length) map_length = min(map_length, bbio->fs_info->max_zone_append_size); sector_offset = bio_split_rw_at(&bbio->bio, &bbio->fs_info->limits, &nr_segs, map_length); - if (sector_offset) - return sector_offset << SECTOR_SHIFT; + if (sector_offset) { + /* + * bio_split_rw_at could split at a size smaller than the + * file system sector size and thus cause unaligned I/Os. + * Fix that by always rounding down to the nearest boundary. + */ + return ALIGN_DOWN(sector_offset << SECTOR_SHIFT, + bbio->fs_info->sectorsize); + } return map_length; }