Message ID | 20230621172052.1499919-4-linan666@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4231311vqr; Wed, 21 Jun 2023 02:26:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54lL8A8KiUMmT4R3GIucFOwaDSGLwlveFIviulNrrrBbeWJ9RaWuSvmXRvcmDiF/tfLwCI X-Received: by 2002:a9d:748a:0:b0:6af:9900:1a87 with SMTP id t10-20020a9d748a000000b006af99001a87mr9912553otk.29.1687339598269; Wed, 21 Jun 2023 02:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339598; cv=none; d=google.com; s=arc-20160816; b=vSmxJwg6mOSw7TZnEy1XaQ7OhCoRihoMwRI6YmRbEZXygLEopIrVuWULuutAW1rkP3 uAb67x3+8nOgHxJk9/IpCxfXQs+3dBF490yty9t6WgsYjW/oIWmgEno/UiVt0rILc+es tNp3eZ+URkOyowUb3Px30gFKRqOdsFMULw5uSa+3IuCxj1gRFfwgUsXHZKxPtgPGkaSN G+w5NnFHy/zlOIuFTTtx9raszSc1uLbxU90jrN63koKO8rtpzN/ovexQeo1Fgao9KKOH yTi5IUZb+d0r8KFc/Ctb67wxajHE5+1+ku1ejmsSiJsJcUHRFEzPN3+eGNFRDZJxRV3f XpvQ== 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=7YDMbJGlbrs6jgM4souE92x9DKKzPqH3yLqogJfRM3A=; b=M1I7pMfofYeJHMK0IVdA1VrtOnw/I8ZjY4wPty9cAaYaFBRND/hgOhOWn2KeYg0+hB e9lt+gk9JA1fTiANEpIAD9h4FkObE3gyBx5PO6szDZWSaHuf1iHqlYRyyKkXaf+syYBl OKK3oqlg32Z5r5X+bXxEloO/LPkoQ6IG2UnMjslG6+SdXxDwunA1RPDtT8fHkEre7+8F H2u/mtsKwPkzTlyhkolm7caWXRqMjr3teDPiTPtJbEw9ozNXNw2ZqwI4yT/bVrEEO1dn td6s/9aXsvyX40VxMd9cW8s1ERdoKVtKHJRZ6jXE6mz0hX7dwoIEz/HR0YHZiflXPYoh 7uJg== 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 h193-20020a636cca000000b005030925d31asi3538389pgc.203.2023.06.21.02.26.20; Wed, 21 Jun 2023 02:26:38 -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 S231363AbjFUJWj (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Wed, 21 Jun 2023 05:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbjFUJW2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 21 Jun 2023 05:22:28 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A01C10F8; Wed, 21 Jun 2023 02:22:26 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QmJ1W09Xsz4f3pFv; Wed, 21 Jun 2023 17:22:23 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgCHLaFMwZJk+OrGMA--.39130S7; Wed, 21 Jun 2023 17:22:23 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, dan.j.williams@intel.com, vishal.l.verma@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 v3 3/4] block/badblocks: fix badblocks loss when badblocks combine Date: Thu, 22 Jun 2023 01:20:51 +0800 Message-Id: <20230621172052.1499919-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230621172052.1499919-1-linan666@huaweicloud.com> References: <20230621172052.1499919-1-linan666@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgCHLaFMwZJk+OrGMA--.39130S7 X-Coremail-Antispam: 1UD129KBjvJXoWxJrW8urW3AryDWw17Kry3urg_yoW8XrW5pw 1fZwnIgr1IgFyv9F4UX3WDGF1Sg3Z7JF45Ga1Yqa48uFyDAw1xKF4vq3WYvrW0gF4xXF90 va1rWryDZFyfG37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQIb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcx kEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v2 6r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2 Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAK I48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7 xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xII jxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x02 67AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU0gJ57UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, KHOP_HELO_FCRDNS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769303806135035879?= X-GMAIL-MSGID: =?utf-8?q?1769303806135035879?= |
Series |
block/badblocks: fix badblocks setting error
|
|
Commit Message
Li Nan
June 21, 2023, 5:20 p.m. UTC
From: Li Nan <linan122@huawei.com> 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 <linan122@huawei.com> --- block/badblocks.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
Comments
On Thu, Jun 22, 2023 at 01:20:51AM +0800, linan666@huaweicloud.com wrote: > From: Li Nan <linan122@huawei.com> > > 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]. Reconsider rewriting the commit log. It seems you converted code to sentence ;-). Also it might help to show after the patch how the above example would be for cat bad_blocks > > Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") > Signed-off-by: Li Nan <linan122@huawei.com> > --- > 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--; > -- > 2.39.2 >
在 2023/6/21 22:09, Ashok Raj 写道: > On Thu, Jun 22, 2023 at 01:20:51AM +0800, linan666@huaweicloud.com wrote: >> From: Li Nan <linan122@huawei.com> >> >> 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]. > > Reconsider rewriting the commit log. It seems you converted code to > sentence ;-). I will rewrite log. > > Also it might help to show after the patch how the above example would be > for cat bad_blocks > after patch: # cat bad_blocks 1 5 I will show it in next version. Thanks for your suggestion. >> >> Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") >> Signed-off-by: Li Nan <linan122@huawei.com> >> --- >> 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--; >> -- >> 2.39.2 >> > > .
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--;