1 This functionality is mainly used during testing, in order to
2 simulate a server crash for ldiskfs by discarding all of the
3 writes to the filesystem. For recovery testing we could simulate
4 this by using a special loopback or DM device that also discards
7 This functionality is also used by target "failback" in order
8 to speed up service shutdown and takeover by the other node
9 during controlled operation. However, it would also be possible
10 to do this by simply allowing all of the in-flight requests to
11 complete and then waiting for the service to stop. This will
12 also be needed by the DMU-OSD, because discarding of writes on
13 a DMU-based target is not safe as it could trigger a storage
14 failure if the data is ever read from disk again and the
15 checksum does not match that expected by the block pointer.
17 Initial efforts to remove this patch are under way in bug 20776.
18 Once this work comes to fruition this patch can be dropped.
20 Index: linux-2.6.32-131.0.15.el6.x86_64/block/blk-core.c
21 ===================================================================
22 --- linux-2.6.32-131.0.15.el6.x86_64.orig/block/blk-core.c 2011-05-10 21:38:33.000000000 +0300
23 +++ linux-2.6.32-131.0.15.el6.x86_64/block/blk-core.c 2011-05-19 21:01:04.000000000 +0300
24 @@ -1416,6 +1416,8 @@ static inline int should_fail_request(st
26 #endif /* CONFIG_FAIL_MAKE_REQUEST */
28 +int dev_check_rdonly(struct block_device *bdev);
31 * Check whether this bio extends beyond the end of the device.
33 @@ -1517,6 +1519,23 @@ static inline void __generic_make_reques
34 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
37 + /* this is cfs's dev_rdonly check */
38 + if (bio_rw(bio) == WRITE && dev_check_rdonly(bio->bi_bdev)) {
39 + struct block_device *bdev = bio->bi_bdev;
41 + printk(KERN_WARNING "Write to readonly device %s (%#x) "
42 + "bi_flags: %lx, bi_vcnt: %d, bi_idx: %d, "
43 + "bi->size: %d, bi_cnt: %d, bi_private: %p\n",
44 + bdev->bd_disk ? bdev->bd_disk->disk_name : "",
45 + bdev->bd_dev, bio->bi_flags, bio->bi_vcnt,
46 + bio->bi_idx, bio->bi_size,
47 + atomic_read(&bio->bi_cnt), bio->bi_private);
48 + set_bit(BIO_RDONLY, &bio->bi_flags);
50 + clear_bit(BIO_RDONLY, &bio->bi_flags);
54 if (should_fail_request(bio))
57 @@ -2628,6 +2647,99 @@ int kblockd_schedule_work(struct request
59 EXPORT_SYMBOL(kblockd_schedule_work);
62 + * Debug code for turning block devices "read-only" (will discard writes
63 + * silently). This is for filesystem crash/recovery testing.
67 + struct deventry *next;
70 +static struct deventry *devlist = NULL;
71 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED;
73 +int dev_check_rdonly(struct block_device *bdev)
75 + struct deventry *cur;
80 + spin_lock(&devlock);
83 + if (bdev->bd_dev == cur->dev) {
84 + spin_unlock(&devlock);
89 + spin_unlock(&devlock);
93 +void dev_set_rdonly(struct block_device *bdev)
95 + struct deventry *newdev, *cur;
100 + newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
104 + spin_lock(&devlock);
107 + if (bdev->bd_dev == cur->dev) {
108 + spin_unlock(&devlock);
114 + newdev->dev = bdev->bd_dev;
115 + newdev->next = devlist;
117 + spin_unlock(&devlock);
118 + printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
119 + bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
122 +void dev_clear_rdonly(struct block_device *bdev)
124 + struct deventry *cur, *last = NULL;
129 + spin_lock(&devlock);
132 + if (bdev->bd_dev == cur->dev) {
134 + last->next = cur->next;
136 + devlist = cur->next;
137 + spin_unlock(&devlock);
139 + printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
140 + bdev->bd_disk ? bdev->bd_disk->disk_name :
148 + spin_unlock(&devlock);
151 +EXPORT_SYMBOL(dev_set_rdonly);
152 +EXPORT_SYMBOL(dev_clear_rdonly);
153 +EXPORT_SYMBOL(dev_check_rdonly);
154 int __init blk_dev_init(void)
156 BUILD_BUG_ON(__REQ_NR_BITS > 8 *
157 Index: linux-2.6.32-131.0.15.el6.x86_64/fs/block_dev.c
158 ===================================================================
159 --- linux-2.6.32-131.0.15.el6.x86_64.orig/fs/block_dev.c 2011-05-10 21:38:29.000000000 +0300
160 +++ linux-2.6.32-131.0.15.el6.x86_64/fs/block_dev.c 2011-05-19 21:01:04.000000000 +0300
161 @@ -1389,6 +1389,7 @@ static int __blkdev_put(struct block_dev
162 if (bdev != bdev->bd_contains)
163 victim = bdev->bd_contains;
164 bdev->bd_contains = NULL;
165 + dev_clear_rdonly(bdev);
168 mutex_unlock(&bdev->bd_mutex);
169 Index: linux-2.6.32-131.0.15.el6.x86_64/include/linux/blk_types.h
170 ===================================================================
171 --- linux-2.6.32-131.0.15.el6.x86_64.orig/include/linux/blk_types.h 2011-05-10 21:37:58.000000000 +0300
172 +++ linux-2.6.32-131.0.15.el6.x86_64/include/linux/blk_types.h 2011-05-19 21:03:42.000000000 +0300
174 #define BIO_NULL_MAPPED 9 /* contains invalid user pages */
175 #define BIO_FS_INTEGRITY 10 /* fs owns integrity data, not block layer */
176 #define BIO_QUIET 11 /* Make BIO Quiet */
177 +#define BIO_RDONLY 31 /* device is readonly */
178 #define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag)))
181 Index: linux-2.6.32-131.0.15.el6.x86_64/include/linux/fs.h
182 ===================================================================
183 --- linux-2.6.32-131.0.15.el6.x86_64.orig/include/linux/fs.h 2011-05-10 21:38:29.000000000 +0300
184 +++ linux-2.6.32-131.0.15.el6.x86_64/include/linux/fs.h 2011-05-19 21:01:04.000000000 +0300
185 @@ -2244,6 +2244,10 @@ struct bio;
186 extern void submit_bio(int, struct bio *);
187 extern int bdev_read_only(struct block_device *);
189 +#define HAVE_CLEAR_RDONLY_ON_PUT
190 +extern void dev_set_rdonly(struct block_device *bdev);
191 +extern int dev_check_rdonly(struct block_device *bdev);
192 +extern void dev_clear_rdonly(struct block_device *bdev);
193 extern int set_blocksize(struct block_device *, int);
194 extern int sb_set_blocksize(struct super_block *, int);
195 extern int sb_min_blocksize(struct super_block *, int);