Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp937411pxb; Wed, 3 Mar 2021 21:45:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeRjmMldddywrsHcB23YnLjiccmH3IDUisqlRN4vqKa90tHeKnhfj+lZXBCvNEB/9Qs7s3 X-Received: by 2002:a17:906:388d:: with SMTP id q13mr2489230ejd.34.1614836744955; Wed, 03 Mar 2021 21:45:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614836744; cv=none; d=google.com; s=arc-20160816; b=yWRW2A4b32LllF2+oSkozn0JA3sY1EJF5Kke6IHLdRy+eBkTamdUg3vHynNuKUgrt+ OXa/o8XljwzCamizPAemLAZeaCOMDDYG4QUGif+7Y0owJNbbx1yWBMMIAAtYMoXhcuTG Elv7MXjrndG/FbLmHR5VUiplze42LENdb8yfBnpPNmXSTz1/g/5uCgjMcQaw6Ulm6/he gEi1qNCwpQI2RH8b6h05G9EgwRIon3z4897PjPmp89bwqbSFSFVHTC+IBFpHfsg1MXVb ZVNPn+oVUH93RuFuaPHMG66KzG2X5YEffvrR6kHJGfbuLtTpxfn7/vCpBGPwsV1gLjDt 3RXA== 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=c4q/REUw1ZW8K6k32dHUdnDYg60QwSTMcHR4Whz3BSQ=; b=Q3lAjKofzJkTylgbEGxZc+BDRFISBhriEPsboKvGwsEu2vuLe+WnoBEj1p+fLyTAhH MQPcbYOz1zqsiLqU8doKfCJ2Bz3J5rDVkRwLSJqBR0z0efKUlsmvSTzAN4nHYLRYtqCF p7QaGhFm/0r3KrpLDDvd8Ru6bUxYFhHVmc8R9PtXyCekutMMQsoOAlP+8EMRNql/2Jq2 mcNxnQxiJWyeHAGVJygCGwEJ4UDYIm4xCU051X9OiHo2Q+vozkVBM8O9ASq9IciMQ13I EeI/WQ0NorPByxpCPpkx6uU/jMKga7CjMJXCwSqbTQLFJhRLd5ahbf5VictAUM/9povJ MWQg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si15989915eje.581.2021.03.03.21.45.22; Wed, 03 Mar 2021 21:45:44 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574962AbhCBGVE (ORCPT + 99 others); Tue, 2 Mar 2021 01:21:04 -0500 Received: from mx2.suse.de ([195.135.220.15]:39278 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236440AbhCBEGq (ORCPT ); Mon, 1 Mar 2021 23:06:46 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3F926ABF4; Tue, 2 Mar 2021 04:03:04 +0000 (UTC) From: Coly Li To: linux-block@vger.kernel.org, axboe@kernel.dk, dan.j.williams@intel.com, vishal.l.verma@intel.com, neilb@suse.de Cc: antlists@youngman.org.uk, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, linux-nvdimm@lists.01.org, Coly Li Subject: [RFC PATCH v1 1/6] badblocks: add more helper structure and routines in badblocks.h Date: Tue, 2 Mar 2021 12:02:47 +0800 Message-Id: <20210302040252.103720-2-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210302040252.103720-1-colyli@suse.de> References: <20210302040252.103720-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 bad_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 --- 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 bad_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.26.2