Whamcloud - gitweb
LU-781 kernel: kernel update [RHEL6.2 2.6.32-220]
[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-131.0.15.el6.x86_64/block/blk-core.c
21 ===================================================================
22 --- linux-2.6.32-131.0.15.el6.x86_64.orig/block/blk-core.c      2011-05-10 21:38:33.000000000 +0300
23 +++ linux-2.6.32-131.0.15.el6.x86_64/block/blk-core.c   2011-05-19 21:01:04.000000000 +0300
24 @@ -1416,6 +1416,8 @@ static inline int should_fail_request(st
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 @@ -1517,6 +1519,21 @@ static inline void __generic_make_reques
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 +                       err = 0;
49 +                       goto end_io;
50 +               }
51 +
52                 if (should_fail_request(bio))
53                         goto end_io;
54  
55 @@ -2628,6 +2647,99 @@ int kblockd_schedule_work(struct request
56  }
57  EXPORT_SYMBOL(kblockd_schedule_work);
58  
59 + /*
60 + * Debug code for turning block devices "read-only" (will discard writes
61 + * silently).  This is for filesystem crash/recovery testing.
62 + */
63 +struct deventry {
64 +       dev_t dev;
65 +       struct deventry *next;
66 +};
67 +
68 +static struct deventry *devlist = NULL;
69 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED;
70 +
71 +int dev_check_rdonly(struct block_device *bdev)
72 +{
73 +       struct deventry *cur;
74 +
75 +       if (!bdev)
76 +               return 0;
77 +
78 +       spin_lock(&devlock);
79 +       cur = devlist;
80 +       while(cur) {
81 +               if (bdev->bd_dev == cur->dev) {
82 +                       spin_unlock(&devlock);
83 +                       return 1;
84 +               }
85 +               cur = cur->next;
86 +       }
87 +       spin_unlock(&devlock);
88 +       return 0;
89 +}
90 +
91 +void dev_set_rdonly(struct block_device *bdev)
92 +{
93 +       struct deventry *newdev, *cur;
94 +
95 +       if (!bdev)
96 +               return;
97 +
98 +       newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
99 +       if (!newdev)
100 +               return;
101 +
102 +       spin_lock(&devlock);
103 +       cur = devlist;
104 +       while(cur) {
105 +               if (bdev->bd_dev == cur->dev) {
106 +                       spin_unlock(&devlock);
107 +                       kfree(newdev);
108 +                       return;
109 +               }
110 +               cur = cur->next;
111 +       }
112 +       newdev->dev = bdev->bd_dev;
113 +       newdev->next = devlist;
114 +       devlist = newdev;
115 +       spin_unlock(&devlock);
116 +       printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
117 +               bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
118 +}
119 +
120 +void dev_clear_rdonly(struct block_device *bdev)
121 +{
122 +       struct deventry *cur, *last = NULL;
123 +
124 +       if (!bdev)
125 +               return;
126 +
127 +       spin_lock(&devlock);
128 +       cur = devlist;
129 +       while(cur) {
130 +               if (bdev->bd_dev == cur->dev) {
131 +                       if (last)
132 +                               last->next = cur->next;
133 +                       else
134 +                               devlist = cur->next;
135 +                       spin_unlock(&devlock);
136 +                       kfree(cur);
137 +                       printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
138 +                               bdev->bd_disk ? bdev->bd_disk->disk_name :
139 +                                               "unknown block",
140 +                               bdev->bd_dev);
141 +                       return;
142 +               }
143 +               last = cur;
144 +               cur = cur->next;
145 +       }
146 +       spin_unlock(&devlock);
147 +}
148 +
149 +EXPORT_SYMBOL(dev_set_rdonly);
150 +EXPORT_SYMBOL(dev_clear_rdonly);
151 +EXPORT_SYMBOL(dev_check_rdonly);
152  int __init blk_dev_init(void)
153  {
154         BUILD_BUG_ON(__REQ_NR_BITS > 8 *
155 Index: linux-2.6.32-131.0.15.el6.x86_64/fs/block_dev.c
156 ===================================================================
157 --- linux-2.6.32-131.0.15.el6.x86_64.orig/fs/block_dev.c        2011-05-10 21:38:29.000000000 +0300
158 +++ linux-2.6.32-131.0.15.el6.x86_64/fs/block_dev.c     2011-05-19 21:01:04.000000000 +0300
159 @@ -1389,6 +1389,7 @@ static int __blkdev_put(struct block_dev
160                 if (bdev != bdev->bd_contains)
161                         victim = bdev->bd_contains;
162                 bdev->bd_contains = NULL;
163 +               dev_clear_rdonly(bdev);
164         }
165         unlock_kernel();
166         mutex_unlock(&bdev->bd_mutex);
167 Index: linux-2.6.32-131.0.15.el6.x86_64/include/linux/fs.h
168 ===================================================================
169 --- linux-2.6.32-131.0.15.el6.x86_64.orig/include/linux/fs.h    2011-05-10 21:38:29.000000000 +0300
170 +++ linux-2.6.32-131.0.15.el6.x86_64/include/linux/fs.h 2011-05-19 21:01:04.000000000 +0300
171 @@ -2244,6 +2244,10 @@ struct bio;
172  extern void submit_bio(int, struct bio *);
173  extern int bdev_read_only(struct block_device *);
174  #endif
175 +#define HAVE_CLEAR_RDONLY_ON_PUT
176 +extern void dev_set_rdonly(struct block_device *bdev);
177 +extern int dev_check_rdonly(struct block_device *bdev);
178 +extern void dev_clear_rdonly(struct block_device *bdev);
179  extern int set_blocksize(struct block_device *, int);
180  extern int sb_set_blocksize(struct super_block *, int);
181  extern int sb_min_blocksize(struct super_block *, int);