dm-raid.c 18 KB

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