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-71.18.1.el6-master/block/blk-core.c
21 ===================================================================
22 --- linux-2.6.32-71.18.1.el6-master.orig/block/blk-core.c 2011-03-05 11:35:40.404043293 +0800
23 +++ linux-2.6.32-71.18.1.el6-master/block/blk-core.c 2011-03-11 20:21:10.492302510 +0800
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 @@ -1506,6 +1508,23 @@
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 @@ -2578,6 +2586,99 @@
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-71.18.1.el6-master/fs/block_dev.c
158 ===================================================================
159 --- linux-2.6.32-71.18.1.el6-master.orig/fs/block_dev.c 2011-03-05 11:35:40.486042782 +0800
160 +++ linux-2.6.32-71.18.1.el6-master/fs/block_dev.c 2011-03-05 11:37:35.624324775 +0800
161 @@ -1389,6 +1389,7 @@
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-71.18.1.el6-master/include/linux/fs.h
170 ===================================================================
171 --- linux-2.6.32-71.18.1.el6-master.orig/include/linux/fs.h 2011-03-05 11:35:40.445043037 +0800
172 +++ linux-2.6.32-71.18.1.el6-master/include/linux/fs.h 2011-03-05 11:37:35.726324137 +0800
173 @@ -2204,6 +2204,10 @@
174 extern void submit_bio(int, struct bio *);
175 extern int bdev_read_only(struct block_device *);
177 +#define HAVE_CLEAR_RDONLY_ON_PUT
178 +extern void dev_set_rdonly(struct block_device *bdev);
179 +extern int dev_check_rdonly(struct block_device *bdev);
180 +extern void dev_clear_rdonly(struct block_device *bdev);
181 extern int set_blocksize(struct block_device *, int);
182 extern int sb_set_blocksize(struct super_block *, int);
183 extern int sb_min_blocksize(struct super_block *, int);
184 Index: linux+rh+chaos/include/linux/bio.h
185 ===================================================================
186 --- linux+rh+chaos.orig/include/linux/bio.h
187 +++ linux+rh+chaos/include/linux/bio.h
188 @@ -126,6 +126,7 @@ struct bio {
189 #define BIO_NULL_MAPPED 9 /* contains invalid user pages */
190 #define BIO_FS_INTEGRITY 10 /* fs owns integrity data, not block layer */
191 #define BIO_QUIET 11 /* Make BIO Quiet */
192 +#define BIO_RDONLY 31 /* device is readonly */
193 #define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag)))