Whamcloud - gitweb
71e6359c129c6b933ec8d3ac139e6517c4e0d0b5
[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,23 @@ 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 +                       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 @@ -2628,6 +2647,99 @@ int kblockd_schedule_work(struct request
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-131.0.15.el6.x86_64/fs/block_dev.c
158 ===================================================================
159 --- linux-2.6.32-131.0.15.el6.x86_64.orig/fs/block_dev.c        2011-05-10 21:38:29.000000000 +0300
160 +++ linux-2.6.32-131.0.15.el6.x86_64/fs/block_dev.c     2011-05-19 21:01:04.000000000 +0300
161 @@ -1389,6 +1389,7 @@ static int __blkdev_put(struct block_dev
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-131.0.15.el6.x86_64/include/linux/blk_types.h
170 ===================================================================
171 --- linux-2.6.32-131.0.15.el6.x86_64.orig/include/linux/blk_types.h     2011-05-10 21:37:58.000000000 +0300
172 +++ linux-2.6.32-131.0.15.el6.x86_64/include/linux/blk_types.h  2011-05-19 21:03:42.000000000 +0300
173 @@ -24,6 +24,7 @@
174  #define BIO_NULL_MAPPED 9      /* contains invalid user pages */
175  #define BIO_FS_INTEGRITY 10    /* fs owns integrity data, not block layer */
176  #define BIO_QUIET      11      /* Make BIO Quiet */
177 +#define BIO_RDONLY     31      /* device is readonly */
178  #define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag)))
179  
180  /*
181 Index: linux-2.6.32-131.0.15.el6.x86_64/include/linux/fs.h
182 ===================================================================
183 --- linux-2.6.32-131.0.15.el6.x86_64.orig/include/linux/fs.h    2011-05-10 21:38:29.000000000 +0300
184 +++ linux-2.6.32-131.0.15.el6.x86_64/include/linux/fs.h 2011-05-19 21:01:04.000000000 +0300
185 @@ -2244,6 +2244,10 @@ struct bio;
186  extern void submit_bio(int, struct bio *);
187  extern int bdev_read_only(struct block_device *);
188  #endif
189 +#define HAVE_CLEAR_RDONLY_ON_PUT
190 +extern void dev_set_rdonly(struct block_device *bdev);
191 +extern int dev_check_rdonly(struct block_device *bdev);
192 +extern void dev_clear_rdonly(struct block_device *bdev);
193  extern int set_blocksize(struct block_device *, int);
194  extern int sb_set_blocksize(struct super_block *, int);
195  extern int sb_min_blocksize(struct super_block *, int);