Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1730552iog; Thu, 16 Jun 2022 12:32:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uValtdrc8JLFjv6/fIJ/3vNK+D/Vrjxp47nLqaDZ3kYQA0fDYeVIqEe1JJTbtqAcHlKGuR X-Received: by 2002:a05:6402:17c8:b0:42d:dc6f:f17c with SMTP id s8-20020a05640217c800b0042ddc6ff17cmr8457593edy.17.1655407966262; Thu, 16 Jun 2022 12:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655407966; cv=none; d=google.com; s=arc-20160816; b=WBXivqpRgVTHwKZYGR7cuuzr2ofRJAqQP03QQvUTt+0tnEIHhycAcghAopLVO0ZR2M 3pSHR9viY+1zyT7csHvQgTTFfsD743XSBIkgPbM8RrjMWqfky5LCjU0FM6lFnH8vuP2S gkpTlDUiImnMXBQRh9ptKL1cNi8vJCySzxq/bH2I1wLZiH88YaNEf9tukNi4y7IvGCd7 5lhgNPhSoTXZKSsYskzflCJdYnijAVwVoGo2kIQWTSacLXphudhH5IrIEiV3ozl5mwgK BP4n6wxmxZOXATXntrHgNtxcnVF00jn8kLshL1Y2+b+nGCU2OqwHBv7Lxy0n4J13d4iE na8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=1xNPrl/pbNOCuIDTZgLgk3AL8c256RaW8iEguFOOEkA=; b=nUL2tdHOhFiHd97tXOMckybYrMUiA6gPoeqNiyoLZbvqrlmdjMxjTYIHHTQ44JMZmh 7eeW8kR5t1p3x29+aUZciJSxh9WD8QuZHhOUx0c9usFLbYt8P7hQ6S+ZCzCL+2EZPEZa bQYzGcP20iItuwioKXxu9JEtbarkL9kReUCEk30qXQoTSCQqIbWbAVXSUV0pGo25jMin N9JzG7J/Tp+f1XzCsHkNRmqlDrkZ+Op7wGLYN5e+WXw8oh+1dJvnd05PAK3NBQV7cvRy g/R6B4uF2yOpdcgzTEB+fox4SJZsCMAsJtCaN+kKuyL1XdOwrHle7wXjbd8TO4zUH8/n sCaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=rjky8FLU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga2-20020a1709070c0200b0070f257ba384si3038463ejc.661.2022.06.16.12.32.11; Thu, 16 Jun 2022 12:32:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=rjky8FLU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233013AbiFPTUE (ORCPT + 99 others); Thu, 16 Jun 2022 15:20:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238330AbiFPTTz (ORCPT ); Thu, 16 Jun 2022 15:19:55 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8E975622F; Thu, 16 Jun 2022 12:19:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=1xNPrl/pbNOCuIDTZgLgk3AL8c256RaW8iEguFOOEkA=; b=rjky8FLUGVXDrB+1odXOkPieDR uVKu/KJc7hov+xSoeDuE1fCld7Z7mF8QyYL18RUAWPcRQnPQQlgFumq2V2RdWNrvsLM8pCfFRxdyb 2sXOYZsP4CTD5Pf9pkJM2Xndw/ZUcwBEzZDeBlonNVMbJtaWlbh0ZhTOVZCCXT98eja/i6b1y+mco p5MY/eS2hAb9o7sNgkbMyfXcua1mHAAMLEHG6gFYcDL+uGWiiktapdDHmYwlaW2Sk80CHutI2AJZZ QAgnCAPA4poIgC5FEF7KDUX7IjBRYcG4wpVVB2xgy14KabxsOsAXOT/sxVMHA6KbU3ks2gffATQoZ LDs1NbOQ==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1o1v1y-0092ik-Qt; Thu, 16 Jun 2022 13:19:51 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1o1v1v-0006F9-1n; Thu, 16 Jun 2022 13:19:47 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, Song Liu Cc: Christoph Hellwig , Guoqing Jiang , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Christoph Hellwig Date: Thu, 16 Jun 2022 13:19:32 -0600 Message-Id: <20220616191945.23935-3-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616191945.23935-1-logang@deltatee.com> References: <20220616191945.23935-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, song@kernel.org, hch@infradead.org, guoqing.jiang@linux.dev, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, hch@lst.de X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 02/15] md/raid5: Factor out ahead_of_reshape() function X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are a few uses of an ugly ternary operator in raid5_make_request() to check if a sector is a head of a reshape sector. Factor this out into a simple helper called ahead_of_reshape(). No functional changes intended. Suggested-by: Christoph Hellwig Signed-off-by: Logan Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/md/raid5.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index b3d1f894f154..6e53b8490fff 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -5784,6 +5784,13 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi) bio_endio(bi); } +static bool ahead_of_reshape(struct mddev *mddev, sector_t sector, + sector_t reshape_sector) +{ + return mddev->reshape_backwards ? sector < reshape_sector : + sector >= reshape_sector; +} + static bool raid5_make_request(struct mddev *mddev, struct bio * bi) { struct r5conf *conf = mddev->private; @@ -5840,9 +5847,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) /* Bail out if conflicts with reshape and REQ_NOWAIT is set */ if ((bi->bi_opf & REQ_NOWAIT) && (conf->reshape_progress != MaxSector) && - (mddev->reshape_backwards - ? (logical_sector >= conf->reshape_progress && logical_sector < conf->reshape_safe) - : (logical_sector >= conf->reshape_safe && logical_sector < conf->reshape_progress))) { + !ahead_of_reshape(mddev, logical_sector, conf->reshape_progress) && + ahead_of_reshape(mddev, logical_sector, conf->reshape_safe)) { bio_wouldblock_error(bi); if (rw == WRITE) md_write_end(mddev); @@ -5871,14 +5877,12 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) * to check again. */ spin_lock_irq(&conf->device_lock); - if (mddev->reshape_backwards - ? logical_sector < conf->reshape_progress - : logical_sector >= conf->reshape_progress) { + if (ahead_of_reshape(mddev, logical_sector, + conf->reshape_progress)) { previous = 1; } else { - if (mddev->reshape_backwards - ? logical_sector < conf->reshape_safe - : logical_sector >= conf->reshape_safe) { + if (ahead_of_reshape(mddev, logical_sector, + conf->reshape_safe)) { spin_unlock_irq(&conf->device_lock); schedule(); do_prepare = true; @@ -5909,9 +5913,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) */ int must_retry = 0; spin_lock_irq(&conf->device_lock); - if (mddev->reshape_backwards - ? logical_sector >= conf->reshape_progress - : logical_sector < conf->reshape_progress) + if (!ahead_of_reshape(mddev, logical_sector, + conf->reshape_progress)) /* mismatch, need to try again */ must_retry = 1; spin_unlock_irq(&conf->device_lock); -- 2.30.2