Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / kernel_patches / patches / dev_read_only-2.6-suse.patch
1 Index: linux-2.6.9/drivers/block/ll_rw_blk.c
2 ===================================================================
3 --- linux-2.6.9.orig/drivers/block/ll_rw_blk.c
4 +++ linux-2.6.9/drivers/block/ll_rw_blk.c
5 @@ -2326,6 +2326,8 @@ static inline int attempt_front_merge(re
6         return 0;
7  }
8  
9 +int dev_check_rdonly(struct block_device *bdev);
10 +
11  /**
12   * blk_attempt_remerge  - attempt to remerge active head with next request
13   * @q:    The &request_queue_t belonging to the device
14 @@ -2631,6 +2633,13 @@ end_io:
15                 if (test_bit(QUEUE_FLAG_DEAD, &q->queue_flags))
16                         goto end_io;
17  
18 +               /* this is cfs's dev_rdonly check */
19 +               if (bio->bi_rw == WRITE &&
20 +                               dev_check_rdonly(bio->bi_bdev)) {
21 +                       bio_endio(bio, bio->bi_size, 0);
22 +                       break;
23 +               }
24 +
25                 /*
26                  * If this device has partitions, remap block n
27                  * of partition p to block n+start(p) of the disk.
28 @@ -3180,6 +3189,92 @@ void swap_io_context(struct io_context *
29  
30  
31  /*
32 + * Debug code for turning block devices "read-only" (will discard writes
33 + * silently).  This is for filesystem crash/recovery testing.
34 + */
35 +struct deventry {
36 +       dev_t dev;
37 +       struct deventry *next;
38 +};
39 +
40 +static struct deventry *devlist = NULL;
41 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED; 
42 +
43 +int dev_check_rdonly(struct block_device *bdev) 
44 +{
45 +       struct deventry *cur;
46 +       if (!bdev) return 0;
47 +       spin_lock(&devlock);
48 +       cur = devlist;
49 +       while(cur) {
50 +               if (bdev->bd_dev == cur->dev) {
51 +                       spin_unlock(&devlock);
52 +                       return 1;
53 +       }
54 +               cur = cur->next;
55 +       }
56 +       spin_unlock(&devlock);
57 +       return 0;
58 +}
59 +
60 +void dev_set_rdonly(struct block_device *bdev)
61 +{
62 +       struct deventry *newdev, *cur;
63 +
64 +       if (!bdev) 
65 +               return;
66 +       newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
67 +       if (!newdev) 
68 +               return;
69 +       
70 +       spin_lock(&devlock);
71 +       cur = devlist;
72 +       while(cur) {
73 +               if (bdev->bd_dev == cur->dev) {
74 +                       spin_unlock(&devlock);
75 +                       kfree(newdev);
76 +                       return;
77 +               }
78 +               cur = cur->next;
79 +       }
80 +       newdev->dev = bdev->bd_dev;
81 +       newdev->next = devlist;
82 +       devlist = newdev;
83 +       spin_unlock(&devlock);
84 +       printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
85 +              bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
86 +}
87 +
88 +void dev_clear_rdonly(struct block_device *bdev) 
89 +{
90 +       struct deventry *cur, *last = NULL;
91 +       if (!bdev) return;
92 +       spin_lock(&devlock);
93 +       cur = devlist;
94 +       while(cur) {
95 +               if (bdev->bd_dev == cur->dev) {
96 +                       if (last) 
97 +                               last->next = cur->next;
98 +                       else
99 +                               devlist = cur->next;
100 +                       spin_unlock(&devlock);
101 +                       kfree(cur);
102 +                       printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
103 +                              bdev->bd_disk ? bdev->bd_disk->disk_name :
104 +                                              "unknown block", bdev->bd_dev);
105 +                       return;
106 +               }
107 +               last = cur;
108 +               cur = cur->next;
109 +       }
110 +       spin_unlock(&devlock);
111 +}
112 +
113 +EXPORT_SYMBOL(dev_set_rdonly);
114 +EXPORT_SYMBOL(dev_clear_rdonly);
115 +EXPORT_SYMBOL(dev_check_rdonly);
116 +
117 +/*
118   * sysfs parts below
119   */
120  struct queue_sysfs_entry {
121 Index: linux-2.6.9/fs/block_dev.c
122 ===================================================================
123 --- linux-2.6.9.orig/fs/block_dev.c
124 +++ linux-2.6.9/fs/block_dev.c
125 @@ -60,6 +60,7 @@ static void kill_bdev(struct block_devic
126  {
127         invalidate_bdev(bdev, 1);
128         truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
129 +       dev_clear_rdonly(bdev);
130  }      
131  
132  int set_blocksize(struct block_device *bdev, int size)
133 Index: linux-2.6.9/include/linux/fs.h
134 ===================================================================
135 --- linux-2.6.9.orig/include/linux/fs.h
136 +++ linux-2.6.9/include/linux/fs.h
137 @@ -1492,6 +1492,10 @@ extern void file_kill(struct file *f);
138  struct bio;
139  extern void submit_bio(int, struct bio *);
140  extern int bdev_read_only(struct block_device *);
141 +#define HAVE_CLEAR_RDONLY_ON_PUT
142 +void dev_set_rdonly(struct block_device *bdev);
143 +int dev_check_rdonly(struct block_device *bdev);
144 +void dev_clear_rdonly(struct block_device *bdev);
145  extern int set_blocksize(struct block_device *, int);
146  extern int sb_set_blocksize(struct super_block *, int);
147  extern int sb_min_blocksize(struct super_block *, int);