From patchwork Tue Mar 7 16:39:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164182 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8EB7C6FD1A for ; Tue, 7 Mar 2023 16:42:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230232AbjCGQms (ORCPT ); Tue, 7 Mar 2023 11:42:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbjCGQmV (ORCPT ); Tue, 7 Mar 2023 11:42:21 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 121BB96C0E for ; Tue, 7 Mar 2023 08:40:08 -0800 (PST) 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=GRzg7t/WTJr4Es62ge5iNhsv0t0DTv+ZqYmEl7Dy3yE=; b=0R/UobueHOO2E52/IJ5qlN1ew+ hK92kLIDp5vyfBjCHMbD3Y8eU/2RLagCV2eQL9quyrFtDbVBYWTnS/32lV/zTmUmP0LmuNcVULWrl 9nSbje9jLORiU+HF1mi/CmDW6rMuCluzLVltSM6qsOSzAYfRM7UPoTHGGMZ8+EFtXkIRuhKV28YQG CeeOX1CFZ/94gz1g93I/h6e91QL9yAQE2BZ3Vnn3joKuuMLWJmBxEpmQbtLl/Kk2mFpyowFbf3oDn J+eSYH/mtMgsz7ViJNcdhB60sNzA089lRRvOKg71dZHgyG9mAQry+SgaSlEi76G82uaKStb7t+V5o ohdqLGyg==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaM8-001bNl-Iu; Tue, 07 Mar 2023 16:40:05 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn , Qu Wenruo Subject: [PATCH 01/10] btrfs: remove unused members from struct btrfs_encoded_read_private Date: Tue, 7 Mar 2023 17:39:36 +0100 Message-Id: <20230307163945.31770-2-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The inode and file_offset members in struct btrfs_encoded_read_private are unused, so remove them. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 45102785c72329..cce4729bbca177 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9926,8 +9926,6 @@ static ssize_t btrfs_encoded_read_inline( } struct btrfs_encoded_read_private { - struct btrfs_inode *inode; - u64 file_offset; wait_queue_head_t wait; atomic_t pending; blk_status_t status; @@ -9958,8 +9956,6 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, u64 disk_io_size, struct page **pages) { struct btrfs_encoded_read_private priv = { - .inode = inode, - .file_offset = file_offset, .pending = ATOMIC_INIT(1), }; unsigned long i = 0; From patchwork Tue Mar 7 16:39:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0593BC6FD1A for ; Tue, 7 Mar 2023 16:43:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229549AbjCGQnZ (ORCPT ); Tue, 7 Mar 2023 11:43:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbjCGQmx (ORCPT ); Tue, 7 Mar 2023 11:42:53 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3A9E960BA for ; Tue, 7 Mar 2023 08:40:25 -0800 (PST) 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=MdEFuhbrRZ8hE4ftE/QH4OsFneAiycOVg5REx6yKKno=; b=r9MkxrpTtXDVxf7pK+1VO3KgK3 W9LSNtR4Di3yp3/O8TABXY+upL4B9/mMQ2hWdQaP2IZiRaDxPzif+X2mOwaw+RUb8seKrE4FPyyNG GfOivZ3rvB54dCxwtN/NBsAuFIZqDslbisSaMLZdCz3igKuEFQfoDpWyylKDzEyffYb5111/Kyvnl bFJ1lavm2AYfhPR4dTFWEbEwyL2e0ocCI+0rbxOG1tcO/VGkovH3mMyMMWO48IGksl1+jY76nYR7A 0gxn13IFT0JEfPUQg72tafGBJItYYjyMotKBi+wtVtLptv03PXdibMNcDp+uc4CZJFZqQn/lMrW9T 4ZRsWGAA==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaML-001bRM-S6; Tue, 07 Mar 2023 16:40:18 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn Subject: [PATCH 02/10] btrfs: cleanup btrfs_encoded_read_regular_fill_pages Date: Tue, 7 Mar 2023 17:39:37 +0100 Message-Id: <20230307163945.31770-3-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_encoded_read_regular_fill_pages has a pretty odd control flow. Unwind it so that there is a single loop over the pages array. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 51 ++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index cce4729bbca177..bba3013894b76c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9959,39 +9959,34 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, .pending = ATOMIC_INIT(1), }; unsigned long i = 0; - u64 cur = 0; + struct bio *bio; init_waitqueue_head(&priv.wait); - /* Submit bios for the extent, splitting due to bio limits as necessary. */ - while (cur < disk_io_size) { - struct bio *bio = NULL; - u64 remaining = disk_io_size - cur; - - while (bio || remaining) { - size_t bytes = min_t(u64, remaining, PAGE_SIZE); - - if (!bio) { - bio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, - inode, - btrfs_encoded_read_endio, - &priv); - bio->bi_iter.bi_sector = - (disk_bytenr + cur) >> SECTOR_SHIFT; - } - if (!bytes || - bio_add_page(bio, pages[i], bytes, 0) < bytes) { - atomic_inc(&priv.pending); - btrfs_submit_bio(bio, 0); - bio = NULL; - continue; - } + bio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, + btrfs_encoded_read_endio, &priv); + bio->bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; - i++; - cur += bytes; - remaining -= bytes; + do { + size_t bytes = min_t(u64, disk_io_size, PAGE_SIZE); + + if (bio_add_page(bio, pages[i], bytes, 0) < bytes) { + atomic_inc(&priv.pending); + btrfs_submit_bio(bio, 0); + + bio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, + btrfs_encoded_read_endio, &priv); + bio->bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; + continue; } - } + + i++; + disk_bytenr += bytes; + disk_io_size -= bytes; + } while (disk_io_size); + + atomic_inc(&priv.pending); + btrfs_submit_bio(bio, 0); if (atomic_dec_return(&priv.pending)) io_wait_event(priv.wait, !atomic_read(&priv.pending)); From patchwork Tue Mar 7 16:39:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164184 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4680C6FD1D for ; Tue, 7 Mar 2023 16:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbjCGQnh (ORCPT ); Tue, 7 Mar 2023 11:43:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229983AbjCGQnN (ORCPT ); Tue, 7 Mar 2023 11:43:13 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E05984CD for ; Tue, 7 Mar 2023 08:40:42 -0800 (PST) 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=dlpBKC7fXUNlqHGA/uEu90lxyroe94n8JhlDpu1ufbM=; b=zNZfgqUANpiRoc0e/j1pLIdbfS ecB3lFTQP4C6WyoYUz23yHiKztSh9Tt8zuWAOkAj0uSLe5RsYaHk2zPpfLDhrGhwHsQXDK4K6ChFO sJZBGp2ViepQ1O4DKMkWjWTrxZSKJbr1f0Y2zMJVAHgRekJ/glJF+L2TzkBDRtt7R2E77QrB2A7+r l40iPXiHXTNKOOZp8EzLKvzceUJd2w74c/a2WnH6b9CyY09wTN+n6z3BDI/g9NKQJE6IuXFqb8bZv zZPMyDztYZWRFKdvw7HwHv8GdCd0QHZa7Q9X3XLR0FuwpP3xZVF2jKDxW62LQP3aZjARTkVO9GrKs 1Nom0+Ow==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaMU-001bW4-Kw; Tue, 07 Mar 2023 16:40:26 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn , Qu Wenruo Subject: [PATCH 03/10] btrfs: move zero filling of compressed read bios into common code Date: Tue, 7 Mar 2023 17:39:38 +0100 Message-Id: <20230307163945.31770-4-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org All algorithms have to fill the remainder of the orig_bio with zeroes, so do it in common code. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/compression.c | 2 ++ fs/btrfs/lzo.c | 14 +++++--------- fs/btrfs/zlib.c | 2 -- fs/btrfs/zstd.c | 1 - 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 5b1de1c19991e9..64c804dc3962f6 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -965,6 +965,8 @@ static int btrfs_decompress_bio(struct compressed_bio *cb) ret = compression_decompress_bio(workspace, cb); put_workspace(type, workspace); + if (!ret) + zero_fill_bio(cb->orig_bio); return ret; } diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index dc66ee98989e90..3a095b9c6373ea 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -389,8 +389,7 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb) */ btrfs_err(fs_info, "unexpectedly large lzo segment len %u", seg_len); - ret = -EIO; - goto out; + return -EIO; } /* Copy the compressed segment payload into workspace */ @@ -401,8 +400,7 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb) workspace->buf, &out_len); if (ret != LZO_E_OK) { btrfs_err(fs_info, "failed to decompress"); - ret = -EIO; - goto out; + return -EIO; } /* Copy the data into inode pages */ @@ -411,7 +409,7 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb) /* All data read, exit */ if (ret == 0) - goto out; + return 0; ret = 0; /* Check if the sector has enough space for a segment header */ @@ -422,10 +420,8 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb) /* Skip the padding zeros */ cur_in += sector_bytes_left; } -out: - if (!ret) - zero_fill_bio(cb->orig_bio); - return ret; + + return 0; } int lzo_decompress(struct list_head *ws, const u8 *data_in, diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index da7bb9187b68a3..8acb05e176c540 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -350,8 +350,6 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb) zlib_inflateEnd(&workspace->strm); if (data_in) kunmap_local(data_in); - if (!ret) - zero_fill_bio(cb->orig_bio); return ret; } diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index e34f1ab99d56fe..f798da267590d4 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -609,7 +609,6 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb) } } ret = 0; - zero_fill_bio(cb->orig_bio); done: if (workspace->in_buf.src) kunmap_local(workspace->in_buf.src); From patchwork Tue Mar 7 16:39:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7DB0C678D5 for ; Tue, 7 Mar 2023 16:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbjCGQnl (ORCPT ); Tue, 7 Mar 2023 11:43:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbjCGQnQ (ORCPT ); Tue, 7 Mar 2023 11:43:16 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FE79984D6 for ; Tue, 7 Mar 2023 08:40:45 -0800 (PST) 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=1LFtr21r2RNGRpFuvdulAy0nb4i8njJ1KK4iB/dqd1U=; b=AArflZ4ycqRBobwo9vBkGBiqTR Gh6fCag3ZwCzaEZBzSzPwzCM8ZuQ18Y5Yk4Qt1BON3qMcRI1qNyoLZbI/tpIJCdYmVD+eCc9OaFLP aTdIb4VjMv0fvmeoQnkS7bE9m3j6lnfvUA6DrS16mMC3zIQjEGp9HYloekmLhylO988Wk8ijANLRC O2vr5zAFNPMoya3ELwTgSqpm8SBHeZquSF3urLjkf8e/QOHo6xgHnQEoY7FTcBtU/toCksa8nmFUF 5A8c6MHiZzLn28BOSEbI75mtt19PNEGGu9SarRKbXWrdHGnIq0WblAIcbW9f4t5fZMu+ZO+kMDFsG tuDSE/tg==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaMc-001bZJ-0K; Tue, 07 Mar 2023 16:40:34 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn , Qu Wenruo Subject: [PATCH 04/10] btrfs: pass a btrfs_bio to btrfs_submit_bio Date: Tue, 7 Mar 2023 17:39:39 +0100 Message-Id: <20230307163945.31770-5-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_submit_bio expects the bio passed to it to be embedded into a btrfs_bio structure. Pass the btrfs_bio directly to increase type safety and make the code self-documenting. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/bio.c | 14 +++++++------- fs/btrfs/bio.h | 2 +- fs/btrfs/compression.c | 4 ++-- fs/btrfs/extent_io.c | 2 +- fs/btrfs/inode.c | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 726592868e9c5c..c04e103f876853 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -164,7 +164,7 @@ static void btrfs_end_repair_bio(struct btrfs_bio *repair_bbio, goto done; } - btrfs_submit_bio(&repair_bbio->bio, mirror); + btrfs_submit_bio(repair_bbio, mirror); return; } @@ -232,7 +232,7 @@ static struct btrfs_failed_bio *repair_one_sector(struct btrfs_bio *failed_bbio, mirror = next_repair_mirror(fbio, failed_bbio->mirror_num); btrfs_debug(fs_info, "submitting repair read to mirror %d", mirror); - btrfs_submit_bio(repair_bio, mirror); + btrfs_submit_bio(repair_bbio, mirror); return fbio; } @@ -603,12 +603,12 @@ static bool btrfs_wq_submit_bio(struct btrfs_bio *bbio, return true; } -static bool btrfs_submit_chunk(struct bio *bio, int mirror_num) +static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) { - struct btrfs_bio *bbio = btrfs_bio(bio); struct btrfs_inode *inode = bbio->inode; struct btrfs_fs_info *fs_info = inode->root->fs_info; struct btrfs_bio *orig_bbio = bbio; + struct bio *bio = &bbio->bio; u64 logical = bio->bi_iter.bi_sector << 9; u64 length = bio->bi_iter.bi_size; u64 map_length = length; @@ -650,7 +650,7 @@ static bool btrfs_submit_chunk(struct bio *bio, int mirror_num) if (use_append) { bio->bi_opf &= ~REQ_OP_WRITE; bio->bi_opf |= REQ_OP_ZONE_APPEND; - ret = btrfs_extract_ordered_extent(btrfs_bio(bio)); + ret = btrfs_extract_ordered_extent(bbio); if (ret) goto fail_put_bio; } @@ -686,9 +686,9 @@ static bool btrfs_submit_chunk(struct bio *bio, int mirror_num) return true; } -void btrfs_submit_bio(struct bio *bio, int mirror_num) +void btrfs_submit_bio(struct btrfs_bio *bbio, int mirror_num) { - while (!btrfs_submit_chunk(bio, mirror_num)) + while (!btrfs_submit_chunk(bbio, mirror_num)) ; } diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h index 873ff85817f0b2..b4e7d5ab7d236d 100644 --- a/fs/btrfs/bio.h +++ b/fs/btrfs/bio.h @@ -88,7 +88,7 @@ static inline void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status) /* Bio only refers to one ordered extent. */ #define REQ_BTRFS_ONE_ORDERED REQ_DRV -void btrfs_submit_bio(struct bio *bio, int mirror_num); +void btrfs_submit_bio(struct btrfs_bio *bbio, int mirror_num); int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, u64 length, u64 logical, struct page *page, unsigned int pg_offset, int mirror_num); diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 64c804dc3962f6..27bea05cab1a1b 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -333,7 +333,7 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, cb->nr_pages = nr_pages; btrfs_add_compressed_bio_pages(cb, disk_start); - btrfs_submit_bio(&cb->bbio.bio, 0); + btrfs_submit_bio(&cb->bbio, 0); if (blkcg_css) kthread_associate_blkcg(NULL); @@ -565,7 +565,7 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num) if (memstall) psi_memstall_leave(&pflags); - btrfs_submit_bio(&cb->bbio.bio, mirror_num); + btrfs_submit_bio(&cb->bbio, mirror_num); return; out_free_compressed_pages: diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 924fcb6c97e88d..2e594252af0178 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -157,7 +157,7 @@ static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) bio_ctrl->compress_type != BTRFS_COMPRESS_NONE) btrfs_submit_compressed_read(bio, mirror_num); else - btrfs_submit_bio(bio, mirror_num); + btrfs_submit_bio(btrfs_bio(bio), mirror_num); /* The bio is owned by the end_io handler now */ bio_ctrl->bio = NULL; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index bba3013894b76c..cb3c387e57993b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7787,7 +7787,7 @@ static void btrfs_dio_submit_io(const struct iomap_iter *iter, struct bio *bio, dip->bytes = bio->bi_iter.bi_size; dio_data->submitted += bio->bi_iter.bi_size; - btrfs_submit_bio(bio, 0); + btrfs_submit_bio(bbio, 0); } static const struct iomap_ops btrfs_dio_iomap_ops = { @@ -9972,7 +9972,7 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, if (bio_add_page(bio, pages[i], bytes, 0) < bytes) { atomic_inc(&priv.pending); - btrfs_submit_bio(bio, 0); + btrfs_submit_bio(btrfs_bio(bio), 0); bio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, btrfs_encoded_read_endio, &priv); @@ -9986,7 +9986,7 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, } while (disk_io_size); atomic_inc(&priv.pending); - btrfs_submit_bio(bio, 0); + btrfs_submit_bio(btrfs_bio(bio), 0); if (atomic_dec_return(&priv.pending)) io_wait_event(priv.wait, !atomic_read(&priv.pending)); From patchwork Tue Mar 7 16:39:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EF2CC678D5 for ; Tue, 7 Mar 2023 16:43:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbjCGQny (ORCPT ); Tue, 7 Mar 2023 11:43:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230326AbjCGQnY (ORCPT ); Tue, 7 Mar 2023 11:43:24 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BDF72A6E6 for ; Tue, 7 Mar 2023 08:40:47 -0800 (PST) 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=4O9IenRyuraVOyy5mWNjvhjZVusuywbp9CQWoD1XsW0=; b=DwGwNdIav1ewzGFjxJEDsYY3w0 3PZK/DeMhZ+CLipjdzJGpEwX8EUMOAinH2BsIlyNytQezPltOiR5Es9fz2HdVeZOJi2A5VdoSG4An 5Cavaf53Jcm2S7By1LLoDCUbQ/MWOsvrTyHC0BV3VlRKwX43gk4RZI8drIfPHVk3VBdlzLHtiNCRN Xbv2TP6bK3MDWqoCitsGFzk1w7APPGQrO4X+qjihFkMlc0Qf8Izd0nvuC5zfBDLP2PrVDQ1XNXvAV YtiAK7Q/t8FkaG9v3p1UctOAS+JB5j4j5zs13AWpaswnxlecFNtcqe6u6+IzxTttx8UJ2HjefvcWu Tv5YSW9w==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaMk-001bcJ-75; Tue, 07 Mar 2023 16:40:42 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn , Qu Wenruo Subject: [PATCH 05/10] btrfs: pass a btrfs_bio to btrfs_submit_compressed_read Date: Tue, 7 Mar 2023 17:39:40 +0100 Message-Id: <20230307163945.31770-6-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_submit_compressed_read expects the bio passed to it to be embedded into a btrfs_bio structure. Pass the btrfs_bio directly to increase type safety and make the code self-documenting. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/compression.c | 16 ++++++++-------- fs/btrfs/compression.h | 2 +- fs/btrfs/extent_io.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 27bea05cab1a1b..c12e317e133624 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -498,15 +498,15 @@ static noinline int add_ra_bio_pages(struct inode *inode, * After the compressed pages are read, we copy the bytes into the * bio we were passed and then call the bio end_io calls */ -void btrfs_submit_compressed_read(struct bio *bio, int mirror_num) +void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num) { - struct btrfs_inode *inode = btrfs_bio(bio)->inode; + struct btrfs_inode *inode = bbio->inode; struct btrfs_fs_info *fs_info = inode->root->fs_info; struct extent_map_tree *em_tree = &inode->extent_tree; struct compressed_bio *cb; unsigned int compressed_len; - const u64 disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT; - u64 file_offset = btrfs_bio(bio)->file_offset; + const u64 disk_bytenr = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT; + u64 file_offset = bbio->file_offset; u64 em_len; u64 em_start; struct extent_map *em; @@ -534,10 +534,10 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num) em_len = em->len; em_start = em->start; - cb->len = bio->bi_iter.bi_size; + cb->len = bbio->bio.bi_iter.bi_size; cb->compressed_len = compressed_len; cb->compress_type = em->compress_type; - cb->orig_bio = bio; + cb->orig_bio = &bbio->bio; free_extent_map(em); @@ -558,7 +558,7 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num) &pflags); /* include any pages we added in add_ra-bio_pages */ - cb->len = bio->bi_iter.bi_size; + cb->len = bbio->bio.bi_iter.bi_size; btrfs_add_compressed_bio_pages(cb, disk_bytenr); @@ -573,7 +573,7 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num) out_free_bio: bio_put(&cb->bbio.bio); out: - btrfs_bio_end_io(btrfs_bio(bio), ret); + btrfs_bio_end_io(bbio, ret); } /* diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 95d2e85c6e4eea..692bafa1050e8e 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -94,7 +94,7 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, blk_opf_t write_flags, struct cgroup_subsys_state *blkcg_css, bool writeback); -void btrfs_submit_compressed_read(struct bio *bio, int mirror_num); +void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num); unsigned int btrfs_compress_str2level(unsigned int type, const char *str); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 2e594252af0178..2b9e24782b36f5 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -155,7 +155,7 @@ static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) if (btrfs_op(bio) == BTRFS_MAP_READ && bio_ctrl->compress_type != BTRFS_COMPRESS_NONE) - btrfs_submit_compressed_read(bio, mirror_num); + btrfs_submit_compressed_read(btrfs_bio(bio), mirror_num); else btrfs_submit_bio(btrfs_bio(bio), mirror_num); From patchwork Tue Mar 7 16:39:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5A94C6FD1A for ; Tue, 7 Mar 2023 16:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbjCGQoC (ORCPT ); Tue, 7 Mar 2023 11:44:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbjCGQn3 (ORCPT ); Tue, 7 Mar 2023 11:43:29 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBECA90B43 for ; Tue, 7 Mar 2023 08:40:52 -0800 (PST) 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=i/gQ8P09S+Twu7N7eDqC10ZDTKXItv25ICiyq88nXLs=; b=F8X25MHOr0sfwEdYCcC60FEFNW Dpk34ikgGLa3TxUpXkEA2PmtaL4HsE19FXIHjhcHl+dTDHkOUXpHcMvWrE9ffguSW0dNelD49Fe7G txhS3tGMCRoe4TiIec3lLTKq4fo6OVH5FFPBfN/CdjamjRN4L5M16HzlOA5q8IUihRh8NiyPCNkom RHqZ8QRwtfU4wZ4DnEgNh6/lLLzXTQJn32IxdfBJ6Fpt3i87UYfqQBvsI5raNDYmg7Lz858toKkG7 IXJa5JswKCuwZxqe5z+J2MOILUlzRp/7PZ5Db8ZCBXqccQneKUC1MBVUNBzjFiJhNWqY0TBs1JF+M msUp7Spg==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaMs-001bfc-06; Tue, 07 Mar 2023 16:40:50 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn , Qu Wenruo Subject: [PATCH 06/10] btrfs: store a pointer to the original btrfs_bio in struct compressed_bio Date: Tue, 7 Mar 2023 17:39:41 +0100 Message-Id: <20230307163945.31770-7-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The original bio must be a btrfs_bio, so store a pointer to the btrfs_bio for better type checking. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/compression.c | 15 ++++++++------- fs/btrfs/compression.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index c12e317e133624..c5839d04690d67 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -177,7 +177,7 @@ static void end_compressed_bio_read(struct btrfs_bio *bbio) status = errno_to_blk_status(btrfs_decompress_bio(cb)); btrfs_free_compressed_pages(cb); - btrfs_bio_end_io(btrfs_bio(cb->orig_bio), status); + btrfs_bio_end_io(cb->orig_bbio, status); bio_put(&bbio->bio); } @@ -357,7 +357,8 @@ static noinline int add_ra_bio_pages(struct inode *inode, { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); unsigned long end_index; - u64 cur = btrfs_bio(cb->orig_bio)->file_offset + cb->orig_bio->bi_iter.bi_size; + struct bio *orig_bio = &cb->orig_bbio->bio; + u64 cur = cb->orig_bbio->file_offset + orig_bio->bi_iter.bi_size; u64 isize = i_size_read(inode); int ret; struct page *page; @@ -447,7 +448,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, */ if (!em || cur < em->start || (cur + fs_info->sectorsize > extent_map_end(em)) || - (em->block_start >> 9) != cb->orig_bio->bi_iter.bi_sector) { + (em->block_start >> 9) != orig_bio->bi_iter.bi_sector) { free_extent_map(em); unlock_extent(tree, cur, page_end, NULL); unlock_page(page); @@ -467,7 +468,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, } add_size = min(em->start + em->len, page_end + 1) - cur; - ret = bio_add_page(cb->orig_bio, page, add_size, offset_in_page(cur)); + ret = bio_add_page(orig_bio, page, add_size, offset_in_page(cur)); if (ret != add_size) { unlock_extent(tree, cur, page_end, NULL); unlock_page(page); @@ -537,7 +538,7 @@ void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num) cb->len = bbio->bio.bi_iter.bi_size; cb->compressed_len = compressed_len; cb->compress_type = em->compress_type; - cb->orig_bio = &bbio->bio; + cb->orig_bbio = bbio; free_extent_map(em); @@ -966,7 +967,7 @@ static int btrfs_decompress_bio(struct compressed_bio *cb) put_workspace(type, workspace); if (!ret) - zero_fill_bio(cb->orig_bio); + zero_fill_bio(&cb->orig_bbio->bio); return ret; } @@ -1044,7 +1045,7 @@ void __cold btrfs_exit_compress(void) int btrfs_decompress_buf2page(const char *buf, u32 buf_len, struct compressed_bio *cb, u32 decompressed) { - struct bio *orig_bio = cb->orig_bio; + struct bio *orig_bio = &cb->orig_bbio->bio; /* Offset inside the full decompressed extent */ u32 cur_offset; diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 692bafa1050e8e..5d5146e72a860b 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -55,7 +55,7 @@ struct compressed_bio { union { /* For reads, this is the bio we are copying the data into */ - struct bio *orig_bio; + struct btrfs_bio *orig_bbio; struct work_struct write_end_work; }; From patchwork Tue Mar 7 16:39:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29D9DC678D5 for ; Tue, 7 Mar 2023 16:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230310AbjCGQoK (ORCPT ); Tue, 7 Mar 2023 11:44:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbjCGQnd (ORCPT ); Tue, 7 Mar 2023 11:43:33 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9AD01448B for ; Tue, 7 Mar 2023 08:40:59 -0800 (PST) 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=wj1CuQNogxSXqxQpskttZ6KNhBFyapCU0NwQkInS6KM=; b=jyVwoXAnBbpAritoYzhqB1Etxv MQUqSYTxGCvCBqBOOBZ758yF8DMFzqHqRoqUO8L7OlCm/UpPaIfHRFZB7MRZec8qZ3u1rAfAcxYjd 5VWhNwUmr2t8yq9OwQwAtT3oVwAbJUXC/i5GUYc3XGcGyu1izzBB5y0H85vXN3ISxSoeDzhH162Bj 6p1sCGfJ+SW4oF5q1Ab6c5UHvZ62Q7A6xu09MBnuPWqB41pxW/+yH+oKGJ9ew37PGZyQmMWxqLzoY 43ijjKCJbrL0n1Domgh63ibxp/yAzLVulwUkA+oDRLcg8jk9BfDpjJO9mO3q8aT6sobGisv4ykgWc N1/neQIQ==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaMy-001bir-Vs; Tue, 07 Mar 2023 16:40:57 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn , Qu Wenruo Subject: [PATCH 07/10] btrfs: simplify finding the inode in submit_one_bio Date: Tue, 7 Mar 2023 17:39:42 +0100 Message-Id: <20230307163945.31770-8-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org struct btrfs_bio now has an always valid inode pointer that can be used to find the inode in submit_one_bio, so use that and initialize all variables for which it is possible at declaration time. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/extent_io.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 2b9e24782b36f5..2670c479847094 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -123,23 +123,16 @@ struct btrfs_bio_ctrl { static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) { - struct bio *bio; - struct bio_vec *bv; - struct inode *inode; - int mirror_num; + struct bio *bio = bio_ctrl->bio; + int mirror_num = bio_ctrl->mirror_num; - if (!bio_ctrl->bio) + if (!bio) return; - bio = bio_ctrl->bio; - bv = bio_first_bvec_all(bio); - inode = bv->bv_page->mapping->host; - mirror_num = bio_ctrl->mirror_num; - /* Caller should ensure the bio has at least some range added */ ASSERT(bio->bi_iter.bi_size); - if (!is_data_inode(inode)) { + if (!is_data_inode(&btrfs_bio(bio)->inode->vfs_inode)) { if (btrfs_op(bio) != BTRFS_MAP_WRITE) { /* * For metadata read, we should have the parent_check, From patchwork Tue Mar 7 16:39:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8BF7C678D5 for ; Tue, 7 Mar 2023 16:44:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbjCGQoW (ORCPT ); Tue, 7 Mar 2023 11:44:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbjCGQnw (ORCPT ); Tue, 7 Mar 2023 11:43:52 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0D0C42BE3 for ; Tue, 7 Mar 2023 08:41:07 -0800 (PST) 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=xnqg6qbKpFWrlK4aYA2Drfq8/rBtmYvRNtIPuKCQVkM=; b=uunY7jaUi2/WeO9ItgFxOHuZCE NTbepN5MNbVaalggHkscG4Lopc9uRx97C3xVowuguUDjCWSsRLph2HXV5m8mdOEayGh24bZpvuqBu aepBjRZNTR+cSb3LBzoFtpibpD5+K+xWz0MvHoeuhHzYnSJ2P1u2+pu+SXKUEJDHwTPueLRFrSyvU b0+sGTXDLrm2oiYJog/yUs0hXUqCUr6fgvIvlo1PxtoGun/cEaKDdZSVm5oMo07YKXFge3HzQHCiX wcM0QO03pEtgIvsZgPc0x5hMQ3T+Tmq/tFyZ2b9Vx4t2gD6bAMkf7QWji8NEDBmM6nncfcFy9HUbJ AHea70xA==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaN6-001bl7-BE; Tue, 07 Mar 2023 16:41:04 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Qu Wenruo , Johannes Thumshirn Subject: [PATCH 08/10] btrfs: store a pointer to a btrfs_bio in struct btrfs_bio_ctrl Date: Tue, 7 Mar 2023 17:39:43 +0100 Message-Id: <20230307163945.31770-9-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The bio in struct btrfs_bio_ctrl must be a btrfs_bio, so store a pointer to the btrfs_bio for better type checking. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Qu Wenruo Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent_io.c | 49 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 2670c479847094..aece6f020d1473 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -97,7 +97,7 @@ void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info) * how many bytes are there before stripe/ordered extent boundary. */ struct btrfs_bio_ctrl { - struct bio *bio; + struct btrfs_bio *bbio; int mirror_num; enum btrfs_compression_type compress_type; u32 len_to_oe_boundary; @@ -123,37 +123,37 @@ struct btrfs_bio_ctrl { static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) { - struct bio *bio = bio_ctrl->bio; + struct btrfs_bio *bbio = bio_ctrl->bbio; int mirror_num = bio_ctrl->mirror_num; - if (!bio) + if (!bbio) return; /* Caller should ensure the bio has at least some range added */ - ASSERT(bio->bi_iter.bi_size); + ASSERT(bbio->bio.bi_iter.bi_size); - if (!is_data_inode(&btrfs_bio(bio)->inode->vfs_inode)) { - if (btrfs_op(bio) != BTRFS_MAP_WRITE) { + if (!is_data_inode(&bbio->inode->vfs_inode)) { + if (btrfs_op(&bbio->bio) != BTRFS_MAP_WRITE) { /* * For metadata read, we should have the parent_check, * and copy it to bbio for metadata verification. */ ASSERT(bio_ctrl->parent_check); - memcpy(&btrfs_bio(bio)->parent_check, + memcpy(&bbio->parent_check, bio_ctrl->parent_check, sizeof(struct btrfs_tree_parent_check)); } - bio->bi_opf |= REQ_META; + bbio->bio.bi_opf |= REQ_META; } - if (btrfs_op(bio) == BTRFS_MAP_READ && + if (btrfs_op(&bbio->bio) == BTRFS_MAP_READ && bio_ctrl->compress_type != BTRFS_COMPRESS_NONE) - btrfs_submit_compressed_read(btrfs_bio(bio), mirror_num); + btrfs_submit_compressed_read(bbio, mirror_num); else - btrfs_submit_bio(btrfs_bio(bio), mirror_num); + btrfs_submit_bio(bbio, mirror_num); - /* The bio is owned by the end_io handler now */ - bio_ctrl->bio = NULL; + /* The bbio is owned by the end_io handler now */ + bio_ctrl->bbio = NULL; } /* @@ -161,16 +161,16 @@ static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) */ static void submit_write_bio(struct btrfs_bio_ctrl *bio_ctrl, int ret) { - struct bio *bio = bio_ctrl->bio; + struct btrfs_bio *bbio = bio_ctrl->bbio; - if (!bio) + if (!bbio) return; if (ret) { ASSERT(ret < 0); - btrfs_bio_end_io(btrfs_bio(bio), errno_to_blk_status(ret)); + btrfs_bio_end_io(bbio, errno_to_blk_status(ret)); /* The bio is owned by the end_io handler now */ - bio_ctrl->bio = NULL; + bio_ctrl->bbio = NULL; } else { submit_one_bio(bio_ctrl); } @@ -863,7 +863,7 @@ static bool btrfs_bio_is_contig(struct btrfs_bio_ctrl *bio_ctrl, struct page *page, u64 disk_bytenr, unsigned int pg_offset) { - struct bio *bio = bio_ctrl->bio; + struct bio *bio = &bio_ctrl->bbio->bio; struct bio_vec *bvec = bio_last_bvec_all(bio); const sector_t sector = disk_bytenr >> SECTOR_SHIFT; @@ -902,7 +902,7 @@ static void alloc_new_bio(struct btrfs_inode *inode, bio_ctrl->end_io_func, NULL); bio->bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; btrfs_bio(bio)->file_offset = file_offset; - bio_ctrl->bio = bio; + bio_ctrl->bbio = btrfs_bio(bio); bio_ctrl->len_to_oe_boundary = U32_MAX; /* @@ -942,8 +942,8 @@ static void alloc_new_bio(struct btrfs_inode *inode, * @pg_offset: offset of the new bio or to check whether we are adding * a contiguous page to the previous one * - * The will either add the page into the existing @bio_ctrl->bio, or allocate a - * new one in @bio_ctrl->bio. + * The will either add the page into the existing @bio_ctrl->bbio, or allocate a + * new one in @bio_ctrl->bbio. * The mirror number for this IO should already be initizlied in * @bio_ctrl->mirror_num. */ @@ -956,7 +956,7 @@ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl, ASSERT(pg_offset + size <= PAGE_SIZE); ASSERT(bio_ctrl->end_io_func); - if (bio_ctrl->bio && + if (bio_ctrl->bbio && !btrfs_bio_is_contig(bio_ctrl, page, disk_bytenr, pg_offset)) submit_one_bio(bio_ctrl); @@ -964,7 +964,7 @@ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl, u32 len = size; /* Allocate new bio if needed */ - if (!bio_ctrl->bio) { + if (!bio_ctrl->bbio) { alloc_new_bio(inode, bio_ctrl, disk_bytenr, page_offset(page) + pg_offset); } @@ -976,7 +976,8 @@ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl, len = bio_ctrl->len_to_oe_boundary; } - if (bio_add_page(bio_ctrl->bio, page, len, pg_offset) != len) { + if (bio_add_page(&bio_ctrl->bbio->bio, page, len, pg_offset) != + len) { /* bio full: move on to a new one */ submit_one_bio(bio_ctrl); continue; From patchwork Tue Mar 7 16:39:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164190 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 447F8C6FD1B for ; Tue, 7 Mar 2023 16:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230362AbjCGQoe (ORCPT ); Tue, 7 Mar 2023 11:44:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbjCGQoO (ORCPT ); Tue, 7 Mar 2023 11:44:14 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CE1C85A4E for ; Tue, 7 Mar 2023 08:41:17 -0800 (PST) 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=MaMu7jUBdYTEX8oI9d8nNbqSO4vI2V/PA3zPcxhhTJA=; b=u4OqL/AdlhteScvekkhm7XMKcY GAhIz0mWJlxFyAB0EAU0nzHVH/EI6tIzrUGEvMw/qutxCanfcjtylW2+qFypQvITBhM7KXxKIaAVH OyCiUcKbB4wAN0sGHauk5O0Y07FtP5axFvaDca2obTZVFCJtqRthNidx7qd7sY6jDn8i2aqHWmmS5 yNMso0hSXulo8PZK9mK6JRmV8JrCQqlsS10/1uaryIdfxBE+SvlQph2lSSGw0HJ9YIO0/tg4Y8V3B 6NqkemrdTlQh8BLB/QQntrp4uNznFpwNOuygxCeW4RepLMROFYQ9Y/NkXvsatSVOsVWGGlj7IdwkN jBR0zZWQ==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaNE-001bnT-T7; Tue, 07 Mar 2023 16:41:13 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn , Qu Wenruo Subject: [PATCH 09/10] btrfs: return a btrfs_bio from btrfs_bio_alloc Date: Tue, 7 Mar 2023 17:39:44 +0100 Message-Id: <20230307163945.31770-10-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Return the containing struct btrfs_bio instead of the less type safe struct bio from btrfs_bio_alloc. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/bio.c | 12 +++++++----- fs/btrfs/bio.h | 6 +++--- fs/btrfs/extent_io.c | 18 +++++++++--------- fs/btrfs/inode.c | 18 +++++++++--------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index c04e103f876853..527081abca026f 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -48,15 +48,17 @@ void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_inode *inode, * Just like the underlying bio_alloc_bioset it will not fail as it is backed by * a mempool. */ -struct bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf, - struct btrfs_inode *inode, - btrfs_bio_end_io_t end_io, void *private) +struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf, + struct btrfs_inode *inode, + btrfs_bio_end_io_t end_io, void *private) { + struct btrfs_bio *bbio; struct bio *bio; bio = bio_alloc_bioset(NULL, nr_vecs, opf, GFP_NOFS, &btrfs_bioset); - btrfs_bio_init(btrfs_bio(bio), inode, end_io, private); - return bio; + bbio = btrfs_bio(bio); + btrfs_bio_init(bbio, inode, end_io, private); + return bbio; } static struct bio *btrfs_split_bio(struct btrfs_fs_info *fs_info, diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h index b4e7d5ab7d236d..dbf125f6fa336d 100644 --- a/fs/btrfs/bio.h +++ b/fs/btrfs/bio.h @@ -75,9 +75,9 @@ void __cold btrfs_bioset_exit(void); void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_inode *inode, btrfs_bio_end_io_t end_io, void *private); -struct bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf, - struct btrfs_inode *inode, - btrfs_bio_end_io_t end_io, void *private); +struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf, + struct btrfs_inode *inode, + btrfs_bio_end_io_t end_io, void *private); static inline void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status) { diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index aece6f020d1473..3150bc45306520 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -896,13 +896,13 @@ static void alloc_new_bio(struct btrfs_inode *inode, u64 disk_bytenr, u64 file_offset) { struct btrfs_fs_info *fs_info = inode->root->fs_info; - struct bio *bio; + struct btrfs_bio *bbio; - bio = btrfs_bio_alloc(BIO_MAX_VECS, bio_ctrl->opf, inode, - bio_ctrl->end_io_func, NULL); - bio->bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; - btrfs_bio(bio)->file_offset = file_offset; - bio_ctrl->bbio = btrfs_bio(bio); + bbio = btrfs_bio_alloc(BIO_MAX_VECS, bio_ctrl->opf, inode, + bio_ctrl->end_io_func, NULL); + bbio->bio.bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; + bbio->file_offset = file_offset; + bio_ctrl->bbio = bbio; bio_ctrl->len_to_oe_boundary = U32_MAX; /* @@ -911,7 +911,7 @@ static void alloc_new_bio(struct btrfs_inode *inode, * them. */ if (bio_ctrl->compress_type == BTRFS_COMPRESS_NONE && - btrfs_use_zone_append(btrfs_bio(bio))) { + btrfs_use_zone_append(bbio)) { struct btrfs_ordered_extent *ordered; ordered = btrfs_lookup_ordered_extent(inode, file_offset); @@ -930,8 +930,8 @@ static void alloc_new_bio(struct btrfs_inode *inode, * to always be set on the last added/replaced device. * This is a bit odd but has been like that for a long time. */ - bio_set_dev(bio, fs_info->fs_devices->latest_dev->bdev); - wbc_init_bio(bio_ctrl->wbc, bio); + bio_set_dev(&bbio->bio, fs_info->fs_devices->latest_dev->bdev); + wbc_init_bio(bio_ctrl->wbc, &bbio->bio); } } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index cb3c387e57993b..8d86134598f56b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9959,24 +9959,24 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, .pending = ATOMIC_INIT(1), }; unsigned long i = 0; - struct bio *bio; + struct btrfs_bio *bbio; init_waitqueue_head(&priv.wait); - bio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, + bbio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, btrfs_encoded_read_endio, &priv); - bio->bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; + bbio->bio.bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; do { size_t bytes = min_t(u64, disk_io_size, PAGE_SIZE); - if (bio_add_page(bio, pages[i], bytes, 0) < bytes) { + if (bio_add_page(&bbio->bio, pages[i], bytes, 0) < bytes) { atomic_inc(&priv.pending); - btrfs_submit_bio(btrfs_bio(bio), 0); + btrfs_submit_bio(bbio, 0); - bio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, - btrfs_encoded_read_endio, &priv); - bio->bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; + bbio = btrfs_bio_alloc(BIO_MAX_VECS, REQ_OP_READ, inode, + btrfs_encoded_read_endio, &priv); + bbio->bio.bi_iter.bi_sector = disk_bytenr >> SECTOR_SHIFT; continue; } @@ -9986,7 +9986,7 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, } while (disk_io_size); atomic_inc(&priv.pending); - btrfs_submit_bio(btrfs_bio(bio), 0); + btrfs_submit_bio(bbio, 0); if (atomic_dec_return(&priv.pending)) io_wait_event(priv.wait, !atomic_read(&priv.pending)); From patchwork Tue Mar 7 16:39:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13164191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9308C6FD1A for ; Tue, 7 Mar 2023 16:44:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230381AbjCGQoq (ORCPT ); Tue, 7 Mar 2023 11:44:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229983AbjCGQoS (ORCPT ); Tue, 7 Mar 2023 11:44:18 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 565F78C95A for ; Tue, 7 Mar 2023 08:41:23 -0800 (PST) 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=2eA1LD2wI4zYh/i1ovDr12J4j6Kfdj94mWn8wsXMJJE=; b=ttVIyCjZQ51IgTEH4gbAsg1e7k 0HmPul/TwKqKP8IK4vzemgxqegO3ZJIwwRXTxPILp01whR0+dyRwSug+e1/2t3GpbAP5OL0iGdURN 2k6KZgfF2slEDJHjpBErIrqGDV+PdboXtI+lqjyZOL9yNAO2PpJ09C/2MIf3JhznHECsjrskDs3hF xqlFBgSEt7FCFmB3su7hilolo8Zty8qrqdderl6y+ZDKUSXtkWTsjBSFgYIBPr2LaZQ0zqxfbIvvA mcl3P9SVQLOBfWycTImp0UvRJFPy5qbvpR6/Wiao9Gtee6WrMgMom44n/9ekKYU14x5ChAqIITOuX 4qEuTTHQ==; Received: from [213.208.157.31] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZaNM-001brA-55; Tue, 07 Mar 2023 16:41:20 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Anand Jain , Johannes Thumshirn , Qu Wenruo Subject: [PATCH 10/10] btrfs: make btrfs_split_bio work on struct btrfs_bio Date: Tue, 7 Mar 2023 17:39:45 +0100 Message-Id: <20230307163945.31770-11-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230307163945.31770-1-hch@lst.de> References: <20230307163945.31770-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_split_bio expects a btrfs_bio as argument and always allocates one. Type both the orig_bio argument and the return value as struct btrfs_bio to improve type safety. Signed-off-by: Christoph Hellwig Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/bio.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 527081abca026f..cf09c6271edbee 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -61,30 +61,31 @@ struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf, return bbio; } -static struct bio *btrfs_split_bio(struct btrfs_fs_info *fs_info, - struct bio *orig, u64 map_length, - bool use_append) +static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info, + struct btrfs_bio *orig_bbio, + u64 map_length, bool use_append) { - struct btrfs_bio *orig_bbio = btrfs_bio(orig); + struct btrfs_bio *bbio; struct bio *bio; if (use_append) { unsigned int nr_segs; - bio = bio_split_rw(orig, &fs_info->limits, &nr_segs, + bio = bio_split_rw(&orig_bbio->bio, &fs_info->limits, &nr_segs, &btrfs_clone_bioset, map_length); } else { - bio = bio_split(orig, map_length >> SECTOR_SHIFT, GFP_NOFS, - &btrfs_clone_bioset); + bio = bio_split(&orig_bbio->bio, map_length >> SECTOR_SHIFT, + GFP_NOFS, &btrfs_clone_bioset); } - btrfs_bio_init(btrfs_bio(bio), orig_bbio->inode, NULL, orig_bbio); + bbio = btrfs_bio(bio); + btrfs_bio_init(bbio, orig_bbio->inode, NULL, orig_bbio); - btrfs_bio(bio)->file_offset = orig_bbio->file_offset; - if (!(orig->bi_opf & REQ_BTRFS_ONE_ORDERED)) + bbio->file_offset = orig_bbio->file_offset; + if (!(orig_bbio->bio.bi_opf & REQ_BTRFS_ONE_ORDERED)) orig_bbio->file_offset += map_length; atomic_inc(&orig_bbio->pending_ios); - return bio; + return bbio; } static void btrfs_orig_write_end_io(struct bio *bio); @@ -633,8 +634,8 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) map_length = min(map_length, fs_info->max_zone_append_size); if (map_length < length) { - bio = btrfs_split_bio(fs_info, bio, map_length, use_append); - bbio = btrfs_bio(bio); + bbio = btrfs_split_bio(fs_info, bbio, map_length, use_append); + bio = &bbio->bio; } /*