Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / dev_read_only-2.6-fc5.patch
1 Index: linux-2.6.16.i686/fs/block_dev.c
2 ===================================================================
3 --- linux-2.6.16.i686.orig/fs/block_dev.c       2006-03-20 13:53:29.000000000 +0800
4 +++ linux-2.6.16.i686/fs/block_dev.c    2006-05-30 21:15:22.000000000 +0800
5 @@ -747,6 +747,7 @@
6         }
7         unlock_kernel();
8         up(&bdev->bd_sem);
9 +       dev_clear_rdonly(bdev);
10         bdput(bdev);
11         return ret;
12  }
13 Index: linux-2.6.16.i686/block/ll_rw_blk.c
14 ===================================================================
15 --- linux-2.6.16.i686.orig/block/ll_rw_blk.c    2006-05-30 15:47:03.000000000 +0800
16 +++ linux-2.6.16.i686/block/ll_rw_blk.c 2006-05-30 21:18:49.000000000 +0800
17 @@ -2940,6 +2940,8 @@
18         set_bit(BIO_EOF, &bio->bi_flags);
19  }
20  
21 +int dev_check_rdonly(struct block_device *bdev);
22 +
23  /**
24   * generic_make_request: hand a buffer to its device driver for I/O
25   * @bio:  The bio describing the location in memory and on the device.
26 @@ -3020,6 +3022,12 @@
27  
28                 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
29                         goto end_io;
30 +               /* this is cfs's dev_rdonly check */
31 +               if (bio->bi_rw == WRITE &&
32 +                               dev_check_rdonly(bio->bi_bdev)) {
33 +                       bio_endio(bio, bio->bi_size, 0);
34 +                       break;
35 +               }
36  
37                 /*
38                  * If this device has partitions, remap block n
39 @@ -3593,6 +3601,91 @@
40         *ioc2 = temp;
41  }
42  EXPORT_SYMBOL(swap_io_context);
43 + /*
44 + * Debug code for turning block devices "read-only" (will discard writes
45 + * silently).  This is for filesystem crash/recovery testing.
46 + */
47 +struct deventry {
48 +       dev_t dev;
49 +       struct deventry *next;
50 +};
51 +
52 +static struct deventry *devlist = NULL;
53 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED; 
54 +
55 +int dev_check_rdonly(struct block_device *bdev) 
56 +{
57 +       struct deventry *cur;
58 +       if (!bdev) return 0;
59 +       spin_lock(&devlock);
60 +       cur = devlist;
61 +       while(cur) {
62 +               if (bdev->bd_dev == cur->dev) {
63 +                       spin_unlock(&devlock);
64 +                       return 1;
65 +       }
66 +               cur = cur->next;
67 +       }
68 +       spin_unlock(&devlock);
69 +       return 0;
70 +}
71 +
72 +void dev_set_rdonly(struct block_device *bdev)
73 +{
74 +       struct deventry *newdev, *cur;
75 +
76 +       if (!bdev) 
77 +               return;
78 +       newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
79 +       if (!newdev) 
80 +               return;
81 +       
82 +       spin_lock(&devlock);
83 +       cur = devlist;
84 +       while(cur) {
85 +               if (bdev->bd_dev == cur->dev) {
86 +                       spin_unlock(&devlock);
87 +                       kfree(newdev);
88 +                       return;
89 +               }
90 +               cur = cur->next;
91 +       }
92 +       newdev->dev = bdev->bd_dev;
93 +       newdev->next = devlist;
94 +       devlist = newdev;
95 +       spin_unlock(&devlock);
96 +       printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
97 +              bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
98 +}
99 +
100 +void dev_clear_rdonly(struct block_device *bdev) 
101 +{
102 +       struct deventry *cur, *last = NULL;
103 +       if (!bdev) return;
104 +       spin_lock(&devlock);
105 +       cur = devlist;
106 +       while(cur) {
107 +               if (bdev->bd_dev == cur->dev) {
108 +                       if (last) 
109 +                               last->next = cur->next;
110 +                       else
111 +                               devlist = cur->next;
112 +                       spin_unlock(&devlock);
113 +                       kfree(cur);
114 +                       printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
115 +                              bdev->bd_disk ? bdev->bd_disk->disk_name :
116 +                                              "unknown block", bdev->bd_dev);
117 +                       return;
118 +               }
119 +               last = cur;
120 +               cur = cur->next;
121 +       }
122 +       spin_unlock(&devlock);
123 +}
124 +
125 +EXPORT_SYMBOL(dev_set_rdonly);
126 +EXPORT_SYMBOL(dev_clear_rdonly);
127 +EXPORT_SYMBOL(dev_check_rdonly);
128  
129  /*
130   * sysfs parts below
131 Index: linux-2.6.16.i686/include/linux/fs.h
132 ===================================================================
133 --- linux-2.6.16.i686.orig/include/linux/fs.h   2006-05-30 21:12:27.000000000 +0800
134 +++ linux-2.6.16.i686/include/linux/fs.h        2006-05-30 21:15:22.000000000 +0800
135 @@ -1558,6 +1558,10 @@
136  struct bio;
137  extern void submit_bio(int, struct bio *);
138  extern int bdev_read_only(struct block_device *);
139 +#define HAVE_CLEAR_RDONLY_ON_PUT
140 +void dev_set_rdonly(struct block_device *bdev);
141 +int dev_check_rdonly(struct block_device *bdev);
142 +void dev_clear_rdonly(struct block_device *bdev);
143  extern int set_blocksize(struct block_device *, int);
144  extern int sb_set_blocksize(struct super_block *, int);
145  extern int sb_min_blocksize(struct super_block *, int);