Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9448492rwd; Wed, 21 Jun 2023 07:35:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7O+CNS4u/UHcKOgf4MjtxC4/QHOnBQafcmK69dvL5gky8JRTskpERWxXLKXyWu36smLWaf X-Received: by 2002:a17:90a:f182:b0:258:842e:e23b with SMTP id bv2-20020a17090af18200b00258842ee23bmr7175904pjb.34.1687358140985; Wed, 21 Jun 2023 07:35:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687358140; cv=none; d=google.com; s=arc-20160816; b=F/ra1cGI/sAk3VHAy7nBMDOcb6UP6TY/8MLYyscp+xDLmaefCPUYnBnI4QykFKr7iv KybtUGPBy/pzn3QwE/v35jVdgrNgDSElAT9inblakFLzZhhnK41g9SkZL30lOf6gAKr9 4PJ81cBaQSL1L1zNMttASt4dWesNEbqucP25JXap3Q4bKMuS5E8ygqEWAf+ZIvFV4G7P WZb7TVsf7yqZsm3dv/58B2/cSUhoKdylHvNpTpNkfUrGkvIohBhm2BLG37SS3VIdZHz8 ymc2dMF8PFsLw+N+Q4crv3bbLat6O2b/7mJQbMglurWZMapb8486e2vOTkmDeQUNEHbg stMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xvNgWPRh+9jwj8/RGA7XaU9+YSJUwNiCHm9qrldjRQ0=; b=frUtp/ekx4w649uDGZ5J28BtzQ0TjVOw9fydI21Shw1tCxhqQZLSJmFwJ+1f17Kd8x z/G4i+nKXUCb/XA23ij3JLinEAHet1Gl8dxKw4b8heL4jfiNH3/+QneTl3iAcYwIO+zH geRIExe48ARKg9CNEm/FPXjvnBBK6DkBGw9QiEwjHlZAezWhBprRNJaEOSfsD2g2d0Iv OKaThcUFjar7RejZ7y5mudGtyfmdP0QKkUiddgJuKsx8Ohu9+VDC130le7fLK+Nr1Zwv SePzn5LO9ASYtynpH3TKVU97dA2aiqN4JVkZA3tmiJ+0J5Sg68USj4TB3z7Fao3NsulQ LglA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fD1HzSBM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a170902ec8500b001b075efce34si4597736plg.388.2023.06.21.07.35.28; Wed, 21 Jun 2023 07:35:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fD1HzSBM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232875AbjFUONG (ORCPT + 99 others); Wed, 21 Jun 2023 10:13:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232860AbjFUOMt (ORCPT ); Wed, 21 Jun 2023 10:12:49 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75C8426AF; Wed, 21 Jun 2023 07:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687356723; x=1718892723; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=9QEdUvQrDLjg3arxdysgvHN5B7VgeWjap2iI9K/7yhU=; b=fD1HzSBMcvj6s7z8SPbJUTCVpReS04wup6HFhxHQM6xCjrcQu5i09MCV RmrJkfRtx+aktMmfbpsfIZ0TKAAHJC5VdmxI6n1dHsmVsS+M9ZBs7gU7u yiiWBuVk8j9H8L5pIxDNgJN1nSiALuFN+/vtBZ6nYluDTv3zmmbt2ZZyO Wsmox1YQ+zsdc7z42W8My7tJRMptJVUjQaE6skrADSmEFZdzHpbRhpzWe AfVVMkhCsm9nb3Fcd5LeTaaEKzNOr3iBY9/OKPfN36dqcJpFXL6In7Glf QWr+PaPvkv+bTyTjEALNXrR9z+Sxuf1BK4DUzzOXh7ozI6Dh4Q84gW5/t Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="363604495" X-IronPort-AV: E=Sophos;i="6.00,260,1681196400"; d="scan'208";a="363604495" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 07:11:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="714500912" X-IronPort-AV: E=Sophos;i="6.00,260,1681196400"; d="scan'208";a="714500912" Received: from araj-dh-work.jf.intel.com (HELO araj-dh-work) ([10.165.157.158]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 07:11:34 -0700 Date: Wed, 21 Jun 2023 07:09:56 -0700 From: Ashok Raj To: linan666@huaweicloud.com Cc: axboe@kernel.dk, linan122@huawei.com, dan.j.williams@intel.com, vishal.l.verma@intel.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com, Ashok Raj Subject: Re: [PATCH v3 3/4] block/badblocks: fix badblocks loss when badblocks combine Message-ID: References: <20230621172052.1499919-1-linan666@huaweicloud.com> <20230621172052.1499919-4-linan666@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230621172052.1499919-4-linan666@huaweicloud.com> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Thu, Jun 22, 2023 at 01:20:51AM +0800, linan666@huaweicloud.com wrote: > 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]. 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 > --- > 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 >