Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / dev_read_only-2.6-suse.patch
1 --- linux-2.6.5.orig/drivers/block/ll_rw_blk.c  2005-03-16 11:08:47.404935605 -0800
2 +++ linux-2.6.5/drivers/block/ll_rw_blk.c       2005-03-16 10:57:38.197357003 -0800
3 @@ -2458,6 +2458,8 @@ static inline void blk_partition_remap(s
4         }
5  }
6  
7 +int dev_check_rdonly(struct block_device *bdev);
8 +
9  /**
10   * generic_make_request: hand a buffer to its device driver for I/O
11   * @bio:  The bio describing the location in memory and on the device.
12 @@ -2546,6 +2548,13 @@ end_io:
13                 if (test_bit(QUEUE_FLAG_DEAD, &q->queue_flags))
14                         goto end_io;
15  
16 +               /* this is cfs's dev_rdonly check */
17 +               if (bio->bi_rw == WRITE &&
18 +                               dev_check_rdonly(bio->bi_bdev)) {
19 +                       bio_endio(bio, bio->bi_size, 0);
20 +                       break;
21 +               }
22 +
23                 /*
24                  * If this device has partitions, remap block n
25                  * of partition p to block n+start(p) of the disk.
26 @@ -3078,6 +3087,91 @@ void swap_io_context(struct io_context *
27  }
28  
29  /*
30 + * Debug code for turning block devices "read-only" (will discard writes
31 + * silently).  This is for filesystem crash/recovery testing.
32 + */
33 +struct deventry {
34 +        dev_t dev;
35 +        struct deventry *next;
36 +};
37 +
38 +static struct deventry *devlist = NULL;
39 +static spinlock_t devlock = SPIN_LOCK_UNLOCKED; 
40 +
41 +int dev_check_rdonly(struct block_device *bdev) 
42 +{
43 +        struct deventry *cur;
44 +        if (!bdev) return 0;
45 +        spin_lock(&devlock);
46 +        cur = devlist;
47 +        while(cur) {
48 +                if (bdev->bd_dev == cur->dev) {
49 +                        spin_unlock(&devlock);
50 +                        return 1;
51 +                }
52 +                cur = cur->next;
53 +        }
54 +        spin_unlock(&devlock);
55 +        return 0;
56 +}
57 +
58 +void dev_set_rdonly(struct block_device *bdev)
59 +{
60 +        struct deventry *newdev, *cur;
61 +
62 +        if (!bdev) 
63 +               return;
64 +        newdev = kmalloc(sizeof(struct deventry), GFP_KERNEL);
65 +        if (!newdev) 
66 +               return;
67 +
68 +        spin_lock(&devlock);
69 +        cur = devlist;
70 +        while(cur) {
71 +                if (bdev->bd_dev == cur->dev) {
72 +                        spin_unlock(&devlock);
73 +                        kfree(newdev);
74 +                        return;
75 +                }
76 +                cur = cur->next;
77 +        }
78 +        newdev->dev = bdev->bd_dev;
79 +        newdev->next = devlist;
80 +        devlist = newdev;
81 +        spin_unlock(&devlock);
82 +        printk(KERN_WARNING "Turning device %s read-only\n",
83 +               bdev->bd_disk ? bdev->bd_disk->disk_name : "?");
84 +}
85 +
86 +void dev_clear_rdonly(struct block_device *bdev) 
87 +{
88 +        struct deventry *cur, *last = NULL;
89 +        if (!bdev) return;
90 +        spin_lock(&devlock);
91 +        cur = devlist;
92 +        while(cur) {
93 +                if (bdev->bd_dev == cur->dev) {
94 +                        if (last) 
95 +                                last->next = cur->next;
96 +                        else
97 +                                devlist = cur->next;
98 +                        spin_unlock(&devlock);
99 +                        kfree(cur);
100 +                        printk(KERN_WARNING "Removing read-only on %s\n",
101 +                              bdev->bd_disk ? bdev->bd_disk->disk_name : "?");
102 +                       return;
103 +                }
104 +                last = cur;
105 +                cur = cur->next;
106 +        }
107 +        spin_unlock(&devlock);
108 +}
109 +
110 +EXPORT_SYMBOL(dev_set_rdonly);
111 +EXPORT_SYMBOL(dev_clear_rdonly);
112 +EXPORT_SYMBOL(dev_check_rdonly);
113 +
114 +/*
115   * sysfs parts below
116   */
117  struct queue_sysfs_entry {