]>
Commit | Line | Data |
---|---|---|
9d09e663 N |
1 | /* |
2 | * Copyright (C) 2010-2011 Neil Brown | |
3 | * Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved. | |
4 | * | |
5 | * This file is released under the GPL. | |
6 | */ | |
7 | ||
8 | #include <linux/slab.h> | |
9 | ||
10 | #include "md.h" | |
11 | #include "raid5.h" | |
9d09e663 N |
12 | #include "bitmap.h" |
13 | ||
3e8dbb7f AK |
14 | #include <linux/device-mapper.h> |
15 | ||
9d09e663 N |
16 | #define DM_MSG_PREFIX "raid" |
17 | ||
18 | /* | |
19 | * If the MD doesn't support MD_SYNC_STATE_FORCED yet, then | |
20 | * make it so the flag doesn't set anything. | |
21 | */ | |
22 | #ifndef MD_SYNC_STATE_FORCED | |
23 | #define MD_SYNC_STATE_FORCED 0 | |
24 | #endif | |
25 | ||
26 | struct raid_dev { | |
27 | /* | |
28 | * Two DM devices, one to hold metadata and one to hold the | |
29 | * actual data/parity. The reason for this is to not confuse | |
30 | * ti->len and give more flexibility in altering size and | |
31 | * characteristics. | |
32 | * | |
33 | * While it is possible for this device to be associated | |
34 | * with a different physical device than the data_dev, it | |
35 | * is intended for it to be the same. | |
36 | * |--------- Physical Device ---------| | |
37 | * |- meta_dev -|------ data_dev ------| | |
38 | */ | |
39 | struct dm_dev *meta_dev; | |
40 | struct dm_dev *data_dev; | |
41 | struct mdk_rdev_s rdev; | |
42 | }; | |
43 | ||
44 | /* | |
45 | * Flags for rs->print_flags field. | |
46 | */ | |
13c87583 JB |
47 | #define DMPF_SYNC 0x1 |
48 | #define DMPF_NOSYNC 0x2 | |
49 | #define DMPF_REBUILD 0x4 | |
50 | #define DMPF_DAEMON_SLEEP 0x8 | |
51 | #define DMPF_MIN_RECOVERY_RATE 0x10 | |
52 | #define DMPF_MAX_RECOVERY_RATE 0x20 | |
53 | #define DMPF_MAX_WRITE_BEHIND 0x40 | |
54 | #define DMPF_STRIPE_CACHE 0x80 | |
9d09e663 N |
55 | |
56 | struct raid_set { | |
57 | struct dm_target *ti; | |
58 | ||
59 | uint64_t print_flags; | |
60 | ||
61 | struct mddev_s md; | |
62 | struct raid_type *raid_type; | |
63 | struct dm_target_callbacks callbacks; | |
64 | ||
65 | struct raid_dev dev[0]; | |
66 | }; | |
67 | ||
68 | /* Supported raid types and properties. */ | |
69 | static struct raid_type { | |
70 | const char *name; /* RAID algorithm. */ | |
71 | const char *descr; /* Descriptor text for logging. */ | |
72 | const unsigned parity_devs; /* # of parity devices. */ | |
73 | const unsigned minimal_devs; /* minimal # of devices in set. */ | |
74 | const unsigned level; /* RAID level. */ | |
75 | const unsigned algorithm; /* RAID algorithm. */ | |
76 | } raid_types[] = { | |
77 | {"raid4", "RAID4 (dedicated parity disk)", 1, 2, 5, ALGORITHM_PARITY_0}, | |
78 | {"raid5_la", "RAID5 (left asymmetric)", 1, 2, 5, ALGORITHM_LEFT_ASYMMETRIC}, | |
79 | {"raid5_ra", "RAID5 (right asymmetric)", 1, 2, 5, ALGORITHM_RIGHT_ASYMMETRIC}, | |
80 | {"raid5_ls", "RAID5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC}, | |
81 | {"raid5_rs", "RAID5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC}, | |
82 | {"raid6_zr", "RAID6 (zero restart)", 2, 4, 6, ALGORITHM_ROTATING_ZERO_RESTART}, | |
83 | {"raid6_nr", "RAID6 (N restart)", 2, 4, 6, ALGORITHM_ROTATING_N_RESTART}, | |
84 | {"raid6_nc", "RAID6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE} | |
85 | }; | |
86 | ||
87 | static struct raid_type *get_raid_type(char *name) | |
88 | { | |
89 | int i; | |
90 | ||
91 | for (i = 0; i < ARRAY_SIZE(raid_types); i++) | |
92 | if (!strcmp(raid_types[i].name, name)) | |
93 | return &raid_types[i]; | |
94 | ||
95 | return NULL; | |
96 | } | |
97 | ||
98 | static struct raid_set *context_alloc(struct dm_target *ti, struct raid_type *raid_type, unsigned raid_devs) | |
99 | { | |
100 | unsigned i; | |
101 | struct raid_set *rs; | |
102 | sector_t sectors_per_dev; | |
103 | ||
104 | if (raid_devs <= raid_type->parity_devs) { | |
105 | ti->error = "Insufficient number of devices"; | |
106 | return ERR_PTR(-EINVAL); | |
107 | } | |
108 | ||
109 | sectors_per_dev = ti->len; | |
110 | if (sector_div(sectors_per_dev, (raid_devs - raid_type->parity_devs))) { | |
111 | ti->error = "Target length not divisible by number of data devices"; | |
112 | return ERR_PTR(-EINVAL); | |
113 | } | |
114 | ||
115 | rs = kzalloc(sizeof(*rs) + raid_devs * sizeof(rs->dev[0]), GFP_KERNEL); | |
116 | if (!rs) { | |
117 | ti->error = "Cannot allocate raid context"; | |
118 | return ERR_PTR(-ENOMEM); | |
119 | } | |
120 | ||
121 | mddev_init(&rs->md); | |
122 | ||
123 | rs->ti = ti; | |
124 | rs->raid_type = raid_type; | |
125 | rs->md.raid_disks = raid_devs; | |
126 | rs->md.level = raid_type->level; | |
127 | rs->md.new_level = rs->md.level; | |
128 | rs->md.dev_sectors = sectors_per_dev; | |
129 | rs->md.layout = raid_type->algorithm; | |
130 | rs->md.new_layout = rs->md.layout; | |
131 | rs->md.delta_disks = 0; | |
132 | rs->md.recovery_cp = 0; | |
133 | ||
134 | for (i = 0; i < raid_devs; i++) | |
135 | md_rdev_init(&rs->dev[i].rdev); | |
136 | ||
137 | /* | |
138 | * Remaining items to be initialized by further RAID params: | |
139 | * rs->md.persistent | |
140 | * rs->md.external | |
141 | * rs->md.chunk_sectors | |
142 | * rs->md.new_chunk_sectors | |
143 | */ | |
144 | ||
145 | return rs; | |
146 | } | |
147 | ||
148 | static void context_free(struct raid_set *rs) | |
149 | { | |
150 | int i; | |
151 | ||
152 | for (i = 0; i < rs->md.raid_disks; i++) | |
153 | if (rs->dev[i].data_dev) | |
154 | dm_put_device(rs->ti, rs->dev[i].data_dev); | |
155 | ||
156 | kfree(rs); | |
157 | } | |
158 | ||
159 | /* | |
160 | * For every device we have two words | |
161 | * <meta_dev>: meta device name or '-' if missing | |
162 | * <data_dev>: data device name or '-' if missing | |
163 | * | |
164 | * This code parses those words. | |
165 | */ | |
166 | static int dev_parms(struct raid_set *rs, char **argv) | |
167 | { | |
168 | int i; | |
169 | int rebuild = 0; | |
170 | int metadata_available = 0; | |
171 | int ret = 0; | |
172 | ||
173 | for (i = 0; i < rs->md.raid_disks; i++, argv += 2) { | |
174 | rs->dev[i].rdev.raid_disk = i; | |
175 | ||
176 | rs->dev[i].meta_dev = NULL; | |
177 | rs->dev[i].data_dev = NULL; | |
178 | ||
179 | /* | |
180 | * There are no offsets, since there is a separate device | |
181 | * for data and metadata. | |
182 | */ | |
183 | rs->dev[i].rdev.data_offset = 0; | |
184 | rs->dev[i].rdev.mddev = &rs->md; | |
185 | ||
186 | if (strcmp(argv[0], "-")) { | |
187 | rs->ti->error = "Metadata devices not supported"; | |
188 | return -EINVAL; | |
189 | } | |
190 | ||
191 | if (!strcmp(argv[1], "-")) { | |
192 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags) && | |
193 | (!rs->dev[i].rdev.recovery_offset)) { | |
194 | rs->ti->error = "Drive designated for rebuild not specified"; | |
195 | return -EINVAL; | |
196 | } | |
197 | ||
198 | continue; | |
199 | } | |
200 | ||
201 | ret = dm_get_device(rs->ti, argv[1], | |
202 | dm_table_get_mode(rs->ti->table), | |
203 | &rs->dev[i].data_dev); | |
204 | if (ret) { | |
205 | rs->ti->error = "RAID device lookup failure"; | |
206 | return ret; | |
207 | } | |
208 | ||
209 | rs->dev[i].rdev.bdev = rs->dev[i].data_dev->bdev; | |
210 | list_add(&rs->dev[i].rdev.same_set, &rs->md.disks); | |
211 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags)) | |
212 | rebuild++; | |
213 | } | |
214 | ||
215 | if (metadata_available) { | |
216 | rs->md.external = 0; | |
217 | rs->md.persistent = 1; | |
218 | rs->md.major_version = 2; | |
219 | } else if (rebuild && !rs->md.recovery_cp) { | |
220 | /* | |
221 | * Without metadata, we will not be able to tell if the array | |
222 | * is in-sync or not - we must assume it is not. Therefore, | |
223 | * it is impossible to rebuild a drive. | |
224 | * | |
225 | * Even if there is metadata, the on-disk information may | |
226 | * indicate that the array is not in-sync and it will then | |
227 | * fail at that time. | |
228 | * | |
229 | * User could specify 'nosync' option if desperate. | |
230 | */ | |
231 | DMERR("Unable to rebuild drive while array is not in-sync"); | |
232 | rs->ti->error = "RAID device lookup failure"; | |
233 | return -EINVAL; | |
234 | } | |
235 | ||
236 | return 0; | |
237 | } | |
238 | ||
239 | /* | |
240 | * Possible arguments are... | |
241 | * RAID456: | |
242 | * <chunk_size> [optional_args] | |
243 | * | |
244 | * Optional args: | |
245 | * [[no]sync] Force or prevent recovery of the entire array | |
246 | * [rebuild <idx>] Rebuild the drive indicated by the index | |
247 | * [daemon_sleep <ms>] Time between bitmap daemon work to clear bits | |
248 | * [min_recovery_rate <kB/sec/disk>] Throttle RAID initialization | |
249 | * [max_recovery_rate <kB/sec/disk>] Throttle RAID initialization | |
250 | * [max_write_behind <sectors>] See '-write-behind=' (man mdadm) | |
251 | * [stripe_cache <sectors>] Stripe cache size for higher RAIDs | |
252 | */ | |
253 | static int parse_raid_params(struct raid_set *rs, char **argv, | |
254 | unsigned num_raid_params) | |
255 | { | |
256 | unsigned i, rebuild_cnt = 0; | |
257 | unsigned long value; | |
258 | char *key; | |
259 | ||
260 | /* | |
261 | * First, parse the in-order required arguments | |
262 | */ | |
263 | if ((strict_strtoul(argv[0], 10, &value) < 0) || | |
264 | !is_power_of_2(value) || (value < 8)) { | |
265 | rs->ti->error = "Bad chunk size"; | |
266 | return -EINVAL; | |
267 | } | |
268 | ||
269 | rs->md.new_chunk_sectors = rs->md.chunk_sectors = value; | |
270 | argv++; | |
271 | num_raid_params--; | |
272 | ||
273 | /* | |
274 | * Second, parse the unordered optional arguments | |
275 | */ | |
276 | for (i = 0; i < rs->md.raid_disks; i++) | |
277 | set_bit(In_sync, &rs->dev[i].rdev.flags); | |
278 | ||
279 | for (i = 0; i < num_raid_params; i++) { | |
13c87583 | 280 | if (!strcasecmp(argv[i], "nosync")) { |
9d09e663 N |
281 | rs->md.recovery_cp = MaxSector; |
282 | rs->print_flags |= DMPF_NOSYNC; | |
283 | rs->md.flags |= MD_SYNC_STATE_FORCED; | |
284 | continue; | |
285 | } | |
13c87583 | 286 | if (!strcasecmp(argv[i], "sync")) { |
9d09e663 N |
287 | rs->md.recovery_cp = 0; |
288 | rs->print_flags |= DMPF_SYNC; | |
289 | rs->md.flags |= MD_SYNC_STATE_FORCED; | |
290 | continue; | |
291 | } | |
292 | ||
293 | /* The rest of the optional arguments come in key/value pairs */ | |
294 | if ((i + 1) >= num_raid_params) { | |
295 | rs->ti->error = "Wrong number of raid parameters given"; | |
296 | return -EINVAL; | |
297 | } | |
298 | ||
299 | key = argv[i++]; | |
300 | if (strict_strtoul(argv[i], 10, &value) < 0) { | |
301 | rs->ti->error = "Bad numerical argument given in raid params"; | |
302 | return -EINVAL; | |
303 | } | |
304 | ||
13c87583 | 305 | if (!strcasecmp(key, "rebuild")) { |
9d09e663 N |
306 | if (++rebuild_cnt > rs->raid_type->parity_devs) { |
307 | rs->ti->error = "Too many rebuild drives given"; | |
308 | return -EINVAL; | |
309 | } | |
310 | if (value > rs->md.raid_disks) { | |
311 | rs->ti->error = "Invalid rebuild index given"; | |
312 | return -EINVAL; | |
313 | } | |
314 | clear_bit(In_sync, &rs->dev[value].rdev.flags); | |
315 | rs->dev[value].rdev.recovery_offset = 0; | |
13c87583 JB |
316 | rs->print_flags |= DMPF_REBUILD; |
317 | } else if (!strcasecmp(key, "max_write_behind")) { | |
9d09e663 N |
318 | rs->print_flags |= DMPF_MAX_WRITE_BEHIND; |
319 | ||
320 | /* | |
321 | * In device-mapper, we specify things in sectors, but | |
322 | * MD records this value in kB | |
323 | */ | |
324 | value /= 2; | |
325 | if (value > COUNTER_MAX) { | |
326 | rs->ti->error = "Max write-behind limit out of range"; | |
327 | return -EINVAL; | |
328 | } | |
329 | rs->md.bitmap_info.max_write_behind = value; | |
13c87583 | 330 | } else if (!strcasecmp(key, "daemon_sleep")) { |
9d09e663 N |
331 | rs->print_flags |= DMPF_DAEMON_SLEEP; |
332 | if (!value || (value > MAX_SCHEDULE_TIMEOUT)) { | |
333 | rs->ti->error = "daemon sleep period out of range"; | |
334 | return -EINVAL; | |
335 | } | |
336 | rs->md.bitmap_info.daemon_sleep = value; | |
13c87583 | 337 | } else if (!strcasecmp(key, "stripe_cache")) { |
9d09e663 N |
338 | rs->print_flags |= DMPF_STRIPE_CACHE; |
339 | ||
340 | /* | |
341 | * In device-mapper, we specify things in sectors, but | |
342 | * MD records this value in kB | |
343 | */ | |
344 | value /= 2; | |
345 | ||
346 | if (rs->raid_type->level < 5) { | |
347 | rs->ti->error = "Inappropriate argument: stripe_cache"; | |
348 | return -EINVAL; | |
349 | } | |
350 | if (raid5_set_cache_size(&rs->md, (int)value)) { | |
351 | rs->ti->error = "Bad stripe_cache size"; | |
352 | return -EINVAL; | |
353 | } | |
13c87583 | 354 | } else if (!strcasecmp(key, "min_recovery_rate")) { |
9d09e663 N |
355 | rs->print_flags |= DMPF_MIN_RECOVERY_RATE; |
356 | if (value > INT_MAX) { | |
357 | rs->ti->error = "min_recovery_rate out of range"; | |
358 | return -EINVAL; | |
359 | } | |
360 | rs->md.sync_speed_min = (int)value; | |
13c87583 | 361 | } else if (!strcasecmp(key, "max_recovery_rate")) { |
9d09e663 N |
362 | rs->print_flags |= DMPF_MAX_RECOVERY_RATE; |
363 | if (value > INT_MAX) { | |
364 | rs->ti->error = "max_recovery_rate out of range"; | |
365 | return -EINVAL; | |
366 | } | |
367 | rs->md.sync_speed_max = (int)value; | |
368 | } else { | |
369 | DMERR("Unable to parse RAID parameter: %s", key); | |
370 | rs->ti->error = "Unable to parse RAID parameters"; | |
371 | return -EINVAL; | |
372 | } | |
373 | } | |
374 | ||
375 | /* Assume there are no metadata devices until the drives are parsed */ | |
376 | rs->md.persistent = 0; | |
377 | rs->md.external = 1; | |
378 | ||
379 | return 0; | |
380 | } | |
381 | ||
382 | static void do_table_event(struct work_struct *ws) | |
383 | { | |
384 | struct raid_set *rs = container_of(ws, struct raid_set, md.event_work); | |
385 | ||
386 | dm_table_event(rs->ti->table); | |
387 | } | |
388 | ||
389 | static int raid_is_congested(struct dm_target_callbacks *cb, int bits) | |
390 | { | |
391 | struct raid_set *rs = container_of(cb, struct raid_set, callbacks); | |
392 | ||
393 | return md_raid5_congested(&rs->md, bits); | |
394 | } | |
395 | ||
9d09e663 N |
396 | /* |
397 | * Construct a RAID4/5/6 mapping: | |
398 | * Args: | |
399 | * <raid_type> <#raid_params> <raid_params> \ | |
400 | * <#raid_devs> { <meta_dev1> <dev1> .. <meta_devN> <devN> } | |
401 | * | |
402 | * ** metadata devices are not supported yet, use '-' instead ** | |
403 | * | |
404 | * <raid_params> varies by <raid_type>. See 'parse_raid_params' for | |
405 | * details on possible <raid_params>. | |
406 | */ | |
407 | static int raid_ctr(struct dm_target *ti, unsigned argc, char **argv) | |
408 | { | |
409 | int ret; | |
410 | struct raid_type *rt; | |
411 | unsigned long num_raid_params, num_raid_devs; | |
412 | struct raid_set *rs = NULL; | |
413 | ||
414 | /* Must have at least <raid_type> <#raid_params> */ | |
415 | if (argc < 2) { | |
416 | ti->error = "Too few arguments"; | |
417 | return -EINVAL; | |
418 | } | |
419 | ||
420 | /* raid type */ | |
421 | rt = get_raid_type(argv[0]); | |
422 | if (!rt) { | |
423 | ti->error = "Unrecognised raid_type"; | |
424 | return -EINVAL; | |
425 | } | |
426 | argc--; | |
427 | argv++; | |
428 | ||
429 | /* number of RAID parameters */ | |
430 | if (strict_strtoul(argv[0], 10, &num_raid_params) < 0) { | |
431 | ti->error = "Cannot understand number of RAID parameters"; | |
432 | return -EINVAL; | |
433 | } | |
434 | argc--; | |
435 | argv++; | |
436 | ||
437 | /* Skip over RAID params for now and find out # of devices */ | |
438 | if (num_raid_params + 1 > argc) { | |
439 | ti->error = "Arguments do not agree with counts given"; | |
440 | return -EINVAL; | |
441 | } | |
442 | ||
443 | if ((strict_strtoul(argv[num_raid_params], 10, &num_raid_devs) < 0) || | |
444 | (num_raid_devs >= INT_MAX)) { | |
445 | ti->error = "Cannot understand number of raid devices"; | |
446 | return -EINVAL; | |
447 | } | |
448 | ||
449 | rs = context_alloc(ti, rt, (unsigned)num_raid_devs); | |
450 | if (IS_ERR(rs)) | |
451 | return PTR_ERR(rs); | |
452 | ||
453 | ret = parse_raid_params(rs, argv, (unsigned)num_raid_params); | |
454 | if (ret) | |
455 | goto bad; | |
456 | ||
457 | ret = -EINVAL; | |
458 | ||
459 | argc -= num_raid_params + 1; /* +1: we already have num_raid_devs */ | |
460 | argv += num_raid_params + 1; | |
461 | ||
462 | if (argc != (num_raid_devs * 2)) { | |
463 | ti->error = "Supplied RAID devices does not match the count given"; | |
464 | goto bad; | |
465 | } | |
466 | ||
467 | ret = dev_parms(rs, argv); | |
468 | if (ret) | |
469 | goto bad; | |
470 | ||
471 | INIT_WORK(&rs->md.event_work, do_table_event); | |
472 | ti->split_io = rs->md.chunk_sectors; | |
473 | ti->private = rs; | |
474 | ||
475 | mutex_lock(&rs->md.reconfig_mutex); | |
476 | ret = md_run(&rs->md); | |
477 | rs->md.in_sync = 0; /* Assume already marked dirty */ | |
478 | mutex_unlock(&rs->md.reconfig_mutex); | |
479 | ||
480 | if (ret) { | |
481 | ti->error = "Fail to run raid array"; | |
482 | goto bad; | |
483 | } | |
484 | ||
485 | rs->callbacks.congested_fn = raid_is_congested; | |
9d09e663 N |
486 | dm_table_add_target_callbacks(ti->table, &rs->callbacks); |
487 | ||
488 | return 0; | |
489 | ||
490 | bad: | |
491 | context_free(rs); | |
492 | ||
493 | return ret; | |
494 | } | |
495 | ||
496 | static void raid_dtr(struct dm_target *ti) | |
497 | { | |
498 | struct raid_set *rs = ti->private; | |
499 | ||
500 | list_del_init(&rs->callbacks.list); | |
501 | md_stop(&rs->md); | |
502 | context_free(rs); | |
503 | } | |
504 | ||
505 | static int raid_map(struct dm_target *ti, struct bio *bio, union map_info *map_context) | |
506 | { | |
507 | struct raid_set *rs = ti->private; | |
508 | mddev_t *mddev = &rs->md; | |
509 | ||
510 | mddev->pers->make_request(mddev, bio); | |
511 | ||
512 | return DM_MAPIO_SUBMITTED; | |
513 | } | |
514 | ||
515 | static int raid_status(struct dm_target *ti, status_type_t type, | |
516 | char *result, unsigned maxlen) | |
517 | { | |
518 | struct raid_set *rs = ti->private; | |
519 | unsigned raid_param_cnt = 1; /* at least 1 for chunksize */ | |
520 | unsigned sz = 0; | |
521 | int i; | |
522 | sector_t sync; | |
523 | ||
524 | switch (type) { | |
525 | case STATUSTYPE_INFO: | |
526 | DMEMIT("%s %d ", rs->raid_type->name, rs->md.raid_disks); | |
527 | ||
528 | for (i = 0; i < rs->md.raid_disks; i++) { | |
529 | if (test_bit(Faulty, &rs->dev[i].rdev.flags)) | |
530 | DMEMIT("D"); | |
531 | else if (test_bit(In_sync, &rs->dev[i].rdev.flags)) | |
532 | DMEMIT("A"); | |
533 | else | |
534 | DMEMIT("a"); | |
535 | } | |
536 | ||
537 | if (test_bit(MD_RECOVERY_RUNNING, &rs->md.recovery)) | |
538 | sync = rs->md.curr_resync_completed; | |
539 | else | |
540 | sync = rs->md.recovery_cp; | |
541 | ||
542 | if (sync > rs->md.resync_max_sectors) | |
543 | sync = rs->md.resync_max_sectors; | |
544 | ||
545 | DMEMIT(" %llu/%llu", | |
546 | (unsigned long long) sync, | |
547 | (unsigned long long) rs->md.resync_max_sectors); | |
548 | ||
549 | break; | |
550 | case STATUSTYPE_TABLE: | |
551 | /* The string you would use to construct this array */ | |
552 | for (i = 0; i < rs->md.raid_disks; i++) | |
13c87583 JB |
553 | if ((rs->print_flags & DMPF_REBUILD) && |
554 | rs->dev[i].data_dev && | |
9d09e663 | 555 | !test_bit(In_sync, &rs->dev[i].rdev.flags)) |
13c87583 | 556 | raid_param_cnt += 2; /* for rebuilds */ |
9d09e663 | 557 | |
13c87583 | 558 | raid_param_cnt += (hweight64(rs->print_flags & ~DMPF_REBUILD) * 2); |
9d09e663 N |
559 | if (rs->print_flags & (DMPF_SYNC | DMPF_NOSYNC)) |
560 | raid_param_cnt--; | |
561 | ||
562 | DMEMIT("%s %u %u", rs->raid_type->name, | |
563 | raid_param_cnt, rs->md.chunk_sectors); | |
564 | ||
565 | if ((rs->print_flags & DMPF_SYNC) && | |
566 | (rs->md.recovery_cp == MaxSector)) | |
567 | DMEMIT(" sync"); | |
568 | if (rs->print_flags & DMPF_NOSYNC) | |
569 | DMEMIT(" nosync"); | |
570 | ||
571 | for (i = 0; i < rs->md.raid_disks; i++) | |
13c87583 JB |
572 | if ((rs->print_flags & DMPF_REBUILD) && |
573 | rs->dev[i].data_dev && | |
9d09e663 N |
574 | !test_bit(In_sync, &rs->dev[i].rdev.flags)) |
575 | DMEMIT(" rebuild %u", i); | |
576 | ||
577 | if (rs->print_flags & DMPF_DAEMON_SLEEP) | |
578 | DMEMIT(" daemon_sleep %lu", | |
579 | rs->md.bitmap_info.daemon_sleep); | |
580 | ||
581 | if (rs->print_flags & DMPF_MIN_RECOVERY_RATE) | |
582 | DMEMIT(" min_recovery_rate %d", rs->md.sync_speed_min); | |
583 | ||
584 | if (rs->print_flags & DMPF_MAX_RECOVERY_RATE) | |
585 | DMEMIT(" max_recovery_rate %d", rs->md.sync_speed_max); | |
586 | ||
587 | if (rs->print_flags & DMPF_MAX_WRITE_BEHIND) | |
588 | DMEMIT(" max_write_behind %lu", | |
589 | rs->md.bitmap_info.max_write_behind); | |
590 | ||
591 | if (rs->print_flags & DMPF_STRIPE_CACHE) { | |
592 | raid5_conf_t *conf = rs->md.private; | |
593 | ||
594 | /* convert from kiB to sectors */ | |
595 | DMEMIT(" stripe_cache %d", | |
596 | conf ? conf->max_nr_stripes * 2 : 0); | |
597 | } | |
598 | ||
599 | DMEMIT(" %d", rs->md.raid_disks); | |
600 | for (i = 0; i < rs->md.raid_disks; i++) { | |
601 | DMEMIT(" -"); /* metadata device */ | |
602 | ||
603 | if (rs->dev[i].data_dev) | |
604 | DMEMIT(" %s", rs->dev[i].data_dev->name); | |
605 | else | |
606 | DMEMIT(" -"); | |
607 | } | |
608 | } | |
609 | ||
610 | return 0; | |
611 | } | |
612 | ||
613 | static int raid_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data) | |
614 | { | |
615 | struct raid_set *rs = ti->private; | |
616 | unsigned i; | |
617 | int ret = 0; | |
618 | ||
619 | for (i = 0; !ret && i < rs->md.raid_disks; i++) | |
620 | if (rs->dev[i].data_dev) | |
621 | ret = fn(ti, | |
622 | rs->dev[i].data_dev, | |
623 | 0, /* No offset on data devs */ | |
624 | rs->md.dev_sectors, | |
625 | data); | |
626 | ||
627 | return ret; | |
628 | } | |
629 | ||
630 | static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits) | |
631 | { | |
632 | struct raid_set *rs = ti->private; | |
633 | unsigned chunk_size = rs->md.chunk_sectors << 9; | |
634 | raid5_conf_t *conf = rs->md.private; | |
635 | ||
636 | blk_limits_io_min(limits, chunk_size); | |
637 | blk_limits_io_opt(limits, chunk_size * (conf->raid_disks - conf->max_degraded)); | |
638 | } | |
639 | ||
640 | static void raid_presuspend(struct dm_target *ti) | |
641 | { | |
642 | struct raid_set *rs = ti->private; | |
643 | ||
644 | md_stop_writes(&rs->md); | |
645 | } | |
646 | ||
647 | static void raid_postsuspend(struct dm_target *ti) | |
648 | { | |
649 | struct raid_set *rs = ti->private; | |
650 | ||
651 | mddev_suspend(&rs->md); | |
652 | } | |
653 | ||
654 | static void raid_resume(struct dm_target *ti) | |
655 | { | |
656 | struct raid_set *rs = ti->private; | |
657 | ||
658 | mddev_resume(&rs->md); | |
659 | } | |
660 | ||
661 | static struct target_type raid_target = { | |
662 | .name = "raid", | |
663 | .version = {1, 0, 0}, | |
664 | .module = THIS_MODULE, | |
665 | .ctr = raid_ctr, | |
666 | .dtr = raid_dtr, | |
667 | .map = raid_map, | |
668 | .status = raid_status, | |
669 | .iterate_devices = raid_iterate_devices, | |
670 | .io_hints = raid_io_hints, | |
671 | .presuspend = raid_presuspend, | |
672 | .postsuspend = raid_postsuspend, | |
673 | .resume = raid_resume, | |
674 | }; | |
675 | ||
676 | static int __init dm_raid_init(void) | |
677 | { | |
678 | return dm_register_target(&raid_target); | |
679 | } | |
680 | ||
681 | static void __exit dm_raid_exit(void) | |
682 | { | |
683 | dm_unregister_target(&raid_target); | |
684 | } | |
685 | ||
686 | module_init(dm_raid_init); | |
687 | module_exit(dm_raid_exit); | |
688 | ||
689 | MODULE_DESCRIPTION(DM_NAME " raid4/5/6 target"); | |
690 | MODULE_ALIAS("dm-raid4"); | |
691 | MODULE_ALIAS("dm-raid5"); | |
692 | MODULE_ALIAS("dm-raid6"); | |
693 | MODULE_AUTHOR("Neil Brown <dm-devel@redhat.com>"); | |
694 | MODULE_LICENSE("GPL"); |