Commit a22c96c737a9cefbe8d6e991c0032ad6db825a67

Authored by Kevin Corry
Committed by Linus Torvalds
1 parent b4cf1b72ee

[PATCH] dm: remove unnecessary typecast

Signed-off-by: Kevin Corry <kevcorry@us.ibm.com>
Cc: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

drivers/md/dm-stripe.c
1 /* 1 /*
2 * Copyright (C) 2001-2003 Sistina Software (UK) Limited. 2 * Copyright (C) 2001-2003 Sistina Software (UK) Limited.
3 * 3 *
4 * This file is released under the GPL. 4 * This file is released under the GPL.
5 */ 5 */
6 6
7 #include "dm.h" 7 #include "dm.h"
8 8
9 #include <linux/module.h> 9 #include <linux/module.h>
10 #include <linux/init.h> 10 #include <linux/init.h>
11 #include <linux/blkdev.h> 11 #include <linux/blkdev.h>
12 #include <linux/bio.h> 12 #include <linux/bio.h>
13 #include <linux/slab.h> 13 #include <linux/slab.h>
14 14
15 struct stripe { 15 struct stripe {
16 struct dm_dev *dev; 16 struct dm_dev *dev;
17 sector_t physical_start; 17 sector_t physical_start;
18 }; 18 };
19 19
20 struct stripe_c { 20 struct stripe_c {
21 uint32_t stripes; 21 uint32_t stripes;
22 22
23 /* The size of this target / num. stripes */ 23 /* The size of this target / num. stripes */
24 sector_t stripe_width; 24 sector_t stripe_width;
25 25
26 /* stripe chunk size */ 26 /* stripe chunk size */
27 uint32_t chunk_shift; 27 uint32_t chunk_shift;
28 sector_t chunk_mask; 28 sector_t chunk_mask;
29 29
30 struct stripe stripe[0]; 30 struct stripe stripe[0];
31 }; 31 };
32 32
33 static inline struct stripe_c *alloc_context(unsigned int stripes) 33 static inline struct stripe_c *alloc_context(unsigned int stripes)
34 { 34 {
35 size_t len; 35 size_t len;
36 36
37 if (array_too_big(sizeof(struct stripe_c), sizeof(struct stripe), 37 if (array_too_big(sizeof(struct stripe_c), sizeof(struct stripe),
38 stripes)) 38 stripes))
39 return NULL; 39 return NULL;
40 40
41 len = sizeof(struct stripe_c) + (sizeof(struct stripe) * stripes); 41 len = sizeof(struct stripe_c) + (sizeof(struct stripe) * stripes);
42 42
43 return kmalloc(len, GFP_KERNEL); 43 return kmalloc(len, GFP_KERNEL);
44 } 44 }
45 45
46 /* 46 /*
47 * Parse a single <dev> <sector> pair 47 * Parse a single <dev> <sector> pair
48 */ 48 */
49 static int get_stripe(struct dm_target *ti, struct stripe_c *sc, 49 static int get_stripe(struct dm_target *ti, struct stripe_c *sc,
50 unsigned int stripe, char **argv) 50 unsigned int stripe, char **argv)
51 { 51 {
52 unsigned long long start; 52 unsigned long long start;
53 53
54 if (sscanf(argv[1], "%llu", &start) != 1) 54 if (sscanf(argv[1], "%llu", &start) != 1)
55 return -EINVAL; 55 return -EINVAL;
56 56
57 if (dm_get_device(ti, argv[0], start, sc->stripe_width, 57 if (dm_get_device(ti, argv[0], start, sc->stripe_width,
58 dm_table_get_mode(ti->table), 58 dm_table_get_mode(ti->table),
59 &sc->stripe[stripe].dev)) 59 &sc->stripe[stripe].dev))
60 return -ENXIO; 60 return -ENXIO;
61 61
62 sc->stripe[stripe].physical_start = start; 62 sc->stripe[stripe].physical_start = start;
63 return 0; 63 return 0;
64 } 64 }
65 65
66 /* 66 /*
67 * Construct a striped mapping. 67 * Construct a striped mapping.
68 * <number of stripes> <chunk size (2^^n)> [<dev_path> <offset>]+ 68 * <number of stripes> <chunk size (2^^n)> [<dev_path> <offset>]+
69 */ 69 */
70 static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv) 70 static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
71 { 71 {
72 struct stripe_c *sc; 72 struct stripe_c *sc;
73 sector_t width; 73 sector_t width;
74 uint32_t stripes; 74 uint32_t stripes;
75 uint32_t chunk_size; 75 uint32_t chunk_size;
76 char *end; 76 char *end;
77 int r; 77 int r;
78 unsigned int i; 78 unsigned int i;
79 79
80 if (argc < 2) { 80 if (argc < 2) {
81 ti->error = "dm-stripe: Not enough arguments"; 81 ti->error = "dm-stripe: Not enough arguments";
82 return -EINVAL; 82 return -EINVAL;
83 } 83 }
84 84
85 stripes = simple_strtoul(argv[0], &end, 10); 85 stripes = simple_strtoul(argv[0], &end, 10);
86 if (*end) { 86 if (*end) {
87 ti->error = "dm-stripe: Invalid stripe count"; 87 ti->error = "dm-stripe: Invalid stripe count";
88 return -EINVAL; 88 return -EINVAL;
89 } 89 }
90 90
91 chunk_size = simple_strtoul(argv[1], &end, 10); 91 chunk_size = simple_strtoul(argv[1], &end, 10);
92 if (*end) { 92 if (*end) {
93 ti->error = "dm-stripe: Invalid chunk_size"; 93 ti->error = "dm-stripe: Invalid chunk_size";
94 return -EINVAL; 94 return -EINVAL;
95 } 95 }
96 96
97 /* 97 /*
98 * chunk_size is a power of two 98 * chunk_size is a power of two
99 */ 99 */
100 if (!chunk_size || (chunk_size & (chunk_size - 1)) || 100 if (!chunk_size || (chunk_size & (chunk_size - 1)) ||
101 (chunk_size < (PAGE_SIZE >> SECTOR_SHIFT))) { 101 (chunk_size < (PAGE_SIZE >> SECTOR_SHIFT))) {
102 ti->error = "dm-stripe: Invalid chunk size"; 102 ti->error = "dm-stripe: Invalid chunk size";
103 return -EINVAL; 103 return -EINVAL;
104 } 104 }
105 105
106 if (((uint32_t)ti->len) & (chunk_size - 1)) { 106 if (ti->len & (chunk_size - 1)) {
107 ti->error = "dm-stripe: Target length not divisible by " 107 ti->error = "dm-stripe: Target length not divisible by "
108 "chunk size"; 108 "chunk size";
109 return -EINVAL; 109 return -EINVAL;
110 } 110 }
111 111
112 width = ti->len; 112 width = ti->len;
113 if (sector_div(width, stripes)) { 113 if (sector_div(width, stripes)) {
114 ti->error = "dm-stripe: Target length not divisible by " 114 ti->error = "dm-stripe: Target length not divisible by "
115 "number of stripes"; 115 "number of stripes";
116 return -EINVAL; 116 return -EINVAL;
117 } 117 }
118 118
119 /* 119 /*
120 * Do we have enough arguments for that many stripes ? 120 * Do we have enough arguments for that many stripes ?
121 */ 121 */
122 if (argc != (2 + 2 * stripes)) { 122 if (argc != (2 + 2 * stripes)) {
123 ti->error = "dm-stripe: Not enough destinations " 123 ti->error = "dm-stripe: Not enough destinations "
124 "specified"; 124 "specified";
125 return -EINVAL; 125 return -EINVAL;
126 } 126 }
127 127
128 sc = alloc_context(stripes); 128 sc = alloc_context(stripes);
129 if (!sc) { 129 if (!sc) {
130 ti->error = "dm-stripe: Memory allocation for striped context " 130 ti->error = "dm-stripe: Memory allocation for striped context "
131 "failed"; 131 "failed";
132 return -ENOMEM; 132 return -ENOMEM;
133 } 133 }
134 134
135 sc->stripes = stripes; 135 sc->stripes = stripes;
136 sc->stripe_width = width; 136 sc->stripe_width = width;
137 ti->split_io = chunk_size; 137 ti->split_io = chunk_size;
138 138
139 sc->chunk_mask = ((sector_t) chunk_size) - 1; 139 sc->chunk_mask = ((sector_t) chunk_size) - 1;
140 for (sc->chunk_shift = 0; chunk_size; sc->chunk_shift++) 140 for (sc->chunk_shift = 0; chunk_size; sc->chunk_shift++)
141 chunk_size >>= 1; 141 chunk_size >>= 1;
142 sc->chunk_shift--; 142 sc->chunk_shift--;
143 143
144 /* 144 /*
145 * Get the stripe destinations. 145 * Get the stripe destinations.
146 */ 146 */
147 for (i = 0; i < stripes; i++) { 147 for (i = 0; i < stripes; i++) {
148 argv += 2; 148 argv += 2;
149 149
150 r = get_stripe(ti, sc, i, argv); 150 r = get_stripe(ti, sc, i, argv);
151 if (r < 0) { 151 if (r < 0) {
152 ti->error = "dm-stripe: Couldn't parse stripe " 152 ti->error = "dm-stripe: Couldn't parse stripe "
153 "destination"; 153 "destination";
154 while (i--) 154 while (i--)
155 dm_put_device(ti, sc->stripe[i].dev); 155 dm_put_device(ti, sc->stripe[i].dev);
156 kfree(sc); 156 kfree(sc);
157 return r; 157 return r;
158 } 158 }
159 } 159 }
160 160
161 ti->private = sc; 161 ti->private = sc;
162 return 0; 162 return 0;
163 } 163 }
164 164
165 static void stripe_dtr(struct dm_target *ti) 165 static void stripe_dtr(struct dm_target *ti)
166 { 166 {
167 unsigned int i; 167 unsigned int i;
168 struct stripe_c *sc = (struct stripe_c *) ti->private; 168 struct stripe_c *sc = (struct stripe_c *) ti->private;
169 169
170 for (i = 0; i < sc->stripes; i++) 170 for (i = 0; i < sc->stripes; i++)
171 dm_put_device(ti, sc->stripe[i].dev); 171 dm_put_device(ti, sc->stripe[i].dev);
172 172
173 kfree(sc); 173 kfree(sc);
174 } 174 }
175 175
176 static int stripe_map(struct dm_target *ti, struct bio *bio, 176 static int stripe_map(struct dm_target *ti, struct bio *bio,
177 union map_info *map_context) 177 union map_info *map_context)
178 { 178 {
179 struct stripe_c *sc = (struct stripe_c *) ti->private; 179 struct stripe_c *sc = (struct stripe_c *) ti->private;
180 180
181 sector_t offset = bio->bi_sector - ti->begin; 181 sector_t offset = bio->bi_sector - ti->begin;
182 sector_t chunk = offset >> sc->chunk_shift; 182 sector_t chunk = offset >> sc->chunk_shift;
183 uint32_t stripe = sector_div(chunk, sc->stripes); 183 uint32_t stripe = sector_div(chunk, sc->stripes);
184 184
185 bio->bi_bdev = sc->stripe[stripe].dev->bdev; 185 bio->bi_bdev = sc->stripe[stripe].dev->bdev;
186 bio->bi_sector = sc->stripe[stripe].physical_start + 186 bio->bi_sector = sc->stripe[stripe].physical_start +
187 (chunk << sc->chunk_shift) + (offset & sc->chunk_mask); 187 (chunk << sc->chunk_shift) + (offset & sc->chunk_mask);
188 return 1; 188 return 1;
189 } 189 }
190 190
191 static int stripe_status(struct dm_target *ti, 191 static int stripe_status(struct dm_target *ti,
192 status_type_t type, char *result, unsigned int maxlen) 192 status_type_t type, char *result, unsigned int maxlen)
193 { 193 {
194 struct stripe_c *sc = (struct stripe_c *) ti->private; 194 struct stripe_c *sc = (struct stripe_c *) ti->private;
195 unsigned int sz = 0; 195 unsigned int sz = 0;
196 unsigned int i; 196 unsigned int i;
197 197
198 switch (type) { 198 switch (type) {
199 case STATUSTYPE_INFO: 199 case STATUSTYPE_INFO:
200 result[0] = '\0'; 200 result[0] = '\0';
201 break; 201 break;
202 202
203 case STATUSTYPE_TABLE: 203 case STATUSTYPE_TABLE:
204 DMEMIT("%d %llu", sc->stripes, 204 DMEMIT("%d %llu", sc->stripes,
205 (unsigned long long)sc->chunk_mask + 1); 205 (unsigned long long)sc->chunk_mask + 1);
206 for (i = 0; i < sc->stripes; i++) 206 for (i = 0; i < sc->stripes; i++)
207 DMEMIT(" %s %llu", sc->stripe[i].dev->name, 207 DMEMIT(" %s %llu", sc->stripe[i].dev->name,
208 (unsigned long long)sc->stripe[i].physical_start); 208 (unsigned long long)sc->stripe[i].physical_start);
209 break; 209 break;
210 } 210 }
211 return 0; 211 return 0;
212 } 212 }
213 213
214 static struct target_type stripe_target = { 214 static struct target_type stripe_target = {
215 .name = "striped", 215 .name = "striped",
216 .version= {1, 0, 2}, 216 .version= {1, 0, 2},
217 .module = THIS_MODULE, 217 .module = THIS_MODULE,
218 .ctr = stripe_ctr, 218 .ctr = stripe_ctr,
219 .dtr = stripe_dtr, 219 .dtr = stripe_dtr,
220 .map = stripe_map, 220 .map = stripe_map,
221 .status = stripe_status, 221 .status = stripe_status,
222 }; 222 };
223 223
224 int __init dm_stripe_init(void) 224 int __init dm_stripe_init(void)
225 { 225 {
226 int r; 226 int r;
227 227
228 r = dm_register_target(&stripe_target); 228 r = dm_register_target(&stripe_target);
229 if (r < 0) 229 if (r < 0)
230 DMWARN("striped target registration failed"); 230 DMWARN("striped target registration failed");
231 231
232 return r; 232 return r;
233 } 233 }
234 234
235 void dm_stripe_exit(void) 235 void dm_stripe_exit(void)
236 { 236 {
237 if (dm_unregister_target(&stripe_target)) 237 if (dm_unregister_target(&stripe_target))
238 DMWARN("striped target unregistration failed"); 238 DMWARN("striped target unregistration failed");
239 239
240 return; 240 return;
241 } 241 }
242 242