Whamcloud - gitweb
LU-354 test: Change dev_set_rdonly() check to warning
[fs/lustre-release.git] / lustre / kernel_patches / patches / dev_read_only-2.6.27-vanilla.patch
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.
5
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
10 writes to the device.
11
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.
21
22 Index: linux-2.6.27.21-0.1/block/blk-core.c
23 ===================================================================
24 --- linux-2.6.27.21-0.1.orig/block/blk-core.c   2009-04-23 02:12:51.000000000 -0600
25 +++ linux-2.6.27.21-0.1/block/blk-core.c        2009-05-22 08:38:02.000000000 -0600
26 @@ -1335,6 +1335,8 @@
27  
28  #endif /* CONFIG_FAIL_MAKE_REQUEST */
29  
30 +int dev_check_rdonly(struct block_device *bdev);
31 +
32  /*
33   * Check whether this bio extends beyond the end of the device.
34   */
35 @@ -1436,6 +1438,12 @@
36  
37                 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
38                         goto end_io;
39
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);
43 +                       break;
44 +               }
45 +
46                 if (should_fail_request(bio))
47                         goto end_io;
48 @@ -2189,6 +2197,91 @@
49  }
50  EXPORT_SYMBOL(kblockd_flush_work);
51  
52 + /*
53 + * Debug code for turning block devices "read-only" (will discard writes
54 + * silently).  This is for filesystem crash/recovery testing.
55 + */
56 +struct deventry {
57 +       dev_t dev;
58 +       struct deventry *next;
59 +};
60 +
61 +static struct deventry *devlist = NULL;
62 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED; 
63 +
64 +int dev_check_rdonly(struct block_device *bdev) 
65 +{
66 +       struct deventry *cur;
67 +       if (!bdev) return 0;
68 +       spin_lock(&devlock);
69 +       cur = devlist;
70 +       while(cur) {
71 +               if (bdev->bd_dev == cur->dev) {
72 +                       spin_unlock(&devlock);
73 +                       return 1;
74 +       }
75 +               cur = cur->next;
76 +       }
77 +       spin_unlock(&devlock);
78 +       return 0;
79 +}
80 +
81 +void dev_set_rdonly(struct block_device *bdev)
82 +{
83 +       struct deventry *newdev, *cur;
84 +
85 +       if (!bdev) 
86 +               return;
87 +       newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
88 +       if (!newdev) 
89 +               return;
90 +       
91 +       spin_lock(&devlock);
92 +       cur = devlist;
93 +       while(cur) {
94 +               if (bdev->bd_dev == cur->dev) {
95 +                       spin_unlock(&devlock);
96 +                       kfree(newdev);
97 +                       return;
98 +               }
99 +               cur = cur->next;
100 +       }
101 +       newdev->dev = bdev->bd_dev;
102 +       newdev->next = devlist;
103 +       devlist = newdev;
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);
107 +}
108 +
109 +void dev_clear_rdonly(struct block_device *bdev) 
110 +{
111 +       struct deventry *cur, *last = NULL;
112 +       if (!bdev) return;
113 +       spin_lock(&devlock);
114 +       cur = devlist;
115 +       while(cur) {
116 +               if (bdev->bd_dev == cur->dev) {
117 +                       if (last) 
118 +                               last->next = cur->next;
119 +                       else
120 +                               devlist = cur->next;
121 +                       spin_unlock(&devlock);
122 +                       kfree(cur);
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);
126 +                       return;
127 +               }
128 +               last = cur;
129 +               cur = cur->next;
130 +       }
131 +       spin_unlock(&devlock);
132 +}
133 +
134 +EXPORT_SYMBOL(dev_set_rdonly);
135 +EXPORT_SYMBOL(dev_clear_rdonly);
136 +EXPORT_SYMBOL(dev_check_rdonly);
137  int __init blk_dev_init(void)
138  {
139         kblockd_workqueue = create_workqueue("kblockd");
140 Index: linux-2.6.27.21-0.1/fs/block_dev.c
141 ===================================================================
142 --- linux-2.6.27.21-0.1.orig/fs/block_dev.c     2009-04-23 02:12:56.000000000 -0600
143 +++ linux-2.6.27.21-0.1/fs/block_dev.c  2009-05-22 08:38:02.000000000 -0600
144 @@ -1208,6 +1208,7 @@
145                 if (bdev != bdev->bd_contains)
146                         victim = bdev->bd_contains;
147                 bdev->bd_contains = NULL;
148 +               dev_clear_rdonly(bdev);
149         }
150         unlock_kernel();
151         mutex_unlock(&bdev->bd_mutex);
152 Index: linux-2.6.27.21-0.1/include/linux/fs.h
153 ===================================================================
154 --- linux-2.6.27.21-0.1.orig/include/linux/fs.h 2009-05-22 08:38:00.000000000 -0600
155 +++ linux-2.6.27.21-0.1/include/linux/fs.h      2009-05-22 08:38:02.000000000 -0600
156 @@ -1898,6 +1898,10 @@
157  extern void submit_bio(int, struct bio *);
158  extern int bdev_read_only(struct block_device *);
159  #endif
160 +#define HAVE_CLEAR_RDONLY_ON_PUT
161 +extern void dev_set_rdonly(struct block_device *bdev);
162 +extern int dev_check_rdonly(struct block_device *bdev);
163 +extern 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);