Whamcloud - gitweb
LU-2442 kernel: SLES11 performance fixes and updates
[fs/lustre-release.git] / lustre / kernel_patches / patches / dev_read_only-2.6.32-sles11.patch
1 diff -ur linux-2.6.32.46-0.orig//block/blk-core.c linux-2.6.32.46-0/block/blk-core.c
2 --- linux-2.6.32.46-0.orig//block/blk-core.c    2013-04-26 10:23:22.000000000 -0400
3 +++ linux-2.6.32.46-0/block/blk-core.c  2013-04-26 10:25:46.000000000 -0400
4 @@ -1350,6 +1350,8 @@
5  
6  #endif /* CONFIG_FAIL_MAKE_REQUEST */
7  
8 +int dev_check_rdonly(struct block_device *bdev);
9 +
10  /*
11   * Check whether this bio extends beyond the end of the device.
12   */
13 @@ -1451,6 +1453,12 @@
14                 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
15                         goto end_io;
16  
17 +               /* this is cfs's dev_rdonly check */
18 +               if (bio_rw(bio) == WRITE && dev_check_rdonly(bio->bi_bdev)) {
19 +                       err = 0;
20 +                       goto end_io;
21 +               }
22 +
23                 if (should_fail_request(bio))
24                         goto end_io;
25  
26 @@ -2494,6 +2502,99 @@
27  }
28  EXPORT_SYMBOL(kblockd_schedule_work);
29  
30 + /*
31 + * Debug code for turning block devices "read-only" (will discard writes
32 + * silently).  This is for filesystem crash/recovery testing.
33 + */
34 +struct deventry {
35 +       dev_t dev;
36 +       struct deventry *next;
37 +};
38 +
39 +static struct deventry *devlist = NULL;
40 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED;
41 +
42 +int dev_check_rdonly(struct block_device *bdev)
43 +{
44 +       struct deventry *cur;
45 +
46 +       if (!bdev)
47 +               return 0;
48 +
49 +       spin_lock(&devlock);
50 +       cur = devlist;
51 +       while(cur) {
52 +               if (bdev->bd_dev == cur->dev) {
53 +                       spin_unlock(&devlock);
54 +                       return 1;
55 +               }
56 +               cur = cur->next;
57 +       }
58 +       spin_unlock(&devlock);
59 +       return 0;
60 +}
61 +
62 +void dev_set_rdonly(struct block_device *bdev)
63 +{
64 +       struct deventry *newdev, *cur;
65 +
66 +       if (!bdev)
67 +               return;
68 +
69 +       newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
70 +       if (!newdev)
71 +               return;
72 +
73 +       spin_lock(&devlock);
74 +       cur = devlist;
75 +       while(cur) {
76 +               if (bdev->bd_dev == cur->dev) {
77 +                       spin_unlock(&devlock);
78 +                       kfree(newdev);
79 +                       return;
80 +               }
81 +               cur = cur->next;
82 +       }
83 +       newdev->dev = bdev->bd_dev;
84 +       newdev->next = devlist;
85 +       devlist = newdev;
86 +       spin_unlock(&devlock);
87 +       printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
88 +               bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
89 +}
90 +
91 +void dev_clear_rdonly(struct block_device *bdev)
92 +{
93 +       struct deventry *cur, *last = NULL;
94 +
95 +       if (!bdev)
96 +               return;
97 +
98 +       spin_lock(&devlock);
99 +       cur = devlist;
100 +       while(cur) {
101 +               if (bdev->bd_dev == cur->dev) {
102 +                       if (last)
103 +                               last->next = cur->next;
104 +                       else
105 +                               devlist = cur->next;
106 +                       spin_unlock(&devlock);
107 +                       kfree(cur);
108 +                       printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
109 +                               bdev->bd_disk ? bdev->bd_disk->disk_name :
110 +                                               "unknown block",
111 +                               bdev->bd_dev);
112 +                       return;
113 +               }
114 +               last = cur;
115 +               cur = cur->next;
116 +       }
117 +       spin_unlock(&devlock);
118 +}
119 +
120 +EXPORT_SYMBOL(dev_set_rdonly);
121 +EXPORT_SYMBOL(dev_clear_rdonly);
122 +EXPORT_SYMBOL(dev_check_rdonly);
123  int __init blk_dev_init(void)
124  {
125         BUILD_BUG_ON(__REQ_NR_BITS > 8 *
126 diff -ur linux-2.6.32.46-0.orig//fs/block_dev.c linux-2.6.32.46-0/fs/block_dev.c
127 --- linux-2.6.32.46-0.orig//fs/block_dev.c      2013-04-26 10:23:31.000000000 -0400
128 +++ linux-2.6.32.46-0/fs/block_dev.c    2013-04-26 10:25:46.000000000 -0400
129 @@ -1374,6 +1374,7 @@
130                 if (bdev != bdev->bd_contains)
131                         victim = bdev->bd_contains;
132                 bdev->bd_contains = NULL;
133 +               dev_clear_rdonly(bdev);
134         }
135         unlock_kernel();
136         mutex_unlock(&bdev->bd_mutex);
137 diff -ur linux-2.6.32.46-0.orig//include/linux/fs.h linux-2.6.32.46-0/include/linux/fs.h
138 --- linux-2.6.32.46-0.orig//include/linux/fs.h  2013-04-26 10:23:39.000000000 -0400
139 +++ linux-2.6.32.46-0/include/linux/fs.h        2013-04-26 10:25:46.000000000 -0400
140 @@ -2237,6 +2237,10 @@
141  extern void submit_bio(int, struct bio *);
142  extern int bdev_read_only(struct block_device *);
143  #endif
144 +#define HAVE_CLEAR_RDONLY_ON_PUT
145 +extern void dev_set_rdonly(struct block_device *bdev);
146 +extern int dev_check_rdonly(struct block_device *bdev);
147 +extern void dev_clear_rdonly(struct block_device *bdev);
148  extern int set_blocksize(struct block_device *, int);
149  extern int sb_set_blocksize(struct super_block *, int);
150  extern int sb_min_blocksize(struct super_block *, int);