All of lore.kernel.org
 help / color / mirror / Atom feed
From: Coly Li <colyli@suse.de>
To: linux-block@vger.kernel.org
Cc: nvdimm@lists.linux.dev, linux-raid@vger.kernel.org,
	Coly Li <colyli@suse.de>, Dan Williams <dan.j.williams@intel.com>,
	Geliang Tang <geliang.tang@suse.com>,
	Hannes Reinecke <hare@suse.de>, Jens Axboe <axboe@kernel.dk>,
	NeilBrown <neilb@suse.de>,
	Vishal L Verma <vishal.l.verma@intel.com>,
	Xiao Ni <xni@redhat.com>
Subject: [PATCH v6 1/7] badblocks: add more helper structure and routines in badblocks.h
Date: Thu, 21 Jul 2022 20:11:46 +0800	[thread overview]
Message-ID: <20220721121152.4180-2-colyli@suse.de> (raw)
In-Reply-To: <20220721121152.4180-1-colyli@suse.de>

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 calculate 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 <colyli@suse.de>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Geliang Tang <geliang.tang@suse.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: NeilBrown <neilb@suse.de>
Cc: Vishal L Verma <vishal.l.verma@intel.com>
Cc: Xiao Ni <xni@redhat.com>
---
 include/linux/badblocks.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/include/linux/badblocks.h b/include/linux/badblocks.h
index 2426276b9bd3..670f2dae692f 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,12 @@ struct badblocks {
 	sector_t size;		/* in sectors */
 };
 
+struct badblocks_context {
+	sector_t	start;
+	sector_t	len;
+	int		ack;
+};
+
 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 +70,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.35.3


  reply	other threads:[~2022-07-21 12:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 12:11 [PATCH v6 0/7] badblocks improvement for multiple bad block ranges Coly Li
2022-07-21 12:11 ` Coly Li [this message]
2022-09-21 12:16   ` [PATCH v6 1/7] badblocks: add more helper structure and routines in badblocks.h Xiao Ni
2022-07-21 12:11 ` [PATCH v6 2/7] badblocks: add helper routines for badblock ranges handling Coly Li
2022-09-21 12:13   ` Xiao Ni
2023-08-11 16:57     ` Coly Li
2022-07-21 12:11 ` [PATCH v6 3/7] badblocks: improve badblocks_set() for multiple " Coly Li
2022-09-21 12:13   ` Xiao Ni
2023-08-11 16:57     ` Coly Li
2022-07-21 12:11 ` [PATCH v6 4/7] badblocks: improve badblocks_clear() " Coly Li
2022-09-21 15:26   ` Xiao Ni
2023-08-11 16:57     ` Coly Li
2023-08-11 16:58     ` Coly Li
2022-07-21 12:11 ` [PATCH v6 5/7] badblocks: improve badblocks_check() " Coly Li
2022-09-21 16:33   ` Xiao Ni
2022-09-23 15:17     ` 3507712
2022-10-28 17:50   ` Lynn.Figore
2022-12-20 13:25   ` Joy.Palmer
2023-03-21 11:17   ` Robert.Nocerino
2022-07-21 12:11 ` [PATCH v6 6/7] badblocks: switch to the improved badblock handling code Coly Li
2022-07-21 12:11 ` [PATCH v6 7/7] test: user space code to test badblocks APIs Coly Li
2023-05-23  2:38 ` [PATCH v6 0/7] badblocks improvement for multiple bad block ranges Li Nan
2023-05-23  4:38   ` Coly Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220721121152.4180-2-colyli@suse.de \
    --to=colyli@suse.de \
    --cc=axboe@kernel.dk \
    --cc=dan.j.williams@intel.com \
    --cc=geliang.tang@suse.com \
    --cc=hare@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    --cc=xni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.