Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3711466pxb; Mon, 27 Sep 2021 00:27:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrSNY7Sa/4x4eWYJXx3vbbctWwe4VBqHiqFQBZz0vbYm9hqaYM8VSN98hGDJrEOvZFGQHV X-Received: by 2002:a17:906:278f:: with SMTP id j15mr2944399ejc.202.1632727659267; Mon, 27 Sep 2021 00:27:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632727659; cv=none; d=google.com; s=arc-20160816; b=q5dmR2LbXVBFMyUbyvi6/4drvgImL7oc7y5zvy1p8uFKU/84ciETGK8yXu01phkflx DpiYrMvEHjKxYhPhghC3d3nm2qRVZn83fLJ+zl6YM/zG8IJgHP0x1uy98318qzvpsyD2 F9XXO/I8kGeKQtGWqtJtjOHjGf7HZcLhldbyweZtazHEDawn5oPAHEHiqNDqmcaTyonp k2tVTj5+/1txUi0sO71mJPQKujbe78r1MuQU/u4s4BYjB0TQ7lasoJwQ1td7++ZvH5Lw eOSpq2KI8u2cYYif5EHTKorEl6yeDA/lO7uwGKB8NgIZmHk+kagPvj4SRx1sZHF5eTYp nb3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=zRcqo9ZRM0x4X1qC1VhpLMYfBLcHfFC5rDADl7ze48U=; b=wmnz2+iqOHzW3dABnmolMRnoM2UkwDSWxUH+MO604CbGZzN+5423silsHDFs4K4g4R 3L5P/bXh2JwNjkytF22kb3cjcC5zAPwUWknmDqdzhM7UecZ/YsxkIjntJFlRB5f+VeyV cAtWxVe1tA1NSqDSHgZDJ62Lg0ORhfcZQQLf0WFB49y/1C/bN+H7yLd+9y4KISA+gt2K pllBeTYpcyON6pNBqeRS0P2YEi7c7GP6hgB7jynD4I7DF1+ps46CcfE+TtGwC9H11ZXY xNrzZv5SUXoZHSKG1ICrZBizAy0v91yo0atYIDO1pxjdHQwRoqPMWhcsPYEND4nfPhJl V31A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bOT9Mpcf; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y97si17412617ede.520.2021.09.27.00.27.16; Mon, 27 Sep 2021 00:27:39 -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=@gmail.com header.s=20210112 header.b=bOT9Mpcf; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233319AbhI0HZo (ORCPT + 99 others); Mon, 27 Sep 2021 03:25:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233149AbhI0HZl (ORCPT ); Mon, 27 Sep 2021 03:25:41 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40EFFC061570; Mon, 27 Sep 2021 00:24:03 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id rm6-20020a17090b3ec600b0019ece2bdd20so3131140pjb.1; Mon, 27 Sep 2021 00:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=zRcqo9ZRM0x4X1qC1VhpLMYfBLcHfFC5rDADl7ze48U=; b=bOT9MpcfrFqg+qIyclqxXB8nUB7bsphZ1S/xpNatC4515Qo0sU2pi7x/EqYfPeIecW mlWgsxwLB5US417ZTRVOTKD08cp+ghdFf4H9oqoHaxWhlzirb3f2FWOuxybhJkvZ/+ja qKOa4lVx0cxzVRr3tICl9/dqMwoYYiDuILPunoXKMJ988zvC3pkXz84SY02xR91xqMeK Mhp2uzUyyW2uZ/0Nc8HRp7/1fexH3wr5WeeDqSNePU1G8UM800sMYpIUEBhhJ1q8EClr 3QGi9A8k5/PF2XUlSqn4bI8rhW3d22Oma7WyaTjuyEkKGu9oyDLD/vKogouMl84vHBQO 3QhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=zRcqo9ZRM0x4X1qC1VhpLMYfBLcHfFC5rDADl7ze48U=; b=y8epyuEL5Y8AOU5pIp9WgsX+eXP1mdh8zJLJTIEloq39mccmRvGTTWapYCHIiYp1AA LRQT92TDn33PygoHn4j9o91DM8QnfwdMHjRdVjU92Sd+VELa6UWIXyWnh97K2BK2jz5f QqZB3eIokKMpHNe2tZOOHCLMPYt9qlcL4cah9YiNbkRrOFqfrwoLQvNaKI8aq3vDgQYn jAgjx1QsLB3fv94n8kUBCm0j/LTRTJZfWnqpbik84OfyNwEKpUO4+hietG9TuWdJbyDn o/qOW3fBhY1CjXULJnozwsOCHw5M4RlTfQnJxNg7GuQI1MJRJkrREddEQYYy/YFkEHBR R77Q== X-Gm-Message-State: AOAM5320wmw7B5Xz3wm4EwfjucL2GuQ0baVKIdRIYSEN0kV45v4u/SKI PAr0yzTmJu7IN+WLlDKeIzpsbmD50AzSjQ== X-Received: by 2002:a17:90a:bc8d:: with SMTP id x13mr18015275pjr.9.1632727442789; Mon, 27 Sep 2021 00:24:02 -0700 (PDT) Received: from [10.239.207.187] ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id q16sm14532927pfh.16.2021.09.27.00.23.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Sep 2021 00:24:02 -0700 (PDT) Message-ID: Date: Mon, 27 Sep 2021 15:23:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v3 1/6] badblocks: add more helper structure and routines in badblocks.h Content-Language: en-US To: Coly Li , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-raid@vger.kernel.org, nvdimm@lists.linux.dev Cc: antlists@youngman.org.uk, Dan Williams , Hannes Reinecke , Jens Axboe , NeilBrown , Richard Fan , Vishal L Verma References: <20210913163643.10233-1-colyli@suse.de> <20210913163643.10233-2-colyli@suse.de> From: Geliang Tang In-Reply-To: <20210913163643.10233-2-colyli@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Coly, On 9/14/21 00:36, Coly Li wrote: > This patch adds the following helper structure and routines into > badblocks.h, > - struct badblocks_context > This structure is used in improved badblocks code for bad table > iteration. > - BB_END() > The macro to culculate end LBA of a bad range record from bad > table. > - badblocks_full() and badblocks_empty() > The inline routines to check whether bad table is full or empty. > - set_changed() and clear_changed() > The inline routines to set and clear 'changed' tag from struct > badblocks. > > These new helper structure and routines can help to make the code more > clear, they will be used in the improved badblocks code in following > patches. > > Signed-off-by: Coly Li > Cc: Dan Williams > Cc: Hannes Reinecke > Cc: Jens Axboe > Cc: NeilBrown > Cc: Richard Fan > Cc: Vishal L Verma > --- > include/linux/badblocks.h | 32 ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/include/linux/badblocks.h b/include/linux/badblocks.h > index 2426276b9bd3..166161842d1f 100644 > --- a/include/linux/badblocks.h > +++ b/include/linux/badblocks.h > @@ -15,6 +15,7 @@ > #define BB_OFFSET(x) (((x) & BB_OFFSET_MASK) >> 9) > #define BB_LEN(x) (((x) & BB_LEN_MASK) + 1) > #define BB_ACK(x) (!!((x) & BB_ACK_MASK)) > +#define BB_END(x) (BB_OFFSET(x) + BB_LEN(x)) > #define BB_MAKE(a, l, ack) (((a)<<9) | ((l)-1) | ((u64)(!!(ack)) << 63)) > > /* Bad block numbers are stored sorted in a single page. > @@ -41,6 +42,14 @@ struct badblocks { > sector_t size; /* in sectors */ > }; > > +struct badblocks_context { > + sector_t start; > + sector_t len; I think the type of 'len' should be 'int' instead of 'sector_t', since we used 'int sectors' as one of the arguments of _badblocks_set(). > + int ack; > + sector_t orig_start; > + sector_t orig_len; I think 'orig_start' and 'orig_len' can be dropped, see comments in patch 3. > +}; > + > int badblocks_check(struct badblocks *bb, sector_t s, int sectors, > sector_t *first_bad, int *bad_sectors); > int badblocks_set(struct badblocks *bb, sector_t s, int sectors, > @@ -63,4 +72,27 @@ static inline void devm_exit_badblocks(struct device *dev, struct badblocks *bb) > } > badblocks_exit(bb); > } > + > +static inline int badblocks_full(struct badblocks *bb) > +{ > + return (bb->count >= MAX_BADBLOCKS); > +} > + > +static inline int badblocks_empty(struct badblocks *bb) > +{ > + return (bb->count == 0); > +} > + > +static inline void set_changed(struct badblocks *bb) > +{ > + if (bb->changed != 1) > + bb->changed = 1; > +} > + > +static inline void clear_changed(struct badblocks *bb) > +{ > + if (bb->changed != 0) > + bb->changed = 0; > +} > + > #endif >