From patchwork Mon Jun 26 08:09:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 112761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7326644vqr; Mon, 26 Jun 2023 01:29:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4X3uFBbBTBRobLcB2nfvlP5CoHOaMj31iN6lOqbzkbyVohPhUb36iisKN+dumUECfDbq9g X-Received: by 2002:aa7:d296:0:b0:51d:96f0:9012 with SMTP id w22-20020aa7d296000000b0051d96f09012mr1990798edq.10.1687768185478; Mon, 26 Jun 2023 01:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687768185; cv=none; d=google.com; s=arc-20160816; b=HM2kezkJgJ9AYVJGF2zCYt7kdkkJ4DOTy8x8c+ZQOACjGYrKZcz0+80XLGi3ztEVVL sH209+to5h97UOglaVnpFEk68GrlCpm4qsdxWG7+kQLXlj4LV5bn6dYCOfASCg/N0PF3 ndAzd3onR1ZAI/QsbHDKCD0eDHzjdA08bMGkX4pb0a95p86chTIJ+j7omIUd/9bVl/Np STfh7zbBXYC6PIBmM4EQ1Xnh/3UT0HmVFNoRQA5ifsqkHsrzie915hEWgay918ZObSd5 NNILHXCESWyrchw9uO+k8ZrpH+FIekdoEf2qb+Tjyl1kR7+reWaaToxRC+vhhv1Sadn9 hxyA== 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=FqdxI8b3YJuxx8INl0F045IjihDQyNgtq/1hGQBWT4o=; fh=3eCKTJ3QhUFKE6vQUOdHlzlShegRylJTJnUErNRn6Gg=; b=R60VJAZufWJcj3nUuQoTsm5T7rfGCsB0Tina7YUEe4Q0m2We/ztxy/irDzXIPDChZZ zS9JTd16wi1MbB3Y/JD7ZRXB2FDRQnEb6Z7lwpQXhdw9cFYDRSILhi2WJgA9A3hBRBwb l7Z7KQHf1iHPozYGGm38luWUGxmavIGBTLBM0EEJOAcKmiksFVqtVhXk1+MFbSaSd4wU 0H0gxyKght/txIa/DVb0GK/CiFUd8JL85ampy8hiOMvhatCZcx4p/6hrNu3rTyZoV1Si mr2fKZ6HefTcvYH50yyb9sPTbjwkAZvCZ5CiePZjLEsrJZGa8BctvRmYgd+m362b3IEg 9j2Q== 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 f9-20020a05640214c900b0051d9ad41f83si716869edx.96.2023.06.26.01.29.21; Mon, 26 Jun 2023 01:29:45 -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 S230087AbjFZIKU (ORCPT + 99 others); Mon, 26 Jun 2023 04:10:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbjFZIKL (ORCPT ); Mon, 26 Jun 2023 04:10:11 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52DF510CC; Mon, 26 Jun 2023 01:10:06 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QqL9h0wZYz4f3nyZ; Mon, 26 Jun 2023 16:10:00 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgAHcLPWR5lkQbNDMg--.19922S5; Mon, 26 Jun 2023 16:10:02 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com, ashok_raj@linux.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 v4 1/4] block/badblocks: change some members of badblocks to bool Date: Mon, 26 Jun 2023 16:09:10 +0800 Message-Id: <20230626080913.3493135-2-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626080913.3493135-1-linan666@huaweicloud.com> References: <20230626080913.3493135-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgAHcLPWR5lkQbNDMg--.19922S5 X-Coremail-Antispam: 1UD129KBjvJXoWxAw45KFW3uryUWFWftw48tFb_yoW5XryUpF nxGwn3tr4jgr1vqF1DZ3W7Cr109w4xJF48t3y7Jw15K34Utw1xJa4kXryrtFWjqrW3CrsI vF1FgrW5Zry8C3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmjb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8BWlDUUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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?1769753212975965864?= X-GMAIL-MSGID: =?utf-8?q?1769753212975965864?= From: Li Nan "changed" and "unacked_exist" are used as boolean type. Change the type of them to bool. No functional changed intended. Signed-off-by: Li Nan --- include/linux/badblocks.h | 9 +++++---- block/badblocks.c | 14 +++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/linux/badblocks.h b/include/linux/badblocks.h index 2426276b9bd3..2feb143a1856 100644 --- a/include/linux/badblocks.h +++ b/include/linux/badblocks.h @@ -27,15 +27,16 @@ 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 + bool unacked_exist; /* there probably are unacknowledged + * bad blocks. This is only cleared + * when a read of unacknowledged bad + * blocks discovers none */ int shift; /* shift from sectors to block size * a -ve shift means badblocks are * disabled.*/ u64 *page; /* badblock list */ - int changed; + bool changed; seqlock_t lock; sector_t sector; sector_t size; /* in sectors */ diff --git a/block/badblocks.c b/block/badblocks.c index 3afb550c0f7b..f28e971a4b94 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 && 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; From patchwork Mon Jun 26 08:09:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 112762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7328440vqr; Mon, 26 Jun 2023 01:33:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6N+2AVbMt1NiIiVEVet1lJjXLgFj9iF2t5HUCkK/IpQ5/4WdGZhrruUSxI7JBK80U1r0pu X-Received: by 2002:a17:907:2bc4:b0:98e:4ec0:da6a with SMTP id gv4-20020a1709072bc400b0098e4ec0da6amr2310385ejc.0.1687768429422; Mon, 26 Jun 2023 01:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687768429; cv=none; d=google.com; s=arc-20160816; b=H7VIRJhnjmc5NU5VzmkQC7hednI88GTC5Q6UDVd0+ojtvor2iQFByCS4rUHHMw0dkp vv9CwJ0elYQw2Lj8ToZy1HOxRhGhcP9DENuP7I9cpi6RTdABzFKqm57t7Se/EEfOWUb+ FECfwyyf8w1IHVTrD+6M5nFiEXd4y/te3Gar8Kdk1bjQj7gReeWtyNmiDSJNlQHQa7Gy jK9hrZvjGTHoIxWEf5uBLaN8R8kxHLrK5RjgmUSjdJpStoaOv/LpxsgAhfo2GD96vRRI JqzCBsW5RS+9HFY14SLo/UysAIr63+OT1VoYHPz6+Tchr6svIpcCfPhrlq7eyy2bnDSr BgHA== 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=bDiSdnyuFSGHiyLUDZO6AOA4xToZOZ0+VKIRvkQYNkY=; fh=3eCKTJ3QhUFKE6vQUOdHlzlShegRylJTJnUErNRn6Gg=; b=qjRiPeA0EwAbaEHf2/baeguNvSANO9u+WbNOaCuBr9QkOuL16iIXJUV2OWTQuafEvC bXc8HzKpnuzDOW7cqSeyHl2NajphBcQx/I+/dfR/iVSgg5DKxKN1HOSavaSL3sAw409C 2y86bY+vEdonlcEeNvkXD+0v5du7SCfVIO6TPnEV2Tumy0/Crss3LOe9ntu/lS2kGsfD TdavcyOl24jbXkziSf9741psXfL9njVA8CflpKgJMYG9tDO2GUT0YVMPS41huSmhUUf+ 4kT0Xh3MXGq2ZlimZ6diddk45b9gm/okENhZzLL3zbuDZY4kCBHK+ewbduXGeB0CTtH+ JEdg== 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 kj25-20020a170907765900b00991c63fc491si749146ejc.773.2023.06.26.01.33.25; Mon, 26 Jun 2023 01:33:49 -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 S229940AbjFZIKZ (ORCPT + 99 others); Mon, 26 Jun 2023 04:10:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbjFZIKQ (ORCPT ); Mon, 26 Jun 2023 04:10:16 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F8110DF; Mon, 26 Jun 2023 01:10:07 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QqL9j66NBz4f4FTB; Mon, 26 Jun 2023 16:10:01 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgAHcLPWR5lkQbNDMg--.19922S6; Mon, 26 Jun 2023 16:10:02 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com, ashok_raj@linux.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 v4 2/4] block/badblocks: only set bb->changed/unacked_exist when badblocks changes Date: Mon, 26 Jun 2023 16:09:11 +0800 Message-Id: <20230626080913.3493135-3-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626080913.3493135-1-linan666@huaweicloud.com> References: <20230626080913.3493135-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgAHcLPWR5lkQbNDMg--.19922S6 X-Coremail-Antispam: 1UD129KBjvJXoW7Cry8uF1DCr43tFyrAw1UWrg_yoW8Cr15pF 98C3WftrWjg3WIgF1UZ3ZxKw1FgayfXF48Gr4ay345Gry8G3s3tF1vq34aqa4jgr1avrnI qa4FgryYva4DC37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmjb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU1H7K7UUUUU== 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?1769753468527370344?= X-GMAIL-MSGID: =?utf-8?q?1769753468527370344?= From: Li Nan In badblocks_set(), even if no badblocks changes, bb->changed and unacked_exist will still be set. Only set 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 f28e971a4b94..7b1ad364e85c 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 Mon Jun 26 08:09:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 112760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7324552vqr; Mon, 26 Jun 2023 01:24:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6R8FMzv/Rc59LCI+ETK6Tv7++aTju8WZG/J9j9cdxcsiBvpL4oARopIijcxRFmUpq7TdB6 X-Received: by 2002:a17:903:124c:b0:1b1:dfbd:a18c with SMTP id u12-20020a170903124c00b001b1dfbda18cmr2810210plh.39.1687767877909; Mon, 26 Jun 2023 01:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687767877; cv=none; d=google.com; s=arc-20160816; b=aNFQ7jzyNkD4tc1jgI+Xyri+C9OvZ+9jfIRjuBdVInWDFeQ8UsHejMCbvxNNdg+1lL efLj8p0uypBlnm72ASl0IZtlS999i/GUo5jKpIpQHTJfhXczi+RgxBErvmBuW9R17UU+ t+uCBZLci/Ppe/uRobXDRqYfuLZ17FDOoz/LyAI60k2fnD23PnWREyqkxutaiA2po9od IzRCL5HUwhz7jcLq5AH3wzRQAelGUypkQjJIJLdK+cN6N9L/um4cPbicB9MbI8mmadpT dRaWy44WTa0MrQpqL8XxgsdTrlHUFGEAxieA8fd6mIJE4ZxaDXQxXFk2bFs2TPt8W+Ev rHZw== 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=ymkhh/WJfPYnsFhekxzHnMKh4BfQIMsBm9vi/AI32YM=; fh=3eCKTJ3QhUFKE6vQUOdHlzlShegRylJTJnUErNRn6Gg=; b=gm/sQpxUbrCH97qXG1z6ONmmRZYHY8PshRlodfr05ztGqiFBjIK4Gmu5qvB3KKTZll asEHFM28zJ7bqR8kJIZ5P4dr76gF0TEpN5B73hGv8CzgqZdW8BJXJLmjHmgnZPcn+HdU AhCDrOi4pFJ4iKbulSTD3MqC43F3jJraPwr19240uvCvJnutNbwckYQxVfQlEcuA+LPX BSQJ6g/DYoU7WtaRYqddFT5NEVstNA2J8pDkL2aOmyFjNE+X+b0E6PeFfG6tj5ZAoLeJ E7eFqwE9o9704abdMB8vxDWhmC9gNV03C675/v/6/aNh424gTll//+zZqL7hsq5M9Fnx 6Lkg== 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 t19-20020a170902e1d300b001b3be6856dasi4124287pla.628.2023.06.26.01.24.24; Mon, 26 Jun 2023 01:24:37 -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 S230133AbjFZIKX (ORCPT + 99 others); Mon, 26 Jun 2023 04:10:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230076AbjFZIKQ (ORCPT ); Mon, 26 Jun 2023 04:10:16 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A576E7A; Mon, 26 Jun 2023 01:10:07 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QqL9k1cbVz4f41Vn; Mon, 26 Jun 2023 16:10:02 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgAHcLPWR5lkQbNDMg--.19922S7; Mon, 26 Jun 2023 16:10:03 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com, ashok_raj@linux.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 v4 3/4] block/badblocks: fix badblocks loss when badblocks combine Date: Mon, 26 Jun 2023 16:09:12 +0800 Message-Id: <20230626080913.3493135-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626080913.3493135-1-linan666@huaweicloud.com> References: <20230626080913.3493135-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgAHcLPWR5lkQbNDMg--.19922S7 X-Coremail-Antispam: 1UD129KBjvJXoW7ur17tr4UuFWkKF1UtF1UKFg_yoW8CF18pw 1fXw1agF18W3W093W8XF1UGF1093W7JF4UJ3y5J3W8WFyUAw1xKF1qqw1YvrW0qF4fXFn0 vay8WryUXFWfC37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmjb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU1BOJ7UUUUU== 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?1769752890363042988?= X-GMAIL-MSGID: =?utf-8?q?1769752890363042988?= From: Li Nan badblocks will loss if set it as below: $ echo 1 1 > bad_blocks $ echo 3 1 > bad_blocks $ echo 1 4 > bad_blocks $ cat bad_blocks 1 3 After the fix, in the same scenario, it will be: $ cat bad_blocks 1 4 In badblocks_set(), if set a new badblocks, first find two existing badblocks adjacent to it, named lo and hi. Then try to merge new with lo. If merge success and there is an intersection between lo and hi, try to combine lo and hi. set 1 4 binary-search: lo: 1 1 |____| hi: 3 1 |____| merge with lo: lo: 1 4 |___________________| hi: 3 1 |____| combine lo and hi: result: 1 3 |______________| | -> hi's end |____| -> lost Now, the end of combined badblocks must be hi's end. However, it should be the larger one between lo and hi. Fix it. 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 7b1ad364e85c..c1745b76d8f1 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 Mon Jun 26 08:09:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 112759 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7321510vqr; Mon, 26 Jun 2023 01:16:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wHYHZve8lIyUI9fQky+GhDISY97qzhDDcsm3VVVcwoaw7jRTFY4086+L8VFJXC7H73180 X-Received: by 2002:a92:509:0:b0:341:e2aa:3552 with SMTP id q9-20020a920509000000b00341e2aa3552mr21180541ile.4.1687767409019; Mon, 26 Jun 2023 01:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687767408; cv=none; d=google.com; s=arc-20160816; b=HaDN2la5w/RQPsbsGwHDX6bMM2f89cWNmuhB5k8Liz4sSm5JV2mqOKhQxed/FNwtoS QaFlnUwvxs7nDsdfMqGZKa5joz1Hr/ge5UdHBxyszbo+wjRo1oXEfnVxkSxhAzICGJE/ 07+g3qJmVa45Z1zgGqkCUiooL7nAvzEhRsGzFOwC1f3DRaJZp1WU47MBEqnhZrmuZScb HUGLLuK/lh8AGGnkseIQ2DmHyTsi26uLfSldy1hmZ07RXznJC5mcCoudWPWQ0QnRspJP lbN3Na5sNfWO2iLDTEdbyXggGczY1w2+lKIAlLETfACMQsNRRnAnPcPcgig87b839sw2 gwVw== 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=4qZ4zDTDAi6SGMlhNlCNMjH0ZywZtUDNrty6kXE/6c4=; fh=3eCKTJ3QhUFKE6vQUOdHlzlShegRylJTJnUErNRn6Gg=; b=wHinEZ1QCMEev3ub7RuCPQXBql0+Tf7/Z+W4O/yKwSEQTBNyhr7NFgFv2y5xkeLjbK +ahG51t0UzzG4PPZEQYV1VCSDFpL1uk+sMlUrw0PdQdskqjqSI8X+zo66pbiO/dbWzfb ObGNSESvhsxa6glkncQYIdKjq6hLsCeS8UHwxZMmxvBcPi27xN0fGZHQLousozcJKE+l 4P6NJtPI1N32CrIb3G51TiQSioJqk/a3qOVNx3FucAJi3VFcaBb4H5DEq4QreQHYZW3w nhiuW3pCEqvlpBaVoxxQS+UGt918uSrjKvlWvHzn7xoPY6tO0Eh9s6yPn09qy3qkqiVv dB/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 p55-20020a056a0026f700b0065dfb27ee3fsi3424223pfw.246.2023.06.26.01.16.36; Mon, 26 Jun 2023 01:16:48 -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 S229757AbjFZIK3 (ORCPT + 99 others); Mon, 26 Jun 2023 04:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230088AbjFZIKN (ORCPT ); Mon, 26 Jun 2023 04:10:13 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43AAC10DB; Mon, 26 Jun 2023 01:10:06 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QqL9k4m2yz4f4689; Mon, 26 Jun 2023 16:10:02 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgAHcLPWR5lkQbNDMg--.19922S8; Mon, 26 Jun 2023 16:10:03 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com, ashok_raj@linux.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 v4 4/4] block/badblocks: fix the bug of reverse order Date: Mon, 26 Jun 2023 16:09:13 +0800 Message-Id: <20230626080913.3493135-5-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626080913.3493135-1-linan666@huaweicloud.com> References: <20230626080913.3493135-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgAHcLPWR5lkQbNDMg--.19922S8 X-Coremail-Antispam: 1UD129KBjvJXoW7uF43Kw4rWFy3GrWDtF18Zrb_yoW8Gr4rpF nxJwn3Gryjgr1UZa18Za4UGr4xCa43XF4UGw45Zr1UGasrJw1xJF1kXayYqryjqF43Xw1q v3W5uryUZa48C37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVF 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?1769752398399060323?= X-GMAIL-MSGID: =?utf-8?q?1769752398399060323?= From: Li Nan Badblocks are arranged from small to large, but order of badblocks will be reversed if we set a large area at once as below: $ echo 0 2048 > bad_blocks $ cat bad_blocks 1536 512 1024 512 512 512 0 512 Actually, it should be: $ echo 0 2048 > bad_blocks $ cat bad_blocks 0 512 512 512 1024 512 1536 512 'hi' remains unchanged while setting continuous badblocks is wrong, the next badblocks is greater than 'p[hi]', and it should be added to 'p[hi+1]'. Let 'hi' +1 each cycle. (0 512) 0 512 |_________| |_________| p[hi] p[hi] (512 512) (0 512) fix 0 512 1024 |_________|_________| ===> |_________|_________| p[hi] p[hi+1] (1024 512)(512 512) (0 512) 0 512 1024 1536 |_________|_________|_________| |_________|_________|_________| p[hi] p[hi+2] ... 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 c1745b76d8f1..b79d37a4bf0e 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -301,6 +301,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; } }