lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230428085020.2283981-11-linan666@huaweicloud.com>
Date:   Fri, 28 Apr 2023 16:50:20 +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 10/10] block/badblocks: try to merge badblocks as much as possible

From: Li Nan <linan122@...wei.com>

If we set a new badblocks, we first merge it with existing region, then
try to combine lo and hi. If there are still badblocks need to be set,
create it. It is a bad way when setting a laget number of badblocks. for
example, it will become chaotic if we set as below:

  # echo 1 1 > bad_blocks
  # echo 512 1 > bad_blocks
  # echo 0 513 > bad_blocks
  # cat bad_blocks
    0 512
    512 1
    512 1

Fix it by trying to merge as much as possible. If we have merged any
badblocks, retry to merge next sectors. Do not check sectors while
combining, we should combine lo and hi each sycle.

Fixes: 9e0e252a048b ("badblocks: Add core badblock management code")
Signed-off-by: Li Nan <linan122@...wei.com>
---
 block/badblocks.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/block/badblocks.c b/block/badblocks.c
index bb0324b66f57..7e6fce10c82d 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -347,8 +347,6 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
 	lo = 0;
 	hi = bb->count;
 	if (bb->count) {
-		int merged_sectors;
-
 		/* Find the last range that starts at-or-before 's' */
 		while (hi - lo > 1) {
 			int mid = (lo + hi) / 2;
@@ -360,12 +358,19 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
 				hi = mid;
 		}
 
-		merged_sectors = badblocks_merge(bb, s, sectors, acknowledged,
-						 &lo, &hi, &changed);
-		s += merged_sectors;
-		sectors -= merged_sectors;
-		if (sectors == 0)
+		while (sectors) {
+			int merged_sectors;
+
+			merged_sectors = badblocks_merge(bb, s, sectors, acknowledged,
+							 &lo, &hi, &changed);
+			/* can't merge, break to create */
+			if (!merged_sectors)
+				break;
+
+			s += merged_sectors;
+			sectors -= merged_sectors;
 			badblocks_combine(bb, lo);
+		}
 	}
 	rv = badblocks_create(bb, s, sectors, hi, acknowledged, &changed);
 
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ