1 Index: linux-2.6.9/drivers/block/ll_rw_blk.c
2 ===================================================================
3 --- linux-2.6.9.orig/drivers/block/ll_rw_blk.c
4 +++ linux-2.6.9/drivers/block/ll_rw_blk.c
5 @@ -2331,6 +2331,8 @@ static inline int attempt_front_merge(re
9 +int dev_check_rdonly(struct block_device *bdev);
12 * blk_attempt_remerge - attempt to remerge active head with next request
13 * @q: The &request_queue_t belonging to the device
14 @@ -2636,6 +2638,13 @@ end_io:
15 if (test_bit(QUEUE_FLAG_DEAD, &q->queue_flags))
18 + /* this is cfs's dev_rdonly check */
19 + if (bio->bi_rw == WRITE &&
20 + dev_check_rdonly(bio->bi_bdev)) {
21 + bio_endio(bio, bio->bi_size, 0);
26 * If this device has partitions, remap block n
27 * of partition p to block n+start(p) of the disk.
28 @@ -3185,6 +3194,92 @@ void swap_io_context(struct io_context *
32 + * Debug code for turning block devices "read-only" (will discard writes
33 + * silently). This is for filesystem crash/recovery testing.
37 + struct deventry *next;
40 +static struct deventry *devlist = NULL;
41 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED;
43 +int dev_check_rdonly(struct block_device *bdev)
45 + struct deventry *cur;
46 + if (!bdev) return 0;
47 + spin_lock(&devlock);
50 + if (bdev->bd_dev == cur->dev) {
51 + spin_unlock(&devlock);
56 + spin_unlock(&devlock);
60 +void dev_set_rdonly(struct block_device *bdev)
62 + struct deventry *newdev, *cur;
66 + newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
70 + spin_lock(&devlock);
73 + if (bdev->bd_dev == cur->dev) {
74 + spin_unlock(&devlock);
80 + newdev->dev = bdev->bd_dev;
81 + newdev->next = devlist;
83 + spin_unlock(&devlock);
84 + printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
85 + bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
88 +void dev_clear_rdonly(struct block_device *bdev)
90 + struct deventry *cur, *last = NULL;
92 + spin_lock(&devlock);
95 + if (bdev->bd_dev == cur->dev) {
97 + last->next = cur->next;
99 + devlist = cur->next;
100 + spin_unlock(&devlock);
102 + printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
103 + bdev->bd_disk ? bdev->bd_disk->disk_name :
104 + "unknown block", bdev->bd_dev);
110 + spin_unlock(&devlock);
113 +EXPORT_SYMBOL(dev_set_rdonly);
114 +EXPORT_SYMBOL(dev_clear_rdonly);
115 +EXPORT_SYMBOL(dev_check_rdonly);
120 struct queue_sysfs_entry {
121 Index: linux-2.6.9/fs/block_dev.c
122 ===================================================================
123 --- linux-2.6.9.orig/fs/block_dev.c
124 +++ linux-2.6.9/fs/block_dev.c
125 @@ -744,6 +744,7 @@ int blkdev_put(struct block_device *bdev
126 blkdev_put(bdev->bd_contains);
128 bdev->bd_contains = NULL;
129 + dev_clear_rdonly(bdev);
133 Index: linux-2.6.9/include/linux/fs.h
134 ===================================================================
135 --- linux-2.6.9.orig/include/linux/fs.h
136 +++ linux-2.6.9/include/linux/fs.h
137 @@ -1479,6 +1479,10 @@ extern void file_kill(struct file *f);
139 extern void submit_bio(int, struct bio *);
140 extern int bdev_read_only(struct block_device *);
141 +#define HAVE_CLEAR_RDONLY_ON_PUT
142 +void dev_set_rdonly(struct block_device *bdev);
143 +int dev_check_rdonly(struct block_device *bdev);
144 +void dev_clear_rdonly(struct block_device *bdev);
145 extern int set_blocksize(struct block_device *, int);
146 extern int sb_set_blocksize(struct super_block *, int);
147 extern int sb_min_blocksize(struct super_block *, int);