raid1.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816
  1. /*
  2. * raid1.c : Multiple Devices driver for Linux
  3. *
  4. * Copyright (C) 1999, 2000, 2001 Ingo Molnar, Red Hat
  5. *
  6. * Copyright (C) 1996, 1997, 1998 Ingo Molnar, Miguel de Icaza, Gadi Oxman
  7. *
  8. * RAID-1 management functions.
  9. *
  10. * Better read-balancing code written by Mika Kuoppala <miku@iki.fi>, 2000
  11. *
  12. * Fixes to reconstruction by Jakob Østergaard" <jakob@ostenfeld.dk>
  13. * Various fixes by Neil Brown <neilb@cse.unsw.edu.au>
  14. *
  15. * Changes by Peter T. Breuer <ptb@it.uc3m.es> 31/1/2003 to support
  16. * bitmapped intelligence in resync:
  17. *
  18. * - bitmap marked during normal i/o
  19. * - bitmap used to skip nondirty blocks during sync
  20. *
  21. * Additions to bitmap code, (C) 2003-2004 Paul Clements, SteelEye Technology:
  22. * - persistent bitmap code
  23. *
  24. * This program is free software; you can redistribute it and/or modify
  25. * it under the terms of the GNU General Public License as published by
  26. * the Free Software Foundation; either version 2, or (at your option)
  27. * any later version.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * (for example /usr/src/linux/COPYING); if not, write to the Free
  31. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32. */
  33. #include "dm-bio-list.h"
  34. #include <linux/raid/raid1.h>
  35. #include <linux/raid/bitmap.h>
  36. #define DEBUG 0
  37. #if DEBUG
  38. #define PRINTK(x...) printk(x)
  39. #else
  40. #define PRINTK(x...)
  41. #endif
  42. /*
  43. * Number of guaranteed r1bios in case of extreme VM load:
  44. */
  45. #define NR_RAID1_BIOS 256
  46. static mdk_personality_t raid1_personality;
  47. static void unplug_slaves(mddev_t *mddev);
  48. static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
  49. {
  50. struct pool_info *pi = data;
  51. r1bio_t *r1_bio;
  52. int size = offsetof(r1bio_t, bios[pi->raid_disks]);
  53. /* allocate a r1bio with room for raid_disks entries in the bios array */
  54. r1_bio = kmalloc(size, gfp_flags);
  55. if (r1_bio)
  56. memset(r1_bio, 0, size);
  57. else
  58. unplug_slaves(pi->mddev);
  59. return r1_bio;
  60. }
  61. static void r1bio_pool_free(void *r1_bio, void *data)
  62. {
  63. kfree(r1_bio);
  64. }
  65. #define RESYNC_BLOCK_SIZE (64*1024)
  66. //#define RESYNC_BLOCK_SIZE PAGE_SIZE
  67. #define RESYNC_SECTORS (RESYNC_BLOCK_SIZE >> 9)
  68. #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
  69. #define RESYNC_WINDOW (2048*1024)
  70. static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
  71. {
  72. struct pool_info *pi = data;
  73. struct page *page;
  74. r1bio_t *r1_bio;
  75. struct bio *bio;
  76. int i, j;
  77. r1_bio = r1bio_pool_alloc(gfp_flags, pi);
  78. if (!r1_bio) {
  79. unplug_slaves(pi->mddev);
  80. return NULL;
  81. }
  82. /*
  83. * Allocate bios : 1 for reading, n-1 for writing
  84. */
  85. for (j = pi->raid_disks ; j-- ; ) {
  86. bio = bio_alloc(gfp_flags, RESYNC_PAGES);
  87. if (!bio)
  88. goto out_free_bio;
  89. r1_bio->bios[j] = bio;
  90. }
  91. /*
  92. * Allocate RESYNC_PAGES data pages and attach them to
  93. * the first bio;
  94. */
  95. bio = r1_bio->bios[0];
  96. for (i = 0; i < RESYNC_PAGES; i++) {
  97. page = alloc_page(gfp_flags);
  98. if (unlikely(!page))
  99. goto out_free_pages;
  100. bio->bi_io_vec[i].bv_page = page;
  101. }
  102. r1_bio->master_bio = NULL;
  103. return r1_bio;
  104. out_free_pages:
  105. for ( ; i > 0 ; i--)
  106. __free_page(bio->bi_io_vec[i-1].bv_page);
  107. out_free_bio:
  108. while ( ++j < pi->raid_disks )
  109. bio_put(r1_bio->bios[j]);
  110. r1bio_pool_free(r1_bio, data);
  111. return NULL;
  112. }
  113. static void r1buf_pool_free(void *__r1_bio, void *data)
  114. {
  115. struct pool_info *pi = data;
  116. int i;
  117. r1bio_t *r1bio = __r1_bio;
  118. struct bio *bio = r1bio->bios[0];
  119. for (i = 0; i < RESYNC_PAGES; i++) {
  120. __free_page(bio->bi_io_vec[i].bv_page);
  121. bio->bi_io_vec[i].bv_page = NULL;
  122. }
  123. for (i=0 ; i < pi->raid_disks; i++)
  124. bio_put(r1bio->bios[i]);
  125. r1bio_pool_free(r1bio, data);
  126. }
  127. static void put_all_bios(conf_t *conf, r1bio_t *r1_bio)
  128. {
  129. int i;
  130. for (i = 0; i < conf->raid_disks; i++) {
  131. struct bio **bio = r1_bio->bios + i;
  132. if (*bio)
  133. bio_put(*bio);
  134. *bio = NULL;
  135. }
  136. }
  137. static inline void free_r1bio(r1bio_t *r1_bio)
  138. {
  139. unsigned long flags;
  140. conf_t *conf = mddev_to_conf(r1_bio->mddev);
  141. /*
  142. * Wake up any possible resync thread that waits for the device
  143. * to go idle.
  144. */
  145. spin_lock_irqsave(&conf->resync_lock, flags);
  146. if (!--conf->nr_pending) {
  147. wake_up(&conf->wait_idle);
  148. wake_up(&conf->wait_resume);
  149. }
  150. spin_unlock_irqrestore(&conf->resync_lock, flags);
  151. put_all_bios(conf, r1_bio);
  152. mempool_free(r1_bio, conf->r1bio_pool);
  153. }
  154. static inline void put_buf(r1bio_t *r1_bio)
  155. {
  156. conf_t *conf = mddev_to_conf(r1_bio->mddev);
  157. unsigned long flags;
  158. mempool_free(r1_bio, conf->r1buf_pool);
  159. spin_lock_irqsave(&conf->resync_lock, flags);
  160. if (!conf->barrier)
  161. BUG();
  162. --conf->barrier;
  163. wake_up(&conf->wait_resume);
  164. wake_up(&conf->wait_idle);
  165. if (!--conf->nr_pending) {
  166. wake_up(&conf->wait_idle);
  167. wake_up(&conf->wait_resume);
  168. }
  169. spin_unlock_irqrestore(&conf->resync_lock, flags);
  170. }
  171. static void reschedule_retry(r1bio_t *r1_bio)
  172. {
  173. unsigned long flags;
  174. mddev_t *mddev = r1_bio->mddev;
  175. conf_t *conf = mddev_to_conf(mddev);
  176. spin_lock_irqsave(&conf->device_lock, flags);
  177. list_add(&r1_bio->retry_list, &conf->retry_list);
  178. spin_unlock_irqrestore(&conf->device_lock, flags);
  179. md_wakeup_thread(mddev->thread);
  180. }
  181. /*
  182. * raid_end_bio_io() is called when we have finished servicing a mirrored
  183. * operation and are ready to return a success/failure code to the buffer
  184. * cache layer.
  185. */
  186. static void raid_end_bio_io(r1bio_t *r1_bio)
  187. {
  188. struct bio *bio = r1_bio->master_bio;
  189. /* if nobody has done the final endio yet, do it now */
  190. if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) {
  191. PRINTK(KERN_DEBUG "raid1: sync end %s on sectors %llu-%llu\n",
  192. (bio_data_dir(bio) == WRITE) ? "write" : "read",
  193. (unsigned long long) bio->bi_sector,
  194. (unsigned long long) bio->bi_sector +
  195. (bio->bi_size >> 9) - 1);
  196. bio_endio(bio, bio->bi_size,
  197. test_bit(R1BIO_Uptodate, &r1_bio->state) ? 0 : -EIO);
  198. }
  199. free_r1bio(r1_bio);
  200. }
  201. /*
  202. * Update disk head position estimator based on IRQ completion info.
  203. */
  204. static inline void update_head_pos(int disk, r1bio_t *r1_bio)
  205. {
  206. conf_t *conf = mddev_to_conf(r1_bio->mddev);
  207. conf->mirrors[disk].head_position =
  208. r1_bio->sector + (r1_bio->sectors);
  209. }
  210. static int raid1_end_read_request(struct bio *bio, unsigned int bytes_done, int error)
  211. {
  212. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  213. r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
  214. int mirror;
  215. conf_t *conf = mddev_to_conf(r1_bio->mddev);
  216. if (bio->bi_size)
  217. return 1;
  218. mirror = r1_bio->read_disk;
  219. /*
  220. * this branch is our 'one mirror IO has finished' event handler:
  221. */
  222. if (!uptodate)
  223. md_error(r1_bio->mddev, conf->mirrors[mirror].rdev);
  224. else
  225. /*
  226. * Set R1BIO_Uptodate in our master bio, so that
  227. * we will return a good error code for to the higher
  228. * levels even if IO on some other mirrored buffer fails.
  229. *
  230. * The 'master' represents the composite IO operation to
  231. * user-side. So if something waits for IO, then it will
  232. * wait for the 'master' bio.
  233. */
  234. set_bit(R1BIO_Uptodate, &r1_bio->state);
  235. update_head_pos(mirror, r1_bio);
  236. /*
  237. * we have only one bio on the read side
  238. */
  239. if (uptodate)
  240. raid_end_bio_io(r1_bio);
  241. else {
  242. /*
  243. * oops, read error:
  244. */
  245. char b[BDEVNAME_SIZE];
  246. if (printk_ratelimit())
  247. printk(KERN_ERR "raid1: %s: rescheduling sector %llu\n",
  248. bdevname(conf->mirrors[mirror].rdev->bdev,b), (unsigned long long)r1_bio->sector);
  249. reschedule_retry(r1_bio);
  250. }
  251. rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev);
  252. return 0;
  253. }
  254. static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int error)
  255. {
  256. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  257. r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
  258. int mirror, behind = test_bit(R1BIO_BehindIO, &r1_bio->state);
  259. conf_t *conf = mddev_to_conf(r1_bio->mddev);
  260. if (bio->bi_size)
  261. return 1;
  262. for (mirror = 0; mirror < conf->raid_disks; mirror++)
  263. if (r1_bio->bios[mirror] == bio)
  264. break;
  265. if (error == -ENOTSUPP && test_bit(R1BIO_Barrier, &r1_bio->state)) {
  266. set_bit(BarriersNotsupp, &conf->mirrors[mirror].rdev->flags);
  267. set_bit(R1BIO_BarrierRetry, &r1_bio->state);
  268. r1_bio->mddev->barriers_work = 0;
  269. } else {
  270. /*
  271. * this branch is our 'one mirror IO has finished' event handler:
  272. */
  273. r1_bio->bios[mirror] = NULL;
  274. if (!uptodate) {
  275. md_error(r1_bio->mddev, conf->mirrors[mirror].rdev);
  276. /* an I/O failed, we can't clear the bitmap */
  277. set_bit(R1BIO_Degraded, &r1_bio->state);
  278. } else
  279. /*
  280. * Set R1BIO_Uptodate in our master bio, so that
  281. * we will return a good error code for to the higher
  282. * levels even if IO on some other mirrored buffer fails.
  283. *
  284. * The 'master' represents the composite IO operation to
  285. * user-side. So if something waits for IO, then it will
  286. * wait for the 'master' bio.
  287. */
  288. set_bit(R1BIO_Uptodate, &r1_bio->state);
  289. update_head_pos(mirror, r1_bio);
  290. if (behind) {
  291. if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags))
  292. atomic_dec(&r1_bio->behind_remaining);
  293. /* In behind mode, we ACK the master bio once the I/O has safely
  294. * reached all non-writemostly disks. Setting the Returned bit
  295. * ensures that this gets done only once -- we don't ever want to
  296. * return -EIO here, instead we'll wait */
  297. if (atomic_read(&r1_bio->behind_remaining) >= (atomic_read(&r1_bio->remaining)-1) &&
  298. test_bit(R1BIO_Uptodate, &r1_bio->state)) {
  299. /* Maybe we can return now */
  300. if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) {
  301. struct bio *mbio = r1_bio->master_bio;
  302. PRINTK(KERN_DEBUG "raid1: behind end write sectors %llu-%llu\n",
  303. (unsigned long long) mbio->bi_sector,
  304. (unsigned long long) mbio->bi_sector +
  305. (mbio->bi_size >> 9) - 1);
  306. bio_endio(mbio, mbio->bi_size, 0);
  307. }
  308. }
  309. }
  310. }
  311. /*
  312. *
  313. * Let's see if all mirrored write operations have finished
  314. * already.
  315. */
  316. if (atomic_dec_and_test(&r1_bio->remaining)) {
  317. if (test_bit(R1BIO_BarrierRetry, &r1_bio->state)) {
  318. reschedule_retry(r1_bio);
  319. /* Don't dec_pending yet, we want to hold
  320. * the reference over the retry
  321. */
  322. return 0;
  323. }
  324. if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
  325. /* free extra copy of the data pages */
  326. int i = bio->bi_vcnt;
  327. while (i--)
  328. __free_page(bio->bi_io_vec[i].bv_page);
  329. }
  330. /* clear the bitmap if all writes complete successfully */
  331. bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
  332. r1_bio->sectors,
  333. !test_bit(R1BIO_Degraded, &r1_bio->state),
  334. behind);
  335. md_write_end(r1_bio->mddev);
  336. raid_end_bio_io(r1_bio);
  337. }
  338. if (r1_bio->bios[mirror]==NULL)
  339. bio_put(bio);
  340. rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev);
  341. return 0;
  342. }
  343. /*
  344. * This routine returns the disk from which the requested read should
  345. * be done. There is a per-array 'next expected sequential IO' sector
  346. * number - if this matches on the next IO then we use the last disk.
  347. * There is also a per-disk 'last know head position' sector that is
  348. * maintained from IRQ contexts, both the normal and the resync IO
  349. * completion handlers update this position correctly. If there is no
  350. * perfect sequential match then we pick the disk whose head is closest.
  351. *
  352. * If there are 2 mirrors in the same 2 devices, performance degrades
  353. * because position is mirror, not device based.
  354. *
  355. * The rdev for the device selected will have nr_pending incremented.
  356. */
  357. static int read_balance(conf_t *conf, r1bio_t *r1_bio)
  358. {
  359. const unsigned long this_sector = r1_bio->sector;
  360. int new_disk = conf->last_used, disk = new_disk;
  361. int wonly_disk = -1;
  362. const int sectors = r1_bio->sectors;
  363. sector_t new_distance, current_distance;
  364. mdk_rdev_t *rdev;
  365. rcu_read_lock();
  366. /*
  367. * Check if we can balance. We can balance on the whole
  368. * device if no resync is going on, or below the resync window.
  369. * We take the first readable disk when above the resync window.
  370. */
  371. retry:
  372. if (conf->mddev->recovery_cp < MaxSector &&
  373. (this_sector + sectors >= conf->next_resync)) {
  374. /* Choose the first operation device, for consistancy */
  375. new_disk = 0;
  376. for (rdev = rcu_dereference(conf->mirrors[new_disk].rdev);
  377. !rdev || !test_bit(In_sync, &rdev->flags)
  378. || test_bit(WriteMostly, &rdev->flags);
  379. rdev = rcu_dereference(conf->mirrors[++new_disk].rdev)) {
  380. if (rdev && test_bit(In_sync, &rdev->flags))
  381. wonly_disk = new_disk;
  382. if (new_disk == conf->raid_disks - 1) {
  383. new_disk = wonly_disk;
  384. break;
  385. }
  386. }
  387. goto rb_out;
  388. }
  389. /* make sure the disk is operational */
  390. for (rdev = rcu_dereference(conf->mirrors[new_disk].rdev);
  391. !rdev || !test_bit(In_sync, &rdev->flags) ||
  392. test_bit(WriteMostly, &rdev->flags);
  393. rdev = rcu_dereference(conf->mirrors[new_disk].rdev)) {
  394. if (rdev && test_bit(In_sync, &rdev->flags))
  395. wonly_disk = new_disk;
  396. if (new_disk <= 0)
  397. new_disk = conf->raid_disks;
  398. new_disk--;
  399. if (new_disk == disk) {
  400. new_disk = wonly_disk;
  401. break;
  402. }
  403. }
  404. if (new_disk < 0)
  405. goto rb_out;
  406. disk = new_disk;
  407. /* now disk == new_disk == starting point for search */
  408. /*
  409. * Don't change to another disk for sequential reads:
  410. */
  411. if (conf->next_seq_sect == this_sector)
  412. goto rb_out;
  413. if (this_sector == conf->mirrors[new_disk].head_position)
  414. goto rb_out;
  415. current_distance = abs(this_sector - conf->mirrors[disk].head_position);
  416. /* Find the disk whose head is closest */
  417. do {
  418. if (disk <= 0)
  419. disk = conf->raid_disks;
  420. disk--;
  421. rdev = rcu_dereference(conf->mirrors[disk].rdev);
  422. if (!rdev ||
  423. !test_bit(In_sync, &rdev->flags) ||
  424. test_bit(WriteMostly, &rdev->flags))
  425. continue;
  426. if (!atomic_read(&rdev->nr_pending)) {
  427. new_disk = disk;
  428. break;
  429. }
  430. new_distance = abs(this_sector - conf->mirrors[disk].head_position);
  431. if (new_distance < current_distance) {
  432. current_distance = new_distance;
  433. new_disk = disk;
  434. }
  435. } while (disk != conf->last_used);
  436. rb_out:
  437. if (new_disk >= 0) {
  438. rdev = rcu_dereference(conf->mirrors[new_disk].rdev);
  439. if (!rdev)
  440. goto retry;
  441. atomic_inc(&rdev->nr_pending);
  442. if (!test_bit(In_sync, &rdev->flags)) {
  443. /* cannot risk returning a device that failed
  444. * before we inc'ed nr_pending
  445. */
  446. atomic_dec(&rdev->nr_pending);
  447. goto retry;
  448. }
  449. conf->next_seq_sect = this_sector + sectors;
  450. conf->last_used = new_disk;
  451. }
  452. rcu_read_unlock();
  453. return new_disk;
  454. }
  455. static void unplug_slaves(mddev_t *mddev)
  456. {
  457. conf_t *conf = mddev_to_conf(mddev);
  458. int i;
  459. rcu_read_lock();
  460. for (i=0; i<mddev->raid_disks; i++) {
  461. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  462. if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) {
  463. request_queue_t *r_queue = bdev_get_queue(rdev->bdev);
  464. atomic_inc(&rdev->nr_pending);
  465. rcu_read_unlock();
  466. if (r_queue->unplug_fn)
  467. r_queue->unplug_fn(r_queue);
  468. rdev_dec_pending(rdev, mddev);
  469. rcu_read_lock();
  470. }
  471. }
  472. rcu_read_unlock();
  473. }
  474. static void raid1_unplug(request_queue_t *q)
  475. {
  476. mddev_t *mddev = q->queuedata;
  477. unplug_slaves(mddev);
  478. md_wakeup_thread(mddev->thread);
  479. }
  480. static int raid1_issue_flush(request_queue_t *q, struct gendisk *disk,
  481. sector_t *error_sector)
  482. {
  483. mddev_t *mddev = q->queuedata;
  484. conf_t *conf = mddev_to_conf(mddev);
  485. int i, ret = 0;
  486. rcu_read_lock();
  487. for (i=0; i<mddev->raid_disks && ret == 0; i++) {
  488. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  489. if (rdev && !test_bit(Faulty, &rdev->flags)) {
  490. struct block_device *bdev = rdev->bdev;
  491. request_queue_t *r_queue = bdev_get_queue(bdev);
  492. if (!r_queue->issue_flush_fn)
  493. ret = -EOPNOTSUPP;
  494. else {
  495. atomic_inc(&rdev->nr_pending);
  496. rcu_read_unlock();
  497. ret = r_queue->issue_flush_fn(r_queue, bdev->bd_disk,
  498. error_sector);
  499. rdev_dec_pending(rdev, mddev);
  500. rcu_read_lock();
  501. }
  502. }
  503. }
  504. rcu_read_unlock();
  505. return ret;
  506. }
  507. /*
  508. * Throttle resync depth, so that we can both get proper overlapping of
  509. * requests, but are still able to handle normal requests quickly.
  510. */
  511. #define RESYNC_DEPTH 32
  512. static void device_barrier(conf_t *conf, sector_t sect)
  513. {
  514. spin_lock_irq(&conf->resync_lock);
  515. wait_event_lock_irq(conf->wait_idle, !waitqueue_active(&conf->wait_resume),
  516. conf->resync_lock, raid1_unplug(conf->mddev->queue));
  517. if (!conf->barrier++) {
  518. wait_event_lock_irq(conf->wait_idle, !conf->nr_pending,
  519. conf->resync_lock, raid1_unplug(conf->mddev->queue));
  520. if (conf->nr_pending)
  521. BUG();
  522. }
  523. wait_event_lock_irq(conf->wait_resume, conf->barrier < RESYNC_DEPTH,
  524. conf->resync_lock, raid1_unplug(conf->mddev->queue));
  525. conf->next_resync = sect;
  526. spin_unlock_irq(&conf->resync_lock);
  527. }
  528. /* duplicate the data pages for behind I/O */
  529. static struct page **alloc_behind_pages(struct bio *bio)
  530. {
  531. int i;
  532. struct bio_vec *bvec;
  533. struct page **pages = kmalloc(bio->bi_vcnt * sizeof(struct page *),
  534. GFP_NOIO);
  535. if (unlikely(!pages))
  536. goto do_sync_io;
  537. memset(pages, 0, bio->bi_vcnt * sizeof(struct page *));
  538. bio_for_each_segment(bvec, bio, i) {
  539. pages[i] = alloc_page(GFP_NOIO);
  540. if (unlikely(!pages[i]))
  541. goto do_sync_io;
  542. memcpy(kmap(pages[i]) + bvec->bv_offset,
  543. kmap(bvec->bv_page) + bvec->bv_offset, bvec->bv_len);
  544. kunmap(pages[i]);
  545. kunmap(bvec->bv_page);
  546. }
  547. return pages;
  548. do_sync_io:
  549. if (pages)
  550. for (i = 0; i < bio->bi_vcnt && pages[i]; i++)
  551. __free_page(pages[i]);
  552. kfree(pages);
  553. PRINTK("%dB behind alloc failed, doing sync I/O\n", bio->bi_size);
  554. return NULL;
  555. }
  556. static int make_request(request_queue_t *q, struct bio * bio)
  557. {
  558. mddev_t *mddev = q->queuedata;
  559. conf_t *conf = mddev_to_conf(mddev);
  560. mirror_info_t *mirror;
  561. r1bio_t *r1_bio;
  562. struct bio *read_bio;
  563. int i, targets = 0, disks;
  564. mdk_rdev_t *rdev;
  565. struct bitmap *bitmap = mddev->bitmap;
  566. unsigned long flags;
  567. struct bio_list bl;
  568. struct page **behind_pages = NULL;
  569. const int rw = bio_data_dir(bio);
  570. int do_barriers;
  571. if (unlikely(!mddev->barriers_work && bio_barrier(bio))) {
  572. bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
  573. return 0;
  574. }
  575. /*
  576. * Register the new request and wait if the reconstruction
  577. * thread has put up a bar for new requests.
  578. * Continue immediately if no resync is active currently.
  579. */
  580. md_write_start(mddev, bio); /* wait on superblock update early */
  581. spin_lock_irq(&conf->resync_lock);
  582. wait_event_lock_irq(conf->wait_resume, !conf->barrier, conf->resync_lock, );
  583. conf->nr_pending++;
  584. spin_unlock_irq(&conf->resync_lock);
  585. disk_stat_inc(mddev->gendisk, ios[rw]);
  586. disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bio));
  587. /*
  588. * make_request() can abort the operation when READA is being
  589. * used and no empty request is available.
  590. *
  591. */
  592. r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO);
  593. r1_bio->master_bio = bio;
  594. r1_bio->sectors = bio->bi_size >> 9;
  595. r1_bio->state = 0;
  596. r1_bio->mddev = mddev;
  597. r1_bio->sector = bio->bi_sector;
  598. if (rw == READ) {
  599. /*
  600. * read balancing logic:
  601. */
  602. int rdisk = read_balance(conf, r1_bio);
  603. if (rdisk < 0) {
  604. /* couldn't find anywhere to read from */
  605. raid_end_bio_io(r1_bio);
  606. return 0;
  607. }
  608. mirror = conf->mirrors + rdisk;
  609. r1_bio->read_disk = rdisk;
  610. read_bio = bio_clone(bio, GFP_NOIO);
  611. r1_bio->bios[rdisk] = read_bio;
  612. read_bio->bi_sector = r1_bio->sector + mirror->rdev->data_offset;
  613. read_bio->bi_bdev = mirror->rdev->bdev;
  614. read_bio->bi_end_io = raid1_end_read_request;
  615. read_bio->bi_rw = READ;
  616. read_bio->bi_private = r1_bio;
  617. generic_make_request(read_bio);
  618. return 0;
  619. }
  620. /*
  621. * WRITE:
  622. */
  623. /* first select target devices under spinlock and
  624. * inc refcount on their rdev. Record them by setting
  625. * bios[x] to bio
  626. */
  627. disks = conf->raid_disks;
  628. #if 0
  629. { static int first=1;
  630. if (first) printk("First Write sector %llu disks %d\n",
  631. (unsigned long long)r1_bio->sector, disks);
  632. first = 0;
  633. }
  634. #endif
  635. rcu_read_lock();
  636. for (i = 0; i < disks; i++) {
  637. if ((rdev=rcu_dereference(conf->mirrors[i].rdev)) != NULL &&
  638. !test_bit(Faulty, &rdev->flags)) {
  639. atomic_inc(&rdev->nr_pending);
  640. if (test_bit(Faulty, &rdev->flags)) {
  641. atomic_dec(&rdev->nr_pending);
  642. r1_bio->bios[i] = NULL;
  643. } else
  644. r1_bio->bios[i] = bio;
  645. targets++;
  646. } else
  647. r1_bio->bios[i] = NULL;
  648. }
  649. rcu_read_unlock();
  650. BUG_ON(targets == 0); /* we never fail the last device */
  651. if (targets < conf->raid_disks) {
  652. /* array is degraded, we will not clear the bitmap
  653. * on I/O completion (see raid1_end_write_request) */
  654. set_bit(R1BIO_Degraded, &r1_bio->state);
  655. }
  656. /* do behind I/O ? */
  657. if (bitmap &&
  658. atomic_read(&bitmap->behind_writes) < bitmap->max_write_behind &&
  659. (behind_pages = alloc_behind_pages(bio)) != NULL)
  660. set_bit(R1BIO_BehindIO, &r1_bio->state);
  661. atomic_set(&r1_bio->remaining, 0);
  662. atomic_set(&r1_bio->behind_remaining, 0);
  663. do_barriers = bio->bi_rw & BIO_RW_BARRIER;
  664. if (do_barriers)
  665. set_bit(R1BIO_Barrier, &r1_bio->state);
  666. bio_list_init(&bl);
  667. for (i = 0; i < disks; i++) {
  668. struct bio *mbio;
  669. if (!r1_bio->bios[i])
  670. continue;
  671. mbio = bio_clone(bio, GFP_NOIO);
  672. r1_bio->bios[i] = mbio;
  673. mbio->bi_sector = r1_bio->sector + conf->mirrors[i].rdev->data_offset;
  674. mbio->bi_bdev = conf->mirrors[i].rdev->bdev;
  675. mbio->bi_end_io = raid1_end_write_request;
  676. mbio->bi_rw = WRITE | do_barriers;
  677. mbio->bi_private = r1_bio;
  678. if (behind_pages) {
  679. struct bio_vec *bvec;
  680. int j;
  681. /* Yes, I really want the '__' version so that
  682. * we clear any unused pointer in the io_vec, rather
  683. * than leave them unchanged. This is important
  684. * because when we come to free the pages, we won't
  685. * know the originial bi_idx, so we just free
  686. * them all
  687. */
  688. __bio_for_each_segment(bvec, mbio, j, 0)
  689. bvec->bv_page = behind_pages[j];
  690. if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
  691. atomic_inc(&r1_bio->behind_remaining);
  692. }
  693. atomic_inc(&r1_bio->remaining);
  694. bio_list_add(&bl, mbio);
  695. }
  696. kfree(behind_pages); /* the behind pages are attached to the bios now */
  697. bitmap_startwrite(bitmap, bio->bi_sector, r1_bio->sectors,
  698. test_bit(R1BIO_BehindIO, &r1_bio->state));
  699. spin_lock_irqsave(&conf->device_lock, flags);
  700. bio_list_merge(&conf->pending_bio_list, &bl);
  701. bio_list_init(&bl);
  702. blk_plug_device(mddev->queue);
  703. spin_unlock_irqrestore(&conf->device_lock, flags);
  704. #if 0
  705. while ((bio = bio_list_pop(&bl)) != NULL)
  706. generic_make_request(bio);
  707. #endif
  708. return 0;
  709. }
  710. static void status(struct seq_file *seq, mddev_t *mddev)
  711. {
  712. conf_t *conf = mddev_to_conf(mddev);
  713. int i;
  714. seq_printf(seq, " [%d/%d] [", conf->raid_disks,
  715. conf->working_disks);
  716. for (i = 0; i < conf->raid_disks; i++)
  717. seq_printf(seq, "%s",
  718. conf->mirrors[i].rdev &&
  719. test_bit(In_sync, &conf->mirrors[i].rdev->flags) ? "U" : "_");
  720. seq_printf(seq, "]");
  721. }
  722. static void error(mddev_t *mddev, mdk_rdev_t *rdev)
  723. {
  724. char b[BDEVNAME_SIZE];
  725. conf_t *conf = mddev_to_conf(mddev);
  726. /*
  727. * If it is not operational, then we have already marked it as dead
  728. * else if it is the last working disks, ignore the error, let the
  729. * next level up know.
  730. * else mark the drive as failed
  731. */
  732. if (test_bit(In_sync, &rdev->flags)
  733. && conf->working_disks == 1)
  734. /*
  735. * Don't fail the drive, act as though we were just a
  736. * normal single drive
  737. */
  738. return;
  739. if (test_bit(In_sync, &rdev->flags)) {
  740. mddev->degraded++;
  741. conf->working_disks--;
  742. /*
  743. * if recovery is running, make sure it aborts.
  744. */
  745. set_bit(MD_RECOVERY_ERR, &mddev->recovery);
  746. }
  747. clear_bit(In_sync, &rdev->flags);
  748. set_bit(Faulty, &rdev->flags);
  749. mddev->sb_dirty = 1;
  750. printk(KERN_ALERT "raid1: Disk failure on %s, disabling device. \n"
  751. " Operation continuing on %d devices\n",
  752. bdevname(rdev->bdev,b), conf->working_disks);
  753. }
  754. static void print_conf(conf_t *conf)
  755. {
  756. int i;
  757. mirror_info_t *tmp;
  758. printk("RAID1 conf printout:\n");
  759. if (!conf) {
  760. printk("(!conf)\n");
  761. return;
  762. }
  763. printk(" --- wd:%d rd:%d\n", conf->working_disks,
  764. conf->raid_disks);
  765. for (i = 0; i < conf->raid_disks; i++) {
  766. char b[BDEVNAME_SIZE];
  767. tmp = conf->mirrors + i;
  768. if (tmp->rdev)
  769. printk(" disk %d, wo:%d, o:%d, dev:%s\n",
  770. i, !test_bit(In_sync, &tmp->rdev->flags), !test_bit(Faulty, &tmp->rdev->flags),
  771. bdevname(tmp->rdev->bdev,b));
  772. }
  773. }
  774. static void close_sync(conf_t *conf)
  775. {
  776. spin_lock_irq(&conf->resync_lock);
  777. wait_event_lock_irq(conf->wait_resume, !conf->barrier,
  778. conf->resync_lock, raid1_unplug(conf->mddev->queue));
  779. spin_unlock_irq(&conf->resync_lock);
  780. if (conf->barrier) BUG();
  781. if (waitqueue_active(&conf->wait_idle)) BUG();
  782. mempool_destroy(conf->r1buf_pool);
  783. conf->r1buf_pool = NULL;
  784. }
  785. static int raid1_spare_active(mddev_t *mddev)
  786. {
  787. int i;
  788. conf_t *conf = mddev->private;
  789. mirror_info_t *tmp;
  790. /*
  791. * Find all failed disks within the RAID1 configuration
  792. * and mark them readable
  793. */
  794. for (i = 0; i < conf->raid_disks; i++) {
  795. tmp = conf->mirrors + i;
  796. if (tmp->rdev
  797. && !test_bit(Faulty, &tmp->rdev->flags)
  798. && !test_bit(In_sync, &tmp->rdev->flags)) {
  799. conf->working_disks++;
  800. mddev->degraded--;
  801. set_bit(In_sync, &tmp->rdev->flags);
  802. }
  803. }
  804. print_conf(conf);
  805. return 0;
  806. }
  807. static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
  808. {
  809. conf_t *conf = mddev->private;
  810. int found = 0;
  811. int mirror = 0;
  812. mirror_info_t *p;
  813. for (mirror=0; mirror < mddev->raid_disks; mirror++)
  814. if ( !(p=conf->mirrors+mirror)->rdev) {
  815. blk_queue_stack_limits(mddev->queue,
  816. rdev->bdev->bd_disk->queue);
  817. /* as we don't honour merge_bvec_fn, we must never risk
  818. * violating it, so limit ->max_sector to one PAGE, as
  819. * a one page request is never in violation.
  820. */
  821. if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
  822. mddev->queue->max_sectors > (PAGE_SIZE>>9))
  823. blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
  824. p->head_position = 0;
  825. rdev->raid_disk = mirror;
  826. found = 1;
  827. /* As all devices are equivalent, we don't need a full recovery
  828. * if this was recently any drive of the array
  829. */
  830. if (rdev->saved_raid_disk < 0)
  831. conf->fullsync = 1;
  832. rcu_assign_pointer(p->rdev, rdev);
  833. break;
  834. }
  835. print_conf(conf);
  836. return found;
  837. }
  838. static int raid1_remove_disk(mddev_t *mddev, int number)
  839. {
  840. conf_t *conf = mddev->private;
  841. int err = 0;
  842. mdk_rdev_t *rdev;
  843. mirror_info_t *p = conf->mirrors+ number;
  844. print_conf(conf);
  845. rdev = p->rdev;
  846. if (rdev) {
  847. if (test_bit(In_sync, &rdev->flags) ||
  848. atomic_read(&rdev->nr_pending)) {
  849. err = -EBUSY;
  850. goto abort;
  851. }
  852. p->rdev = NULL;
  853. synchronize_rcu();
  854. if (atomic_read(&rdev->nr_pending)) {
  855. /* lost the race, try later */
  856. err = -EBUSY;
  857. p->rdev = rdev;
  858. }
  859. }
  860. abort:
  861. print_conf(conf);
  862. return err;
  863. }
  864. static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error)
  865. {
  866. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  867. r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
  868. conf_t *conf = mddev_to_conf(r1_bio->mddev);
  869. if (bio->bi_size)
  870. return 1;
  871. if (r1_bio->bios[r1_bio->read_disk] != bio)
  872. BUG();
  873. update_head_pos(r1_bio->read_disk, r1_bio);
  874. /*
  875. * we have read a block, now it needs to be re-written,
  876. * or re-read if the read failed.
  877. * We don't do much here, just schedule handling by raid1d
  878. */
  879. if (!uptodate) {
  880. md_error(r1_bio->mddev,
  881. conf->mirrors[r1_bio->read_disk].rdev);
  882. } else
  883. set_bit(R1BIO_Uptodate, &r1_bio->state);
  884. rdev_dec_pending(conf->mirrors[r1_bio->read_disk].rdev, conf->mddev);
  885. reschedule_retry(r1_bio);
  886. return 0;
  887. }
  888. static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
  889. {
  890. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  891. r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
  892. mddev_t *mddev = r1_bio->mddev;
  893. conf_t *conf = mddev_to_conf(mddev);
  894. int i;
  895. int mirror=0;
  896. if (bio->bi_size)
  897. return 1;
  898. for (i = 0; i < conf->raid_disks; i++)
  899. if (r1_bio->bios[i] == bio) {
  900. mirror = i;
  901. break;
  902. }
  903. if (!uptodate)
  904. md_error(mddev, conf->mirrors[mirror].rdev);
  905. update_head_pos(mirror, r1_bio);
  906. if (atomic_dec_and_test(&r1_bio->remaining)) {
  907. md_done_sync(mddev, r1_bio->sectors, uptodate);
  908. put_buf(r1_bio);
  909. }
  910. rdev_dec_pending(conf->mirrors[mirror].rdev, mddev);
  911. return 0;
  912. }
  913. static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
  914. {
  915. conf_t *conf = mddev_to_conf(mddev);
  916. int i;
  917. int disks = conf->raid_disks;
  918. struct bio *bio, *wbio;
  919. bio = r1_bio->bios[r1_bio->read_disk];
  920. /*
  921. if (r1_bio->sector == 0) printk("First sync write startss\n");
  922. */
  923. /*
  924. * schedule writes
  925. */
  926. if (!test_bit(R1BIO_Uptodate, &r1_bio->state)) {
  927. /*
  928. * There is no point trying a read-for-reconstruct as
  929. * reconstruct is about to be aborted
  930. */
  931. char b[BDEVNAME_SIZE];
  932. printk(KERN_ALERT "raid1: %s: unrecoverable I/O read error"
  933. " for block %llu\n",
  934. bdevname(bio->bi_bdev,b),
  935. (unsigned long long)r1_bio->sector);
  936. md_done_sync(mddev, r1_bio->sectors, 0);
  937. put_buf(r1_bio);
  938. return;
  939. }
  940. atomic_set(&r1_bio->remaining, 1);
  941. for (i = 0; i < disks ; i++) {
  942. wbio = r1_bio->bios[i];
  943. if (wbio->bi_end_io != end_sync_write)
  944. continue;
  945. atomic_inc(&conf->mirrors[i].rdev->nr_pending);
  946. atomic_inc(&r1_bio->remaining);
  947. md_sync_acct(conf->mirrors[i].rdev->bdev, wbio->bi_size >> 9);
  948. generic_make_request(wbio);
  949. }
  950. if (atomic_dec_and_test(&r1_bio->remaining)) {
  951. /* if we're here, all write(s) have completed, so clean up */
  952. md_done_sync(mddev, r1_bio->sectors, 1);
  953. put_buf(r1_bio);
  954. }
  955. }
  956. /*
  957. * This is a kernel thread which:
  958. *
  959. * 1. Retries failed read operations on working mirrors.
  960. * 2. Updates the raid superblock when problems encounter.
  961. * 3. Performs writes following reads for array syncronising.
  962. */
  963. static void raid1d(mddev_t *mddev)
  964. {
  965. r1bio_t *r1_bio;
  966. struct bio *bio;
  967. unsigned long flags;
  968. conf_t *conf = mddev_to_conf(mddev);
  969. struct list_head *head = &conf->retry_list;
  970. int unplug=0;
  971. mdk_rdev_t *rdev;
  972. md_check_recovery(mddev);
  973. for (;;) {
  974. char b[BDEVNAME_SIZE];
  975. spin_lock_irqsave(&conf->device_lock, flags);
  976. if (conf->pending_bio_list.head) {
  977. bio = bio_list_get(&conf->pending_bio_list);
  978. blk_remove_plug(mddev->queue);
  979. spin_unlock_irqrestore(&conf->device_lock, flags);
  980. /* flush any pending bitmap writes to disk before proceeding w/ I/O */
  981. if (bitmap_unplug(mddev->bitmap) != 0)
  982. printk("%s: bitmap file write failed!\n", mdname(mddev));
  983. while (bio) { /* submit pending writes */
  984. struct bio *next = bio->bi_next;
  985. bio->bi_next = NULL;
  986. generic_make_request(bio);
  987. bio = next;
  988. }
  989. unplug = 1;
  990. continue;
  991. }
  992. if (list_empty(head))
  993. break;
  994. r1_bio = list_entry(head->prev, r1bio_t, retry_list);
  995. list_del(head->prev);
  996. spin_unlock_irqrestore(&conf->device_lock, flags);
  997. mddev = r1_bio->mddev;
  998. conf = mddev_to_conf(mddev);
  999. if (test_bit(R1BIO_IsSync, &r1_bio->state)) {
  1000. sync_request_write(mddev, r1_bio);
  1001. unplug = 1;
  1002. } else if (test_bit(R1BIO_BarrierRetry, &r1_bio->state)) {
  1003. /* some requests in the r1bio were BIO_RW_BARRIER
  1004. * requests which failed with -ENOTSUPP. Hohumm..
  1005. * Better resubmit without the barrier.
  1006. * We know which devices to resubmit for, because
  1007. * all others have had their bios[] entry cleared.
  1008. */
  1009. int i;
  1010. clear_bit(R1BIO_BarrierRetry, &r1_bio->state);
  1011. clear_bit(R1BIO_Barrier, &r1_bio->state);
  1012. for (i=0; i < conf->raid_disks; i++)
  1013. if (r1_bio->bios[i]) {
  1014. struct bio_vec *bvec;
  1015. int j;
  1016. bio = bio_clone(r1_bio->master_bio, GFP_NOIO);
  1017. /* copy pages from the failed bio, as
  1018. * this might be a write-behind device */
  1019. __bio_for_each_segment(bvec, bio, j, 0)
  1020. bvec->bv_page = bio_iovec_idx(r1_bio->bios[i], j)->bv_page;
  1021. bio_put(r1_bio->bios[i]);
  1022. bio->bi_sector = r1_bio->sector +
  1023. conf->mirrors[i].rdev->data_offset;
  1024. bio->bi_bdev = conf->mirrors[i].rdev->bdev;
  1025. bio->bi_end_io = raid1_end_write_request;
  1026. bio->bi_rw = WRITE;
  1027. bio->bi_private = r1_bio;
  1028. r1_bio->bios[i] = bio;
  1029. generic_make_request(bio);
  1030. }
  1031. } else {
  1032. int disk;
  1033. bio = r1_bio->bios[r1_bio->read_disk];
  1034. if ((disk=read_balance(conf, r1_bio)) == -1) {
  1035. printk(KERN_ALERT "raid1: %s: unrecoverable I/O"
  1036. " read error for block %llu\n",
  1037. bdevname(bio->bi_bdev,b),
  1038. (unsigned long long)r1_bio->sector);
  1039. raid_end_bio_io(r1_bio);
  1040. } else {
  1041. r1_bio->bios[r1_bio->read_disk] = NULL;
  1042. r1_bio->read_disk = disk;
  1043. bio_put(bio);
  1044. bio = bio_clone(r1_bio->master_bio, GFP_NOIO);
  1045. r1_bio->bios[r1_bio->read_disk] = bio;
  1046. rdev = conf->mirrors[disk].rdev;
  1047. if (printk_ratelimit())
  1048. printk(KERN_ERR "raid1: %s: redirecting sector %llu to"
  1049. " another mirror\n",
  1050. bdevname(rdev->bdev,b),
  1051. (unsigned long long)r1_bio->sector);
  1052. bio->bi_sector = r1_bio->sector + rdev->data_offset;
  1053. bio->bi_bdev = rdev->bdev;
  1054. bio->bi_end_io = raid1_end_read_request;
  1055. bio->bi_rw = READ;
  1056. bio->bi_private = r1_bio;
  1057. unplug = 1;
  1058. generic_make_request(bio);
  1059. }
  1060. }
  1061. }
  1062. spin_unlock_irqrestore(&conf->device_lock, flags);
  1063. if (unplug)
  1064. unplug_slaves(mddev);
  1065. }
  1066. static int init_resync(conf_t *conf)
  1067. {
  1068. int buffs;
  1069. buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE;
  1070. if (conf->r1buf_pool)
  1071. BUG();
  1072. conf->r1buf_pool = mempool_create(buffs, r1buf_pool_alloc, r1buf_pool_free,
  1073. conf->poolinfo);
  1074. if (!conf->r1buf_pool)
  1075. return -ENOMEM;
  1076. conf->next_resync = 0;
  1077. return 0;
  1078. }
  1079. /*
  1080. * perform a "sync" on one "block"
  1081. *
  1082. * We need to make sure that no normal I/O request - particularly write
  1083. * requests - conflict with active sync requests.
  1084. *
  1085. * This is achieved by tracking pending requests and a 'barrier' concept
  1086. * that can be installed to exclude normal IO requests.
  1087. */
  1088. static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
  1089. {
  1090. conf_t *conf = mddev_to_conf(mddev);
  1091. mirror_info_t *mirror;
  1092. r1bio_t *r1_bio;
  1093. struct bio *bio;
  1094. sector_t max_sector, nr_sectors;
  1095. int disk;
  1096. int i;
  1097. int wonly;
  1098. int write_targets = 0;
  1099. int sync_blocks;
  1100. int still_degraded = 0;
  1101. if (!conf->r1buf_pool)
  1102. {
  1103. /*
  1104. printk("sync start - bitmap %p\n", mddev->bitmap);
  1105. */
  1106. if (init_resync(conf))
  1107. return 0;
  1108. }
  1109. max_sector = mddev->size << 1;
  1110. if (sector_nr >= max_sector) {
  1111. /* If we aborted, we need to abort the
  1112. * sync on the 'current' bitmap chunk (there will
  1113. * only be one in raid1 resync.
  1114. * We can find the current addess in mddev->curr_resync
  1115. */
  1116. if (mddev->curr_resync < max_sector) /* aborted */
  1117. bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
  1118. &sync_blocks, 1);
  1119. else /* completed sync */
  1120. conf->fullsync = 0;
  1121. bitmap_close_sync(mddev->bitmap);
  1122. close_sync(conf);
  1123. return 0;
  1124. }
  1125. /* before building a request, check if we can skip these blocks..
  1126. * This call the bitmap_start_sync doesn't actually record anything
  1127. */
  1128. if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
  1129. !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
  1130. /* We can skip this block, and probably several more */
  1131. *skipped = 1;
  1132. return sync_blocks;
  1133. }
  1134. /*
  1135. * If there is non-resync activity waiting for us then
  1136. * put in a delay to throttle resync.
  1137. */
  1138. if (!go_faster && waitqueue_active(&conf->wait_resume))
  1139. msleep_interruptible(1000);
  1140. device_barrier(conf, sector_nr + RESYNC_SECTORS);
  1141. /*
  1142. * If reconstructing, and >1 working disc,
  1143. * could dedicate one to rebuild and others to
  1144. * service read requests ..
  1145. */
  1146. disk = conf->last_used;
  1147. /* make sure disk is operational */
  1148. wonly = disk;
  1149. while (conf->mirrors[disk].rdev == NULL ||
  1150. !test_bit(In_sync, &conf->mirrors[disk].rdev->flags) ||
  1151. test_bit(WriteMostly, &conf->mirrors[disk].rdev->flags)
  1152. ) {
  1153. if (conf->mirrors[disk].rdev &&
  1154. test_bit(In_sync, &conf->mirrors[disk].rdev->flags))
  1155. wonly = disk;
  1156. if (disk <= 0)
  1157. disk = conf->raid_disks;
  1158. disk--;
  1159. if (disk == conf->last_used) {
  1160. disk = wonly;
  1161. break;
  1162. }
  1163. }
  1164. conf->last_used = disk;
  1165. atomic_inc(&conf->mirrors[disk].rdev->nr_pending);
  1166. mirror = conf->mirrors + disk;
  1167. r1_bio = mempool_alloc(conf->r1buf_pool, GFP_NOIO);
  1168. spin_lock_irq(&conf->resync_lock);
  1169. conf->nr_pending++;
  1170. spin_unlock_irq(&conf->resync_lock);
  1171. r1_bio->mddev = mddev;
  1172. r1_bio->sector = sector_nr;
  1173. r1_bio->state = 0;
  1174. set_bit(R1BIO_IsSync, &r1_bio->state);
  1175. r1_bio->read_disk = disk;
  1176. for (i=0; i < conf->raid_disks; i++) {
  1177. bio = r1_bio->bios[i];
  1178. /* take from bio_init */
  1179. bio->bi_next = NULL;
  1180. bio->bi_flags |= 1 << BIO_UPTODATE;
  1181. bio->bi_rw = 0;
  1182. bio->bi_vcnt = 0;
  1183. bio->bi_idx = 0;
  1184. bio->bi_phys_segments = 0;
  1185. bio->bi_hw_segments = 0;
  1186. bio->bi_size = 0;
  1187. bio->bi_end_io = NULL;
  1188. bio->bi_private = NULL;
  1189. if (i == disk) {
  1190. bio->bi_rw = READ;
  1191. bio->bi_end_io = end_sync_read;
  1192. } else if (conf->mirrors[i].rdev == NULL ||
  1193. test_bit(Faulty, &conf->mirrors[i].rdev->flags)) {
  1194. still_degraded = 1;
  1195. continue;
  1196. } else if (!test_bit(In_sync, &conf->mirrors[i].rdev->flags) ||
  1197. sector_nr + RESYNC_SECTORS > mddev->recovery_cp ||
  1198. test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
  1199. bio->bi_rw = WRITE;
  1200. bio->bi_end_io = end_sync_write;
  1201. write_targets ++;
  1202. } else
  1203. /* no need to read or write here */
  1204. continue;
  1205. bio->bi_sector = sector_nr + conf->mirrors[i].rdev->data_offset;
  1206. bio->bi_bdev = conf->mirrors[i].rdev->bdev;
  1207. bio->bi_private = r1_bio;
  1208. }
  1209. if (write_targets == 0) {
  1210. /* There is nowhere to write, so all non-sync
  1211. * drives must be failed - so we are finished
  1212. */
  1213. sector_t rv = max_sector - sector_nr;
  1214. *skipped = 1;
  1215. put_buf(r1_bio);
  1216. rdev_dec_pending(conf->mirrors[disk].rdev, mddev);
  1217. return rv;
  1218. }
  1219. nr_sectors = 0;
  1220. sync_blocks = 0;
  1221. do {
  1222. struct page *page;
  1223. int len = PAGE_SIZE;
  1224. if (sector_nr + (len>>9) > max_sector)
  1225. len = (max_sector - sector_nr) << 9;
  1226. if (len == 0)
  1227. break;
  1228. if (sync_blocks == 0) {
  1229. if (!bitmap_start_sync(mddev->bitmap, sector_nr,
  1230. &sync_blocks, still_degraded) &&
  1231. !conf->fullsync &&
  1232. !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
  1233. break;
  1234. if (sync_blocks < (PAGE_SIZE>>9))
  1235. BUG();
  1236. if (len > (sync_blocks<<9))
  1237. len = sync_blocks<<9;
  1238. }
  1239. for (i=0 ; i < conf->raid_disks; i++) {
  1240. bio = r1_bio->bios[i];
  1241. if (bio->bi_end_io) {
  1242. page = r1_bio->bios[0]->bi_io_vec[bio->bi_vcnt].bv_page;
  1243. if (bio_add_page(bio, page, len, 0) == 0) {
  1244. /* stop here */
  1245. r1_bio->bios[0]->bi_io_vec[bio->bi_vcnt].bv_page = page;
  1246. while (i > 0) {
  1247. i--;
  1248. bio = r1_bio->bios[i];
  1249. if (bio->bi_end_io==NULL)
  1250. continue;
  1251. /* remove last page from this bio */
  1252. bio->bi_vcnt--;
  1253. bio->bi_size -= len;
  1254. bio->bi_flags &= ~(1<< BIO_SEG_VALID);
  1255. }
  1256. goto bio_full;
  1257. }
  1258. }
  1259. }
  1260. nr_sectors += len>>9;
  1261. sector_nr += len>>9;
  1262. sync_blocks -= (len>>9);
  1263. } while (r1_bio->bios[disk]->bi_vcnt < RESYNC_PAGES);
  1264. bio_full:
  1265. bio = r1_bio->bios[disk];
  1266. r1_bio->sectors = nr_sectors;
  1267. md_sync_acct(mirror->rdev->bdev, nr_sectors);
  1268. generic_make_request(bio);
  1269. return nr_sectors;
  1270. }
  1271. static int run(mddev_t *mddev)
  1272. {
  1273. conf_t *conf;
  1274. int i, j, disk_idx;
  1275. mirror_info_t *disk;
  1276. mdk_rdev_t *rdev;
  1277. struct list_head *tmp;
  1278. if (mddev->level != 1) {
  1279. printk("raid1: %s: raid level not set to mirroring (%d)\n",
  1280. mdname(mddev), mddev->level);
  1281. goto out;
  1282. }
  1283. /*
  1284. * copy the already verified devices into our private RAID1
  1285. * bookkeeping area. [whatever we allocate in run(),
  1286. * should be freed in stop()]
  1287. */
  1288. conf = kmalloc(sizeof(conf_t), GFP_KERNEL);
  1289. mddev->private = conf;
  1290. if (!conf)
  1291. goto out_no_mem;
  1292. memset(conf, 0, sizeof(*conf));
  1293. conf->mirrors = kmalloc(sizeof(struct mirror_info)*mddev->raid_disks,
  1294. GFP_KERNEL);
  1295. if (!conf->mirrors)
  1296. goto out_no_mem;
  1297. memset(conf->mirrors, 0, sizeof(struct mirror_info)*mddev->raid_disks);
  1298. conf->poolinfo = kmalloc(sizeof(*conf->poolinfo), GFP_KERNEL);
  1299. if (!conf->poolinfo)
  1300. goto out_no_mem;
  1301. conf->poolinfo->mddev = mddev;
  1302. conf->poolinfo->raid_disks = mddev->raid_disks;
  1303. conf->r1bio_pool = mempool_create(NR_RAID1_BIOS, r1bio_pool_alloc,
  1304. r1bio_pool_free,
  1305. conf->poolinfo);
  1306. if (!conf->r1bio_pool)
  1307. goto out_no_mem;
  1308. ITERATE_RDEV(mddev, rdev, tmp) {
  1309. disk_idx = rdev->raid_disk;
  1310. if (disk_idx >= mddev->raid_disks
  1311. || disk_idx < 0)
  1312. continue;
  1313. disk = conf->mirrors + disk_idx;
  1314. disk->rdev = rdev;
  1315. blk_queue_stack_limits(mddev->queue,
  1316. rdev->bdev->bd_disk->queue);
  1317. /* as we don't honour merge_bvec_fn, we must never risk
  1318. * violating it, so limit ->max_sector to one PAGE, as
  1319. * a one page request is never in violation.
  1320. */
  1321. if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
  1322. mddev->queue->max_sectors > (PAGE_SIZE>>9))
  1323. blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
  1324. disk->head_position = 0;
  1325. if (!test_bit(Faulty, &rdev->flags) && test_bit(In_sync, &rdev->flags))
  1326. conf->working_disks++;
  1327. }
  1328. conf->raid_disks = mddev->raid_disks;
  1329. conf->mddev = mddev;
  1330. spin_lock_init(&conf->device_lock);
  1331. INIT_LIST_HEAD(&conf->retry_list);
  1332. if (conf->working_disks == 1)
  1333. mddev->recovery_cp = MaxSector;
  1334. spin_lock_init(&conf->resync_lock);
  1335. init_waitqueue_head(&conf->wait_idle);
  1336. init_waitqueue_head(&conf->wait_resume);
  1337. bio_list_init(&conf->pending_bio_list);
  1338. bio_list_init(&conf->flushing_bio_list);
  1339. if (!conf->working_disks) {
  1340. printk(KERN_ERR "raid1: no operational mirrors for %s\n",
  1341. mdname(mddev));
  1342. goto out_free_conf;
  1343. }
  1344. mddev->degraded = 0;
  1345. for (i = 0; i < conf->raid_disks; i++) {
  1346. disk = conf->mirrors + i;
  1347. if (!disk->rdev) {
  1348. disk->head_position = 0;
  1349. mddev->degraded++;
  1350. }
  1351. }
  1352. /*
  1353. * find the first working one and use it as a starting point
  1354. * to read balancing.
  1355. */
  1356. for (j = 0; j < conf->raid_disks &&
  1357. (!conf->mirrors[j].rdev ||
  1358. !test_bit(In_sync, &conf->mirrors[j].rdev->flags)) ; j++)
  1359. /* nothing */;
  1360. conf->last_used = j;
  1361. mddev->thread = md_register_thread(raid1d, mddev, "%s_raid1");
  1362. if (!mddev->thread) {
  1363. printk(KERN_ERR
  1364. "raid1: couldn't allocate thread for %s\n",
  1365. mdname(mddev));
  1366. goto out_free_conf;
  1367. }
  1368. if (mddev->bitmap) mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
  1369. printk(KERN_INFO
  1370. "raid1: raid set %s active with %d out of %d mirrors\n",
  1371. mdname(mddev), mddev->raid_disks - mddev->degraded,
  1372. mddev->raid_disks);
  1373. /*
  1374. * Ok, everything is just fine now
  1375. */
  1376. mddev->array_size = mddev->size;
  1377. mddev->queue->unplug_fn = raid1_unplug;
  1378. mddev->queue->issue_flush_fn = raid1_issue_flush;
  1379. return 0;
  1380. out_no_mem:
  1381. printk(KERN_ERR "raid1: couldn't allocate memory for %s\n",
  1382. mdname(mddev));
  1383. out_free_conf:
  1384. if (conf) {
  1385. if (conf->r1bio_pool)
  1386. mempool_destroy(conf->r1bio_pool);
  1387. kfree(conf->mirrors);
  1388. kfree(conf->poolinfo);
  1389. kfree(conf);
  1390. mddev->private = NULL;
  1391. }
  1392. out:
  1393. return -EIO;
  1394. }
  1395. static int stop(mddev_t *mddev)
  1396. {
  1397. conf_t *conf = mddev_to_conf(mddev);
  1398. struct bitmap *bitmap = mddev->bitmap;
  1399. int behind_wait = 0;
  1400. /* wait for behind writes to complete */
  1401. while (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
  1402. behind_wait++;
  1403. printk(KERN_INFO "raid1: behind writes in progress on device %s, waiting to stop (%d)\n", mdname(mddev), behind_wait);
  1404. set_current_state(TASK_UNINTERRUPTIBLE);
  1405. schedule_timeout(HZ); /* wait a second */
  1406. /* need to kick something here to make sure I/O goes? */
  1407. }
  1408. md_unregister_thread(mddev->thread);
  1409. mddev->thread = NULL;
  1410. blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
  1411. if (conf->r1bio_pool)
  1412. mempool_destroy(conf->r1bio_pool);
  1413. kfree(conf->mirrors);
  1414. kfree(conf->poolinfo);
  1415. kfree(conf);
  1416. mddev->private = NULL;
  1417. return 0;
  1418. }
  1419. static int raid1_resize(mddev_t *mddev, sector_t sectors)
  1420. {
  1421. /* no resync is happening, and there is enough space
  1422. * on all devices, so we can resize.
  1423. * We need to make sure resync covers any new space.
  1424. * If the array is shrinking we should possibly wait until
  1425. * any io in the removed space completes, but it hardly seems
  1426. * worth it.
  1427. */
  1428. mddev->array_size = sectors>>1;
  1429. set_capacity(mddev->gendisk, mddev->array_size << 1);
  1430. mddev->changed = 1;
  1431. if (mddev->array_size > mddev->size && mddev->recovery_cp == MaxSector) {
  1432. mddev->recovery_cp = mddev->size << 1;
  1433. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  1434. }
  1435. mddev->size = mddev->array_size;
  1436. mddev->resync_max_sectors = sectors;
  1437. return 0;
  1438. }
  1439. static int raid1_reshape(mddev_t *mddev, int raid_disks)
  1440. {
  1441. /* We need to:
  1442. * 1/ resize the r1bio_pool
  1443. * 2/ resize conf->mirrors
  1444. *
  1445. * We allocate a new r1bio_pool if we can.
  1446. * Then raise a device barrier and wait until all IO stops.
  1447. * Then resize conf->mirrors and swap in the new r1bio pool.
  1448. *
  1449. * At the same time, we "pack" the devices so that all the missing
  1450. * devices have the higher raid_disk numbers.
  1451. */
  1452. mempool_t *newpool, *oldpool;
  1453. struct pool_info *newpoolinfo;
  1454. mirror_info_t *newmirrors;
  1455. conf_t *conf = mddev_to_conf(mddev);
  1456. int cnt;
  1457. int d, d2;
  1458. if (raid_disks < conf->raid_disks) {
  1459. cnt=0;
  1460. for (d= 0; d < conf->raid_disks; d++)
  1461. if (conf->mirrors[d].rdev)
  1462. cnt++;
  1463. if (cnt > raid_disks)
  1464. return -EBUSY;
  1465. }
  1466. newpoolinfo = kmalloc(sizeof(*newpoolinfo), GFP_KERNEL);
  1467. if (!newpoolinfo)
  1468. return -ENOMEM;
  1469. newpoolinfo->mddev = mddev;
  1470. newpoolinfo->raid_disks = raid_disks;
  1471. newpool = mempool_create(NR_RAID1_BIOS, r1bio_pool_alloc,
  1472. r1bio_pool_free, newpoolinfo);
  1473. if (!newpool) {
  1474. kfree(newpoolinfo);
  1475. return -ENOMEM;
  1476. }
  1477. newmirrors = kmalloc(sizeof(struct mirror_info) * raid_disks, GFP_KERNEL);
  1478. if (!newmirrors) {
  1479. kfree(newpoolinfo);
  1480. mempool_destroy(newpool);
  1481. return -ENOMEM;
  1482. }
  1483. memset(newmirrors, 0, sizeof(struct mirror_info)*raid_disks);
  1484. spin_lock_irq(&conf->resync_lock);
  1485. conf->barrier++;
  1486. wait_event_lock_irq(conf->wait_idle, !conf->nr_pending,
  1487. conf->resync_lock, raid1_unplug(mddev->queue));
  1488. spin_unlock_irq(&conf->resync_lock);
  1489. /* ok, everything is stopped */
  1490. oldpool = conf->r1bio_pool;
  1491. conf->r1bio_pool = newpool;
  1492. for (d=d2=0; d < conf->raid_disks; d++)
  1493. if (conf->mirrors[d].rdev) {
  1494. conf->mirrors[d].rdev->raid_disk = d2;
  1495. newmirrors[d2++].rdev = conf->mirrors[d].rdev;
  1496. }
  1497. kfree(conf->mirrors);
  1498. conf->mirrors = newmirrors;
  1499. kfree(conf->poolinfo);
  1500. conf->poolinfo = newpoolinfo;
  1501. mddev->degraded += (raid_disks - conf->raid_disks);
  1502. conf->raid_disks = mddev->raid_disks = raid_disks;
  1503. conf->last_used = 0; /* just make sure it is in-range */
  1504. spin_lock_irq(&conf->resync_lock);
  1505. conf->barrier--;
  1506. spin_unlock_irq(&conf->resync_lock);
  1507. wake_up(&conf->wait_resume);
  1508. wake_up(&conf->wait_idle);
  1509. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  1510. md_wakeup_thread(mddev->thread);
  1511. mempool_destroy(oldpool);
  1512. return 0;
  1513. }
  1514. static void raid1_quiesce(mddev_t *mddev, int state)
  1515. {
  1516. conf_t *conf = mddev_to_conf(mddev);
  1517. switch(state) {
  1518. case 1:
  1519. spin_lock_irq(&conf->resync_lock);
  1520. conf->barrier++;
  1521. wait_event_lock_irq(conf->wait_idle, !conf->nr_pending,
  1522. conf->resync_lock, raid1_unplug(mddev->queue));
  1523. spin_unlock_irq(&conf->resync_lock);
  1524. break;
  1525. case 0:
  1526. spin_lock_irq(&conf->resync_lock);
  1527. conf->barrier--;
  1528. spin_unlock_irq(&conf->resync_lock);
  1529. wake_up(&conf->wait_resume);
  1530. wake_up(&conf->wait_idle);
  1531. break;
  1532. }
  1533. if (mddev->thread) {
  1534. if (mddev->bitmap)
  1535. mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
  1536. else
  1537. mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
  1538. md_wakeup_thread(mddev->thread);
  1539. }
  1540. }
  1541. static mdk_personality_t raid1_personality =
  1542. {
  1543. .name = "raid1",
  1544. .owner = THIS_MODULE,
  1545. .make_request = make_request,
  1546. .run = run,
  1547. .stop = stop,
  1548. .status = status,
  1549. .error_handler = error,
  1550. .hot_add_disk = raid1_add_disk,
  1551. .hot_remove_disk= raid1_remove_disk,
  1552. .spare_active = raid1_spare_active,
  1553. .sync_request = sync_request,
  1554. .resize = raid1_resize,
  1555. .reshape = raid1_reshape,
  1556. .quiesce = raid1_quiesce,
  1557. };
  1558. static int __init raid_init(void)
  1559. {
  1560. return register_md_personality(RAID1, &raid1_personality);
  1561. }
  1562. static void raid_exit(void)
  1563. {
  1564. unregister_md_personality(RAID1);
  1565. }
  1566. module_init(raid_init);
  1567. module_exit(raid_exit);
  1568. MODULE_LICENSE("GPL");
  1569. MODULE_ALIAS("md-personality-3"); /* RAID1 */