1 diff -ur linux-2.6.32.46-0.orig//block/blk-core.c linux-2.6.32.46-0/block/blk-core.c
2 --- linux-2.6.32.46-0.orig//block/blk-core.c 2013-04-26 10:23:22.000000000 -0400
3 +++ linux-2.6.32.46-0/block/blk-core.c 2013-04-26 10:25:46.000000000 -0400
6 #endif /* CONFIG_FAIL_MAKE_REQUEST */
8 +int dev_check_rdonly(struct block_device *bdev);
11 * Check whether this bio extends beyond the end of the device.
13 @@ -1451,6 +1453,12 @@
14 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
17 + /* this is cfs's dev_rdonly check */
18 + if (bio_rw(bio) == WRITE && dev_check_rdonly(bio->bi_bdev)) {
23 if (should_fail_request(bio))
26 @@ -2494,6 +2502,99 @@
28 EXPORT_SYMBOL(kblockd_schedule_work);
31 + * Debug code for turning block devices "read-only" (will discard writes
32 + * silently). This is for filesystem crash/recovery testing.
36 + struct deventry *next;
39 +static struct deventry *devlist = NULL;
40 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED;
42 +int dev_check_rdonly(struct block_device *bdev)
44 + struct deventry *cur;
49 + spin_lock(&devlock);
52 + if (bdev->bd_dev == cur->dev) {
53 + spin_unlock(&devlock);
58 + spin_unlock(&devlock);
62 +void dev_set_rdonly(struct block_device *bdev)
64 + struct deventry *newdev, *cur;
69 + newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
73 + spin_lock(&devlock);
76 + if (bdev->bd_dev == cur->dev) {
77 + spin_unlock(&devlock);
83 + newdev->dev = bdev->bd_dev;
84 + newdev->next = devlist;
86 + spin_unlock(&devlock);
87 + printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
88 + bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
91 +void dev_clear_rdonly(struct block_device *bdev)
93 + struct deventry *cur, *last = NULL;
98 + spin_lock(&devlock);
101 + if (bdev->bd_dev == cur->dev) {
103 + last->next = cur->next;
105 + devlist = cur->next;
106 + spin_unlock(&devlock);
108 + printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
109 + bdev->bd_disk ? bdev->bd_disk->disk_name :
117 + spin_unlock(&devlock);
120 +EXPORT_SYMBOL(dev_set_rdonly);
121 +EXPORT_SYMBOL(dev_clear_rdonly);
122 +EXPORT_SYMBOL(dev_check_rdonly);
123 int __init blk_dev_init(void)
125 BUILD_BUG_ON(__REQ_NR_BITS > 8 *
126 diff -ur linux-2.6.32.46-0.orig//fs/block_dev.c linux-2.6.32.46-0/fs/block_dev.c
127 --- linux-2.6.32.46-0.orig//fs/block_dev.c 2013-04-26 10:23:31.000000000 -0400
128 +++ linux-2.6.32.46-0/fs/block_dev.c 2013-04-26 10:25:46.000000000 -0400
129 @@ -1374,6 +1374,7 @@
130 if (bdev != bdev->bd_contains)
131 victim = bdev->bd_contains;
132 bdev->bd_contains = NULL;
133 + dev_clear_rdonly(bdev);
136 mutex_unlock(&bdev->bd_mutex);
137 diff -ur linux-2.6.32.46-0.orig//include/linux/fs.h linux-2.6.32.46-0/include/linux/fs.h
138 --- linux-2.6.32.46-0.orig//include/linux/fs.h 2013-04-26 10:23:39.000000000 -0400
139 +++ linux-2.6.32.46-0/include/linux/fs.h 2013-04-26 10:25:46.000000000 -0400
140 @@ -2237,6 +2237,10 @@
141 extern void submit_bio(int, struct bio *);
142 extern int bdev_read_only(struct block_device *);
144 +#define HAVE_CLEAR_RDONLY_ON_PUT
145 +extern void dev_set_rdonly(struct block_device *bdev);
146 +extern int dev_check_rdonly(struct block_device *bdev);
147 +extern void dev_clear_rdonly(struct block_device *bdev);
148 extern int set_blocksize(struct block_device *, int);
149 extern int sb_set_blocksize(struct super_block *, int);
150 extern int sb_min_blocksize(struct super_block *, int);