Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1988623pxb; Mon, 13 Sep 2021 09:33:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx43iERl+vl7/DGBCrAN1BfWPUY93AgTZYpnKo+ggvAqHE3kZcbTywL43YENIjsmSPAolbz X-Received: by 2002:a05:6402:48b:: with SMTP id k11mr14391664edv.7.1631550785075; Mon, 13 Sep 2021 09:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631550785; cv=none; d=google.com; s=arc-20160816; b=MaGGEeXQmKhP00MFPTe/EwAunb9Vw2OoYKrQobrJPqvSWFqANJpYYEjqgYaJpuDnWZ rRRmW5/T/XBFZjc8J0StAk8h1ZoFQQc80EPlpm/zuHlkw0hRBa3R35W73M4HViqp7Z5I bRnnbDCPyYPceTY0L1ncEWNlYKeh+L66TB9Ye4jjpEU/Bz6FwE1s4l+jcdq1nWZL9Ac+ NS2GDBaxsHBMWJpQYKA6kaggNVdy3TW61u9d3+Cy3UZ54FNMGSwYmTCbMNPuKs/ohaiB sn9wqpFkSX5FZQK3pAiyUiqZ8B4X/h/QoUPHEKdEIRq459OcmeO28ltOUVn7TjyDjSQ7 /utA== 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 :dkim-signature:dkim-signature; bh=1cLnNgahnRqZc9jVnTIqodTE0s49FfRLlP6thBPVEdE=; b=QebdcG30fjJ9u93x5XxSC7MR9jAUKLE8nlwgAmqIEEtw6VTxpu0fFyedZGwx8q6yZb sJP3U7GJryuUSpa+kq2JS7B3NCyxLgz4ZvU62AvvDCM0LL3p3F2b03t2mLbXSErCHaSY r8ib+H6kAP9MEr2Js4TPwyOwa6Ob6ET7v3xfj5ZlFNsw0OgnDDQkVWfh8lBpCU3AoCh/ Ph5teeycUBpwBSUr00V+FPDE5orgOB4H/H/1qbbhoNwzom3ZCdpxgLZYXtxE+OWhbG9Z F5FA9SHozr4c57zXS7ecFHMYTmz7S51GLDEJ4g2ZC5+ZSDXwb1xvkbLcawn/4pcUt3Q9 g3Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=G4B0dKcc; 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 x16si10099681edd.25.2021.09.13.09.32.40; Mon, 13 Sep 2021 09:33:05 -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=G4B0dKcc; 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 S237913AbhIMQcN (ORCPT + 99 others); Mon, 13 Sep 2021 12:32:13 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55508 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237878AbhIMQcF (ORCPT ); Mon, 13 Sep 2021 12:32:05 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id DF22A1FD9B; Mon, 13 Sep 2021 16:30:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1631550647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1cLnNgahnRqZc9jVnTIqodTE0s49FfRLlP6thBPVEdE=; b=G4B0dKcceWAc3dPBA9v/gt34/Gyd09ih7imvIkZc6JUfO4WkjMAYL3V0yukTYjsfdOaS1f l0JJMfWTM4PknivRzLiSZPAd/pzromG8sG/RmXHsy0mHAgPe1mfLEDd8XwvZ6c0/UG5ZLp JEHFuuryx0xrDTHIqWFLyTq6GO6atOA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1631550647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1cLnNgahnRqZc9jVnTIqodTE0s49FfRLlP6thBPVEdE=; b=i46mclSR4SG/t74dq02Fjnwcq2Z/bP7MzTKIp9C1ZOgDzRiz2UK2usQSGwywbygQWpPuOw sQU+3oQ+Rr/4kfDQ== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 20EBAA3B92; Mon, 13 Sep 2021 16:30:42 +0000 (UTC) From: Coly Li To: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-raid@vger.kernel.org, nvdimm@lists.linux.dev Cc: antlists@youngman.org.uk, Coly Li , Dan Williams , Hannes Reinecke , Jens Axboe , NeilBrown , Vishal L Verma Subject: [PATCH v2 1/6] badblocks: add more helper structure and routines in badblocks.h Date: Tue, 14 Sep 2021 00:30:10 +0800 Message-Id: <20210913163016.10088-2-colyli@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210913163016.10088-1-colyli@suse.de> References: <20210913163016.10088-1-colyli@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 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; + int ack; + sector_t orig_start; + sector_t orig_len; +}; + 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 -- 2.31.1