From patchwork Tue Jun 27 06:13:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13294015 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 20EF7EB64DD for ; Tue, 27 Jun 2023 06:13:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbjF0GNg (ORCPT ); Tue, 27 Jun 2023 02:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbjF0GNe (ORCPT ); Tue, 27 Jun 2023 02:13:34 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32E601722 for ; Mon, 26 Jun 2023 23:13:32 -0700 (PDT) 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=UQjv/CAi2gT4MpDNCNIx3Qe8M1aGoVtdodGOt4ykH0E=; b=AwADniww5QiN8Q52V7U3R8Aqnp pvrvG746Ov7m6ObD7KYpsmdWsfOZSCHXWUsP/fsAmsgjrrye35MPUZo0S9i+NwVcvk/Pi1Qe8wotq Ys+YDtIqanttF4gvnafVR3ePrjPBx0nEThfr1Juoc+TQhJ7OnBA8+q86w5++hIwNY9l5K0GHBSFYE 9xnz21I2zrF1K/Z61HbeXeFusHoQwdSS0bwcX8eeU3M5kd958+x80TURZjlGLUW33gmlzhz31+6nb FXjQOJBdBNh5ol8O1qCFwGMLJbL1YNUa61mSb7Q/v7rKt/ICeNygnKGlc9PHKUVnjNg07KOn0gwvn GJNx+F1w==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qE1xC-00C5I3-31; Tue, 27 Jun 2023 06:13:31 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Dan Carpenter Subject: [PATCH 1/2] btrfs: be a bit more careful when setting mirror_num_ret in btrfs_map_block Date: Tue, 27 Jun 2023 08:13:23 +0200 Message-Id: <20230627061324.85216-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230627061324.85216-1-hch@lst.de> References: <20230627061324.85216-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 mirror_num_ret is allowed to be NULL, although it has to be set when smap is set. Unfortunately that is not a well enough specifiable invariant for static type checkers, so add a NULL check to make sure they are fine. Fixes: 03793cbbc80f ("btrfs: add fast path for single device io in __btrfs_map_block") Reported-by: Dan Carpenter Signed-off-by: Christoph Hellwig Reviewed-by: Qu Wenruo Reviewed-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a536d0e0e05566..0d386ed44279ce 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6406,7 +6406,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, (op == BTRFS_MAP_READ || !dev_replace_is_ongoing || !dev_replace->tgtdev)) { set_io_stripe(smap, map, stripe_index, stripe_offset, stripe_nr); - *mirror_num_ret = mirror_num; + if (mirror_num_ret) + *mirror_num_ret = mirror_num; *bioc_ret = NULL; ret = 0; goto out; From patchwork Tue Jun 27 06:13:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13294016 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 BF38DEB64DC for ; Tue, 27 Jun 2023 06:13:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229899AbjF0GNg (ORCPT ); Tue, 27 Jun 2023 02:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229861AbjF0GNf (ORCPT ); Tue, 27 Jun 2023 02:13:35 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BDF310DA for ; Mon, 26 Jun 2023 23:13:35 -0700 (PDT) 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=o2cFYyiL3HaMeykVXU+lwBsbQy/VmIS14nCqZ4QI3B0=; b=tzaxlJB/VVZKo6Jykb4RuIOn66 zQONephggy58+veooeGMPsU8bjpDFrC99rz+Atg7sUuFaNSXQSc1CmbT4MQcaqRvo68EWhTUqnWi8 g0NieNV3gFo3HgV8cJIApNgG9nx8bkcV30pNV6H9K7xLgERww3bTqYgfMNQnK5UN3vCdHZfmWZWgp e4FtsBGsnB4Z11Pkpq4H+RcxjV62MHIj81/1CVBhxncli989ETHsm2xkhnQ3/GxscBhd7MuQkxLbe 3fTZm7geDs/bjzQI61A95oH6joRBQzknRpNKSto9bD09OPszOwnXJAmZS6QxTQmJl3iETXv3ZaJJb xFO73J3w==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qE1xF-00C5Ig-1M; Tue, 27 Jun 2023 06:13:33 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs: simplify the no-bioc fast path condition in btrfs_map_block Date: Tue, 27 Jun 2023 08:13:24 +0200 Message-Id: <20230627061324.85216-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230627061324.85216-1-hch@lst.de> References: <20230627061324.85216-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 nr_alloc_stripes can't be one if we are writing to a replacement device, as it is incremented for that case right above. Remove the duplicate checks. Signed-off-by: Christoph Hellwig Reviewed-by: Qu Wenruo Reviewed-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 0d386ed44279ce..4907ed9809109d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6402,9 +6402,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * I/O context structure. */ if (smap && num_alloc_stripes == 1 && - !((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1) && - (op == BTRFS_MAP_READ || !dev_replace_is_ongoing || - !dev_replace->tgtdev)) { + !((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1)) { set_io_stripe(smap, map, stripe_index, stripe_offset, stripe_nr); if (mirror_num_ret) *mirror_num_ret = mirror_num;