Whamcloud - gitweb
a12fb3fde4796b56fa826953045bcbce792e2fd1
[fs/lustre-release.git] / lustre / kernel_patches / patches / dev_read_only-2.6.18-vanilla.patch
1 This patch is no longer needed for Lustre.  It is only included
2 for testing and ease of using the same kernel with older Lustre
3 versions.  This testing functionality was replaced in Linux 3.0
4 by the dm-flakey driver.
5
6 This functionality is mainly used during testing, in order to
7 simulate a server crash for ldiskfs by discarding all of the
8 writes to the filesystem.  For recovery testing we could simulate
9 this by using a special loopback or DM device that also discards
10 writes to the device.
11
12 This functionality is also used by target "failback" in order
13 to speed up service shutdown and takeover by the other node
14 during controlled operation.  However, it would also be possible
15 to do this by simply allowing all of the in-flight requests to
16 complete and then waiting for the service to stop.  This will
17 also be needed by the DMU-OSD, because discarding of writes on
18 a DMU-based target is not safe as it could trigger a storage
19 failure if the data is ever read from disk again and the
20 checksum does not match that expected by the block pointer.
21
22 Index: linux-2.6.18.1/block/ll_rw_blk.c
23 ===================================================================
24 --- linux-2.6.18.1.orig/block/ll_rw_blk.c
25 +++ linux-2.6.18.1/block/ll_rw_blk.c
26 @@ -3067,6 +3067,8 @@ static void handle_bad_sector(struct bio
27         set_bit(BIO_EOF, &bio->bi_flags);
28  }
29  
30 +int dev_check_rdonly(struct block_device *bdev);
31 +
32  /**
33   * generic_make_request: hand a buffer to its device driver for I/O
34   * @bio:  The bio describing the location in memory and on the device.
35 @@ -3151,6 +3153,12 @@ end_io:
36  
37                 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
38                         goto end_io;
39
40 +               /* this is cfs's dev_rdonly check */
41 +               if (bio_rw(bio) == WRITE && dev_check_rdonly(bio->bi_bdev)) {
42 +                       bio_endio(bio, bio->bi_size, 0);
43 +                       break;
44 +               }
45 +
46                 /*
47                  * If this device has partitions, remap block n
48 @@ -3765,6 +3773,91 @@ void swap_io_context(struct io_context *
49         *ioc2 = temp;
50  }
51  EXPORT_SYMBOL(swap_io_context);
52 + /*
53 + * Debug code for turning block devices "read-only" (will discard writes
54 + * silently).  This is for filesystem crash/recovery testing.
55 + */
56 +struct deventry {
57 +       dev_t dev;
58 +       struct deventry *next;
59 +};
60 +
61 +static struct deventry *devlist = NULL;
62 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED; 
63 +
64 +int dev_check_rdonly(struct block_device *bdev) 
65 +{
66 +       struct deventry *cur;
67 +       if (!bdev) return 0;
68 +       spin_lock(&devlock);
69 +       cur = devlist;
70 +       while(cur) {
71 +               if (bdev->bd_dev == cur->dev) {
72 +                       spin_unlock(&devlock);
73 +                       return 1;
74 +       }
75 +               cur = cur->next;
76 +       }
77 +       spin_unlock(&devlock);
78 +       return 0;
79 +}
80 +
81 +void dev_set_rdonly(struct block_device *bdev)
82 +{
83 +       struct deventry *newdev, *cur;
84 +
85 +       if (!bdev) 
86 +               return;
87 +       newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
88 +       if (!newdev) 
89 +               return;
90 +       
91 +       spin_lock(&devlock);
92 +       cur = devlist;
93 +       while(cur) {
94 +               if (bdev->bd_dev == cur->dev) {
95 +                       spin_unlock(&devlock);
96 +                       kfree(newdev);
97 +                       return;
98 +               }
99 +               cur = cur->next;
100 +       }
101 +       newdev->dev = bdev->bd_dev;
102 +       newdev->next = devlist;
103 +       devlist = newdev;
104 +       spin_unlock(&devlock);
105 +       printk(KERN_WARNING "Turning device %s (%#x) read-only\n",
106 +              bdev->bd_disk ? bdev->bd_disk->disk_name : "", bdev->bd_dev);
107 +}
108 +
109 +void dev_clear_rdonly(struct block_device *bdev) 
110 +{
111 +       struct deventry *cur, *last = NULL;
112 +       if (!bdev) return;
113 +       spin_lock(&devlock);
114 +       cur = devlist;
115 +       while(cur) {
116 +               if (bdev->bd_dev == cur->dev) {
117 +                       if (last) 
118 +                               last->next = cur->next;
119 +                       else
120 +                               devlist = cur->next;
121 +                       spin_unlock(&devlock);
122 +                       kfree(cur);
123 +                       printk(KERN_WARNING "Removing read-only on %s (%#x)\n",
124 +                              bdev->bd_disk ? bdev->bd_disk->disk_name :
125 +                                              "unknown block", bdev->bd_dev);
126 +                       return;
127 +               }
128 +               last = cur;
129 +               cur = cur->next;
130 +       }
131 +       spin_unlock(&devlock);
132 +}
133 +
134 +EXPORT_SYMBOL(dev_set_rdonly);
135 +EXPORT_SYMBOL(dev_clear_rdonly);
136 +EXPORT_SYMBOL(dev_check_rdonly);
137  
138  /*
139   * sysfs parts below
140 Index: linux-2.6.18.1/fs/block_dev.c
141 ===================================================================
142 --- linux-2.6.18.1.orig/fs/block_dev.c
143 +++ linux-2.6.18.1/fs/block_dev.c
144 @@ -1059,6 +1059,7 @@ static int __blkdev_put(struct block_dev
145                 if (bdev != bdev->bd_contains)
146                         victim = bdev->bd_contains;
147                 bdev->bd_contains = NULL;
148 +               dev_clear_rdonly(bdev);
149         }
150         unlock_kernel();
151         mutex_unlock(&bdev->bd_mutex);
152 Index: linux-2.6.18.1/include/linux/fs.h
153 ===================================================================
154 --- linux-2.6.18.1.orig/include/linux/fs.h
155 +++ linux-2.6.18.1/include/linux/fs.h
156 @@ -1685,6 +1685,10 @@ extern void file_kill(struct file *f);
157  struct bio;
158  extern void submit_bio(int, struct bio *);
159  extern int bdev_read_only(struct block_device *);
160 +#define HAVE_CLEAR_RDONLY_ON_PUT
161 +void dev_set_rdonly(struct block_device *bdev);
162 +int dev_check_rdonly(struct block_device *bdev);
163 +void dev_clear_rdonly(struct block_device *bdev);
164  extern int set_blocksize(struct block_device *, int);
165  extern int sb_set_blocksize(struct super_block *, int);
166  extern int sb_min_blocksize(struct super_block *, int);