From patchwork Thu May 4 12:48:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp292992vqo; Thu, 4 May 2023 05:58:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ygOMSlN0KzL39N90aDGmTDMRuXS2pVOqp9npoppI0QeYbKA92LF7MYF/yM+oAz8rAM+f1 X-Received: by 2002:a17:903:120e:b0:1aa:e30e:29d3 with SMTP id l14-20020a170903120e00b001aae30e29d3mr4517370plh.29.1683205121021; Thu, 04 May 2023 05:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683205121; cv=none; d=google.com; s=arc-20160816; b=Mo6/ivbj0mUlEbc8K5z5DQFhGmty+D3CI5TfMaHIe9DUnv3Zr4Zs6lk+kCCgaIQKPs 06Tgh1sulEb9w2UGQvDhQFzkcovaQeCbf9f1qaFVS3j+PQJkja/X3mZHkSckJ2bjXSVZ +MSgDPy8t4VldUx//ND5y7uM3te9dg3cskoaoAfylUEHpl6ODzL95a4m/XJOyi3VoKxE wK9CieU5ddVYxPfWuUrn63hii7UlZAz1QgKkI7NAzKjuCzVzUKELgEfSBizZ9q/eoTsZ j1789J1GV0Bv0R8kK9R1bcgdCn10btE31VFV4jxYEwroaX4l3kU2WzkC5lNYkfRxH4xX 39AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=iYxTWbpPw62so3bxUnECFUwWylMPnmKJi8J94n9qRFc=; b=D7ShAMWgc95CaMr4osjxpsfGYFVRLv8d6ahyDFIdeJmMw2c0WBpbBY8xSOlD9YHxpx JPdfzzU93niaWTmrhfpx/jfRxjSWr4UuLaImd63ay0JT0Z98OGwXRf/y3RA4K8iyrE11 0exOFp12g20ap/m6FC/vvELwDtsWqbBpFiroW5sNdGPTAHHRWKqCOunuMlPLML4Md1ND 6woM0oyg4pSbvUM6F7y0/s/psZ+hi4+xI3xfJ59pZphF9nve70awcXybsY6hVVWqCn2H K5K98Vr7WqxnsYIM+w6GxlNYBdVHQFIXWydzapwlO6fgFg5r6J4faVqxeykeStrK7ZrD uCDw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a1709027b8e00b001ab012a1ba9si7691013pll.402.2023.05.04.05.58.25; Thu, 04 May 2023 05:58:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230400AbjEDMty (ORCPT + 99 others); Thu, 4 May 2023 08:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230395AbjEDMtt (ORCPT ); Thu, 4 May 2023 08:49:49 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D2336A60; Thu, 4 May 2023 05:49:39 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QBttk5vflz4f3jq5; Thu, 4 May 2023 20:49:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S5; Thu, 04 May 2023 20:49:36 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 01/11] block/badblocks: change some members of badblocks to bool Date: Thu, 4 May 2023 20:48:18 +0800 Message-Id: <20230504124828.679770-2-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S5 X-Coremail-Antispam: 1UD129KBjvJXoWxAw45KFW3uryUXw4DGF45KFg_yoW5XF1UpF nxGwnayr4jgr1vqF1DZ3W7Aw109w4xJF48J3y7Jw15K34Utwn7ta4kXryrtFWjqr4a9FsI vF1FgrWjvry8C3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm0b4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVj vjDU0xZFpf9x07jbjjgUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968492651325448?= X-GMAIL-MSGID: =?utf-8?q?1764968492651325448?= From: Li Nan "changed" and "unacked_exist" are used as boolean type. Change the type of them to bool. And reorder fields to reduce memory hole. No functional changed intended. Signed-off-by: Li Nan --- block/badblocks.c | 14 +++++++------- include/linux/badblocks.h | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index 3afb550c0f7b..1b4caa42c5f1 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -141,7 +141,7 @@ static void badblocks_update_acked(struct badblocks *bb) } if (!unacked) - bb->unacked_exist = 0; + bb->unacked_exist = false; } /** @@ -302,9 +302,9 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, } } - bb->changed = 1; + bb->changed = true; if (!acknowledged) - bb->unacked_exist = 1; + bb->unacked_exist = true; else badblocks_update_acked(bb); write_sequnlock_irqrestore(&bb->lock, flags); @@ -414,7 +414,7 @@ int badblocks_clear(struct badblocks *bb, sector_t s, int sectors) } badblocks_update_acked(bb); - bb->changed = 1; + bb->changed = true; out: write_sequnlock_irq(&bb->lock); return rv; @@ -435,7 +435,7 @@ void ack_all_badblocks(struct badblocks *bb) return; write_seqlock_irq(&bb->lock); - if (bb->changed == 0 && bb->unacked_exist) { + if (bb->changed == false && bb->unacked_exist) { u64 *p = bb->page; int i; @@ -447,7 +447,7 @@ void ack_all_badblocks(struct badblocks *bb) p[i] = BB_MAKE(start, len, 1); } } - bb->unacked_exist = 0; + bb->unacked_exist = false; } write_sequnlock_irq(&bb->lock); } @@ -493,7 +493,7 @@ ssize_t badblocks_show(struct badblocks *bb, char *page, int unack) length << bb->shift); } if (unack && len == 0) - bb->unacked_exist = 0; + bb->unacked_exist = false; if (read_seqretry(&bb->lock, seq)) goto retry; diff --git a/include/linux/badblocks.h b/include/linux/badblocks.h index 2426276b9bd3..c2723f97d22d 100644 --- a/include/linux/badblocks.h +++ b/include/linux/badblocks.h @@ -27,15 +27,15 @@ struct badblocks { struct device *dev; /* set by devm_init_badblocks */ int count; /* count of bad blocks */ - int unacked_exist; /* there probably are unacknowledged - * bad blocks. This is only cleared - * when a read discovers none - */ int shift; /* shift from sectors to block size * a -ve shift means badblocks are * disabled.*/ + bool unacked_exist; /* there probably are unacknowledged + * bad blocks. This is only cleared + * when a read discovers none + */ + bool changed; u64 *page; /* badblock list */ - int changed; seqlock_t lock; sector_t sector; sector_t size; /* in sectors */ From patchwork Thu May 4 12:48:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp306905vqo; Thu, 4 May 2023 06:14:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48DTMefYEqyLJ7eqtqhJSsfbkQ289QZnBGORLNAXFqgvN7gNmUTDfNH2en5K6oIQTrtMgE X-Received: by 2002:a17:902:6b86:b0:1a2:9183:a49c with SMTP id p6-20020a1709026b8600b001a29183a49cmr3324405plk.32.1683206055997; Thu, 04 May 2023 06:14:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683206055; cv=none; d=google.com; s=arc-20160816; b=YXeV4iNVrClajfCRmjqvSUfzw7uDts96fKFtkkw4CXaL5t7mPBWincIvzmOqhruGgD mdxEP3WU77tmejJxbHb4TUEVRZiK7UsXoj+vgLnyAxk90By0OQx96wXreJ/v8rlpzDNN QKWPlmltIcoWttyV4xQA7+9eRShl8H6oYIFehPbG4xx940kgYHeMthPEc6C+cxR7lNJa p/on58KpkAHpNz0ztWq2sgCXfp8n+URUwlFOBJQeeXm+1Y2K3TZO92RN6Uq06vM6i1tV od5/XJbgR70yoGr8hSu77Tr90D8EJ6pD0XcQ9v/j/F3XzNqF3UNjiCVuYKTtLnY8PTZH sXHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HGYvcyNRoahxBhWKNL6z7vmDL7TIVZKrJcAXdJw5qGE=; b=PELEVNBEhxMPeF/YGePpdjfqnmijuZQhIX2pIARqjHmyxyTzWTgnbRopLi+S9y6Paj 6FfEotR2slKv656Vu/E0qAK2E2XgW0tKYgAMs6NLQVKoKwYvrafjInQZ4sQUbayIVuq7 B/0886HckxhBjJbXbdVLJ/BxI+Vg1HWXvjUh3aaqoprJYCsy2aiFca1pCuw7Ti9+1Wxr zVwlSTl/mwVzwQuYKrDtEguGFuMN6/4LzE6u6v+nUlt8W0kIgRROX3+Kb8bOBcf02f9T 48AoqHMXSY1fheiYC1UebdmeQ8umCOZveSTx+mVz5VP3YU/G1GTYGTjUZJ9xsUYawls2 ytqg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o2-20020a1709026b0200b0019a9f8bdba0si33344275plk.62.2023.05.04.06.13.35; Thu, 04 May 2023 06:14:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230459AbjEDMt5 (ORCPT + 99 others); Thu, 4 May 2023 08:49:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbjEDMtu (ORCPT ); Thu, 4 May 2023 08:49:50 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6919865B5; Thu, 4 May 2023 05:49:40 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QBttk5jZsz4f3v6Y; Thu, 4 May 2023 20:49:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S6; Thu, 04 May 2023 20:49:36 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 02/11] block/badblocks: only set bb->changed when badblocks changes Date: Thu, 4 May 2023 20:48:19 +0800 Message-Id: <20230504124828.679770-3-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S6 X-Coremail-Antispam: 1UD129KBjvJXoW7AFykGw4rJr4xJw4Dtry8Grg_yoW8CrW8pr 9xC3Wftryjg3WIgF1UZ3W7Kw1FgayfXF48Gw4ay345GryxG3s3tF1vq34Yqa4j9r1a9rnI qa4Fgryjva4DC37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVj vjDU0xZFpf9x07jYHqcUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764969473612254469?= X-GMAIL-MSGID: =?utf-8?q?1764969473612254469?= From: Li Nan bb->changed and unacked_exist is set and badblocks_update_acked() is involked even if no badblocks changes in badblocks_set(). Only update them when badblocks changes. Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") Signed-off-by: Li Nan --- block/badblocks.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index 1b4caa42c5f1..7e6ebe2ac12c 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -166,6 +166,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, int lo, hi; int rv = 0; unsigned long flags; + bool changed = false; if (bb->shift < 0) /* badblocks are disabled */ @@ -229,6 +230,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, s = a + BB_MAX_LEN; } sectors = e - s; + changed = true; } } if (sectors && hi < bb->count) { @@ -259,6 +261,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, sectors = e - s; lo = hi; hi++; + changed = true; } } if (sectors == 0 && hi < bb->count) { @@ -277,6 +280,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, memmove(p + hi, p + hi + 1, (bb->count - hi - 1) * 8); bb->count--; + changed = true; } } while (sectors) { @@ -299,14 +303,17 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, p[hi] = BB_MAKE(s, this_sectors, acknowledged); sectors -= this_sectors; s += this_sectors; + changed = true; } } - bb->changed = true; - if (!acknowledged) - bb->unacked_exist = true; - else - badblocks_update_acked(bb); + if (changed) { + bb->changed = changed; + if (!acknowledged) + bb->unacked_exist = true; + else + badblocks_update_acked(bb); + } write_sequnlock_irqrestore(&bb->lock, flags); return rv; From patchwork Thu May 4 12:48:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp299615vqo; Thu, 4 May 2023 06:05:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7C+UVHXY0QIzMoVKAbR00zUWQBZbP5ejMM7owU/s4pYNH7gKmjnjga40HkMAU5JpFMjzIS X-Received: by 2002:a17:902:ce82:b0:1aa:efad:f2d4 with SMTP id f2-20020a170902ce8200b001aaefadf2d4mr4450606plg.63.1683205546964; Thu, 04 May 2023 06:05:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683205546; cv=none; d=google.com; s=arc-20160816; b=eHGifAaYsmLiq/JZcHsChiTDZNHsPDiWfXIP31X4rC5y1OLYx9ZME/ILyHPEgOik2J eTaW4qm+rjW4h4mTz8VTCpx/DgXNyjuBVU2+BkIwNK40CBsLb7uT58A57xvYhwIeGhhI /i12XlVSlR6ws3cTLi5YQSqioEe10PTNBV8S83SifAkp3UWCThyHRkub+B9qhn7Pfabo QW1GTWGSgXYq6vC753j3eot1Tgr94oe2BXZmion/5WoGb5mSDutSMHrHuIKFh6kPhxjH OIREUam9DUIv2siy7Hbs40raNpyK1iDmh7hZUvM50cs2a+72rlE4PI6184ESitIyOwwu CC6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hbzXYLeWWyTWLSwhEoH7K+HTpakuKKF4/Z2M9C5K6D4=; b=nDD2CK+cZhUlSvP9x3drGYfCZI9f587VOJCbTgmH5rTMANhpnua6MQlTqfLRAKwCvQ cbzOkB0kxXpZkk+U4C6q6+PZngvkegBzbDvk8rsYBwtK/RIc9HhWVH6qVt++13gBxArg Yrflmw9gCIc5M6bPu8Xy13YTnC9yO+zUg3Z83CsKHsfa5XCqZgJ2a5b6xm+S+uQTXd1/ GVRRRcL2oSXiRrebrM4hi+I96sGJhvLam62/a+Puz54Ydv3WfMPWuLKD90nmKULq1mFC VB3lRK+6llOdQv15E4isgCP9aUBZpD9ZpekjC0FGDHn9pDcEZDj9TKolGziQkDtGzBue /9Zg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a1709027b8e00b001ab012a1ba9si7691013pll.402.2023.05.04.06.05.26; Thu, 04 May 2023 06:05: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230469AbjEDMuA (ORCPT + 99 others); Thu, 4 May 2023 08:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230403AbjEDMtu (ORCPT ); Thu, 4 May 2023 08:49:50 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAE8C6A64; Thu, 4 May 2023 05:49:39 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QBttl1gWTz4f3v6S; Thu, 4 May 2023 20:49:35 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S7; Thu, 04 May 2023 20:49:36 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 03/11] block/badblocks: fix badblocks loss when badblocks combine Date: Thu, 4 May 2023 20:48:20 +0800 Message-Id: <20230504124828.679770-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S7 X-Coremail-Antispam: 1UD129KBjvJXoWxJrW8urW3AryDWw17Kry3urg_yoW8XrW5pw 1fZwnIgr1IgFyv9F4UX3WDGF1Sg3Z7JF45Ga1Yqa48uFyDAw1xKF4vq3WYvrW0gF4xXF90 va1rWryDZFyfG37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVj vjDU0xZFpf9x07UKXd8UUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968939329077179?= X-GMAIL-MSGID: =?utf-8?q?1764968939329077179?= From: Li Nan badblocks will loss if we set it as below: # echo 1 1 > bad_blocks # echo 3 1 > bad_blocks # echo 1 5 > bad_blocks # cat bad_blocks 1 3 In badblocks_set(), if there is an intersection between p[lo] and p[hi], we will combine them. The end of new badblocks is p[hi]'s end now. but p[lo] may cross p[hi] and new end should be the larger of p[lo] and p[hi]. Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") Signed-off-by: Li Nan --- block/badblocks.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index 7e6ebe2ac12c..2c2ef8284a3f 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -267,16 +267,14 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, if (sectors == 0 && hi < bb->count) { /* we might be able to combine lo and hi */ /* Note: 's' is at the end of 'lo' */ - sector_t a = BB_OFFSET(p[hi]); - int lolen = BB_LEN(p[lo]); - int hilen = BB_LEN(p[hi]); - int newlen = lolen + hilen - (s - a); + sector_t a = BB_OFFSET(p[lo]); + int newlen = max(s, BB_OFFSET(p[hi]) + BB_LEN(p[hi])) - a; - if (s >= a && newlen < BB_MAX_LEN) { + if (s >= BB_OFFSET(p[hi]) && newlen < BB_MAX_LEN) { /* yes, we can combine them */ int ack = BB_ACK(p[lo]) && BB_ACK(p[hi]); - p[lo] = BB_MAKE(BB_OFFSET(p[lo]), newlen, ack); + p[lo] = BB_MAKE(a, newlen, ack); memmove(p + hi, p + hi + 1, (bb->count - hi - 1) * 8); bb->count--; From patchwork Thu May 4 12:48:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp288713vqo; Thu, 4 May 2023 05:51:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/4+r/P7AHRc/LTB6dxEOpynIV8PXLhtwz8tUUITFbgIIlQBfxGWPAbVljO+s7cd6e5SQJ X-Received: by 2002:a17:90a:4293:b0:24e:1b9:8292 with SMTP id p19-20020a17090a429300b0024e01b98292mr1749089pjg.48.1683204663788; Thu, 04 May 2023 05:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683204663; cv=none; d=google.com; s=arc-20160816; b=snLUz+cJYUsW8Yiom3Akl0aJIY2NX47InlJthgJaHxfstexwftQ42QrKT04lgO14wJ b2uSjKBShCQ/oEBqsbECs8zrZkh3Fay63Hrx6v3+9kuQs5XBmOoOAcIWoBO4rDcrQiaL 0CAH5qb5uZa0WDPrMG+Eki1qYHdVviseqboEeR44rm+Oj+AanepWU/jbVE1R+Lkb8ybM H4vdigyEf05ycvFdA8syFkfIGh01u4bXG4KtWTAdJTgues+mfQ6/jjZ18vSoFpynI/hq +LqsHMC7VQ8byLGqVHOR42FaOKirKzcHOH9elFDUFh0aR97O35m4GYd/lD6qjjq5TpkY ZlgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=caYRUAsYiE6ha0l7RzCBFbBf5+9O53xp/i0kO4UwOW8=; b=Nh4M72FZ6f2Uf1+9vZ6zQjHT/RYrn7Tvf/ZvkpOGdBX2lrmKc4tyMV1VKn9ERsUc1p FHut6sE0mbG9NwB2z1WtSxfpoNBg1AssFHRZY0lWWtqvbCYPWWSa4SAq97dm5uZaLtHW ycZSxXmwmn1dgt+OM9/PsEKF7EzL25xskIFSMU1PfI/a6cTjySQevoerCk/AQpRVgSPH VUgxprtkUTOBAWGmbWalV5AflIz2+1xldaExhxbdyFcGicvQYRDZnsQh1L+KlfTcx6N6 sH9HldvSI6AfcjfE5AJxd0aMgHvM5EKDlNZUHxCUJFaWQyMMkDzMm6Fyti45hqTtV/9q 6qvA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a17090a08c600b00246c31928f2si1637829pjn.171.2023.05.04.05.50.51; Thu, 04 May 2023 05:51:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbjEDMuD (ORCPT + 99 others); Thu, 4 May 2023 08:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230418AbjEDMtu (ORCPT ); Thu, 4 May 2023 08:49:50 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE91C6A78; Thu, 4 May 2023 05:49:40 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QBttm1rNzz4f3pFw; Thu, 4 May 2023 20:49:36 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S8; Thu, 04 May 2023 20:49:37 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 04/11] block/badblocks: fix badblocks overlap Date: Thu, 4 May 2023 20:48:21 +0800 Message-Id: <20230504124828.679770-5-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S8 X-Coremail-Antispam: 1UD129KBjvJXoW7ZF17Xw4fuFy8tFWrJrW7XFb_yoW8KF4rpw 1Sy3Wagry8WFyI9F45X3WDWr1fKas7Jr4UGa13A34UWFykCrnakF1ktw1j9rW8KFZ7XFs0 v3yrWFyj9F98GwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVF xhVjvjDU0xZFpf9x07UMa0PUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968013284430742?= X-GMAIL-MSGID: =?utf-8?q?1764968013284430742?= From: Li Nan badblocks will overlap if we set it as below: # echo 0 1 > bad_blocks # echo 3 1 > bad_blocks # echo 5 1 > bad_blocks # echo 0 512 > bad_blocks # cat bad_blocks 0 512 5 1 The reason for this is we only combine two badblocks once even if it should be combined many times. Fix it by classifying combine: 1)lo contain hi just remove hi, and check next hi. 2)lo intersects with hi newlen > BB_MAX_LEN, set lo to MAX, and the remaining is hi. newlen <= BB_MAX_LEN, remain unchanged, 2-in-1. Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") Signed-off-by: Li Nan --- block/badblocks.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index 2c2ef8284a3f..f34351b59414 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -245,6 +245,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, /* merging is possible */ if (e <= s + sectors) { /* full overlap */ + e = s + sectors; ack = acknowledged; } else @@ -267,17 +268,35 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, if (sectors == 0 && hi < bb->count) { /* we might be able to combine lo and hi */ /* Note: 's' is at the end of 'lo' */ - sector_t a = BB_OFFSET(p[lo]); - int newlen = max(s, BB_OFFSET(p[hi]) + BB_LEN(p[hi])) - a; - - if (s >= BB_OFFSET(p[hi]) && newlen < BB_MAX_LEN) { - /* yes, we can combine them */ - int ack = BB_ACK(p[lo]) && BB_ACK(p[hi]); - - p[lo] = BB_MAKE(a, newlen, ack); - memmove(p + hi, p + hi + 1, - (bb->count - hi - 1) * 8); - bb->count--; + sector_t loa = BB_OFFSET(p[lo]), hia = BB_OFFSET(p[hi]); + sector_t hie = hia + BB_LEN(p[hi]); + int newlen = max(s, hie) - loa; + int ack = BB_ACK(p[lo]) && BB_ACK(p[hi]); + + if (s >= hia) { + while (s >= hie) { + /* lo contains hi, just remove hi */ + memmove(p + hi, p + hi + 1, + (bb->count - hi - 1) * 8); + bb->count--; + if (hi >= bb->count) + break; + hia = BB_OFFSET(p[hi]); + hie = hia + BB_LEN(p[hi]); + } + if (s >= hia && hi < bb->count) { + if (newlen > BB_MAX_LEN) { + p[lo] = BB_MAKE(loa, BB_MAX_LEN, ack); + p[hi] = BB_MAKE(loa + BB_MAX_LEN, + newlen - BB_MAX_LEN, + BB_ACK(p[hi])); + } else { + p[lo] = BB_MAKE(loa, newlen, ack); + memmove(p + hi, p + hi + 1, + (bb->count - hi - 1) * 8); + bb->count--; + } + } changed = true; } } From patchwork Thu May 4 12:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp288958vqo; Thu, 4 May 2023 05:51:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5vKQoe6eDRRLNAqTU0def6DppLrRpykGNfl+MeO7JqGfcZQL6kSPyicwL6D7BA8Cg8u0Z7 X-Received: by 2002:a17:90b:3b87:b0:24e:c45:9ae5 with SMTP id pc7-20020a17090b3b8700b0024e0c459ae5mr2251050pjb.8.1683204686433; Thu, 04 May 2023 05:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683204686; cv=none; d=google.com; s=arc-20160816; b=x17N8X98BUaTiehzO/q0g7JgBbQkrOpp+8CaYDpkhIH9YJssXWc85BLs919FPtrxxR /5XZUW7na1/uWhBblwykK30hjbbkWygjaXAz5L1hpFwevULYbKGHYeb5WTlV7ewKQXSn nq76OT+UTWIRSgk3OheYWlpyrO3iks4jgIL7DOTDNquIfiNLT9RxE1Ys162o2DwZaopt LKaLKmEZkiFW4rLzaOBAjAdHMq6B/7h61I0p6mV6p+t0OuvLmqxnoDvhxDb9u/agEEb/ y0pGBXlqDb5of5gwVsdU9+OUFu4/Lw7oyUxAnuAZCeGooSxa1O2zOkAO+aq4HO4cIrtY ntew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Dbr5p3uqmeWLjzMNfnSUXDEmxtDjKXJ9BzYG3E2pfYQ=; b=RzlB5+OBScInFQMrIubP3Vmmm5HPtlkpB74Lburt796VGdQNr3PQkOorzWSWCEcNdt iztzAd207ZtbvHLyUxhQuHCaATDmPSZqDEiqG4rBJDOtdMwgldFlnQVpZuzYTRqnPP/7 8Zen7AbO80ZibwWt27pbdt48k8eLAnotm2fO05a+2h8MN4bXr6aRU33m2TGEzhBYAPAu FGOaWLKU2BPTOFYqWc/YLrSnDTXlNrkmVGGT6s50H2VhX1kR8h3yriOuR3y8xChSuceR MwlXH2SbsXhqBagUfQcUBoXp/SuY2I5WbIbOLShgUYzNLwZKvUy6sRO+Jteb4b1Wy1Ez SNcw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hk3-20020a17090b224300b0024b9ac5462csi17162310pjb.94.2023.05.04.05.51.14; Thu, 04 May 2023 05:51:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbjEDMuK (ORCPT + 99 others); Thu, 4 May 2023 08:50:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230427AbjEDMtv (ORCPT ); Thu, 4 May 2023 08:49:51 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1ACD59E8; Thu, 4 May 2023 05:49:41 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QBttm42vcz4f3k5n; Thu, 4 May 2023 20:49:36 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S9; Thu, 04 May 2023 20:49:37 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 05/11] block/badblocks: fix the bug of reverse order Date: Thu, 4 May 2023 20:48:22 +0800 Message-Id: <20230504124828.679770-6-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S9 X-Coremail-Antispam: 1UD129KBjvdXoWrKFyruF1kuw1xKr4DWr1UGFg_yoWfAFX_Ja 40yay8Xrn5Jr1ayw1SyF1vyF4FvFW5Cr18Kry7Jr1kZa1Uta18Aws8Kr98Xrn8CFyDG39I yryfXr9Ivr4IqjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbvxYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x0262 8vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAI cVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVF xhVjvjDU0xZFpf9x07UMa0PUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968037284243037?= X-GMAIL-MSGID: =?utf-8?q?1764968037284243037?= From: Li Nan Order of badblocks will be reversed if we set a large area at once. 'hi' remains unchanged while adding continuous badblocks is wrong, the next setting is greater than 'hi', it should be added to the next position. Let 'hi' +1 each cycle. # echo 0 2048 > bad_blocks # cat bad_blocks 1536 512 1024 512 512 512 0 512 Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") Signed-off-by: Li Nan --- block/badblocks.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/badblocks.c b/block/badblocks.c index f34351b59414..11e3a3ae2c72 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -320,6 +320,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, p[hi] = BB_MAKE(s, this_sectors, acknowledged); sectors -= this_sectors; s += this_sectors; + hi++; changed = true; } } From patchwork Thu May 4 12:48:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp293361vqo; Thu, 4 May 2023 05:59:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7cw6GqXa7cKzLJ9JfrgKDXFtnVUOGux6Du6u/yWkoHdQkLGYo1n41bVdaZFnBslGnXuZF5 X-Received: by 2002:a05:6a20:940a:b0:f0:929c:e8c5 with SMTP id hl10-20020a056a20940a00b000f0929ce8c5mr1777529pzb.35.1683205163544; Thu, 04 May 2023 05:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683205163; cv=none; d=google.com; s=arc-20160816; b=hqOrqzjcASUPvlTS5gki9BR26Yao+iuyVwN6ZTT2CVHbk5j8UWwfvUujqK5k8GgPNQ 110dp2uVpERTCfYyzQi3rwGsLB2dLyu1rMfGdfQ3WpRmFiOsfDKp4CleE4PJiH99FDGY YIYlzJkWC0KN/ogufJFw8xTyn/UJvjqefNP0Kam39l163g6zc+u8toe5FjzUbE+gQhfE 5fW2i1rM/+KeI7HkYGGihxJFeh3sYQCPByNEBziJ+QPejJtlv0lQdDcGcKzOE9HvxjvU IF8YPdhvQau+GMWaeo4jaOHJSQCisD9Xk3TB3eoq5HGI3RA+b4xiSKFu8+Fqy2hDSsz3 Muqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=liICAxlMwkOQCaI+MkxEFMRFBWeqgO1xww8OLQkyKSk=; b=iLKPjO3IbCf0GPQCLjQ36vYB6mvxdkVAwodlz98swrxNHUktSEcA8oIVPJT4xOMWoj khCsXekLg5FI8JdZdYGt00sWQ26Otfe5dZ6rObEm73em3WAExyjiI/qZIPjjarnwXYms VxXTuNO84euxkLoecGTTjwJNF9Oy8i+A5yZN3+9w5m1upN7xFonCmEun7cPP1qh37F/l i+GHsXhpBdcVLLLmPxylzf/QEoTcJle1gEMTqHqunvx1SjBbESRJ2TJNsMzS90qKGOv8 zjAp6WgNFDoi/ayqto04UNnQAcA/SpYfxbhxkL57YATamJQpBHqkFApqKVScZNT8VRxG puiw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j69-20020a638048000000b00528cf858c87si12858272pgd.156.2023.05.04.05.59.08; Thu, 04 May 2023 05:59:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230424AbjEDMu0 (ORCPT + 99 others); Thu, 4 May 2023 08:50:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbjEDMtv (ORCPT ); Thu, 4 May 2023 08:49:51 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 929A26A7E; Thu, 4 May 2023 05:49:43 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QBttn0tW5z4f3v51; Thu, 4 May 2023 20:49:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S10; Thu, 04 May 2023 20:49:38 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 06/11] block/badblocks: fix ack set fail in badblocks_set Date: Thu, 4 May 2023 20:48:23 +0800 Message-Id: <20230504124828.679770-7-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S10 X-Coremail-Antispam: 1UD129KBjvdXoWrZF4xtrWrWrW8tF17JFWUArb_yoWkXrg_J3 WFyFZ5Xrn5CFs8Cr1Yy3W0qrsY9F45Cr4kCw12qrn7XrsrtF1DJws8tr93Wrn5CFZrC390 v34rXr9Iva4IqjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbvxYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x0262 8vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAI cVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVF xhVjvjDU0xZFpf9x07UMa0PUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968537907659712?= X-GMAIL-MSGID: =?utf-8?q?1764968537907659712?= From: Li Nan If we try to set ack for a BB_MAX_LEN badblocks, it will return 0(success) but did not set ack at all in badblocks_set(). Check ack before setting to fix it, and do not set badblocks already exist. Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") Signed-off-by: Li Nan --- block/badblocks.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index 11e3a3ae2c72..c11eb869f2f3 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -219,18 +219,18 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, if (e < s + sectors) e = s + sectors; if (e - a <= BB_MAX_LEN) { - p[lo] = BB_MAKE(a, e-a, ack); s = e; } else { /* does not all fit in one range, * make p[lo] maximal */ - if (BB_LEN(p[lo]) != BB_MAX_LEN) - p[lo] = BB_MAKE(a, BB_MAX_LEN, ack); s = a + BB_MAX_LEN; } + if (s - a != BB_LEN(p[lo]) || ack != BB_ACK(p[lo])) { + p[lo] = BB_MAKE(a, s - a, ack); + changed = true; + } sectors = e - s; - changed = true; } } if (sectors && hi < bb->count) { From patchwork Thu May 4 12:48:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90070 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp288787vqo; Thu, 4 May 2023 05:51:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6cSho2TeRT+9DE//Kqie1fzqVUeMud3avTlb8wxIxC20AwZLmMsvMazUkQHLshwomGIStX X-Received: by 2002:a17:902:6941:b0:1a1:b440:3773 with SMTP id k1-20020a170902694100b001a1b4403773mr3777255plt.27.1683204671809; Thu, 04 May 2023 05:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683204671; cv=none; d=google.com; s=arc-20160816; b=hmW9KNzQot68FpRF/OiL4Pb3fkHqbSjqPZIpVyoFaq6MOLVGm+Jvi5wk+zC8AhY7zl 3IpNh3VXXCFdL6HDQ3kwY4gD1F3QrfqO/EzazS7O6wjCDX4HiGP1qY2iUv5f+rKFBkc2 frdV/t6iYUqz8xZTyz2sgNM5SMXfqnxkWtYji8mgeUIHN75m6nxySMqwB6Xge8chAyQT KHXj0MLz/rEP6KZtmo8upaJMBuYWcGwh3FLdzEtk6s73a3ZmovovAblMg/IRvOPYKefr Dca0gAw5R2XLVqo2FNvBpLHePRdCSep18oPKoKU2yK3/VuBrsu1qlB6Id2pFGUD4omNW c8uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ACYXxHPa+vP9rDN/AYsc2aYPkM6cE6DnlGAgn/0Hxn8=; b=P/PvqtuGnadNZsJ0HoUxzv3EnMkCCiCbshKmHy4ILOrnbQiNcdPzn0NjTFxrsp6lUt NPgileWXU1rMabQITEKJHRUc399PWF46Uf9gneBr8yCExI2VFPjH0QGFZ6oboQHPDnPG xcwuh1pbnbfPyDNERWZs6wVAGiiiXF2+syGGGzPL1iMwL9hNWDZAIuZ6FICrasXRYwpG h73iCTUfLfUUwjROFc4SXI7RY6IpmS61WDmLHlUCoCDsRE49IkTufS6rl4u0yh1C3azl kMY82WKiXNnvE10cY9N7WaPEA9P5z4EWX/beHuom98Y+FZQ8wFtPBE2ZQWqgUdkmcryA DtYw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x184-20020a6386c1000000b0052c66d4c255si3429193pgd.576.2023.05.04.05.50.59; Thu, 04 May 2023 05:51:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230386AbjEDMuG (ORCPT + 99 others); Thu, 4 May 2023 08:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230419AbjEDMtu (ORCPT ); Thu, 4 May 2023 08:49:50 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 529C465AD; Thu, 4 May 2023 05:49:41 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QBttn4051z4f3vdY; Thu, 4 May 2023 20:49:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S11; Thu, 04 May 2023 20:49:38 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 07/11] block/badblocks: check bb->count instead of 'hi > lo' Date: Thu, 4 May 2023 20:48:24 +0800 Message-Id: <20230504124828.679770-8-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S11 X-Coremail-Antispam: 1UD129KBjvJXoWxJFW7XFykXw1DKw17KFyxGrg_yoWrZryxpw 4SyaySgFy8WF4S9rn8JF4DGF15KayxZr48JF15Jw1xCF1vkr9I9FnFyw10gFWvkFZ3XFn0 qw1rWFyIyFZxAwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmIb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnI WIevJa73UjIFyTuYvjxUwZ2-UUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968022127240633?= X-GMAIL-MSGID: =?utf-8?q?1764968022127240633?= From: Li Nan 'hi > lo' only holds when bb->count is 0. Check it is complicated after dichotomy. Check bb->count instead. And this will make future fix more convenient. No functional change intended. Signed-off-by: Li Nan --- block/badblocks.c | 155 +++++++++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 76 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index c11eb869f2f3..3cb8513cbd7f 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -187,28 +187,32 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, p = bb->page; lo = 0; hi = bb->count; - /* Find the last range that starts at-or-before 's' */ - while (hi - lo > 1) { - int mid = (lo + hi) / 2; - sector_t a = BB_OFFSET(p[mid]); - - if (a <= s) - lo = mid; - else - hi = mid; - } - if (hi > lo && BB_OFFSET(p[lo]) > s) - hi = lo; + if (bb->count) { + sector_t a; + sector_t e; + int ack; + + /* Find the last range that starts at-or-before 's' */ + while (hi - lo > 1) { + int mid = (lo + hi) / 2; + + a = BB_OFFSET(p[mid]); + if (a <= s) + lo = mid; + else + hi = mid; + } - if (hi > lo) { /* we found a range that might merge with the start * of our new range */ - sector_t a = BB_OFFSET(p[lo]); - sector_t e = a + BB_LEN(p[lo]); - int ack = BB_ACK(p[lo]); + a = BB_OFFSET(p[lo]); + e = a + BB_LEN(p[lo]); + ack = BB_ACK(p[lo]); - if (e >= s) { + if (a > s) { + hi = lo; + } else if (e >= s) { /* Yes, we can merge with a previous range */ if (s == a && s + sectors >= e) /* new range covers old */ @@ -232,72 +236,71 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, } sectors = e - s; } - } - if (sectors && hi < bb->count) { - /* 'hi' points to the first range that starts after 's'. - * Maybe we can merge with the start of that range - */ - sector_t a = BB_OFFSET(p[hi]); - sector_t e = a + BB_LEN(p[hi]); - int ack = BB_ACK(p[hi]); - - if (a <= s + sectors) { - /* merging is possible */ - if (e <= s + sectors) { - /* full overlap */ - - e = s + sectors; - ack = acknowledged; - } else - ack = ack && acknowledged; - - a = s; - if (e - a <= BB_MAX_LEN) { - p[hi] = BB_MAKE(a, e-a, ack); - s = e; - } else { - p[hi] = BB_MAKE(a, BB_MAX_LEN, ack); - s = a + BB_MAX_LEN; + if (sectors && hi < bb->count) { + /* 'hi' points to the first range that starts after 's'. + * Maybe we can merge with the start of that range + */ + a = BB_OFFSET(p[hi]); + e = a + BB_LEN(p[hi]); + ack = BB_ACK(p[hi]); + + if (a <= s + sectors) { + /* merging is possible */ + if (e <= s + sectors) { + /* full overlap */ + e = s + sectors; + ack = acknowledged; + } else + ack = ack && acknowledged; + + a = s; + if (e - a <= BB_MAX_LEN) { + p[hi] = BB_MAKE(a, e-a, ack); + s = e; + } else { + p[hi] = BB_MAKE(a, BB_MAX_LEN, ack); + s = a + BB_MAX_LEN; + } + sectors = e - s; + lo = hi; + hi++; + changed = true; } - sectors = e - s; - lo = hi; - hi++; - changed = true; } - } - if (sectors == 0 && hi < bb->count) { - /* we might be able to combine lo and hi */ - /* Note: 's' is at the end of 'lo' */ - sector_t loa = BB_OFFSET(p[lo]), hia = BB_OFFSET(p[hi]); - sector_t hie = hia + BB_LEN(p[hi]); - int newlen = max(s, hie) - loa; - int ack = BB_ACK(p[lo]) && BB_ACK(p[hi]); - - if (s >= hia) { - while (s >= hie) { - /* lo contains hi, just remove hi */ - memmove(p + hi, p + hi + 1, - (bb->count - hi - 1) * 8); - bb->count--; - if (hi >= bb->count) - break; - hia = BB_OFFSET(p[hi]); - hie = hia + BB_LEN(p[hi]); - } - if (s >= hia && hi < bb->count) { - if (newlen > BB_MAX_LEN) { - p[lo] = BB_MAKE(loa, BB_MAX_LEN, ack); - p[hi] = BB_MAKE(loa + BB_MAX_LEN, - newlen - BB_MAX_LEN, - BB_ACK(p[hi])); - } else { - p[lo] = BB_MAKE(loa, newlen, ack); + if (sectors == 0 && hi < bb->count) { + /* we might be able to combine lo and hi */ + /* Note: 's' is at the end of 'lo' */ + sector_t loa = BB_OFFSET(p[lo]), hia = BB_OFFSET(p[hi]); + sector_t hie = hia + BB_LEN(p[hi]); + int newlen = max(s, hie) - loa; + + ack = BB_ACK(p[lo]) && BB_ACK(p[hi]); + if (s >= hia) { + while (s >= hie) { + /* lo contains hi, just remove hi */ memmove(p + hi, p + hi + 1, (bb->count - hi - 1) * 8); bb->count--; + if (hi >= bb->count) + break; + hia = BB_OFFSET(p[hi]); + hie = hia + BB_LEN(p[hi]); + } + if (s >= hia && hi < bb->count) { + if (newlen > BB_MAX_LEN) { + p[lo] = BB_MAKE(loa, BB_MAX_LEN, ack); + p[hi] = BB_MAKE(loa + BB_MAX_LEN, + newlen - BB_MAX_LEN, + BB_ACK(p[hi])); + } else { + p[lo] = BB_MAKE(loa, newlen, ack); + memmove(p + hi, p + hi + 1, + (bb->count - hi - 1) * 8); + bb->count--; + } } + changed = true; } - changed = true; } } while (sectors) { From patchwork Thu May 4 12:48:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90073 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp289252vqo; Thu, 4 May 2023 05:51:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ43txSuiagpCeFp9tzq7CZj9bz5YCPYR9fyHFt25d3qFt3+qOM5GCIrZNfYq3tOJGU+W1dA X-Received: by 2002:a05:6a20:ae15:b0:f0:2222:8b58 with SMTP id dp21-20020a056a20ae1500b000f022228b58mr2046905pzb.12.1683204712189; Thu, 04 May 2023 05:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683204712; cv=none; d=google.com; s=arc-20160816; b=z52cQib8tryEdNfXWIazYXQWlYpmwGOT9GMCsDIhCzvAyQa0RIaSx88D+TxnrJ9ZW9 OF7qhshzKZ12kNnXNamrJL/padi3tGRl7TbCzEgbWlqnCKtU/rVmdXYiZU5goimcaCfv JnB1ZFuPEGLjaGQE9lrDkWIZLxHTzMx0RyeWmSyBd/i+Y4mw78XBP6Ar4NoClwGxux0c 7TPXbdjo1npDoAwYROAues5M5bMIqFndE+/7JPd6m8PVU/wYbre9V0rI8EJ5sDkgmr/u ceDzBA0xG2qFwKmGg65Q4iL0BeXOGjj51cH4wiOrGTwYq4LXxg/TNthOMPd9u5Xm+Q7K R/5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=b0/UZveRjtZECcdJUvJId86DAaawxccBqna4R61/ChM=; b=gYwuy5LWrv+nCtSvtzRudw62BgXvAZJXlRwb/8lOO7quFFEXeIBkUKjDkJhpOzm7ON I+9ZhA9xls9J4XYkpCPSVJ+xeEKBrw1GTo0snkJxCYlbzs3OOaCRjlPFsJ1lLy+hb1J6 cWcQOTwf4jhW9VWA3HqfV0qHLksNa7SdoQvtrZyPt/qrv1IG+yWjRGzy9hF8fLQdxfdv 2i/Qn3Sx4lTVWXM+nNqmgcddZW1VITzti8f9eCG6WX4L+Z556YG2hSl3Q06wTBB7ZEfe DFjETRTdEkQekf3TLmVFZyOP9yxtSWuF6IGkjjB5tJ7doHGsd5+twFvUof3hMHKyjrQT 5lbw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a184-20020a6390c1000000b0050f818e900dsi5941508pge.761.2023.05.04.05.51.39; Thu, 04 May 2023 05:51:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230509AbjEDMuS (ORCPT + 99 others); Thu, 4 May 2023 08:50:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230432AbjEDMtv (ORCPT ); Thu, 4 May 2023 08:49:51 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDACA46BC; Thu, 4 May 2023 05:49:41 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QBttn30SKz4f3tDr; Thu, 4 May 2023 20:49:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S12; Thu, 04 May 2023 20:49:39 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 08/11] block/badblocks: factor out a helper to merge badblocks Date: Thu, 4 May 2023 20:48:25 +0800 Message-Id: <20230504124828.679770-9-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S12 X-Coremail-Antispam: 1UD129KBjvJXoWxCF45WFyUZFW8uw1UuFykXwb_yoWrXFyxpr 1ay3WS9FyUXF47W3Z8JF4DKr1rKayfXr4UAFWfA3ykuF18CrZIqF1v9ryruFy09rZxWFn0 q3WYgry29as8C3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmIb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnI WIevJa73UjIFyTuYvjxUwZ2-UUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968064386817782?= X-GMAIL-MSGID: =?utf-8?q?1764968064386817782?= From: Li Nan Add a helper badblocks_merge() to merge badblocks, it makes code more readable. No functional change. Signed-off-by: Li Nan --- block/badblocks.c | 143 +++++++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 64 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index 3cb8513cbd7f..f498fae201a1 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -144,6 +144,80 @@ static void badblocks_update_acked(struct badblocks *bb) bb->unacked_exist = false; } +/* + * try to merge new range with lo and hi. + * if s is within lo, merge with lo. + * if s + sectors > start of hi, merge with hi. + * + * Return: + * Number of merged sectors + */ +static int badblocks_merge(struct badblocks *bb, sector_t s, int sectors, + int acknowledged, int *lo, int *hi, bool *changed) +{ + u64 *p = bb->page; + sector_t a = BB_OFFSET(p[*lo]); + sector_t e = a + BB_LEN(p[*lo]); + int merged_sectors = 0, ack = acknowledged; + + if (a > s) { + *hi = *lo; + } else if (e >= s) { + /* we can merge with a previous range */ + if (s > a || s + sectors < e) + ack = ack && BB_ACK(p[*lo]); + + if (e < s + sectors) + e = s + sectors; + if (e - a <= BB_MAX_LEN) { + s = e; + } else { + /* + * does not all fit in one range, + * make p[lo] maximal + */ + s = a + BB_MAX_LEN; + } + if (s - a != BB_LEN(p[*lo]) || ack != BB_ACK(p[*lo])) { + p[*lo] = BB_MAKE(a, s - a, ack); + *changed = true; + } + merged_sectors += sectors - e + s; + sectors = e - s; + } + if (sectors && *hi < bb->count) { + /* + * 'hi' points to the first range that starts after 's'. + * Maybe we can merge with the start of that range + */ + a = BB_OFFSET(p[*hi]); + e = a + BB_LEN(p[*hi]); + ack = acknowledged; + + if (a <= s + sectors) { + /* merging is possible */ + if (e <= s + sectors) { + /* full overlap */ + e = s + sectors; + } else + ack = ack && BB_ACK(p[*hi]); + + a = s; + if (e - a <= BB_MAX_LEN) + s = e; + else + s = a + BB_MAX_LEN; + p[*hi] = BB_MAKE(a, s-a, ack); + + merged_sectors += sectors - e + s; + *changed = true; + *lo = *hi; + *hi += 1; + } + } + return merged_sectors; +} + /** * badblocks_set() - Add a range of bad blocks to the table. * @bb: the badblocks structure that holds all badblock information @@ -191,6 +265,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, sector_t a; sector_t e; int ack; + int merged_sectors; /* Find the last range that starts at-or-before 's' */ while (hi - lo > 1) { @@ -203,70 +278,10 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, hi = mid; } - /* we found a range that might merge with the start - * of our new range - */ - a = BB_OFFSET(p[lo]); - e = a + BB_LEN(p[lo]); - ack = BB_ACK(p[lo]); - - if (a > s) { - hi = lo; - } else if (e >= s) { - /* Yes, we can merge with a previous range */ - if (s == a && s + sectors >= e) - /* new range covers old */ - ack = acknowledged; - else - ack = ack && acknowledged; - - if (e < s + sectors) - e = s + sectors; - if (e - a <= BB_MAX_LEN) { - s = e; - } else { - /* does not all fit in one range, - * make p[lo] maximal - */ - s = a + BB_MAX_LEN; - } - if (s - a != BB_LEN(p[lo]) || ack != BB_ACK(p[lo])) { - p[lo] = BB_MAKE(a, s - a, ack); - changed = true; - } - sectors = e - s; - } - if (sectors && hi < bb->count) { - /* 'hi' points to the first range that starts after 's'. - * Maybe we can merge with the start of that range - */ - a = BB_OFFSET(p[hi]); - e = a + BB_LEN(p[hi]); - ack = BB_ACK(p[hi]); - - if (a <= s + sectors) { - /* merging is possible */ - if (e <= s + sectors) { - /* full overlap */ - e = s + sectors; - ack = acknowledged; - } else - ack = ack && acknowledged; - - a = s; - if (e - a <= BB_MAX_LEN) { - p[hi] = BB_MAKE(a, e-a, ack); - s = e; - } else { - p[hi] = BB_MAKE(a, BB_MAX_LEN, ack); - s = a + BB_MAX_LEN; - } - sectors = e - s; - lo = hi; - hi++; - changed = true; - } - } + merged_sectors = badblocks_merge(bb, s, sectors, acknowledged, + &lo, &hi, &changed); + s += merged_sectors; + sectors -= merged_sectors; if (sectors == 0 && hi < bb->count) { /* we might be able to combine lo and hi */ /* Note: 's' is at the end of 'lo' */ From patchwork Thu May 4 12:48:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp289010vqo; Thu, 4 May 2023 05:51:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6a1bDJfJNqcI/afPIbwdp5OwDeb15OeWWyuWGClKda5+75z035g0OgK6UBur3lKARqq9zM X-Received: by 2002:a17:90a:c908:b0:246:91d0:9e6f with SMTP id v8-20020a17090ac90800b0024691d09e6fmr2142667pjt.3.1683204690904; Thu, 04 May 2023 05:51:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683204690; cv=none; d=google.com; s=arc-20160816; b=0uJclveL6TuyTBB7ZKW61RTYZpPFwppeBMm3vuz3PzhVI2YNUeN5popB2/OAuBs+HB 27ETmcgDA7WxsJnWzSr/FuResnFgZ8O8gwYrTV5mukLRqBY335bW3DPQjjojjRGNQJL2 meIfCRpuSgY24eMP/rhEMjBlMaxwjeFPmAm3qcZ+pjFyLWBrR7vVPwayc8mDYjB2GPNC 18YRzVSajxGjAHyXOXo/wyJ9kaIL43RJMlMjtx+NYBo2Fy/eQYxgwzHQal+IUompqp6T xV7TgwAgJDMYGPR+1UuI7llm6z2FLZqeZwh1JZfJBYxAnlfCM54vmyFD6uBl3v+Z6/rn 9uRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=U3Ki99J6gVzLZl75VA2TYeizXFhw6YWBlKGxEkyc5Eo=; b=JxONVmhekgu40WgLAT/wxigwEML2wPrz24JHfwDP86SuV4KNWvtgZXbcKkFyVHAyzY /Uhcqq2J20T9Yxr0vnzde0Z5dywlzBZr5FOOVBBDK8TK23s1/mA3nkfV1yKoKTMkoIzr /OFOXmFaQjyYc/bUoIeann4YEywCA4/jE3ibuvqVoECTCzHSj/44jcDa/8VSb+IvRqD8 qIl83I0idoYLY5u47xAjcmG0xiWW3cnMgMIZE2xOT7J0hxrO8O0a0GKtq9w+W49Sv3aU ljAnc58HPd9X3momEa2bRMQSBdN9VsnArE7M2qsSfBrN03l63EUu57HQDT3xOrpig7Wv Jk+Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020a634749000000b005073e3342eesi35880441pgk.143.2023.05.04.05.51.18; Thu, 04 May 2023 05:51:30 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbjEDMuN (ORCPT + 99 others); Thu, 4 May 2023 08:50:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230431AbjEDMtv (ORCPT ); Thu, 4 May 2023 08:49:51 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60CEB6A5A; Thu, 4 May 2023 05:49:42 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QBttp36s5z4f3v5G; Thu, 4 May 2023 20:49:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S13; Thu, 04 May 2023 20:49:39 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 09/11] block/badblocks: factor out a helper to combine badblocks Date: Thu, 4 May 2023 20:48:26 +0800 Message-Id: <20230504124828.679770-10-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S13 X-Coremail-Antispam: 1UD129KBjvJXoWxAFWrAFyxGF15Kw4xuw4rKrg_yoW5ZFyUpw 1Sy3Waqr1xWFWI9a1UJa1DKr13Ka97Zr4rJF4fAw1xCF18CwnI9rnrJw1Ygay8KFWfXF90 q34rWFyjyF97GwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmIb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnI WIevJa73UjIFyTuYvjxUwZ2-UUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968041911759455?= X-GMAIL-MSGID: =?utf-8?q?1764968041911759455?= From: Li Nan Add a helper badblocks_combine() to combine badblocks, it makes code more readable. No functional change. Signed-off-by: Li Nan --- block/badblocks.c | 87 ++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index f498fae201a1..c87c68d4bcac 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -218,6 +218,51 @@ static int badblocks_merge(struct badblocks *bb, sector_t s, int sectors, return merged_sectors; } +/* + * try to combine lo and hi(lo + 1) if lo intersects with hi + */ +static void badblocks_combine(struct badblocks *bb, int lo) +{ + u64 *p = bb->page; + sector_t loe = BB_OFFSET(p[lo]) + BB_LEN(p[lo]); + int hi = lo + 1; + + if (hi >= bb->count) + return; + /* we might be able to combine lo and hi */ + + if (loe >= BB_OFFSET(p[hi])) { + sector_t loa = BB_OFFSET(p[lo]), hia = BB_OFFSET(p[hi]); + sector_t hie = hia + BB_LEN(p[hi]); + int newlen = max(loe, hie) - loa; + int ack = BB_ACK(p[lo]) && BB_ACK(p[hi]); + + while (loe >= hie) { + /* lo contains hi, just remove hi */ + memmove(p + hi, p + hi + 1, + (bb->count - hi - 1) * 8); + bb->count--; + if (hi >= bb->count) + break; + hia = BB_OFFSET(p[hi]); + hie = hia + BB_LEN(p[hi]); + } + if (loe >= hia && hi < bb->count) { + if (newlen > BB_MAX_LEN) { + p[lo] = BB_MAKE(loa, BB_MAX_LEN, ack); + p[hi] = BB_MAKE(loa + BB_MAX_LEN, + newlen - BB_MAX_LEN, + BB_ACK(p[hi])); + } else { + p[lo] = BB_MAKE(loa, newlen, ack); + memmove(p + hi, p + hi + 1, + (bb->count - hi - 1) * 8); + bb->count--; + } + } + } +} + /** * badblocks_set() - Add a range of bad blocks to the table. * @bb: the badblocks structure that holds all badblock information @@ -262,16 +307,13 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, lo = 0; hi = bb->count; if (bb->count) { - sector_t a; - sector_t e; - int ack; int merged_sectors; /* Find the last range that starts at-or-before 's' */ while (hi - lo > 1) { int mid = (lo + hi) / 2; + int a = BB_OFFSET(p[mid]); - a = BB_OFFSET(p[mid]); if (a <= s) lo = mid; else @@ -282,41 +324,8 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, &lo, &hi, &changed); s += merged_sectors; sectors -= merged_sectors; - if (sectors == 0 && hi < bb->count) { - /* we might be able to combine lo and hi */ - /* Note: 's' is at the end of 'lo' */ - sector_t loa = BB_OFFSET(p[lo]), hia = BB_OFFSET(p[hi]); - sector_t hie = hia + BB_LEN(p[hi]); - int newlen = max(s, hie) - loa; - - ack = BB_ACK(p[lo]) && BB_ACK(p[hi]); - if (s >= hia) { - while (s >= hie) { - /* lo contains hi, just remove hi */ - memmove(p + hi, p + hi + 1, - (bb->count - hi - 1) * 8); - bb->count--; - if (hi >= bb->count) - break; - hia = BB_OFFSET(p[hi]); - hie = hia + BB_LEN(p[hi]); - } - if (s >= hia && hi < bb->count) { - if (newlen > BB_MAX_LEN) { - p[lo] = BB_MAKE(loa, BB_MAX_LEN, ack); - p[hi] = BB_MAKE(loa + BB_MAX_LEN, - newlen - BB_MAX_LEN, - BB_ACK(p[hi])); - } else { - p[lo] = BB_MAKE(loa, newlen, ack); - memmove(p + hi, p + hi + 1, - (bb->count - hi - 1) * 8); - bb->count--; - } - } - changed = true; - } - } + if (sectors == 0) + badblocks_combine(bb, lo); } while (sectors) { /* didn't merge (it all). From patchwork Thu May 4 12:48:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp289580vqo; Thu, 4 May 2023 05:52:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5FwWtvFCvYtiHda1Lnl8jKQ9PRjAhR7rDfGz+rItL1GMB9nS59yS0ftWnCpGRMCRU8feVl X-Received: by 2002:a05:6a20:e68e:b0:f5:83f:9b88 with SMTP id mz14-20020a056a20e68e00b000f5083f9b88mr2118061pzb.9.1683204744768; Thu, 04 May 2023 05:52:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683204744; cv=none; d=google.com; s=arc-20160816; b=OuqjunhXIJmbzM1Cx7E7yfJPVWYS8Tft2q+rWQCMyVjkW3weG3dMZps/QxBXKzTmNM EFycdAlWE3Ce+Rtkzp92+JGtV0lK3m3t4AjnlFvuyTcN6jizU+NHF7bS/b0zr9rboqkw F1JvBIggkaK8t37ahI4CIGJth/YziUKqzTNNbD4GehUwtGYAjww13j8j6s6ehDevP2OC nvM/yWqrreC4Zcuc3h89zmKKo906jmVimamLp1B315HXE86HXxqGH67++J4alKOqafWi Xmhuoqs+08Z3KcYXQzlLCXRGw0FOou9Q3GKVAocus51J9ClYhPdlxqWLxLRlRCtKN0iP J84g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=e4HrmW/Ca4dTOBNdwHlQEQG7M4BC/BS6i0pM+BL/SxQ=; b=wlYKaAkrT+ZvPx7U/AIu/yKp+d3F4W9UVhfAITqdnH90Omfs+goi3/XMK025MoQpyH lnpDDdZgz/LZzVnxNYb2ngfPOfdrZCPvZbWBIoI2nNlJuJwtCbksjax9Ccy8RPWLMvTg uxpHLCiakVt4wEi52yWnv05SBNR1SSmV/Ix7sOHeJsFAc86e4FErf2t+1ngO19bGkTDB cTVI72hyhzq9lO8mc+e2QCPp2SN7upTx4bApEMOgmlRdXdanmZJ5k8YIkIAR3NgrCTLN NGQD0NvDL59zfa7v6kpa8N3KE4YYT2BJ/QUzzddvAvsHrLEBq+abKX1sUAJoXIu3EQv3 SeAA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x184-20020a6386c1000000b0052c66d4c255si3429193pgd.576.2023.05.04.05.52.12; Thu, 04 May 2023 05:52:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230443AbjEDMuW (ORCPT + 99 others); Thu, 4 May 2023 08:50:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbjEDMtv (ORCPT ); Thu, 4 May 2023 08:49:51 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4AAD6A66; Thu, 4 May 2023 05:49:42 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QBttp22fCz4f3v6h; Thu, 4 May 2023 20:49:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S14; Thu, 04 May 2023 20:49:40 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 10/11] block/badblocks: factor out a helper to create badblocks Date: Thu, 4 May 2023 20:48:27 +0800 Message-Id: <20230504124828.679770-11-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S14 X-Coremail-Antispam: 1UD129KBjvJXoW7tw4UCrW7tFW8WrWxZF48tFb_yoW8tr43pr sIy3Zagry7Ww1xXanxX3ZrKr1rK3yfZF1UGr47Aw1UGFyxCwnrtFn2vryfuFyj9Fy3Jr4q q3WYgryY9asrC37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmab4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCw CI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsG vfC2KfnxnUUI43ZEXa7IU1lksDUUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764968098771598290?= X-GMAIL-MSGID: =?utf-8?q?1764968098771598290?= From: Li Nan Add a helper badblocks_create() to create badblocks, it makes code more readable. No functional change. Signed-off-by: Li Nan --- block/badblocks.c | 65 ++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index c87c68d4bcac..bb0324b66f57 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -263,6 +263,46 @@ static void badblocks_combine(struct badblocks *bb, int lo) } } +/* + * creat new badblocks if it can't merge with existing region + * + * Return: + * 0: success + * 1: failed to set badblocks (out of space) + */ +static int badblocks_create(struct badblocks *bb, sector_t s, sector_t sectors, + int hi, int acknowledged, bool *changed) +{ + u64 *p = bb->page; + int rv = 0; + + while (sectors) { + int this_sectors = sectors; + + /* didn't merge (it all). + * Need to add a range just before 'hi' + */ + if (bb->count >= MAX_BADBLOCKS) { + /* No room for more */ + rv = 1; + break; + } + + memmove(p + hi + 1, p + hi, + (bb->count - hi) * 8); + bb->count++; + + if (this_sectors > BB_MAX_LEN) + this_sectors = BB_MAX_LEN; + p[hi] = BB_MAKE(s, this_sectors, acknowledged); + sectors -= this_sectors; + s += this_sectors; + hi++; + *changed = true; + } + return rv; +} + /** * badblocks_set() - Add a range of bad blocks to the table. * @bb: the badblocks structure that holds all badblock information @@ -327,30 +367,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, if (sectors == 0) badblocks_combine(bb, lo); } - while (sectors) { - /* didn't merge (it all). - * Need to add a range just before 'hi' - */ - if (bb->count >= MAX_BADBLOCKS) { - /* No room for more */ - rv = 1; - break; - } else { - int this_sectors = sectors; - - memmove(p + hi + 1, p + hi, - (bb->count - hi) * 8); - bb->count++; - - if (this_sectors > BB_MAX_LEN) - this_sectors = BB_MAX_LEN; - p[hi] = BB_MAKE(s, this_sectors, acknowledged); - sectors -= this_sectors; - s += this_sectors; - hi++; - changed = true; - } - } + rv = badblocks_create(bb, s, sectors, hi, acknowledged, &changed); if (changed) { bb->changed = changed; From patchwork Thu May 4 12:48:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp302806vqo; Thu, 4 May 2023 06:09:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7sGRV7qfvaoLaotWfISTnYncp3+dZPhhG221SwtvlhkQhjP1ppbrAxDg2UBZOYsABxU95d X-Received: by 2002:a17:90b:3101:b0:23f:962e:825d with SMTP id gc1-20020a17090b310100b0023f962e825dmr2290808pjb.1.1683205753375; Thu, 04 May 2023 06:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683205753; cv=none; d=google.com; s=arc-20160816; b=YOo/nHfLGG5FOppd72vJ2a+D2zPnSdhnzKKyXIzDFKGaK63Ucjfal0X2OogXCidYc9 ZSu9iMbTCoum0MYvxnjQKiHwAoS3Y6mYPgMPrFUc0ed6ZWmoKICqifrWLu8PeXT6M3PZ sHl0yK+H03LB7mnRht7EbXFMjG3V7w1DE0HNZXjipwhd6yNRCaRsLKutWuJYhA+cvlnG hgwnqJ4fesU1XQN94LiTqY81S2h9p1qKkM46oW9Fxls4psLIsju7lR3ANmvXXooPk1IV mR+NWEMooFwcS3gZXYoX7qV+JNDQ4UtZJItWthX+l1JVb5R0WiABv6IJyekk6GW2SQ0e CjNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9zvkkRlRCEPBWFsuvLW86XuxHZkHvw0XJ2i8FZZOiM4=; b=XDIAGS+eNIjZ88+sU9EEazRc9ZVdj/BlmyqDzApE2PCgPimeN/qqbiPYNq5KAfnXLz 70DiLFDWsCHZvjMLh1XNUqo6Ci6T2RP9LwokDMumcaYsLPoFmHn7pVRuPauYC3oZnvS0 sfQqb7vgOSx/IHqKE/+ftDovvxdSD1vFZC7Jsves7UoWPl+Zo5oxWrxyJC1FOmIdKQ6j mn4kmqC+DaCciTOEQwGpvzdDgbCYxqex2MjvvX6VrMNHIHWXvXqBFi1+6bRhZYb3edtK IH/u9tJLFjF6S1O5g7YeoGP+H6rAzbFhqERhMstS3Mp/9xEnqawx69r8vGeUnpjwzkxQ RYpQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a13-20020a17090a740d00b0024dec84c2fcsi3882768pjg.122.2023.05.04.06.08.59; Thu, 04 May 2023 06:09:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231139AbjEDMua (ORCPT + 99 others); Thu, 4 May 2023 08:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbjEDMtv (ORCPT ); Thu, 4 May 2023 08:49:51 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23D116A7D; Thu, 4 May 2023 05:49:43 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QBttq1GYTz4f3kkN; Thu, 4 May 2023 20:49:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S15; Thu, 04 May 2023 20:49:40 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 11/11] block/badblocks: try to merge badblocks as much as possible Date: Thu, 4 May 2023 20:48:28 +0800 Message-Id: <20230504124828.679770-12-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S15 X-Coremail-Antispam: 1UD129KBjvJXoW7Ww48tFW5WF4UKF43Cr1xZrb_yoW8Cry7pF n0y3WfKry2gr17W3W5X3W8Kr10g34fJF4UCF43Xw1jkFyxGwn3tF1kZw4FqFyjgF43Wrs0 v3Wruryjva4kCa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmab4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCw CI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsG vfC2KfnxnUUI43ZEXa7IU1lksDUUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764969156517483850?= X-GMAIL-MSGID: =?utf-8?q?1764969156517483850?= From: Li Nan If we set a new badblocks, we first merge it with existing region, then try to combine lo and hi. If there are still badblocks need to be set, create it. It is a bad way when setting a laget number of badblocks. for example, it will become chaotic if we set as below: # echo 1 1 > bad_blocks # echo 512 1 > bad_blocks # echo 0 513 > bad_blocks # cat bad_blocks 0 512 512 1 512 1 Fix it by trying to merge as much as possible. If we have merged any badblocks, retry to merge next sectors. Do not check sectors while combining, we should combine lo and hi each sycle. Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") Signed-off-by: Li Nan --- block/badblocks.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index bb0324b66f57..7e6fce10c82d 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -347,8 +347,6 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, lo = 0; hi = bb->count; if (bb->count) { - int merged_sectors; - /* Find the last range that starts at-or-before 's' */ while (hi - lo > 1) { int mid = (lo + hi) / 2; @@ -360,12 +358,19 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, hi = mid; } - merged_sectors = badblocks_merge(bb, s, sectors, acknowledged, - &lo, &hi, &changed); - s += merged_sectors; - sectors -= merged_sectors; - if (sectors == 0) + while (sectors) { + int merged_sectors; + + merged_sectors = badblocks_merge(bb, s, sectors, acknowledged, + &lo, &hi, &changed); + /* can't merge, break to create */ + if (!merged_sectors) + break; + + s += merged_sectors; + sectors -= merged_sectors; badblocks_combine(bb, lo); + } } rv = badblocks_create(bb, s, sectors, hi, acknowledged, &changed);