[PATCH 1/3] md: add rdev_record_write_error() helper

"Li Youhong" <[email protected]>
Newsgroups gmane.linux.raid
Message-ID <[email protected]>
From: Li Youhong <[email protected]>

The WriteErrorSeen + WantReplacement + MD_RECOVERY_NEEDED sequence is
duplicated across raid1, raid10 and raid5. Factor it into a small
inline helper for readability. No functional change.

Signed-off-by: Li Youhong <[email protected]>
---
 drivers/md/md.h     |  7 +++++++
 drivers/md/raid1.c  | 16 +++-------------
 drivers/md/raid10.c | 21 ++++-----------------
 drivers/md/raid5.c  |  5 +----
 4 files changed, 15 insertions(+), 34 deletions(-)

diff --git a/drivers/md/md.h b/drivers/md/md.h
index b6d2e8929a0f..6440da292105 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -989,6 +989,13 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
 	}
 }
 
+static inline void rdev_record_write_error(struct md_rdev *rdev)
+{
+	set_bit(WriteErrorSeen, &rdev->flags);
+	if (!test_and_set_bit(WantReplacement, &rdev->flags))
+		set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
+}
+
 static inline int mddev_is_clustered(struct mddev *mddev)
 {
 	return mddev->cluster_info && mddev->bitmap_info.nodes > 1;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index f0646fb24371..9d8441348f14 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -483,10 +483,7 @@ static void raid1_end_write_request(struct bio *bio)
 	 * 'one mirror IO has finished' event handler:
 	 */
 	if (bio->bi_status && !ignore_error) {
-		set_bit(WriteErrorSeen,	&rdev->flags);
-		if (!test_and_set_bit(WantReplacement, &rdev->flags))
-			set_bit(MD_RECOVERY_NEEDED, &
-				conf->mddev->recovery);
+		rdev_record_write_error(rdev);
 
 		if (test_bit(FailFast, &rdev->flags) &&
 		    (bio->bi_opf & MD_FAILFAST) &&
@@ -2067,10 +2064,7 @@ static void end_sync_write(struct bio *bio)
 
 	if (bio->bi_status) {
 		abort_sync_write(mddev, r1_bio);
-		set_bit(WriteErrorSeen, &rdev->flags);
-		if (!test_and_set_bit(WantReplacement, &rdev->flags))
-			set_bit(MD_RECOVERY_NEEDED, &
-				mddev->recovery);
+		rdev_record_write_error(rdev);
 		set_bit(R1BIO_WriteError, &r1_bio->state);
 	} else if (rdev_has_badblock(rdev, r1_bio->sector, r1_bio->sectors) &&
 		   !rdev_has_badblock(conf->mirrors[r1_bio->read_disk].rdev,
@@ -2088,11 +2082,7 @@ static int r1_sync_page_io(struct md_rdev *rdev, sector_t sector,
 		/* success */
 		return 1;
 	if (rw == REQ_OP_WRITE) {
-		set_bit(WriteErrorSeen, &rdev->flags);
-		if (!test_and_set_bit(WantReplacement,
-				      &rdev->flags))
-			set_bit(MD_RECOVERY_NEEDED, &
-				rdev->mddev->recovery);
+		rdev_record_write_error(rdev);
 	}
 	/* need to record an error - either for the block or the device */
 	rdev_set_badblocks(rdev, sector, sectors, 0);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 1093c798d9dd..c4218d6483ed 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -496,10 +496,7 @@ static void raid10_end_write_request(struct bio *bio)
 			 */
 			md_error(rdev->mddev, rdev);
 		else {
-			set_bit(WriteErrorSeen,	&rdev->flags);
-			if (!test_and_set_bit(WantReplacement, &rdev->flags))
-				set_bit(MD_RECOVERY_NEEDED,
-					&rdev->mddev->recovery);
+			rdev_record_write_error(rdev);
 
 			dec_rdev = 0;
 			if (test_bit(FailFast, &rdev->flags) &&
@@ -2299,10 +2296,7 @@ static void end_sync_write(struct bio *bio)
 		if (repl)
 			md_error(mddev, rdev);
 		else {
-			set_bit(WriteErrorSeen, &rdev->flags);
-			if (!test_and_set_bit(WantReplacement, &rdev->flags))
-				set_bit(MD_RECOVERY_NEEDED,
-					&rdev->mddev->recovery);
+			rdev_record_write_error(rdev);
 			set_bit(R10BIO_WriteError, &r10_bio->state);
 		}
 	} else if (rdev_has_badblock(rdev, r10_bio->devs[slot].addr,
@@ -2500,11 +2494,7 @@ static void fix_recovery_read_error(struct r10bio *r10_bio)
 					  pages[idx],
 					  REQ_OP_WRITE, false);
 			if (!ok) {
-				set_bit(WriteErrorSeen, &rdev->flags);
-				if (!test_and_set_bit(WantReplacement,
-						      &rdev->flags))
-					set_bit(MD_RECOVERY_NEEDED,
-						&rdev->mddev->recovery);
+				rdev_record_write_error(rdev);
 			}
 		}
 		if (!ok) {
@@ -2585,10 +2575,7 @@ static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
 		/* success */
 		return 1;
 	if (op == REQ_OP_WRITE) {
-		set_bit(WriteErrorSeen, &rdev->flags);
-		if (!test_and_set_bit(WantReplacement, &rdev->flags))
-			set_bit(MD_RECOVERY_NEEDED,
-				&rdev->mddev->recovery);
+		rdev_record_write_error(rdev);
 	}
 	/* need to record an error - either for the block or the device */
 	rdev_set_badblocks(rdev, sector, sectors, 0);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b91545ce090d..caacc06c52c5 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2888,11 +2888,8 @@ static void raid5_end_write_request(struct bio *bi)
 			set_bit(R5_MadeGoodRepl, &sh->dev[i].flags);
 	} else {
 		if (bi->bi_status) {
-			set_bit(WriteErrorSeen, &rdev->flags);
+			rdev_record_write_error(rdev);
 			set_bit(R5_WriteError, &sh->dev[i].flags);
-			if (!test_and_set_bit(WantReplacement, &rdev->flags))
-				set_bit(MD_RECOVERY_NEEDED,
-					&rdev->mddev->recovery);
 		} else if (rdev_has_badblock(rdev, sh->sector,
 					     RAID5_STRIPE_SECTORS(conf))) {
 			set_bit(R5_MadeGood, &sh->dev[i].flags);
-- 
2.25.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.