dm-raid.c 17 KB

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