Commit 7e5102dd authored by Zheng Qixing's avatar Zheng Qixing Committed by Jens Axboe
Browse files

md: improve return types of badblocks handling functions



rdev_set_badblocks() only indicates success/failure, so convert its return
type from int to boolean for better semantic clarity.

rdev_clear_badblocks() return value is never used by any caller, convert it
to void. This removes unnecessary value returns.

Also update narrow_write_error() in both raid1 and raid10 to use boolean
return type to match rdev_set_badblocks().

Signed-off-by: default avatarZheng Qixing <zhengqixing@huawei.com>
Reviewed-by: default avatarYu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250227075507.151331-12-zhengqixing@huaweicloud.com


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent c8775aef
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -9828,8 +9828,8 @@ EXPORT_SYMBOL(md_finish_reshape);

/* Bad block management */

/* Returns 1 on success, 0 on failure */
int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
/* Returns true on success, false on failure */
bool rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
			int is_new)
{
	struct mddev *mddev = rdev->mddev;
@@ -9842,7 +9842,7 @@ int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
	 * avoid it.
	 */
	if (test_bit(Faulty, &rdev->flags))
		return 1;
		return true;

	if (is_new)
		s += rdev->new_data_offset;
@@ -9850,7 +9850,7 @@ int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
		s += rdev->data_offset;

	if (!badblocks_set(&rdev->badblocks, s, sectors, 0))
		return 0;
		return false;

	/* Make sure they get written out promptly */
	if (test_bit(ExternalBbl, &rdev->flags))
@@ -9859,11 +9859,11 @@ int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
	set_mask_bits(&mddev->sb_flags, 0,
		      BIT(MD_SB_CHANGE_CLEAN) | BIT(MD_SB_CHANGE_PENDING));
	md_wakeup_thread(rdev->mddev->thread);
	return 1;
	return true;
}
EXPORT_SYMBOL_GPL(rdev_set_badblocks);

int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
void rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
			  int is_new)
{
	if (is_new)
@@ -9872,11 +9872,10 @@ int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
		s += rdev->data_offset;

	if (!badblocks_clear(&rdev->badblocks, s, sectors))
		return 0;
		return;

	if (test_bit(ExternalBbl, &rdev->flags))
		sysfs_notify_dirent_safe(rdev->sysfs_badblocks);
	return 1;
}
EXPORT_SYMBOL_GPL(rdev_clear_badblocks);

+4 −4
Original line number Diff line number Diff line
@@ -289,9 +289,9 @@ static inline int rdev_has_badblock(struct md_rdev *rdev, sector_t s,
	return is_badblock(rdev, s, sectors, &first_bad, &bad_sectors);
}

extern int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
extern bool rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
			       int is_new);
extern int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
extern void rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
				 int is_new);
struct md_cluster_info;

+3 −3
Original line number Diff line number Diff line
@@ -2486,7 +2486,7 @@ static void fix_read_error(struct r1conf *conf, struct r1bio *r1_bio)
	}
}

static int narrow_write_error(struct r1bio *r1_bio, int i)
static bool narrow_write_error(struct r1bio *r1_bio, int i)
{
	struct mddev *mddev = r1_bio->mddev;
	struct r1conf *conf = mddev->private;
@@ -2507,10 +2507,10 @@ static int narrow_write_error(struct r1bio *r1_bio, int i)
	sector_t sector;
	int sectors;
	int sect_to_write = r1_bio->sectors;
	int ok = 1;
	bool ok = true;

	if (rdev->badblocks.shift < 0)
		return 0;
		return false;

	block_sectors = roundup(1 << rdev->badblocks.shift,
				bdev_logical_block_size(rdev->bdev) >> 9);
+3 −3
Original line number Diff line number Diff line
@@ -2786,7 +2786,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
	}
}

static int narrow_write_error(struct r10bio *r10_bio, int i)
static bool narrow_write_error(struct r10bio *r10_bio, int i)
{
	struct bio *bio = r10_bio->master_bio;
	struct mddev *mddev = r10_bio->mddev;
@@ -2807,10 +2807,10 @@ static int narrow_write_error(struct r10bio *r10_bio, int i)
	sector_t sector;
	int sectors;
	int sect_to_write = r10_bio->sectors;
	int ok = 1;
	bool ok = true;

	if (rdev->badblocks.shift < 0)
		return 0;
		return false;

	block_sectors = roundup(1 << rdev->badblocks.shift,
				bdev_logical_block_size(rdev->bdev) >> 9);