Whamcloud - gitweb
09338812eaad072f82ae2400da3c8e6cb74df033
[fs/lustre-release.git] / lustre / kernel_patches / patches / dev_read_only-2.6.32-rhel6.patch
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
5 writes to the device.
6
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.
16
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.
19
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
24 @@ -1405,6 +1405,8 @@
25  
26  #endif /* CONFIG_FAIL_MAKE_REQUEST */
27  
28 +int dev_check_rdonly(struct block_device *bdev);
29 +
30  /*
31   * Check whether this bio extends beyond the end of the device.
32   */
33 @@ -1506,6 +1508,23 @@
34                 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
35                         goto end_io;
36  
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;
40 +
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);
49 +                       bio_endio(bio, 0);
50 +                       clear_bit(BIO_RDONLY, &bio->bi_flags);
51 +                       break;
52 +               }
53 +
54                 if (should_fail_request(bio))
55                         goto end_io;
56  
57 @@ -2578,6 +2586,99 @@
58  }
59  EXPORT_SYMBOL(kblockd_schedule_work);
60  
61 + /*
62 + * Debug code for turning block devices "read-only" (will discard writes
63 + * silently).  This is for filesystem crash/recovery testing.
64 + */
65 +struct deventry {
66 +       dev_t dev;
67 +       struct deventry *next;
68 +};
69 +
70 +static struct deventry *devlist = NULL;
71 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED;
72 +
73 +int dev_check_rdonly(struct block_device *bdev)
74 +{
75 +       struct deventry *cur;
76 +
77 +       if (!bdev)
78 +               return 0;
79 +
80 +       spin_lock(&devlock);
81 +       cur = devlist;
82 +       while(cur) {
83 +               if (bdev->bd_dev == cur->dev) {
84 +                       spin_unlock(&devlock);
85 +                       return 1;
86 +               }
87 +               cur = cur->next;
88 +       }
89 +       spin_unlock(&devlock);
90 +       return 0;
91 +}
92 +
93 +void dev_set_rdonly(struct block_device *bdev)
94 +{
95 +       struct deventry *newdev, *cur;
96 +
97 +       if (!bdev)
98 +               return;
99 +
100 +       newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
101 +       if (!newdev)
102 +               return;
103 +
104 +       spin_lock(&devlock);
105 +       cur = devlist;
106 +       while(cur) {
107 +               if (bdev->bd_dev == cur->dev) {
108 +                       spin_unlock(&devlock);
109 +                       kfree(newdev);
110 +                       return;
111 +               }
112 +               cur = cur->next;
113 +       }
114 +       newdev->dev = bdev->bd_dev;
115 +       newdev->next = devlist;
116 +       devlist = newdev;
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);
120 +}
121 +
122 +void dev_clear_rdonly(struct block_device *bdev)
123 +{
124 +       struct deventry *cur, *last = NULL;
125 +
126 +       if (!bdev)
127 +               return;
128 +
129 +       spin_lock(&devlock);
130 +       cur = devlist;
131 +       while(cur) {
132 +               if (bdev->bd_dev == cur->dev) {
133 +                       if (last)
134 +                               last->next = cur->next;
135 +                       else
136 +                               devlist = cur->next;
137 +                       spin_unlock(&devlock);
138 +                       kfree(cur);
139 +                       printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
140 +                               bdev->bd_disk ? bdev->bd_disk->disk_name :
141 +                                               "unknown block",
142 +                               bdev->bd_dev);
143 +                       return;
144 +               }
145 +               last = cur;
146 +               cur = cur->next;
147 +       }
148 +       spin_unlock(&devlock);
149 +}
150 +
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)
155  {
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);
166         }
167         unlock_kernel();
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 *);
176  #endif
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)))
194  
195  /*