dm-raid.c 34 KB

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