diff mbox series

[3/3] block: replace hd_struct.make_it_fail with a flag

Message ID 20201113084702.4164912-4-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/3] block: Fix read-only block device setting after revalidate | expand

Commit Message

Christoph Hellwig Nov. 13, 2020, 8:47 a.m. UTC
Use a single bit in ->state instead of a whole int.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-core.c      |  3 ++-
 block/genhd.c         | 11 +++++++----
 include/linux/genhd.h |  4 +---
 3 files changed, 10 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/block/blk-core.c b/block/blk-core.c
index b6dea07e08c9c7..de20aeb7d5f0e0 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -668,7 +668,8 @@  __setup("fail_make_request=", setup_fail_make_request);
 
 static bool should_fail_request(struct hd_struct *part, unsigned int bytes)
 {
-	return part->make_it_fail && should_fail(&fail_make_request, bytes);
+	return test_bit(HD_FAIL_REQUEST, &part->state) &&
+		should_fail(&fail_make_request, bytes);
 }
 
 static int __init fail_make_request_debugfs(void)
diff --git a/block/genhd.c b/block/genhd.c
index 65f6b744f4ebd5..bd49fb43554213 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1407,7 +1407,7 @@  ssize_t part_fail_show(struct device *dev,
 {
 	struct hd_struct *p = dev_to_part(dev);
 
-	return sprintf(buf, "%d\n", p->make_it_fail);
+	return sprintf(buf, "%d\n", test_bit(HD_FAIL_REQUEST, &p->state));
 }
 
 ssize_t part_fail_store(struct device *dev,
@@ -1417,9 +1417,12 @@  ssize_t part_fail_store(struct device *dev,
 	struct hd_struct *p = dev_to_part(dev);
 	int i;
 
-	if (count > 0 && sscanf(buf, "%d", &i) > 0)
-		p->make_it_fail = (i == 0) ? 0 : 1;
-
+	if (count > 0 && sscanf(buf, "%d", &i) > 0) {
+		if (i)
+			clear_bit(HD_FAIL_REQUEST, &p->state);
+		else
+			set_bit(HD_FAIL_REQUEST, &p->state);
+	}
 	return count;
 }
 
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 2609bc78ff131b..91b37a738b52b5 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -70,10 +70,8 @@  struct hd_struct {
 	int partno;
 	unsigned long state;
 #define HD_RO_POLICY			0
+#define HD_FAIL_REQUEST			1
 	struct partition_meta_info *info;
-#ifdef CONFIG_FAIL_MAKE_REQUEST
-	int make_it_fail;
-#endif
 	struct rcu_work rcu_work;
 };