[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230428085020.2283981-10-linan666@huaweicloud.com>
Date: Fri, 28 Apr 2023 16:50:19 +0800
From: linan666@...weicloud.com
To: axboe@...nel.dk, vishal.l.verma@...el.com, dan.j.williams@...el.com
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
linan122@...wei.com, yukuai3@...wei.com, yi.zhang@...wei.com,
houtao1@...wei.com, yangerkun@...wei.com
Subject: [PATCH 09/10] block/badblocks: factor out a helper to create badblocks
From: Li Nan <linan122@...wei.com>
Add a helper badblocks_create() to create badblocks, it makes code more
readable. No functional change.
Signed-off-by: Li Nan <linan122@...wei.com>
---
block/badblocks.c | 65 ++++++++++++++++++++++++++++++-----------------
1 file changed, 41 insertions(+), 24 deletions(-)
diff --git a/block/badblocks.c b/block/badblocks.c
index c87c68d4bcac..bb0324b66f57 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -263,6 +263,46 @@ static void badblocks_combine(struct badblocks *bb, int lo)
}
}
+/*
+ * creat new badblocks if it can't merge with existing region
+ *
+ * Return:
+ * 0: success
+ * 1: failed to set badblocks (out of space)
+ */
+static int badblocks_create(struct badblocks *bb, sector_t s, sector_t sectors,
+ int hi, int acknowledged, bool *changed)
+{
+ u64 *p = bb->page;
+ int rv = 0;
+
+ while (sectors) {
+ int this_sectors = sectors;
+
+ /* didn't merge (it all).
+ * Need to add a range just before 'hi'
+ */
+ if (bb->count >= MAX_BADBLOCKS) {
+ /* No room for more */
+ rv = 1;
+ break;
+ }
+
+ memmove(p + hi + 1, p + hi,
+ (bb->count - hi) * 8);
+ bb->count++;
+
+ if (this_sectors > BB_MAX_LEN)
+ this_sectors = BB_MAX_LEN;
+ p[hi] = BB_MAKE(s, this_sectors, acknowledged);
+ sectors -= this_sectors;
+ s += this_sectors;
+ hi++;
+ *changed = true;
+ }
+ return rv;
+}
+
/**
* badblocks_set() - Add a range of bad blocks to the table.
* @bb: the badblocks structure that holds all badblock information
@@ -327,30 +367,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
if (sectors == 0)
badblocks_combine(bb, lo);
}
- while (sectors) {
- /* didn't merge (it all).
- * Need to add a range just before 'hi'
- */
- if (bb->count >= MAX_BADBLOCKS) {
- /* No room for more */
- rv = 1;
- break;
- } else {
- int this_sectors = sectors;
-
- memmove(p + hi + 1, p + hi,
- (bb->count - hi) * 8);
- bb->count++;
-
- if (this_sectors > BB_MAX_LEN)
- this_sectors = BB_MAX_LEN;
- p[hi] = BB_MAKE(s, this_sectors, acknowledged);
- sectors -= this_sectors;
- s += this_sectors;
- hi++;
- changed = true;
- }
- }
+ rv = badblocks_create(bb, s, sectors, hi, acknowledged, &changed);
if (changed) {
bb->changed = changed;
--
2.31.1
Powered by blists - more mailing lists