1 This patch is no longer needed for Lustre. It is only included
2 for testing and ease of using the same kernel with older Lustre
3 versions. This testing functionality was replaced in Linux 3.0
4 by the dm-flakey driver.
6 This functionality is mainly used during testing, in order to
7 simulate a server crash for ldiskfs by discarding all of the
8 writes to the filesystem. For recovery testing we could simulate
9 this by using a special loopback or DM device that also discards
12 This functionality is also used by target "failback" in order
13 to speed up service shutdown and takeover by the other node
14 during controlled operation. However, it would also be possible
15 to do this by simply allowing all of the in-flight requests to
16 complete and then waiting for the service to stop. This will
17 also be needed by the DMU-OSD, because discarding of writes on
18 a DMU-based target is not safe as it could trigger a storage
19 failure if the data is ever read from disk again and the
20 checksum does not match that expected by the block pointer.
22 Index: linux-3.10.0-123.8.1.el7.x86_64/block/blk-core.c
23 ===================================================================
24 --- linux-3.10.0-123.8.1.el7.x86_64.orig/block/blk-core.c
25 +++ linux-3.10.0-123.8.1.el7.x86_64/block/blk-core.c
26 @@ -1667,6 +1667,8 @@ static inline bool should_fail_request(s
28 #endif /* CONFIG_FAIL_MAKE_REQUEST */
30 +int dev_check_rdonly(struct block_device *bdev);
33 * Check whether this bio extends beyond the end of the device.
35 @@ -1729,6 +1731,12 @@ generic_make_request_checks(struct bio *
39 + /* this is cfs's dev_rdonly check */
40 + if (bio_rw(bio) == WRITE && dev_check_rdonly(bio->bi_bdev)) {
45 part = bio->bi_bdev->bd_part;
46 if (should_fail_request(part, bio->bi_size) ||
47 should_fail_request(&part_to_disk(part)->part0,
48 @@ -3240,6 +3248,99 @@ void blk_post_runtime_resume(struct requ
49 EXPORT_SYMBOL(blk_post_runtime_resume);
53 + * Debug code for turning block devices "read-only" (will discard writes
54 + * silently). This is for filesystem crash/recovery testing.
58 + struct deventry *next;
61 +static struct deventry *devlist = NULL;
62 +static spinlock_t devlock = __SPIN_LOCK_UNLOCKED(devlock);
64 +int dev_check_rdonly(struct block_device *bdev)
66 + struct deventry *cur;
71 + spin_lock(&devlock);
74 + if (bdev->bd_dev == cur->dev) {
75 + spin_unlock(&devlock);
80 + spin_unlock(&devlock);
84 +void dev_set_rdonly(struct block_device *bdev)
86 + struct deventry *newdev, *cur;
91 + newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
95 + spin_lock(&devlock);
98 + if (bdev->bd_dev == cur->dev) {
99 + spin_unlock(&devlock);
105 + newdev->dev = bdev->bd_dev;
106 + newdev->next = devlist;
108 + spin_unlock(&devlock);
109 + printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
110 + bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
113 +void dev_clear_rdonly(struct block_device *bdev)
115 + struct deventry *cur, *last = NULL;
120 + spin_lock(&devlock);
123 + if (bdev->bd_dev == cur->dev) {
125 + last->next = cur->next;
127 + devlist = cur->next;
128 + spin_unlock(&devlock);
130 + printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
131 + bdev->bd_disk ? bdev->bd_disk->disk_name :
132 + "unknown block", bdev->bd_dev);
138 + spin_unlock(&devlock);
141 +EXPORT_SYMBOL(dev_set_rdonly);
142 +EXPORT_SYMBOL(dev_clear_rdonly);
143 +EXPORT_SYMBOL(dev_check_rdonly);
145 int __init blk_dev_init(void)
147 BUILD_BUG_ON(__REQ_NR_BITS > 8 *
148 Index: linux-3.10.0-123.8.1.el7.x86_64/fs/block_dev.c
149 ===================================================================
150 --- linux-3.10.0-123.8.1.el7.x86_64.orig/fs/block_dev.c
151 +++ linux-3.10.0-123.8.1.el7.x86_64/fs/block_dev.c
152 @@ -1441,6 +1441,7 @@ static void __blkdev_put(struct block_de
153 if (bdev != bdev->bd_contains)
154 victim = bdev->bd_contains;
155 bdev->bd_contains = NULL;
156 + dev_clear_rdonly(bdev);
160 Index: linux-3.10.0-123.8.1.el7.x86_64/include/linux/fs.h
161 ===================================================================
162 --- linux-3.10.0-123.8.1.el7.x86_64.orig/include/linux/fs.h
163 +++ linux-3.10.0-123.8.1.el7.x86_64/include/linux/fs.h
164 @@ -2440,6 +2440,10 @@ extern void inode_sb_list_add(struct ino
165 extern void submit_bio(int, struct bio *);
166 extern int bdev_read_only(struct block_device *);
168 +#define HAVE_CLEAR_RDONLY_ON_PUT
169 +extern void dev_set_rdonly(struct block_device *bdev);
170 +extern int dev_check_rdonly(struct block_device *bdev);
171 +extern void dev_clear_rdonly(struct block_device *bdev);
172 extern int set_blocksize(struct block_device *, int);
173 extern int sb_set_blocksize(struct super_block *, int);
174 extern int sb_min_blocksize(struct super_block *, int);