dm-raid.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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 <linux/module.h>
  9. #include "md.h"
  10. #include "raid1.h"
  11. #include "raid5.h"
  12. #include "bitmap.h"
  13. #include <linux/device-mapper.h>
  14. #define DM_MSG_PREFIX "raid"
  15. /*
  16. * The following flags are used by dm-raid.c to set up the array state.
  17. * They must be cleared before md_run is called.
  18. */
  19. #define FirstUse 10 /* rdev flag */
  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 md_rdev 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. #define DMPF_REGION_SIZE 0X100
  49. struct raid_set {
  50. struct dm_target *ti;
  51. uint32_t bitmap_loaded;
  52. uint32_t print_flags;
  53. struct mddev md;
  54. struct raid_type *raid_type;
  55. struct dm_target_callbacks callbacks;
  56. struct raid_dev dev[0];
  57. };
  58. /* Supported raid types and properties. */
  59. static struct raid_type {
  60. const char *name; /* RAID algorithm. */
  61. const char *descr; /* Descriptor text for logging. */
  62. const unsigned parity_devs; /* # of parity devices. */
  63. const unsigned minimal_devs; /* minimal # of devices in set. */
  64. const unsigned level; /* RAID level. */
  65. const unsigned algorithm; /* RAID algorithm. */
  66. } raid_types[] = {
  67. {"raid1", "RAID1 (mirroring)", 0, 2, 1, 0 /* NONE */},
  68. {"raid4", "RAID4 (dedicated parity disk)", 1, 2, 5, ALGORITHM_PARITY_0},
  69. {"raid5_la", "RAID5 (left asymmetric)", 1, 2, 5, ALGORITHM_LEFT_ASYMMETRIC},
  70. {"raid5_ra", "RAID5 (right asymmetric)", 1, 2, 5, ALGORITHM_RIGHT_ASYMMETRIC},
  71. {"raid5_ls", "RAID5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC},
  72. {"raid5_rs", "RAID5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC},
  73. {"raid6_zr", "RAID6 (zero restart)", 2, 4, 6, ALGORITHM_ROTATING_ZERO_RESTART},
  74. {"raid6_nr", "RAID6 (N restart)", 2, 4, 6, ALGORITHM_ROTATING_N_RESTART},
  75. {"raid6_nc", "RAID6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE}
  76. };
  77. static struct raid_type *get_raid_type(char *name)
  78. {
  79. int i;
  80. for (i = 0; i < ARRAY_SIZE(raid_types); i++)
  81. if (!strcmp(raid_types[i].name, name))
  82. return &raid_types[i];
  83. return NULL;
  84. }
  85. static struct raid_set *context_alloc(struct dm_target *ti, struct raid_type *raid_type, unsigned raid_devs)
  86. {
  87. unsigned i;
  88. struct raid_set *rs;
  89. sector_t sectors_per_dev;
  90. if (raid_devs <= raid_type->parity_devs) {
  91. ti->error = "Insufficient number of devices";
  92. return ERR_PTR(-EINVAL);
  93. }
  94. sectors_per_dev = ti->len;
  95. if ((raid_type->level > 1) &&
  96. sector_div(sectors_per_dev, (raid_devs - raid_type->parity_devs))) {
  97. ti->error = "Target length not divisible by number of data devices";
  98. return ERR_PTR(-EINVAL);
  99. }
  100. rs = kzalloc(sizeof(*rs) + raid_devs * sizeof(rs->dev[0]), GFP_KERNEL);
  101. if (!rs) {
  102. ti->error = "Cannot allocate raid context";
  103. return ERR_PTR(-ENOMEM);
  104. }
  105. mddev_init(&rs->md);
  106. rs->ti = ti;
  107. rs->raid_type = raid_type;
  108. rs->md.raid_disks = raid_devs;
  109. rs->md.level = raid_type->level;
  110. rs->md.new_level = rs->md.level;
  111. rs->md.dev_sectors = sectors_per_dev;
  112. rs->md.layout = raid_type->algorithm;
  113. rs->md.new_layout = rs->md.layout;
  114. rs->md.delta_disks = 0;
  115. rs->md.recovery_cp = 0;
  116. for (i = 0; i < raid_devs; i++)
  117. md_rdev_init(&rs->dev[i].rdev);
  118. /*
  119. * Remaining items to be initialized by further RAID params:
  120. * rs->md.persistent
  121. * rs->md.external
  122. * rs->md.chunk_sectors
  123. * rs->md.new_chunk_sectors
  124. */
  125. return rs;
  126. }
  127. static void context_free(struct raid_set *rs)
  128. {
  129. int i;
  130. for (i = 0; i < rs->md.raid_disks; i++) {
  131. if (rs->dev[i].meta_dev)
  132. dm_put_device(rs->ti, rs->dev[i].meta_dev);
  133. if (rs->dev[i].rdev.sb_page)
  134. put_page(rs->dev[i].rdev.sb_page);
  135. rs->dev[i].rdev.sb_page = NULL;
  136. rs->dev[i].rdev.sb_loaded = 0;
  137. if (rs->dev[i].data_dev)
  138. dm_put_device(rs->ti, rs->dev[i].data_dev);
  139. }
  140. kfree(rs);
  141. }
  142. /*
  143. * For every device we have two words
  144. * <meta_dev>: meta device name or '-' if missing
  145. * <data_dev>: data device name or '-' if missing
  146. *
  147. * The following are permitted:
  148. * - -
  149. * - <data_dev>
  150. * <meta_dev> <data_dev>
  151. *
  152. * The following is not allowed:
  153. * <meta_dev> -
  154. *
  155. * This code parses those words. If there is a failure,
  156. * the caller must use context_free to unwind the operations.
  157. */
  158. static int dev_parms(struct raid_set *rs, char **argv)
  159. {
  160. int i;
  161. int rebuild = 0;
  162. int metadata_available = 0;
  163. int ret = 0;
  164. for (i = 0; i < rs->md.raid_disks; i++, argv += 2) {
  165. rs->dev[i].rdev.raid_disk = i;
  166. rs->dev[i].meta_dev = NULL;
  167. rs->dev[i].data_dev = NULL;
  168. /*
  169. * There are no offsets, since there is a separate device
  170. * for data and metadata.
  171. */
  172. rs->dev[i].rdev.data_offset = 0;
  173. rs->dev[i].rdev.mddev = &rs->md;
  174. if (strcmp(argv[0], "-")) {
  175. ret = dm_get_device(rs->ti, argv[0],
  176. dm_table_get_mode(rs->ti->table),
  177. &rs->dev[i].meta_dev);
  178. rs->ti->error = "RAID metadata device lookup failure";
  179. if (ret)
  180. return ret;
  181. rs->dev[i].rdev.sb_page = alloc_page(GFP_KERNEL);
  182. if (!rs->dev[i].rdev.sb_page)
  183. return -ENOMEM;
  184. }
  185. if (!strcmp(argv[1], "-")) {
  186. if (!test_bit(In_sync, &rs->dev[i].rdev.flags) &&
  187. (!rs->dev[i].rdev.recovery_offset)) {
  188. rs->ti->error = "Drive designated for rebuild not specified";
  189. return -EINVAL;
  190. }
  191. rs->ti->error = "No data device supplied with metadata device";
  192. if (rs->dev[i].meta_dev)
  193. return -EINVAL;
  194. continue;
  195. }
  196. ret = dm_get_device(rs->ti, argv[1],
  197. dm_table_get_mode(rs->ti->table),
  198. &rs->dev[i].data_dev);
  199. if (ret) {
  200. rs->ti->error = "RAID device lookup failure";
  201. return ret;
  202. }
  203. if (rs->dev[i].meta_dev) {
  204. metadata_available = 1;
  205. rs->dev[i].rdev.meta_bdev = rs->dev[i].meta_dev->bdev;
  206. }
  207. rs->dev[i].rdev.bdev = rs->dev[i].data_dev->bdev;
  208. list_add(&rs->dev[i].rdev.same_set, &rs->md.disks);
  209. if (!test_bit(In_sync, &rs->dev[i].rdev.flags))
  210. rebuild++;
  211. }
  212. if (metadata_available) {
  213. rs->md.external = 0;
  214. rs->md.persistent = 1;
  215. rs->md.major_version = 2;
  216. } else if (rebuild && !rs->md.recovery_cp) {
  217. /*
  218. * Without metadata, we will not be able to tell if the array
  219. * is in-sync or not - we must assume it is not. Therefore,
  220. * it is impossible to rebuild a drive.
  221. *
  222. * Even if there is metadata, the on-disk information may
  223. * indicate that the array is not in-sync and it will then
  224. * fail at that time.
  225. *
  226. * User could specify 'nosync' option if desperate.
  227. */
  228. DMERR("Unable to rebuild drive while array is not in-sync");
  229. rs->ti->error = "RAID device lookup failure";
  230. return -EINVAL;
  231. }
  232. return 0;
  233. }
  234. /*
  235. * validate_region_size
  236. * @rs
  237. * @region_size: region size in sectors. If 0, pick a size (4MiB default).
  238. *
  239. * Set rs->md.bitmap_info.chunksize (which really refers to 'region size').
  240. * Ensure that (ti->len/region_size < 2^21) - required by MD bitmap.
  241. *
  242. * Returns: 0 on success, -EINVAL on failure.
  243. */
  244. static int validate_region_size(struct raid_set *rs, unsigned long region_size)
  245. {
  246. unsigned long min_region_size = rs->ti->len / (1 << 21);
  247. if (!region_size) {
  248. /*
  249. * Choose a reasonable default. All figures in sectors.
  250. */
  251. if (min_region_size > (1 << 13)) {
  252. DMINFO("Choosing default region size of %lu sectors",
  253. region_size);
  254. region_size = min_region_size;
  255. } else {
  256. DMINFO("Choosing default region size of 4MiB");
  257. region_size = 1 << 13; /* sectors */
  258. }
  259. } else {
  260. /*
  261. * Validate user-supplied value.
  262. */
  263. if (region_size > rs->ti->len) {
  264. rs->ti->error = "Supplied region size is too large";
  265. return -EINVAL;
  266. }
  267. if (region_size < min_region_size) {
  268. DMERR("Supplied region_size (%lu sectors) below minimum (%lu)",
  269. region_size, min_region_size);
  270. rs->ti->error = "Supplied region size is too small";
  271. return -EINVAL;
  272. }
  273. if (!is_power_of_2(region_size)) {
  274. rs->ti->error = "Region size is not a power of 2";
  275. return -EINVAL;
  276. }
  277. if (region_size < rs->md.chunk_sectors) {
  278. rs->ti->error = "Region size is smaller than the chunk size";
  279. return -EINVAL;
  280. }
  281. }
  282. /*
  283. * Convert sectors to bytes.
  284. */
  285. rs->md.bitmap_info.chunksize = (region_size << 9);
  286. return 0;
  287. }
  288. /*
  289. * Possible arguments are...
  290. * <chunk_size> [optional_args]
  291. *
  292. * Argument definitions
  293. * <chunk_size> The number of sectors per disk that
  294. * will form the "stripe"
  295. * [[no]sync] Force or prevent recovery of the
  296. * entire array
  297. * [rebuild <idx>] Rebuild the drive indicated by the index
  298. * [daemon_sleep <ms>] Time between bitmap daemon work to
  299. * clear bits
  300. * [min_recovery_rate <kB/sec/disk>] Throttle RAID initialization
  301. * [max_recovery_rate <kB/sec/disk>] Throttle RAID initialization
  302. * [write_mostly <idx>] Indicate a write mostly drive via index
  303. * [max_write_behind <sectors>] See '-write-behind=' (man mdadm)
  304. * [stripe_cache <sectors>] Stripe cache size for higher RAIDs
  305. * [region_size <sectors>] Defines granularity of bitmap
  306. */
  307. static int parse_raid_params(struct raid_set *rs, char **argv,
  308. unsigned num_raid_params)
  309. {
  310. unsigned i, rebuild_cnt = 0;
  311. unsigned long value, region_size = 0;
  312. char *key;
  313. /*
  314. * First, parse the in-order required arguments
  315. * "chunk_size" is the only argument of this type.
  316. */
  317. if ((strict_strtoul(argv[0], 10, &value) < 0)) {
  318. rs->ti->error = "Bad chunk size";
  319. return -EINVAL;
  320. } else if (rs->raid_type->level == 1) {
  321. if (value)
  322. DMERR("Ignoring chunk size parameter for RAID 1");
  323. value = 0;
  324. } else if (!is_power_of_2(value)) {
  325. rs->ti->error = "Chunk size must be a power of 2";
  326. return -EINVAL;
  327. } else if (value < 8) {
  328. rs->ti->error = "Chunk size value is too small";
  329. return -EINVAL;
  330. }
  331. rs->md.new_chunk_sectors = rs->md.chunk_sectors = value;
  332. argv++;
  333. num_raid_params--;
  334. /*
  335. * We set each individual device as In_sync with a completed
  336. * 'recovery_offset'. If there has been a device failure or
  337. * replacement then one of the following cases applies:
  338. *
  339. * 1) User specifies 'rebuild'.
  340. * - Device is reset when param is read.
  341. * 2) A new device is supplied.
  342. * - No matching superblock found, resets device.
  343. * 3) Device failure was transient and returns on reload.
  344. * - Failure noticed, resets device for bitmap replay.
  345. * 4) Device hadn't completed recovery after previous failure.
  346. * - Superblock is read and overrides recovery_offset.
  347. *
  348. * What is found in the superblocks of the devices is always
  349. * authoritative, unless 'rebuild' or '[no]sync' was specified.
  350. */
  351. for (i = 0; i < rs->md.raid_disks; i++) {
  352. set_bit(In_sync, &rs->dev[i].rdev.flags);
  353. rs->dev[i].rdev.recovery_offset = MaxSector;
  354. }
  355. /*
  356. * Second, parse the unordered optional arguments
  357. */
  358. for (i = 0; i < num_raid_params; i++) {
  359. if (!strcasecmp(argv[i], "nosync")) {
  360. rs->md.recovery_cp = MaxSector;
  361. rs->print_flags |= DMPF_NOSYNC;
  362. continue;
  363. }
  364. if (!strcasecmp(argv[i], "sync")) {
  365. rs->md.recovery_cp = 0;
  366. rs->print_flags |= DMPF_SYNC;
  367. continue;
  368. }
  369. /* The rest of the optional arguments come in key/value pairs */
  370. if ((i + 1) >= num_raid_params) {
  371. rs->ti->error = "Wrong number of raid parameters given";
  372. return -EINVAL;
  373. }
  374. key = argv[i++];
  375. if (strict_strtoul(argv[i], 10, &value) < 0) {
  376. rs->ti->error = "Bad numerical argument given in raid params";
  377. return -EINVAL;
  378. }
  379. if (!strcasecmp(key, "rebuild")) {
  380. rebuild_cnt++;
  381. if (((rs->raid_type->level != 1) &&
  382. (rebuild_cnt > rs->raid_type->parity_devs)) ||
  383. ((rs->raid_type->level == 1) &&
  384. (rebuild_cnt > (rs->md.raid_disks - 1)))) {
  385. rs->ti->error = "Too many rebuild devices specified for given RAID type";
  386. return -EINVAL;
  387. }
  388. if (value > rs->md.raid_disks) {
  389. rs->ti->error = "Invalid rebuild index given";
  390. return -EINVAL;
  391. }
  392. clear_bit(In_sync, &rs->dev[value].rdev.flags);
  393. rs->dev[value].rdev.recovery_offset = 0;
  394. rs->print_flags |= DMPF_REBUILD;
  395. } else if (!strcasecmp(key, "write_mostly")) {
  396. if (rs->raid_type->level != 1) {
  397. rs->ti->error = "write_mostly option is only valid for RAID1";
  398. return -EINVAL;
  399. }
  400. if (value >= rs->md.raid_disks) {
  401. rs->ti->error = "Invalid write_mostly drive index given";
  402. return -EINVAL;
  403. }
  404. set_bit(WriteMostly, &rs->dev[value].rdev.flags);
  405. } else if (!strcasecmp(key, "max_write_behind")) {
  406. if (rs->raid_type->level != 1) {
  407. rs->ti->error = "max_write_behind option is only valid for RAID1";
  408. return -EINVAL;
  409. }
  410. rs->print_flags |= DMPF_MAX_WRITE_BEHIND;
  411. /*
  412. * In device-mapper, we specify things in sectors, but
  413. * MD records this value in kB
  414. */
  415. value /= 2;
  416. if (value > COUNTER_MAX) {
  417. rs->ti->error = "Max write-behind limit out of range";
  418. return -EINVAL;
  419. }
  420. rs->md.bitmap_info.max_write_behind = value;
  421. } else if (!strcasecmp(key, "daemon_sleep")) {
  422. rs->print_flags |= DMPF_DAEMON_SLEEP;
  423. if (!value || (value > MAX_SCHEDULE_TIMEOUT)) {
  424. rs->ti->error = "daemon sleep period out of range";
  425. return -EINVAL;
  426. }
  427. rs->md.bitmap_info.daemon_sleep = value;
  428. } else if (!strcasecmp(key, "stripe_cache")) {
  429. rs->print_flags |= DMPF_STRIPE_CACHE;
  430. /*
  431. * In device-mapper, we specify things in sectors, but
  432. * MD records this value in kB
  433. */
  434. value /= 2;
  435. if (rs->raid_type->level < 5) {
  436. rs->ti->error = "Inappropriate argument: stripe_cache";
  437. return -EINVAL;
  438. }
  439. if (raid5_set_cache_size(&rs->md, (int)value)) {
  440. rs->ti->error = "Bad stripe_cache size";
  441. return -EINVAL;
  442. }
  443. } else if (!strcasecmp(key, "min_recovery_rate")) {
  444. rs->print_flags |= DMPF_MIN_RECOVERY_RATE;
  445. if (value > INT_MAX) {
  446. rs->ti->error = "min_recovery_rate out of range";
  447. return -EINVAL;
  448. }
  449. rs->md.sync_speed_min = (int)value;
  450. } else if (!strcasecmp(key, "max_recovery_rate")) {
  451. rs->print_flags |= DMPF_MAX_RECOVERY_RATE;
  452. if (value > INT_MAX) {
  453. rs->ti->error = "max_recovery_rate out of range";
  454. return -EINVAL;
  455. }
  456. rs->md.sync_speed_max = (int)value;
  457. } else if (!strcasecmp(key, "region_size")) {
  458. rs->print_flags |= DMPF_REGION_SIZE;
  459. region_size = value;
  460. } else {
  461. DMERR("Unable to parse RAID parameter: %s", key);
  462. rs->ti->error = "Unable to parse RAID parameters";
  463. return -EINVAL;
  464. }
  465. }
  466. if (validate_region_size(rs, region_size))
  467. return -EINVAL;
  468. if (rs->md.chunk_sectors)
  469. rs->ti->split_io = rs->md.chunk_sectors;
  470. else
  471. rs->ti->split_io = region_size;
  472. if (rs->md.chunk_sectors)
  473. rs->ti->split_io = rs->md.chunk_sectors;
  474. else
  475. rs->ti->split_io = region_size;
  476. /* Assume there are no metadata devices until the drives are parsed */
  477. rs->md.persistent = 0;
  478. rs->md.external = 1;
  479. return 0;
  480. }
  481. static void do_table_event(struct work_struct *ws)
  482. {
  483. struct raid_set *rs = container_of(ws, struct raid_set, md.event_work);
  484. dm_table_event(rs->ti->table);
  485. }
  486. static int raid_is_congested(struct dm_target_callbacks *cb, int bits)
  487. {
  488. struct raid_set *rs = container_of(cb, struct raid_set, callbacks);
  489. if (rs->raid_type->level == 1)
  490. return md_raid1_congested(&rs->md, bits);
  491. return md_raid5_congested(&rs->md, bits);
  492. }
  493. /*
  494. * This structure is never routinely used by userspace, unlike md superblocks.
  495. * Devices with this superblock should only ever be accessed via device-mapper.
  496. */
  497. #define DM_RAID_MAGIC 0x64526D44
  498. struct dm_raid_superblock {
  499. __le32 magic; /* "DmRd" */
  500. __le32 features; /* Used to indicate possible future changes */
  501. __le32 num_devices; /* Number of devices in this array. (Max 64) */
  502. __le32 array_position; /* The position of this drive in the array */
  503. __le64 events; /* Incremented by md when superblock updated */
  504. __le64 failed_devices; /* Bit field of devices to indicate failures */
  505. /*
  506. * This offset tracks the progress of the repair or replacement of
  507. * an individual drive.
  508. */
  509. __le64 disk_recovery_offset;
  510. /*
  511. * This offset tracks the progress of the initial array
  512. * synchronisation/parity calculation.
  513. */
  514. __le64 array_resync_offset;
  515. /*
  516. * RAID characteristics
  517. */
  518. __le32 level;
  519. __le32 layout;
  520. __le32 stripe_sectors;
  521. /* Remainder of a logical block is zero-filled when writing (see super_sync()). */
  522. } __packed;
  523. static int read_disk_sb(struct md_rdev *rdev, int size)
  524. {
  525. BUG_ON(!rdev->sb_page);
  526. if (rdev->sb_loaded)
  527. return 0;
  528. if (!sync_page_io(rdev, 0, size, rdev->sb_page, READ, 1)) {
  529. DMERR("Failed to read superblock of device at position %d",
  530. rdev->raid_disk);
  531. set_bit(Faulty, &rdev->flags);
  532. return -EINVAL;
  533. }
  534. rdev->sb_loaded = 1;
  535. return 0;
  536. }
  537. static void super_sync(struct mddev *mddev, struct md_rdev *rdev)
  538. {
  539. struct md_rdev *r;
  540. uint64_t failed_devices;
  541. struct dm_raid_superblock *sb;
  542. sb = page_address(rdev->sb_page);
  543. failed_devices = le64_to_cpu(sb->failed_devices);
  544. rdev_for_each(r, mddev)
  545. if ((r->raid_disk >= 0) && test_bit(Faulty, &r->flags))
  546. failed_devices |= (1ULL << r->raid_disk);
  547. memset(sb + 1, 0, rdev->sb_size - sizeof(*sb));
  548. sb->magic = cpu_to_le32(DM_RAID_MAGIC);
  549. sb->features = cpu_to_le32(0); /* No features yet */
  550. sb->num_devices = cpu_to_le32(mddev->raid_disks);
  551. sb->array_position = cpu_to_le32(rdev->raid_disk);
  552. sb->events = cpu_to_le64(mddev->events);
  553. sb->failed_devices = cpu_to_le64(failed_devices);
  554. sb->disk_recovery_offset = cpu_to_le64(rdev->recovery_offset);
  555. sb->array_resync_offset = cpu_to_le64(mddev->recovery_cp);
  556. sb->level = cpu_to_le32(mddev->level);
  557. sb->layout = cpu_to_le32(mddev->layout);
  558. sb->stripe_sectors = cpu_to_le32(mddev->chunk_sectors);
  559. }
  560. /*
  561. * super_load
  562. *
  563. * This function creates a superblock if one is not found on the device
  564. * and will decide which superblock to use if there's a choice.
  565. *
  566. * Return: 1 if use rdev, 0 if use refdev, -Exxx otherwise
  567. */
  568. static int super_load(struct md_rdev *rdev, struct md_rdev *refdev)
  569. {
  570. int ret;
  571. struct dm_raid_superblock *sb;
  572. struct dm_raid_superblock *refsb;
  573. uint64_t events_sb, events_refsb;
  574. rdev->sb_start = 0;
  575. rdev->sb_size = bdev_logical_block_size(rdev->meta_bdev);
  576. if (rdev->sb_size < sizeof(*sb) || rdev->sb_size > PAGE_SIZE) {
  577. DMERR("superblock size of a logical block is no longer valid");
  578. return -EINVAL;
  579. }
  580. ret = read_disk_sb(rdev, rdev->sb_size);
  581. if (ret)
  582. return ret;
  583. sb = page_address(rdev->sb_page);
  584. /*
  585. * Two cases that we want to write new superblocks and rebuild:
  586. * 1) New device (no matching magic number)
  587. * 2) Device specified for rebuild (!In_sync w/ offset == 0)
  588. */
  589. if ((sb->magic != cpu_to_le32(DM_RAID_MAGIC)) ||
  590. (!test_bit(In_sync, &rdev->flags) && !rdev->recovery_offset)) {
  591. super_sync(rdev->mddev, rdev);
  592. set_bit(FirstUse, &rdev->flags);
  593. /* Force writing of superblocks to disk */
  594. set_bit(MD_CHANGE_DEVS, &rdev->mddev->flags);
  595. /* Any superblock is better than none, choose that if given */
  596. return refdev ? 0 : 1;
  597. }
  598. if (!refdev)
  599. return 1;
  600. events_sb = le64_to_cpu(sb->events);
  601. refsb = page_address(refdev->sb_page);
  602. events_refsb = le64_to_cpu(refsb->events);
  603. return (events_sb > events_refsb) ? 1 : 0;
  604. }
  605. static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev)
  606. {
  607. int role;
  608. struct raid_set *rs = container_of(mddev, struct raid_set, md);
  609. uint64_t events_sb;
  610. uint64_t failed_devices;
  611. struct dm_raid_superblock *sb;
  612. uint32_t new_devs = 0;
  613. uint32_t rebuilds = 0;
  614. struct md_rdev *r;
  615. struct dm_raid_superblock *sb2;
  616. sb = page_address(rdev->sb_page);
  617. events_sb = le64_to_cpu(sb->events);
  618. failed_devices = le64_to_cpu(sb->failed_devices);
  619. /*
  620. * Initialise to 1 if this is a new superblock.
  621. */
  622. mddev->events = events_sb ? : 1;
  623. /*
  624. * Reshaping is not currently allowed
  625. */
  626. if ((le32_to_cpu(sb->level) != mddev->level) ||
  627. (le32_to_cpu(sb->layout) != mddev->layout) ||
  628. (le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors)) {
  629. DMERR("Reshaping arrays not yet supported.");
  630. return -EINVAL;
  631. }
  632. /* We can only change the number of devices in RAID1 right now */
  633. if ((rs->raid_type->level != 1) &&
  634. (le32_to_cpu(sb->num_devices) != mddev->raid_disks)) {
  635. DMERR("Reshaping arrays not yet supported.");
  636. return -EINVAL;
  637. }
  638. if (!(rs->print_flags & (DMPF_SYNC | DMPF_NOSYNC)))
  639. mddev->recovery_cp = le64_to_cpu(sb->array_resync_offset);
  640. /*
  641. * During load, we set FirstUse if a new superblock was written.
  642. * There are two reasons we might not have a superblock:
  643. * 1) The array is brand new - in which case, all of the
  644. * devices must have their In_sync bit set. Also,
  645. * recovery_cp must be 0, unless forced.
  646. * 2) This is a new device being added to an old array
  647. * and the new device needs to be rebuilt - in which
  648. * case the In_sync bit will /not/ be set and
  649. * recovery_cp must be MaxSector.
  650. */
  651. rdev_for_each(r, mddev) {
  652. if (!test_bit(In_sync, &r->flags)) {
  653. DMINFO("Device %d specified for rebuild: "
  654. "Clearing superblock", r->raid_disk);
  655. rebuilds++;
  656. } else if (test_bit(FirstUse, &r->flags))
  657. new_devs++;
  658. }
  659. if (!rebuilds) {
  660. if (new_devs == mddev->raid_disks) {
  661. DMINFO("Superblocks created for new array");
  662. set_bit(MD_ARRAY_FIRST_USE, &mddev->flags);
  663. } else if (new_devs) {
  664. DMERR("New device injected "
  665. "into existing array without 'rebuild' "
  666. "parameter specified");
  667. return -EINVAL;
  668. }
  669. } else if (new_devs) {
  670. DMERR("'rebuild' devices cannot be "
  671. "injected into an array with other first-time devices");
  672. return -EINVAL;
  673. } else if (mddev->recovery_cp != MaxSector) {
  674. DMERR("'rebuild' specified while array is not in-sync");
  675. return -EINVAL;
  676. }
  677. /*
  678. * Now we set the Faulty bit for those devices that are
  679. * recorded in the superblock as failed.
  680. */
  681. rdev_for_each(r, mddev) {
  682. if (!r->sb_page)
  683. continue;
  684. sb2 = page_address(r->sb_page);
  685. sb2->failed_devices = 0;
  686. /*
  687. * Check for any device re-ordering.
  688. */
  689. if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) {
  690. role = le32_to_cpu(sb2->array_position);
  691. if (role != r->raid_disk) {
  692. if (rs->raid_type->level != 1) {
  693. rs->ti->error = "Cannot change device "
  694. "positions in RAID array";
  695. return -EINVAL;
  696. }
  697. DMINFO("RAID1 device #%d now at position #%d",
  698. role, r->raid_disk);
  699. }
  700. /*
  701. * Partial recovery is performed on
  702. * returning failed devices.
  703. */
  704. if (failed_devices & (1 << role))
  705. set_bit(Faulty, &r->flags);
  706. }
  707. }
  708. return 0;
  709. }
  710. static int super_validate(struct mddev *mddev, struct md_rdev *rdev)
  711. {
  712. struct dm_raid_superblock *sb = page_address(rdev->sb_page);
  713. /*
  714. * If mddev->events is not set, we know we have not yet initialized
  715. * the array.
  716. */
  717. if (!mddev->events && super_init_validation(mddev, rdev))
  718. return -EINVAL;
  719. mddev->bitmap_info.offset = 4096 >> 9; /* Enable bitmap creation */
  720. rdev->mddev->bitmap_info.default_offset = 4096 >> 9;
  721. if (!test_bit(FirstUse, &rdev->flags)) {
  722. rdev->recovery_offset = le64_to_cpu(sb->disk_recovery_offset);
  723. if (rdev->recovery_offset != MaxSector)
  724. clear_bit(In_sync, &rdev->flags);
  725. }
  726. /*
  727. * If a device comes back, set it as not In_sync and no longer faulty.
  728. */
  729. if (test_bit(Faulty, &rdev->flags)) {
  730. clear_bit(Faulty, &rdev->flags);
  731. clear_bit(In_sync, &rdev->flags);
  732. rdev->saved_raid_disk = rdev->raid_disk;
  733. rdev->recovery_offset = 0;
  734. }
  735. clear_bit(FirstUse, &rdev->flags);
  736. return 0;
  737. }
  738. /*
  739. * Analyse superblocks and select the freshest.
  740. */
  741. static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs)
  742. {
  743. int ret;
  744. unsigned redundancy = 0;
  745. struct raid_dev *dev;
  746. struct md_rdev *rdev, *tmp, *freshest;
  747. struct mddev *mddev = &rs->md;
  748. switch (rs->raid_type->level) {
  749. case 1:
  750. redundancy = rs->md.raid_disks - 1;
  751. break;
  752. case 4:
  753. case 5:
  754. case 6:
  755. redundancy = rs->raid_type->parity_devs;
  756. break;
  757. default:
  758. ti->error = "Unknown RAID type";
  759. return -EINVAL;
  760. }
  761. freshest = NULL;
  762. rdev_for_each_safe(rdev, tmp, mddev) {
  763. if (!rdev->meta_bdev)
  764. continue;
  765. ret = super_load(rdev, freshest);
  766. switch (ret) {
  767. case 1:
  768. freshest = rdev;
  769. break;
  770. case 0:
  771. break;
  772. default:
  773. dev = container_of(rdev, struct raid_dev, rdev);
  774. if (redundancy--) {
  775. if (dev->meta_dev)
  776. dm_put_device(ti, dev->meta_dev);
  777. dev->meta_dev = NULL;
  778. rdev->meta_bdev = NULL;
  779. if (rdev->sb_page)
  780. put_page(rdev->sb_page);
  781. rdev->sb_page = NULL;
  782. rdev->sb_loaded = 0;
  783. /*
  784. * We might be able to salvage the data device
  785. * even though the meta device has failed. For
  786. * now, we behave as though '- -' had been
  787. * set for this device in the table.
  788. */
  789. if (dev->data_dev)
  790. dm_put_device(ti, dev->data_dev);
  791. dev->data_dev = NULL;
  792. rdev->bdev = NULL;
  793. list_del(&rdev->same_set);
  794. continue;
  795. }
  796. ti->error = "Failed to load superblock";
  797. return ret;
  798. }
  799. }
  800. if (!freshest)
  801. return 0;
  802. /*
  803. * Validation of the freshest device provides the source of
  804. * validation for the remaining devices.
  805. */
  806. ti->error = "Unable to assemble array: Invalid superblocks";
  807. if (super_validate(mddev, freshest))
  808. return -EINVAL;
  809. rdev_for_each(rdev, mddev)
  810. if ((rdev != freshest) && super_validate(mddev, rdev))
  811. return -EINVAL;
  812. return 0;
  813. }
  814. /*
  815. * Construct a RAID4/5/6 mapping:
  816. * Args:
  817. * <raid_type> <#raid_params> <raid_params> \
  818. * <#raid_devs> { <meta_dev1> <dev1> .. <meta_devN> <devN> }
  819. *
  820. * <raid_params> varies by <raid_type>. See 'parse_raid_params' for
  821. * details on possible <raid_params>.
  822. */
  823. static int raid_ctr(struct dm_target *ti, unsigned argc, char **argv)
  824. {
  825. int ret;
  826. struct raid_type *rt;
  827. unsigned long num_raid_params, num_raid_devs;
  828. struct raid_set *rs = NULL;
  829. /* Must have at least <raid_type> <#raid_params> */
  830. if (argc < 2) {
  831. ti->error = "Too few arguments";
  832. return -EINVAL;
  833. }
  834. /* raid type */
  835. rt = get_raid_type(argv[0]);
  836. if (!rt) {
  837. ti->error = "Unrecognised raid_type";
  838. return -EINVAL;
  839. }
  840. argc--;
  841. argv++;
  842. /* number of RAID parameters */
  843. if (strict_strtoul(argv[0], 10, &num_raid_params) < 0) {
  844. ti->error = "Cannot understand number of RAID parameters";
  845. return -EINVAL;
  846. }
  847. argc--;
  848. argv++;
  849. /* Skip over RAID params for now and find out # of devices */
  850. if (num_raid_params + 1 > argc) {
  851. ti->error = "Arguments do not agree with counts given";
  852. return -EINVAL;
  853. }
  854. if ((strict_strtoul(argv[num_raid_params], 10, &num_raid_devs) < 0) ||
  855. (num_raid_devs >= INT_MAX)) {
  856. ti->error = "Cannot understand number of raid devices";
  857. return -EINVAL;
  858. }
  859. rs = context_alloc(ti, rt, (unsigned)num_raid_devs);
  860. if (IS_ERR(rs))
  861. return PTR_ERR(rs);
  862. ret = parse_raid_params(rs, argv, (unsigned)num_raid_params);
  863. if (ret)
  864. goto bad;
  865. ret = -EINVAL;
  866. argc -= num_raid_params + 1; /* +1: we already have num_raid_devs */
  867. argv += num_raid_params + 1;
  868. if (argc != (num_raid_devs * 2)) {
  869. ti->error = "Supplied RAID devices does not match the count given";
  870. goto bad;
  871. }
  872. ret = dev_parms(rs, argv);
  873. if (ret)
  874. goto bad;
  875. rs->md.sync_super = super_sync;
  876. ret = analyse_superblocks(ti, rs);
  877. if (ret)
  878. goto bad;
  879. INIT_WORK(&rs->md.event_work, do_table_event);
  880. ti->private = rs;
  881. ti->num_flush_requests = 1;
  882. mutex_lock(&rs->md.reconfig_mutex);
  883. ret = md_run(&rs->md);
  884. rs->md.in_sync = 0; /* Assume already marked dirty */
  885. mutex_unlock(&rs->md.reconfig_mutex);
  886. if (ret) {
  887. ti->error = "Fail to run raid array";
  888. goto bad;
  889. }
  890. rs->callbacks.congested_fn = raid_is_congested;
  891. dm_table_add_target_callbacks(ti->table, &rs->callbacks);
  892. mddev_suspend(&rs->md);
  893. return 0;
  894. bad:
  895. context_free(rs);
  896. return ret;
  897. }
  898. static void raid_dtr(struct dm_target *ti)
  899. {
  900. struct raid_set *rs = ti->private;
  901. list_del_init(&rs->callbacks.list);
  902. md_stop(&rs->md);
  903. context_free(rs);
  904. }
  905. static int raid_map(struct dm_target *ti, struct bio *bio, union map_info *map_context)
  906. {
  907. struct raid_set *rs = ti->private;
  908. struct mddev *mddev = &rs->md;
  909. mddev->pers->make_request(mddev, bio);
  910. return DM_MAPIO_SUBMITTED;
  911. }
  912. static void raid_status(struct dm_target *ti, status_type_t type,
  913. char *result, unsigned maxlen)
  914. {
  915. struct raid_set *rs = ti->private;
  916. unsigned raid_param_cnt = 1; /* at least 1 for chunksize */
  917. unsigned sz = 0;
  918. int i, array_in_sync = 0;
  919. sector_t sync;
  920. switch (type) {
  921. case STATUSTYPE_INFO:
  922. DMEMIT("%s %d ", rs->raid_type->name, rs->md.raid_disks);
  923. if (test_bit(MD_RECOVERY_RUNNING, &rs->md.recovery))
  924. sync = rs->md.curr_resync_completed;
  925. else
  926. sync = rs->md.recovery_cp;
  927. if (sync >= rs->md.resync_max_sectors) {
  928. array_in_sync = 1;
  929. sync = rs->md.resync_max_sectors;
  930. } else {
  931. /*
  932. * The array may be doing an initial sync, or it may
  933. * be rebuilding individual components. If all the
  934. * devices are In_sync, then it is the array that is
  935. * being initialized.
  936. */
  937. for (i = 0; i < rs->md.raid_disks; i++)
  938. if (!test_bit(In_sync, &rs->dev[i].rdev.flags))
  939. array_in_sync = 1;
  940. }
  941. /*
  942. * Status characters:
  943. * 'D' = Dead/Failed device
  944. * 'a' = Alive but not in-sync
  945. * 'A' = Alive and in-sync
  946. */
  947. for (i = 0; i < rs->md.raid_disks; i++) {
  948. if (test_bit(Faulty, &rs->dev[i].rdev.flags))
  949. DMEMIT("D");
  950. else if (!array_in_sync ||
  951. !test_bit(In_sync, &rs->dev[i].rdev.flags))
  952. DMEMIT("a");
  953. else
  954. DMEMIT("A");
  955. }
  956. /*
  957. * In-sync ratio:
  958. * The in-sync ratio shows the progress of:
  959. * - Initializing the array
  960. * - Rebuilding a subset of devices of the array
  961. * The user can distinguish between the two by referring
  962. * to the status characters.
  963. */
  964. DMEMIT(" %llu/%llu",
  965. (unsigned long long) sync,
  966. (unsigned long long) rs->md.resync_max_sectors);
  967. break;
  968. case STATUSTYPE_TABLE:
  969. /* The string you would use to construct this array */
  970. for (i = 0; i < rs->md.raid_disks; i++) {
  971. if ((rs->print_flags & DMPF_REBUILD) &&
  972. rs->dev[i].data_dev &&
  973. !test_bit(In_sync, &rs->dev[i].rdev.flags))
  974. raid_param_cnt += 2; /* for rebuilds */
  975. if (rs->dev[i].data_dev &&
  976. test_bit(WriteMostly, &rs->dev[i].rdev.flags))
  977. raid_param_cnt += 2;
  978. }
  979. raid_param_cnt += (hweight32(rs->print_flags & ~DMPF_REBUILD) * 2);
  980. if (rs->print_flags & (DMPF_SYNC | DMPF_NOSYNC))
  981. raid_param_cnt--;
  982. DMEMIT("%s %u %u", rs->raid_type->name,
  983. raid_param_cnt, rs->md.chunk_sectors);
  984. if ((rs->print_flags & DMPF_SYNC) &&
  985. (rs->md.recovery_cp == MaxSector))
  986. DMEMIT(" sync");
  987. if (rs->print_flags & DMPF_NOSYNC)
  988. DMEMIT(" nosync");
  989. for (i = 0; i < rs->md.raid_disks; i++)
  990. if ((rs->print_flags & DMPF_REBUILD) &&
  991. rs->dev[i].data_dev &&
  992. !test_bit(In_sync, &rs->dev[i].rdev.flags))
  993. DMEMIT(" rebuild %u", i);
  994. if (rs->print_flags & DMPF_DAEMON_SLEEP)
  995. DMEMIT(" daemon_sleep %lu",
  996. rs->md.bitmap_info.daemon_sleep);
  997. if (rs->print_flags & DMPF_MIN_RECOVERY_RATE)
  998. DMEMIT(" min_recovery_rate %d", rs->md.sync_speed_min);
  999. if (rs->print_flags & DMPF_MAX_RECOVERY_RATE)
  1000. DMEMIT(" max_recovery_rate %d", rs->md.sync_speed_max);
  1001. for (i = 0; i < rs->md.raid_disks; i++)
  1002. if (rs->dev[i].data_dev &&
  1003. test_bit(WriteMostly, &rs->dev[i].rdev.flags))
  1004. DMEMIT(" write_mostly %u", i);
  1005. if (rs->print_flags & DMPF_MAX_WRITE_BEHIND)
  1006. DMEMIT(" max_write_behind %lu",
  1007. rs->md.bitmap_info.max_write_behind);
  1008. if (rs->print_flags & DMPF_STRIPE_CACHE) {
  1009. struct r5conf *conf = rs->md.private;
  1010. /* convert from kiB to sectors */
  1011. DMEMIT(" stripe_cache %d",
  1012. conf ? conf->max_nr_stripes * 2 : 0);
  1013. }
  1014. if (rs->print_flags & DMPF_REGION_SIZE)
  1015. DMEMIT(" region_size %lu",
  1016. rs->md.bitmap_info.chunksize >> 9);
  1017. DMEMIT(" %d", rs->md.raid_disks);
  1018. for (i = 0; i < rs->md.raid_disks; i++) {
  1019. if (rs->dev[i].meta_dev)
  1020. DMEMIT(" %s", rs->dev[i].meta_dev->name);
  1021. else
  1022. DMEMIT(" -");
  1023. if (rs->dev[i].data_dev)
  1024. DMEMIT(" %s", rs->dev[i].data_dev->name);
  1025. else
  1026. DMEMIT(" -");
  1027. }
  1028. }
  1029. }
  1030. static int raid_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data)
  1031. {
  1032. struct raid_set *rs = ti->private;
  1033. unsigned i;
  1034. int ret = 0;
  1035. for (i = 0; !ret && i < rs->md.raid_disks; i++)
  1036. if (rs->dev[i].data_dev)
  1037. ret = fn(ti,
  1038. rs->dev[i].data_dev,
  1039. 0, /* No offset on data devs */
  1040. rs->md.dev_sectors,
  1041. data);
  1042. return ret;
  1043. }
  1044. static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits)
  1045. {
  1046. struct raid_set *rs = ti->private;
  1047. unsigned chunk_size = rs->md.chunk_sectors << 9;
  1048. struct r5conf *conf = rs->md.private;
  1049. blk_limits_io_min(limits, chunk_size);
  1050. blk_limits_io_opt(limits, chunk_size * (conf->raid_disks - conf->max_degraded));
  1051. }
  1052. static void raid_presuspend(struct dm_target *ti)
  1053. {
  1054. struct raid_set *rs = ti->private;
  1055. md_stop_writes(&rs->md);
  1056. }
  1057. static void raid_postsuspend(struct dm_target *ti)
  1058. {
  1059. struct raid_set *rs = ti->private;
  1060. mddev_suspend(&rs->md);
  1061. }
  1062. static void raid_resume(struct dm_target *ti)
  1063. {
  1064. struct raid_set *rs = ti->private;
  1065. if (!rs->bitmap_loaded) {
  1066. bitmap_load(&rs->md);
  1067. rs->bitmap_loaded = 1;
  1068. } else
  1069. md_wakeup_thread(rs->md.thread);
  1070. mddev_resume(&rs->md);
  1071. }
  1072. static struct target_type raid_target = {
  1073. .name = "raid",
  1074. .version = {1, 2, 0},
  1075. .module = THIS_MODULE,
  1076. .ctr = raid_ctr,
  1077. .dtr = raid_dtr,
  1078. .map = raid_map,
  1079. .status = raid_status,
  1080. .iterate_devices = raid_iterate_devices,
  1081. .io_hints = raid_io_hints,
  1082. .presuspend = raid_presuspend,
  1083. .postsuspend = raid_postsuspend,
  1084. .resume = raid_resume,
  1085. };
  1086. static int __init dm_raid_init(void)
  1087. {
  1088. return dm_register_target(&raid_target);
  1089. }
  1090. static void __exit dm_raid_exit(void)
  1091. {
  1092. dm_unregister_target(&raid_target);
  1093. }
  1094. module_init(dm_raid_init);
  1095. module_exit(dm_raid_exit);
  1096. MODULE_DESCRIPTION(DM_NAME " raid4/5/6 target");
  1097. MODULE_ALIAS("dm-raid4");
  1098. MODULE_ALIAS("dm-raid5");
  1099. MODULE_ALIAS("dm-raid6");
  1100. MODULE_AUTHOR("Neil Brown <dm-devel@redhat.com>");
  1101. MODULE_LICENSE("GPL");