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-2.6.18.1/block/ll_rw_blk.c
23 ===================================================================
24 --- linux-2.6.18.1.orig/block/ll_rw_blk.c
25 +++ linux-2.6.18.1/block/ll_rw_blk.c
26 @@ -3067,6 +3067,8 @@ static void handle_bad_sector(struct bio
27 set_bit(BIO_EOF, &bio->bi_flags);
30 +int dev_check_rdonly(struct block_device *bdev);
33 * generic_make_request: hand a buffer to its device driver for I/O
34 * @bio: The bio describing the location in memory and on the device.
35 @@ -3151,6 +3153,12 @@ end_io:
37 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
40 + /* this is cfs's dev_rdonly check */
41 + if (bio_rw(bio) == WRITE && dev_check_rdonly(bio->bi_bdev)) {
42 + bio_endio(bio, bio->bi_size, 0);
47 * If this device has partitions, remap block n
48 @@ -3765,6 +3773,91 @@ void swap_io_context(struct io_context *
51 EXPORT_SYMBOL(swap_io_context);
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;
64 +int dev_check_rdonly(struct block_device *bdev)
66 + struct deventry *cur;
67 + if (!bdev) return 0;
68 + spin_lock(&devlock);
71 + if (bdev->bd_dev == cur->dev) {
72 + spin_unlock(&devlock);
77 + spin_unlock(&devlock);
81 +void dev_set_rdonly(struct block_device *bdev)
83 + struct deventry *newdev, *cur;
87 + newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
91 + spin_lock(&devlock);
94 + if (bdev->bd_dev == cur->dev) {
95 + spin_unlock(&devlock);
101 + newdev->dev = bdev->bd_dev;
102 + newdev->next = devlist;
104 + spin_unlock(&devlock);
105 + printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
106 + bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
109 +void dev_clear_rdonly(struct block_device *bdev)
111 + struct deventry *cur, *last = NULL;
113 + spin_lock(&devlock);
116 + if (bdev->bd_dev == cur->dev) {
118 + last->next = cur->next;
120 + devlist = cur->next;
121 + spin_unlock(&devlock);
123 + printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
124 + bdev->bd_disk ? bdev->bd_disk->disk_name :
125 + "unknown block", bdev->bd_dev);
131 + spin_unlock(&devlock);
134 +EXPORT_SYMBOL(dev_set_rdonly);
135 +EXPORT_SYMBOL(dev_clear_rdonly);
136 +EXPORT_SYMBOL(dev_check_rdonly);
140 Index: linux-2.6.18.1/fs/block_dev.c
141 ===================================================================
142 --- linux-2.6.18.1.orig/fs/block_dev.c
143 +++ linux-2.6.18.1/fs/block_dev.c
144 @@ -1059,6 +1059,7 @@ static int __blkdev_put(struct block_dev
145 if (bdev != bdev->bd_contains)
146 victim = bdev->bd_contains;
147 bdev->bd_contains = NULL;
148 + dev_clear_rdonly(bdev);
151 mutex_unlock(&bdev->bd_mutex);
152 Index: linux-2.6.18.1/include/linux/fs.h
153 ===================================================================
154 --- linux-2.6.18.1.orig/include/linux/fs.h
155 +++ linux-2.6.18.1/include/linux/fs.h
156 @@ -1685,6 +1685,10 @@ extern void file_kill(struct file *f);
158 extern void submit_bio(int, struct bio *);
159 extern int bdev_read_only(struct block_device *);
160 +#define HAVE_CLEAR_RDONLY_ON_PUT
161 +void dev_set_rdonly(struct block_device *bdev);
162 +int dev_check_rdonly(struct block_device *bdev);
163 +void dev_clear_rdonly(struct block_device *bdev);
164 extern int set_blocksize(struct block_device *, int);
165 extern int sb_set_blocksize(struct super_block *, int);
166 extern int sb_min_blocksize(struct super_block *, int);