Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3745596pxb; Mon, 27 Sep 2021 01:21:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtNb37xBVUEnp4PTuaX2ZZ0UPgLmGMcsn2YTsbTW6Wmj0sd74Tb/LmcW3z4BxpQmWCBJz+ X-Received: by 2002:a17:907:1c01:: with SMTP id nc1mr26516781ejc.504.1632730916916; Mon, 27 Sep 2021 01:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632730916; cv=none; d=google.com; s=arc-20160816; b=EPVSq5bkkmbrCXHD2K9FJyV1+Lfo3SW7D+lE0sDTxN9u1k8G6l35UxsUpolBaOiRBM Z+7lSM09lEMJqqKr/rVunCYBZ+n1JXzBL0rbMCvvwnOeGEGowwmOIa6U6N3fXos/B65h tA42sjz+7d23zXkfXVi/D+KANv76ymgI06hlv38Xz5l/l33JuYBFWCPCbKWgr0QTToxw 7r/BIbdAWOgkQxFNOir9doEistwAUs8tLQJ3ZHrej7W/KsK05zoDFE0FbLSqVdJHXHj9 jgiLixBP8/rJtwbM91q04marrFmCjueBRg0Ka7senqRKSqmJkbPKkFnzWTbE88qj6+0R hrfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:dkim-signature; bh=zGL/AMe26hmAIklf9HbbaB1fkOCI1nKEMJa0VhuyrZg=; b=j14Bk46GvJACQH4uFIBGur9X2ARUBGvPQK1GyBCVI9+PyQvsnYozqaeq6uS8G1qQBk PL+3dIwx1dYuZ2JRX9VeoVHTJYGrMWDEI3Ha2COB+r5IYwyJBg3/1BbGVG8XX4tR+xXm y+gMaNPsoPfiYRyUJghw56W1+3UcmHK+peFcZW9pnQZbFSXzdBmN2z2jdzNrKYphM85v eXKlclVv6WyMU9mTqYVgxjrVreRTGmwj+DqPjoTnXUOK1M5I5HfOM/HmkvgQHy6DdwS6 gGmyf1mMK8rDib7CQDFewP8i+ulCT4/pGRbSLTI6WE2eMws97BWlCXCou9W0/x1vYxMu coeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=VP+ovcQ3; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b27si19640369ejl.260.2021.09.27.01.21.33; Mon, 27 Sep 2021 01:21:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=VP+ovcQ3; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233434AbhI0ITd (ORCPT + 99 others); Mon, 27 Sep 2021 04:19:33 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:52594 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233404AbhI0ITc (ORCPT ); Mon, 27 Sep 2021 04:19:32 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9CC9A220B7; Mon, 27 Sep 2021 08:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632730673; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zGL/AMe26hmAIklf9HbbaB1fkOCI1nKEMJa0VhuyrZg=; b=VP+ovcQ35C+CrLSKQ3QLLeawqkoxFoBvpKmZYgQ1zKhEmObNj8c6BO+aaWkiFkW0DTu0eq QgPhEU/v3WpVe2jdupbqwcleCICMaXAhNLYTC0lRMu+Bvt1lpyT8spT9PqT1rZKVnhS/41 4RkzhpPseqqDtrkEtFZkhOUshikFLto= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632730673; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zGL/AMe26hmAIklf9HbbaB1fkOCI1nKEMJa0VhuyrZg=; b=Zck/hcOT5GU0qM+t7QHk+KwnLsbOtRs64yLXCIeBds7UZ/fTeZmiJHmH0DlswYLo4cDcI9 NTU9Cxpca+qHaIAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AEEEC13A42; Mon, 27 Sep 2021 08:17:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zO+cHi5+UWHlRwAAMHmgww (envelope-from ); Mon, 27 Sep 2021 08:17:50 +0000 Subject: Re: [PATCH v3 2/6] badblocks: add helper routines for badblock ranges handling To: Geliang Tang Cc: antlists@youngman.org.uk, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-raid@vger.kernel.org, linux-block@vger.kernel.org, Dan Williams , Hannes Reinecke , Jens Axboe , NeilBrown , Richard Fan , Vishal L Verma References: <20210913163643.10233-1-colyli@suse.de> <20210913163643.10233-3-colyli@suse.de> From: Coly Li Message-ID: Date: Mon, 27 Sep 2021 16:17:47 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/27/21 3:25 PM, Geliang Tang wrote: > On 9/14/21 00:36, Coly Li wrote: >> This patch adds several helper routines to improve badblock ranges >> handling. These helper routines will be used later in the improved >> version of badblocks_set()/badblocks_clear()/badblocks_check(). >> >> - Helpers prev_by_hint() and prev_badblocks() are used to find the bad >>    range from bad table which the searching range starts at or after. >> >> - The following helpers are to decide the relative layout between the >>    manipulating range and existing bad block range from bad table. >>    - can_merge_behind() >>      Return 'true' if the manipulating range can backward merge with the >>      bad block range. >>    - can_merge_front() >>      Return 'true' if the manipulating range can forward merge with the >>      bad block range. >>    - can_combine_front() >>      Return 'true' if two adjacent bad block ranges before the >>      manipulating range can be merged. >>    - overlap_front() >>      Return 'true' if the manipulating range exactly overlaps with the >>      bad block range in front of its range. >>    - overlap_behind() >>      Return 'true' if the manipulating range exactly overlaps with the >>      bad block range behind its range. >>    - can_front_overwrite() >>      Return 'true' if the manipulating range can forward overwrite the >>      bad block range in front of its range. >> >> - The following helpers are to add the manipulating range into the bad >>    block table. Different routine is called with the specific relative >>    layout between the maniplating range and other bad block range in the >>    bad block table. >>    - behind_merge() >>      Merge the maniplating range with the bad block range behind its >>      range, and return the number of merged length in unit of sector. >>    - front_merge() >>      Merge the maniplating range with the bad block range in front of >>      its range, and return the number of merged length in unit of >> sector. >>    - front_combine() >>      Combine the two adjacent bad block ranges before the manipulating >>      range into a larger one. >>    - front_overwrite() >>      Overwrite partial of whole bad block range which is in front of the >>      manipulating range. The overwrite may split existing bad block >> range >>      and generate more bad block ranges into the bad block table. >>    - insert_at() >>      Insert the manipulating range at a specific location in the bad >>      block table. >> >> All the above helpers are used in later patches to improve the bad block >> ranges handling for badblocks_set()/badblocks_clear()/badblocks_check(). >> >> Signed-off-by: Coly Li >> Cc: Dan Williams >> Cc: Hannes Reinecke >> Cc: Jens Axboe >> Cc: NeilBrown >> Cc: Richard Fan >> Cc: Vishal L Verma >> --- >>   block/badblocks.c | 374 ++++++++++++++++++++++++++++++++++++++++++++++ >>   1 file changed, 374 insertions(+) >> >> diff --git a/block/badblocks.c b/block/badblocks.c >> index d39056630d9c..efe316181e05 100644 >> --- a/block/badblocks.c >> +++ b/block/badblocks.c >> @@ -16,6 +16,380 @@ >>   #include >>   #include >>   +/* >> + * Find the range starts at-or-before 's' from bad table. The search >> + * starts from index 'hint' and stops at index 'hint_end' from the bad >> + * table. >> + */ >> +static int prev_by_hint(struct badblocks *bb, sector_t s, int hint) >> +{ >> +    u64 *p = bb->page; >> +    int ret = -1; >> +    int hint_end = hint + 2; > > How about declaring these variables following the "reverse Xmas tree" > order. > It makes sense. I will do this in whole set for next version. Thanks for your review. Coly Li