raid1.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393
  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 <linux/slab.h>
  34. #include <linux/delay.h>
  35. #include <linux/blkdev.h>
  36. #include <linux/seq_file.h>
  37. #include "md.h"
  38. #include "raid1.h"
  39. #include "bitmap.h"
  40. #define DEBUG 0
  41. #if DEBUG
  42. #define PRINTK(x...) printk(x)
  43. #else
  44. #define PRINTK(x...)
  45. #endif
  46. /*
  47. * Number of guaranteed r1bios in case of extreme VM load:
  48. */
  49. #define NR_RAID1_BIOS 256
  50. static void unplug_slaves(mddev_t *mddev);
  51. static void allow_barrier(conf_t *conf);
  52. static void lower_barrier(conf_t *conf);
  53. static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
  54. {
  55. struct pool_info *pi = data;
  56. r1bio_t *r1_bio;
  57. int size = offsetof(r1bio_t, bios[pi->raid_disks]);
  58. /* allocate a r1bio with room for raid_disks entries in the bios array */
  59. r1_bio = kzalloc(size, gfp_flags);
  60. if (!r1_bio && pi->mddev)
  61. unplug_slaves(pi->mddev);
  62. return r1_bio;
  63. }
  64. static void r1bio_pool_free(void *r1_bio, void *data)
  65. {
  66. kfree(r1_bio);
  67. }
  68. #define RESYNC_BLOCK_SIZE (64*1024)
  69. //#define RESYNC_BLOCK_SIZE PAGE_SIZE
  70. #define RESYNC_SECTORS (RESYNC_BLOCK_SIZE >> 9)
  71. #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
  72. #define RESYNC_WINDOW (2048*1024)
  73. static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
  74. {
  75. struct pool_info *pi = data;
  76. struct page *page;
  77. r1bio_t *r1_bio;
  78. struct bio *bio;
  79. int i, j;
  80. r1_bio = r1bio_pool_alloc(gfp_flags, pi);
  81. if (!r1_bio) {
  82. unplug_slaves(pi->mddev);
  83. return NULL;
  84. }
  85. /*
  86. * Allocate bios : 1 for reading, n-1 for writing
  87. */
  88. for (j = pi->raid_disks ; j-- ; ) {
  89. bio = bio_alloc(gfp_flags, RESYNC_PAGES);
  90. if (!bio)
  91. goto out_free_bio;
  92. r1_bio->bios[j] = bio;
  93. }
  94. /*
  95. * Allocate RESYNC_PAGES data pages and attach them to
  96. * the first bio.
  97. * If this is a user-requested check/repair, allocate
  98. * RESYNC_PAGES for each bio.
  99. */
  100. if (test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery))
  101. j = pi->raid_disks;
  102. else
  103. j = 1;
  104. while(j--) {
  105. bio = r1_bio->bios[j];
  106. for (i = 0; i < RESYNC_PAGES; i++) {
  107. page = alloc_page(gfp_flags);
  108. if (unlikely(!page))
  109. goto out_free_pages;
  110. bio->bi_io_vec[i].bv_page = page;
  111. bio->bi_vcnt = i+1;
  112. }
  113. }
  114. /* If not user-requests, copy the page pointers to all bios */
  115. if (!test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery)) {
  116. for (i=0; i<RESYNC_PAGES ; i++)
  117. for (j=1; j<pi->raid_disks; j++)
  118. r1_bio->bios[j]->bi_io_vec[i].bv_page =
  119. r1_bio->bios[0]->bi_io_vec[i].bv_page;
  120. }
  121. r1_bio->master_bio = NULL;
  122. return r1_bio;
  123. out_free_pages:
  124. for (j=0 ; j < pi->raid_disks; j++)
  125. for (i=0; i < r1_bio->bios[j]->bi_vcnt ; i++)
  126. put_page(r1_bio->bios[j]->bi_io_vec[i].bv_page);
  127. j = -1;
  128. out_free_bio:
  129. while ( ++j < pi->raid_disks )
  130. bio_put(r1_bio->bios[j]);
  131. r1bio_pool_free(r1_bio, data);
  132. return NULL;
  133. }
  134. static void r1buf_pool_free(void *__r1_bio, void *data)
  135. {
  136. struct pool_info *pi = data;
  137. int i,j;
  138. r1bio_t *r1bio = __r1_bio;
  139. for (i = 0; i < RESYNC_PAGES; i++)
  140. for (j = pi->raid_disks; j-- ;) {
  141. if (j == 0 ||
  142. r1bio->bios[j]->bi_io_vec[i].bv_page !=
  143. r1bio->bios[0]->bi_io_vec[i].bv_page)
  144. safe_put_page(r1bio->bios[j]->bi_io_vec[i].bv_page);
  145. }
  146. for (i=0 ; i < pi->raid_disks; i++)
  147. bio_put(r1bio->bios[i]);
  148. r1bio_pool_free(r1bio, data);
  149. }
  150. static void put_all_bios(conf_t *conf, r1bio_t *r1_bio)
  151. {
  152. int i;
  153. for (i = 0; i < conf->raid_disks; i++) {
  154. struct bio **bio = r1_bio->bios + i;
  155. if (*bio && *bio != IO_BLOCKED)
  156. bio_put(*bio);
  157. *bio = NULL;
  158. }
  159. }
  160. static void free_r1bio(r1bio_t *r1_bio)
  161. {
  162. conf_t *conf = r1_bio->mddev->private;
  163. /*
  164. * Wake up any possible resync thread that waits for the device
  165. * to go idle.
  166. */
  167. allow_barrier(conf);
  168. put_all_bios(conf, r1_bio);
  169. mempool_free(r1_bio, conf->r1bio_pool);
  170. }
  171. static void put_buf(r1bio_t *r1_bio)
  172. {
  173. conf_t *conf = r1_bio->mddev->private;
  174. int i;
  175. for (i=0; i<conf->raid_disks; i++) {
  176. struct bio *bio = r1_bio->bios[i];
  177. if (bio->bi_end_io)
  178. rdev_dec_pending(conf->mirrors[i].rdev, r1_bio->mddev);
  179. }
  180. mempool_free(r1_bio, conf->r1buf_pool);
  181. lower_barrier(conf);
  182. }
  183. static void reschedule_retry(r1bio_t *r1_bio)
  184. {
  185. unsigned long flags;
  186. mddev_t *mddev = r1_bio->mddev;
  187. conf_t *conf = mddev->private;
  188. spin_lock_irqsave(&conf->device_lock, flags);
  189. list_add(&r1_bio->retry_list, &conf->retry_list);
  190. conf->nr_queued ++;
  191. spin_unlock_irqrestore(&conf->device_lock, flags);
  192. wake_up(&conf->wait_barrier);
  193. md_wakeup_thread(mddev->thread);
  194. }
  195. /*
  196. * raid_end_bio_io() is called when we have finished servicing a mirrored
  197. * operation and are ready to return a success/failure code to the buffer
  198. * cache layer.
  199. */
  200. static void raid_end_bio_io(r1bio_t *r1_bio)
  201. {
  202. struct bio *bio = r1_bio->master_bio;
  203. /* if nobody has done the final endio yet, do it now */
  204. if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) {
  205. PRINTK(KERN_DEBUG "raid1: sync end %s on sectors %llu-%llu\n",
  206. (bio_data_dir(bio) == WRITE) ? "write" : "read",
  207. (unsigned long long) bio->bi_sector,
  208. (unsigned long long) bio->bi_sector +
  209. (bio->bi_size >> 9) - 1);
  210. bio_endio(bio,
  211. test_bit(R1BIO_Uptodate, &r1_bio->state) ? 0 : -EIO);
  212. }
  213. free_r1bio(r1_bio);
  214. }
  215. /*
  216. * Update disk head position estimator based on IRQ completion info.
  217. */
  218. static inline void update_head_pos(int disk, r1bio_t *r1_bio)
  219. {
  220. conf_t *conf = r1_bio->mddev->private;
  221. conf->mirrors[disk].head_position =
  222. r1_bio->sector + (r1_bio->sectors);
  223. }
  224. static void raid1_end_read_request(struct bio *bio, int error)
  225. {
  226. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  227. r1bio_t *r1_bio = bio->bi_private;
  228. int mirror;
  229. conf_t *conf = r1_bio->mddev->private;
  230. mirror = r1_bio->read_disk;
  231. /*
  232. * this branch is our 'one mirror IO has finished' event handler:
  233. */
  234. update_head_pos(mirror, r1_bio);
  235. if (uptodate)
  236. set_bit(R1BIO_Uptodate, &r1_bio->state);
  237. else {
  238. /* If all other devices have failed, we want to return
  239. * the error upwards rather than fail the last device.
  240. * Here we redefine "uptodate" to mean "Don't want to retry"
  241. */
  242. unsigned long flags;
  243. spin_lock_irqsave(&conf->device_lock, flags);
  244. if (r1_bio->mddev->degraded == conf->raid_disks ||
  245. (r1_bio->mddev->degraded == conf->raid_disks-1 &&
  246. !test_bit(Faulty, &conf->mirrors[mirror].rdev->flags)))
  247. uptodate = 1;
  248. spin_unlock_irqrestore(&conf->device_lock, flags);
  249. }
  250. if (uptodate)
  251. raid_end_bio_io(r1_bio);
  252. else {
  253. /*
  254. * oops, read error:
  255. */
  256. char b[BDEVNAME_SIZE];
  257. if (printk_ratelimit())
  258. printk(KERN_ERR "md/raid1:%s: %s: rescheduling sector %llu\n",
  259. mdname(conf->mddev),
  260. bdevname(conf->mirrors[mirror].rdev->bdev,b), (unsigned long long)r1_bio->sector);
  261. reschedule_retry(r1_bio);
  262. }
  263. rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev);
  264. }
  265. static void raid1_end_write_request(struct bio *bio, int error)
  266. {
  267. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  268. r1bio_t *r1_bio = bio->bi_private;
  269. int mirror, behind = test_bit(R1BIO_BehindIO, &r1_bio->state);
  270. conf_t *conf = r1_bio->mddev->private;
  271. struct bio *to_put = NULL;
  272. for (mirror = 0; mirror < conf->raid_disks; mirror++)
  273. if (r1_bio->bios[mirror] == bio)
  274. break;
  275. if (error == -EOPNOTSUPP && test_bit(R1BIO_Barrier, &r1_bio->state)) {
  276. set_bit(BarriersNotsupp, &conf->mirrors[mirror].rdev->flags);
  277. set_bit(R1BIO_BarrierRetry, &r1_bio->state);
  278. r1_bio->mddev->barriers_work = 0;
  279. /* Don't rdev_dec_pending in this branch - keep it for the retry */
  280. } else {
  281. /*
  282. * this branch is our 'one mirror IO has finished' event handler:
  283. */
  284. r1_bio->bios[mirror] = NULL;
  285. to_put = bio;
  286. if (!uptodate) {
  287. md_error(r1_bio->mddev, conf->mirrors[mirror].rdev);
  288. /* an I/O failed, we can't clear the bitmap */
  289. set_bit(R1BIO_Degraded, &r1_bio->state);
  290. } else
  291. /*
  292. * Set R1BIO_Uptodate in our master bio, so that
  293. * we will return a good error code for to the higher
  294. * levels even if IO on some other mirrored buffer fails.
  295. *
  296. * The 'master' represents the composite IO operation to
  297. * user-side. So if something waits for IO, then it will
  298. * wait for the 'master' bio.
  299. */
  300. set_bit(R1BIO_Uptodate, &r1_bio->state);
  301. update_head_pos(mirror, r1_bio);
  302. if (behind) {
  303. if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags))
  304. atomic_dec(&r1_bio->behind_remaining);
  305. /* In behind mode, we ACK the master bio once the I/O has safely
  306. * reached all non-writemostly disks. Setting the Returned bit
  307. * ensures that this gets done only once -- we don't ever want to
  308. * return -EIO here, instead we'll wait */
  309. if (atomic_read(&r1_bio->behind_remaining) >= (atomic_read(&r1_bio->remaining)-1) &&
  310. test_bit(R1BIO_Uptodate, &r1_bio->state)) {
  311. /* Maybe we can return now */
  312. if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) {
  313. struct bio *mbio = r1_bio->master_bio;
  314. PRINTK(KERN_DEBUG "raid1: behind end write sectors %llu-%llu\n",
  315. (unsigned long long) mbio->bi_sector,
  316. (unsigned long long) mbio->bi_sector +
  317. (mbio->bi_size >> 9) - 1);
  318. bio_endio(mbio, 0);
  319. }
  320. }
  321. }
  322. rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev);
  323. }
  324. /*
  325. *
  326. * Let's see if all mirrored write operations have finished
  327. * already.
  328. */
  329. if (atomic_dec_and_test(&r1_bio->remaining)) {
  330. if (test_bit(R1BIO_BarrierRetry, &r1_bio->state))
  331. reschedule_retry(r1_bio);
  332. else {
  333. /* it really is the end of this request */
  334. if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
  335. /* free extra copy of the data pages */
  336. int i = bio->bi_vcnt;
  337. while (i--)
  338. safe_put_page(bio->bi_io_vec[i].bv_page);
  339. }
  340. /* clear the bitmap if all writes complete successfully */
  341. bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
  342. r1_bio->sectors,
  343. !test_bit(R1BIO_Degraded, &r1_bio->state),
  344. behind);
  345. md_write_end(r1_bio->mddev);
  346. raid_end_bio_io(r1_bio);
  347. }
  348. }
  349. if (to_put)
  350. bio_put(to_put);
  351. }
  352. /*
  353. * This routine returns the disk from which the requested read should
  354. * be done. There is a per-array 'next expected sequential IO' sector
  355. * number - if this matches on the next IO then we use the last disk.
  356. * There is also a per-disk 'last know head position' sector that is
  357. * maintained from IRQ contexts, both the normal and the resync IO
  358. * completion handlers update this position correctly. If there is no
  359. * perfect sequential match then we pick the disk whose head is closest.
  360. *
  361. * If there are 2 mirrors in the same 2 devices, performance degrades
  362. * because position is mirror, not device based.
  363. *
  364. * The rdev for the device selected will have nr_pending incremented.
  365. */
  366. static int read_balance(conf_t *conf, r1bio_t *r1_bio)
  367. {
  368. const sector_t this_sector = r1_bio->sector;
  369. int new_disk = conf->last_used, disk = new_disk;
  370. int wonly_disk = -1;
  371. const int sectors = r1_bio->sectors;
  372. sector_t new_distance, current_distance;
  373. mdk_rdev_t *rdev;
  374. rcu_read_lock();
  375. /*
  376. * Check if we can balance. We can balance on the whole
  377. * device if no resync is going on, or below the resync window.
  378. * We take the first readable disk when above the resync window.
  379. */
  380. retry:
  381. if (conf->mddev->recovery_cp < MaxSector &&
  382. (this_sector + sectors >= conf->next_resync)) {
  383. /* Choose the first operational device, for consistancy */
  384. new_disk = 0;
  385. for (rdev = rcu_dereference(conf->mirrors[new_disk].rdev);
  386. r1_bio->bios[new_disk] == IO_BLOCKED ||
  387. !rdev || !test_bit(In_sync, &rdev->flags)
  388. || test_bit(WriteMostly, &rdev->flags);
  389. rdev = rcu_dereference(conf->mirrors[++new_disk].rdev)) {
  390. if (rdev && test_bit(In_sync, &rdev->flags) &&
  391. r1_bio->bios[new_disk] != IO_BLOCKED)
  392. wonly_disk = new_disk;
  393. if (new_disk == conf->raid_disks - 1) {
  394. new_disk = wonly_disk;
  395. break;
  396. }
  397. }
  398. goto rb_out;
  399. }
  400. /* make sure the disk is operational */
  401. for (rdev = rcu_dereference(conf->mirrors[new_disk].rdev);
  402. r1_bio->bios[new_disk] == IO_BLOCKED ||
  403. !rdev || !test_bit(In_sync, &rdev->flags) ||
  404. test_bit(WriteMostly, &rdev->flags);
  405. rdev = rcu_dereference(conf->mirrors[new_disk].rdev)) {
  406. if (rdev && test_bit(In_sync, &rdev->flags) &&
  407. r1_bio->bios[new_disk] != IO_BLOCKED)
  408. wonly_disk = new_disk;
  409. if (new_disk <= 0)
  410. new_disk = conf->raid_disks;
  411. new_disk--;
  412. if (new_disk == disk) {
  413. new_disk = wonly_disk;
  414. break;
  415. }
  416. }
  417. if (new_disk < 0)
  418. goto rb_out;
  419. disk = new_disk;
  420. /* now disk == new_disk == starting point for search */
  421. /*
  422. * Don't change to another disk for sequential reads:
  423. */
  424. if (conf->next_seq_sect == this_sector)
  425. goto rb_out;
  426. if (this_sector == conf->mirrors[new_disk].head_position)
  427. goto rb_out;
  428. current_distance = abs(this_sector - conf->mirrors[disk].head_position);
  429. /* Find the disk whose head is closest */
  430. do {
  431. if (disk <= 0)
  432. disk = conf->raid_disks;
  433. disk--;
  434. rdev = rcu_dereference(conf->mirrors[disk].rdev);
  435. if (!rdev || r1_bio->bios[disk] == IO_BLOCKED ||
  436. !test_bit(In_sync, &rdev->flags) ||
  437. test_bit(WriteMostly, &rdev->flags))
  438. continue;
  439. if (!atomic_read(&rdev->nr_pending)) {
  440. new_disk = disk;
  441. break;
  442. }
  443. new_distance = abs(this_sector - conf->mirrors[disk].head_position);
  444. if (new_distance < current_distance) {
  445. current_distance = new_distance;
  446. new_disk = disk;
  447. }
  448. } while (disk != conf->last_used);
  449. rb_out:
  450. if (new_disk >= 0) {
  451. rdev = rcu_dereference(conf->mirrors[new_disk].rdev);
  452. if (!rdev)
  453. goto retry;
  454. atomic_inc(&rdev->nr_pending);
  455. if (!test_bit(In_sync, &rdev->flags)) {
  456. /* cannot risk returning a device that failed
  457. * before we inc'ed nr_pending
  458. */
  459. rdev_dec_pending(rdev, conf->mddev);
  460. goto retry;
  461. }
  462. conf->next_seq_sect = this_sector + sectors;
  463. conf->last_used = new_disk;
  464. }
  465. rcu_read_unlock();
  466. return new_disk;
  467. }
  468. static void unplug_slaves(mddev_t *mddev)
  469. {
  470. conf_t *conf = mddev->private;
  471. int i;
  472. rcu_read_lock();
  473. for (i=0; i<mddev->raid_disks; i++) {
  474. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  475. if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) {
  476. struct request_queue *r_queue = bdev_get_queue(rdev->bdev);
  477. atomic_inc(&rdev->nr_pending);
  478. rcu_read_unlock();
  479. blk_unplug(r_queue);
  480. rdev_dec_pending(rdev, mddev);
  481. rcu_read_lock();
  482. }
  483. }
  484. rcu_read_unlock();
  485. }
  486. static void raid1_unplug(struct request_queue *q)
  487. {
  488. mddev_t *mddev = q->queuedata;
  489. unplug_slaves(mddev);
  490. md_wakeup_thread(mddev->thread);
  491. }
  492. static int raid1_congested(void *data, int bits)
  493. {
  494. mddev_t *mddev = data;
  495. conf_t *conf = mddev->private;
  496. int i, ret = 0;
  497. if (mddev_congested(mddev, bits))
  498. return 1;
  499. rcu_read_lock();
  500. for (i = 0; i < mddev->raid_disks; i++) {
  501. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  502. if (rdev && !test_bit(Faulty, &rdev->flags)) {
  503. struct request_queue *q = bdev_get_queue(rdev->bdev);
  504. /* Note the '|| 1' - when read_balance prefers
  505. * non-congested targets, it can be removed
  506. */
  507. if ((bits & (1<<BDI_async_congested)) || 1)
  508. ret |= bdi_congested(&q->backing_dev_info, bits);
  509. else
  510. ret &= bdi_congested(&q->backing_dev_info, bits);
  511. }
  512. }
  513. rcu_read_unlock();
  514. return ret;
  515. }
  516. static int flush_pending_writes(conf_t *conf)
  517. {
  518. /* Any writes that have been queued but are awaiting
  519. * bitmap updates get flushed here.
  520. * We return 1 if any requests were actually submitted.
  521. */
  522. int rv = 0;
  523. spin_lock_irq(&conf->device_lock);
  524. if (conf->pending_bio_list.head) {
  525. struct bio *bio;
  526. bio = bio_list_get(&conf->pending_bio_list);
  527. blk_remove_plug(conf->mddev->queue);
  528. spin_unlock_irq(&conf->device_lock);
  529. /* flush any pending bitmap writes to
  530. * disk before proceeding w/ I/O */
  531. bitmap_unplug(conf->mddev->bitmap);
  532. while (bio) { /* submit pending writes */
  533. struct bio *next = bio->bi_next;
  534. bio->bi_next = NULL;
  535. generic_make_request(bio);
  536. bio = next;
  537. }
  538. rv = 1;
  539. } else
  540. spin_unlock_irq(&conf->device_lock);
  541. return rv;
  542. }
  543. /* Barriers....
  544. * Sometimes we need to suspend IO while we do something else,
  545. * either some resync/recovery, or reconfigure the array.
  546. * To do this we raise a 'barrier'.
  547. * The 'barrier' is a counter that can be raised multiple times
  548. * to count how many activities are happening which preclude
  549. * normal IO.
  550. * We can only raise the barrier if there is no pending IO.
  551. * i.e. if nr_pending == 0.
  552. * We choose only to raise the barrier if no-one is waiting for the
  553. * barrier to go down. This means that as soon as an IO request
  554. * is ready, no other operations which require a barrier will start
  555. * until the IO request has had a chance.
  556. *
  557. * So: regular IO calls 'wait_barrier'. When that returns there
  558. * is no backgroup IO happening, It must arrange to call
  559. * allow_barrier when it has finished its IO.
  560. * backgroup IO calls must call raise_barrier. Once that returns
  561. * there is no normal IO happeing. It must arrange to call
  562. * lower_barrier when the particular background IO completes.
  563. */
  564. #define RESYNC_DEPTH 32
  565. static void raise_barrier(conf_t *conf)
  566. {
  567. spin_lock_irq(&conf->resync_lock);
  568. /* Wait until no block IO is waiting */
  569. wait_event_lock_irq(conf->wait_barrier, !conf->nr_waiting,
  570. conf->resync_lock,
  571. raid1_unplug(conf->mddev->queue));
  572. /* block any new IO from starting */
  573. conf->barrier++;
  574. /* No wait for all pending IO to complete */
  575. wait_event_lock_irq(conf->wait_barrier,
  576. !conf->nr_pending && conf->barrier < RESYNC_DEPTH,
  577. conf->resync_lock,
  578. raid1_unplug(conf->mddev->queue));
  579. spin_unlock_irq(&conf->resync_lock);
  580. }
  581. static void lower_barrier(conf_t *conf)
  582. {
  583. unsigned long flags;
  584. BUG_ON(conf->barrier <= 0);
  585. spin_lock_irqsave(&conf->resync_lock, flags);
  586. conf->barrier--;
  587. spin_unlock_irqrestore(&conf->resync_lock, flags);
  588. wake_up(&conf->wait_barrier);
  589. }
  590. static void wait_barrier(conf_t *conf)
  591. {
  592. spin_lock_irq(&conf->resync_lock);
  593. if (conf->barrier) {
  594. conf->nr_waiting++;
  595. wait_event_lock_irq(conf->wait_barrier, !conf->barrier,
  596. conf->resync_lock,
  597. raid1_unplug(conf->mddev->queue));
  598. conf->nr_waiting--;
  599. }
  600. conf->nr_pending++;
  601. spin_unlock_irq(&conf->resync_lock);
  602. }
  603. static void allow_barrier(conf_t *conf)
  604. {
  605. unsigned long flags;
  606. spin_lock_irqsave(&conf->resync_lock, flags);
  607. conf->nr_pending--;
  608. spin_unlock_irqrestore(&conf->resync_lock, flags);
  609. wake_up(&conf->wait_barrier);
  610. }
  611. static void freeze_array(conf_t *conf)
  612. {
  613. /* stop syncio and normal IO and wait for everything to
  614. * go quite.
  615. * We increment barrier and nr_waiting, and then
  616. * wait until nr_pending match nr_queued+1
  617. * This is called in the context of one normal IO request
  618. * that has failed. Thus any sync request that might be pending
  619. * will be blocked by nr_pending, and we need to wait for
  620. * pending IO requests to complete or be queued for re-try.
  621. * Thus the number queued (nr_queued) plus this request (1)
  622. * must match the number of pending IOs (nr_pending) before
  623. * we continue.
  624. */
  625. spin_lock_irq(&conf->resync_lock);
  626. conf->barrier++;
  627. conf->nr_waiting++;
  628. wait_event_lock_irq(conf->wait_barrier,
  629. conf->nr_pending == conf->nr_queued+1,
  630. conf->resync_lock,
  631. ({ flush_pending_writes(conf);
  632. raid1_unplug(conf->mddev->queue); }));
  633. spin_unlock_irq(&conf->resync_lock);
  634. }
  635. static void unfreeze_array(conf_t *conf)
  636. {
  637. /* reverse the effect of the freeze */
  638. spin_lock_irq(&conf->resync_lock);
  639. conf->barrier--;
  640. conf->nr_waiting--;
  641. wake_up(&conf->wait_barrier);
  642. spin_unlock_irq(&conf->resync_lock);
  643. }
  644. /* duplicate the data pages for behind I/O */
  645. static struct page **alloc_behind_pages(struct bio *bio)
  646. {
  647. int i;
  648. struct bio_vec *bvec;
  649. struct page **pages = kzalloc(bio->bi_vcnt * sizeof(struct page *),
  650. GFP_NOIO);
  651. if (unlikely(!pages))
  652. goto do_sync_io;
  653. bio_for_each_segment(bvec, bio, i) {
  654. pages[i] = alloc_page(GFP_NOIO);
  655. if (unlikely(!pages[i]))
  656. goto do_sync_io;
  657. memcpy(kmap(pages[i]) + bvec->bv_offset,
  658. kmap(bvec->bv_page) + bvec->bv_offset, bvec->bv_len);
  659. kunmap(pages[i]);
  660. kunmap(bvec->bv_page);
  661. }
  662. return pages;
  663. do_sync_io:
  664. if (pages)
  665. for (i = 0; i < bio->bi_vcnt && pages[i]; i++)
  666. put_page(pages[i]);
  667. kfree(pages);
  668. PRINTK("%dB behind alloc failed, doing sync I/O\n", bio->bi_size);
  669. return NULL;
  670. }
  671. static int make_request(mddev_t *mddev, struct bio * bio)
  672. {
  673. conf_t *conf = mddev->private;
  674. mirror_info_t *mirror;
  675. r1bio_t *r1_bio;
  676. struct bio *read_bio;
  677. int i, targets = 0, disks;
  678. struct bitmap *bitmap;
  679. unsigned long flags;
  680. struct bio_list bl;
  681. struct page **behind_pages = NULL;
  682. const int rw = bio_data_dir(bio);
  683. const bool do_sync = bio_rw_flagged(bio, BIO_RW_SYNCIO);
  684. bool do_barriers;
  685. mdk_rdev_t *blocked_rdev;
  686. /*
  687. * Register the new request and wait if the reconstruction
  688. * thread has put up a bar for new requests.
  689. * Continue immediately if no resync is active currently.
  690. * We test barriers_work *after* md_write_start as md_write_start
  691. * may cause the first superblock write, and that will check out
  692. * if barriers work.
  693. */
  694. md_write_start(mddev, bio); /* wait on superblock update early */
  695. if (bio_data_dir(bio) == WRITE &&
  696. bio->bi_sector + bio->bi_size/512 > mddev->suspend_lo &&
  697. bio->bi_sector < mddev->suspend_hi) {
  698. /* As the suspend_* range is controlled by
  699. * userspace, we want an interruptible
  700. * wait.
  701. */
  702. DEFINE_WAIT(w);
  703. for (;;) {
  704. flush_signals(current);
  705. prepare_to_wait(&conf->wait_barrier,
  706. &w, TASK_INTERRUPTIBLE);
  707. if (bio->bi_sector + bio->bi_size/512 <= mddev->suspend_lo ||
  708. bio->bi_sector >= mddev->suspend_hi)
  709. break;
  710. schedule();
  711. }
  712. finish_wait(&conf->wait_barrier, &w);
  713. }
  714. if (unlikely(!mddev->barriers_work &&
  715. bio_rw_flagged(bio, BIO_RW_BARRIER))) {
  716. if (rw == WRITE)
  717. md_write_end(mddev);
  718. bio_endio(bio, -EOPNOTSUPP);
  719. return 0;
  720. }
  721. wait_barrier(conf);
  722. bitmap = mddev->bitmap;
  723. /*
  724. * make_request() can abort the operation when READA is being
  725. * used and no empty request is available.
  726. *
  727. */
  728. r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO);
  729. r1_bio->master_bio = bio;
  730. r1_bio->sectors = bio->bi_size >> 9;
  731. r1_bio->state = 0;
  732. r1_bio->mddev = mddev;
  733. r1_bio->sector = bio->bi_sector;
  734. if (rw == READ) {
  735. /*
  736. * read balancing logic:
  737. */
  738. int rdisk = read_balance(conf, r1_bio);
  739. if (rdisk < 0) {
  740. /* couldn't find anywhere to read from */
  741. raid_end_bio_io(r1_bio);
  742. return 0;
  743. }
  744. mirror = conf->mirrors + rdisk;
  745. if (test_bit(WriteMostly, &mirror->rdev->flags) &&
  746. bitmap) {
  747. /* Reading from a write-mostly device must
  748. * take care not to over-take any writes
  749. * that are 'behind'
  750. */
  751. wait_event(bitmap->behind_wait,
  752. atomic_read(&bitmap->behind_writes) == 0);
  753. }
  754. r1_bio->read_disk = rdisk;
  755. read_bio = bio_clone(bio, GFP_NOIO);
  756. r1_bio->bios[rdisk] = read_bio;
  757. read_bio->bi_sector = r1_bio->sector + mirror->rdev->data_offset;
  758. read_bio->bi_bdev = mirror->rdev->bdev;
  759. read_bio->bi_end_io = raid1_end_read_request;
  760. read_bio->bi_rw = READ | (do_sync << BIO_RW_SYNCIO);
  761. read_bio->bi_private = r1_bio;
  762. generic_make_request(read_bio);
  763. return 0;
  764. }
  765. /*
  766. * WRITE:
  767. */
  768. /* first select target devices under spinlock and
  769. * inc refcount on their rdev. Record them by setting
  770. * bios[x] to bio
  771. */
  772. disks = conf->raid_disks;
  773. #if 0
  774. { static int first=1;
  775. if (first) printk("First Write sector %llu disks %d\n",
  776. (unsigned long long)r1_bio->sector, disks);
  777. first = 0;
  778. }
  779. #endif
  780. retry_write:
  781. blocked_rdev = NULL;
  782. rcu_read_lock();
  783. for (i = 0; i < disks; i++) {
  784. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  785. if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) {
  786. atomic_inc(&rdev->nr_pending);
  787. blocked_rdev = rdev;
  788. break;
  789. }
  790. if (rdev && !test_bit(Faulty, &rdev->flags)) {
  791. atomic_inc(&rdev->nr_pending);
  792. if (test_bit(Faulty, &rdev->flags)) {
  793. rdev_dec_pending(rdev, mddev);
  794. r1_bio->bios[i] = NULL;
  795. } else {
  796. r1_bio->bios[i] = bio;
  797. targets++;
  798. }
  799. } else
  800. r1_bio->bios[i] = NULL;
  801. }
  802. rcu_read_unlock();
  803. if (unlikely(blocked_rdev)) {
  804. /* Wait for this device to become unblocked */
  805. int j;
  806. for (j = 0; j < i; j++)
  807. if (r1_bio->bios[j])
  808. rdev_dec_pending(conf->mirrors[j].rdev, mddev);
  809. allow_barrier(conf);
  810. md_wait_for_blocked_rdev(blocked_rdev, mddev);
  811. wait_barrier(conf);
  812. goto retry_write;
  813. }
  814. BUG_ON(targets == 0); /* we never fail the last device */
  815. if (targets < conf->raid_disks) {
  816. /* array is degraded, we will not clear the bitmap
  817. * on I/O completion (see raid1_end_write_request) */
  818. set_bit(R1BIO_Degraded, &r1_bio->state);
  819. }
  820. /* do behind I/O ?
  821. * Not if there are too many, or cannot allocate memory,
  822. * or a reader on WriteMostly is waiting for behind writes
  823. * to flush */
  824. if (bitmap &&
  825. (atomic_read(&bitmap->behind_writes)
  826. < mddev->bitmap_info.max_write_behind) &&
  827. !waitqueue_active(&bitmap->behind_wait) &&
  828. (behind_pages = alloc_behind_pages(bio)) != NULL)
  829. set_bit(R1BIO_BehindIO, &r1_bio->state);
  830. atomic_set(&r1_bio->remaining, 0);
  831. atomic_set(&r1_bio->behind_remaining, 0);
  832. do_barriers = bio_rw_flagged(bio, BIO_RW_BARRIER);
  833. if (do_barriers)
  834. set_bit(R1BIO_Barrier, &r1_bio->state);
  835. bio_list_init(&bl);
  836. for (i = 0; i < disks; i++) {
  837. struct bio *mbio;
  838. if (!r1_bio->bios[i])
  839. continue;
  840. mbio = bio_clone(bio, GFP_NOIO);
  841. r1_bio->bios[i] = mbio;
  842. mbio->bi_sector = r1_bio->sector + conf->mirrors[i].rdev->data_offset;
  843. mbio->bi_bdev = conf->mirrors[i].rdev->bdev;
  844. mbio->bi_end_io = raid1_end_write_request;
  845. mbio->bi_rw = WRITE | (do_barriers << BIO_RW_BARRIER) |
  846. (do_sync << BIO_RW_SYNCIO);
  847. mbio->bi_private = r1_bio;
  848. if (behind_pages) {
  849. struct bio_vec *bvec;
  850. int j;
  851. /* Yes, I really want the '__' version so that
  852. * we clear any unused pointer in the io_vec, rather
  853. * than leave them unchanged. This is important
  854. * because when we come to free the pages, we won't
  855. * know the originial bi_idx, so we just free
  856. * them all
  857. */
  858. __bio_for_each_segment(bvec, mbio, j, 0)
  859. bvec->bv_page = behind_pages[j];
  860. if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
  861. atomic_inc(&r1_bio->behind_remaining);
  862. }
  863. atomic_inc(&r1_bio->remaining);
  864. bio_list_add(&bl, mbio);
  865. }
  866. kfree(behind_pages); /* the behind pages are attached to the bios now */
  867. bitmap_startwrite(bitmap, bio->bi_sector, r1_bio->sectors,
  868. test_bit(R1BIO_BehindIO, &r1_bio->state));
  869. spin_lock_irqsave(&conf->device_lock, flags);
  870. bio_list_merge(&conf->pending_bio_list, &bl);
  871. bio_list_init(&bl);
  872. blk_plug_device(mddev->queue);
  873. spin_unlock_irqrestore(&conf->device_lock, flags);
  874. /* In case raid1d snuck into freeze_array */
  875. wake_up(&conf->wait_barrier);
  876. if (do_sync)
  877. md_wakeup_thread(mddev->thread);
  878. #if 0
  879. while ((bio = bio_list_pop(&bl)) != NULL)
  880. generic_make_request(bio);
  881. #endif
  882. return 0;
  883. }
  884. static void status(struct seq_file *seq, mddev_t *mddev)
  885. {
  886. conf_t *conf = mddev->private;
  887. int i;
  888. seq_printf(seq, " [%d/%d] [", conf->raid_disks,
  889. conf->raid_disks - mddev->degraded);
  890. rcu_read_lock();
  891. for (i = 0; i < conf->raid_disks; i++) {
  892. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  893. seq_printf(seq, "%s",
  894. rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
  895. }
  896. rcu_read_unlock();
  897. seq_printf(seq, "]");
  898. }
  899. static void error(mddev_t *mddev, mdk_rdev_t *rdev)
  900. {
  901. char b[BDEVNAME_SIZE];
  902. conf_t *conf = mddev->private;
  903. /*
  904. * If it is not operational, then we have already marked it as dead
  905. * else if it is the last working disks, ignore the error, let the
  906. * next level up know.
  907. * else mark the drive as failed
  908. */
  909. if (test_bit(In_sync, &rdev->flags)
  910. && (conf->raid_disks - mddev->degraded) == 1) {
  911. /*
  912. * Don't fail the drive, act as though we were just a
  913. * normal single drive.
  914. * However don't try a recovery from this drive as
  915. * it is very likely to fail.
  916. */
  917. mddev->recovery_disabled = 1;
  918. return;
  919. }
  920. if (test_and_clear_bit(In_sync, &rdev->flags)) {
  921. unsigned long flags;
  922. spin_lock_irqsave(&conf->device_lock, flags);
  923. mddev->degraded++;
  924. set_bit(Faulty, &rdev->flags);
  925. spin_unlock_irqrestore(&conf->device_lock, flags);
  926. /*
  927. * if recovery is running, make sure it aborts.
  928. */
  929. set_bit(MD_RECOVERY_INTR, &mddev->recovery);
  930. } else
  931. set_bit(Faulty, &rdev->flags);
  932. set_bit(MD_CHANGE_DEVS, &mddev->flags);
  933. printk(KERN_ALERT "md/raid1:%s: Disk failure on %s, disabling device.\n"
  934. KERN_ALERT "md/raid1:%s: Operation continuing on %d devices.\n",
  935. mdname(mddev), bdevname(rdev->bdev, b),
  936. mdname(mddev), conf->raid_disks - mddev->degraded);
  937. }
  938. static void print_conf(conf_t *conf)
  939. {
  940. int i;
  941. printk(KERN_DEBUG "RAID1 conf printout:\n");
  942. if (!conf) {
  943. printk(KERN_DEBUG "(!conf)\n");
  944. return;
  945. }
  946. printk(KERN_DEBUG " --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded,
  947. conf->raid_disks);
  948. rcu_read_lock();
  949. for (i = 0; i < conf->raid_disks; i++) {
  950. char b[BDEVNAME_SIZE];
  951. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  952. if (rdev)
  953. printk(KERN_DEBUG " disk %d, wo:%d, o:%d, dev:%s\n",
  954. i, !test_bit(In_sync, &rdev->flags),
  955. !test_bit(Faulty, &rdev->flags),
  956. bdevname(rdev->bdev,b));
  957. }
  958. rcu_read_unlock();
  959. }
  960. static void close_sync(conf_t *conf)
  961. {
  962. wait_barrier(conf);
  963. allow_barrier(conf);
  964. mempool_destroy(conf->r1buf_pool);
  965. conf->r1buf_pool = NULL;
  966. }
  967. static int raid1_spare_active(mddev_t *mddev)
  968. {
  969. int i;
  970. conf_t *conf = mddev->private;
  971. /*
  972. * Find all failed disks within the RAID1 configuration
  973. * and mark them readable.
  974. * Called under mddev lock, so rcu protection not needed.
  975. */
  976. for (i = 0; i < conf->raid_disks; i++) {
  977. mdk_rdev_t *rdev = conf->mirrors[i].rdev;
  978. if (rdev
  979. && !test_bit(Faulty, &rdev->flags)
  980. && !test_and_set_bit(In_sync, &rdev->flags)) {
  981. unsigned long flags;
  982. spin_lock_irqsave(&conf->device_lock, flags);
  983. mddev->degraded--;
  984. spin_unlock_irqrestore(&conf->device_lock, flags);
  985. }
  986. }
  987. print_conf(conf);
  988. return 0;
  989. }
  990. static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
  991. {
  992. conf_t *conf = mddev->private;
  993. int err = -EEXIST;
  994. int mirror = 0;
  995. mirror_info_t *p;
  996. int first = 0;
  997. int last = mddev->raid_disks - 1;
  998. if (rdev->raid_disk >= 0)
  999. first = last = rdev->raid_disk;
  1000. for (mirror = first; mirror <= last; mirror++)
  1001. if ( !(p=conf->mirrors+mirror)->rdev) {
  1002. disk_stack_limits(mddev->gendisk, rdev->bdev,
  1003. rdev->data_offset << 9);
  1004. /* as we don't honour merge_bvec_fn, we must
  1005. * never risk violating it, so limit
  1006. * ->max_segments to one lying with a single
  1007. * page, as a one page request is never in
  1008. * violation.
  1009. */
  1010. if (rdev->bdev->bd_disk->queue->merge_bvec_fn) {
  1011. blk_queue_max_segments(mddev->queue, 1);
  1012. blk_queue_segment_boundary(mddev->queue,
  1013. PAGE_CACHE_SIZE - 1);
  1014. }
  1015. p->head_position = 0;
  1016. rdev->raid_disk = mirror;
  1017. err = 0;
  1018. /* As all devices are equivalent, we don't need a full recovery
  1019. * if this was recently any drive of the array
  1020. */
  1021. if (rdev->saved_raid_disk < 0)
  1022. conf->fullsync = 1;
  1023. rcu_assign_pointer(p->rdev, rdev);
  1024. break;
  1025. }
  1026. md_integrity_add_rdev(rdev, mddev);
  1027. print_conf(conf);
  1028. return err;
  1029. }
  1030. static int raid1_remove_disk(mddev_t *mddev, int number)
  1031. {
  1032. conf_t *conf = mddev->private;
  1033. int err = 0;
  1034. mdk_rdev_t *rdev;
  1035. mirror_info_t *p = conf->mirrors+ number;
  1036. print_conf(conf);
  1037. rdev = p->rdev;
  1038. if (rdev) {
  1039. if (test_bit(In_sync, &rdev->flags) ||
  1040. atomic_read(&rdev->nr_pending)) {
  1041. err = -EBUSY;
  1042. goto abort;
  1043. }
  1044. /* Only remove non-faulty devices is recovery
  1045. * is not possible.
  1046. */
  1047. if (!test_bit(Faulty, &rdev->flags) &&
  1048. mddev->degraded < conf->raid_disks) {
  1049. err = -EBUSY;
  1050. goto abort;
  1051. }
  1052. p->rdev = NULL;
  1053. synchronize_rcu();
  1054. if (atomic_read(&rdev->nr_pending)) {
  1055. /* lost the race, try later */
  1056. err = -EBUSY;
  1057. p->rdev = rdev;
  1058. goto abort;
  1059. }
  1060. md_integrity_register(mddev);
  1061. }
  1062. abort:
  1063. print_conf(conf);
  1064. return err;
  1065. }
  1066. static void end_sync_read(struct bio *bio, int error)
  1067. {
  1068. r1bio_t *r1_bio = bio->bi_private;
  1069. int i;
  1070. for (i=r1_bio->mddev->raid_disks; i--; )
  1071. if (r1_bio->bios[i] == bio)
  1072. break;
  1073. BUG_ON(i < 0);
  1074. update_head_pos(i, r1_bio);
  1075. /*
  1076. * we have read a block, now it needs to be re-written,
  1077. * or re-read if the read failed.
  1078. * We don't do much here, just schedule handling by raid1d
  1079. */
  1080. if (test_bit(BIO_UPTODATE, &bio->bi_flags))
  1081. set_bit(R1BIO_Uptodate, &r1_bio->state);
  1082. if (atomic_dec_and_test(&r1_bio->remaining))
  1083. reschedule_retry(r1_bio);
  1084. }
  1085. static void end_sync_write(struct bio *bio, int error)
  1086. {
  1087. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  1088. r1bio_t *r1_bio = bio->bi_private;
  1089. mddev_t *mddev = r1_bio->mddev;
  1090. conf_t *conf = mddev->private;
  1091. int i;
  1092. int mirror=0;
  1093. for (i = 0; i < conf->raid_disks; i++)
  1094. if (r1_bio->bios[i] == bio) {
  1095. mirror = i;
  1096. break;
  1097. }
  1098. if (!uptodate) {
  1099. int sync_blocks = 0;
  1100. sector_t s = r1_bio->sector;
  1101. long sectors_to_go = r1_bio->sectors;
  1102. /* make sure these bits doesn't get cleared. */
  1103. do {
  1104. bitmap_end_sync(mddev->bitmap, s,
  1105. &sync_blocks, 1);
  1106. s += sync_blocks;
  1107. sectors_to_go -= sync_blocks;
  1108. } while (sectors_to_go > 0);
  1109. md_error(mddev, conf->mirrors[mirror].rdev);
  1110. }
  1111. update_head_pos(mirror, r1_bio);
  1112. if (atomic_dec_and_test(&r1_bio->remaining)) {
  1113. sector_t s = r1_bio->sectors;
  1114. put_buf(r1_bio);
  1115. md_done_sync(mddev, s, uptodate);
  1116. }
  1117. }
  1118. static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
  1119. {
  1120. conf_t *conf = mddev->private;
  1121. int i;
  1122. int disks = conf->raid_disks;
  1123. struct bio *bio, *wbio;
  1124. bio = r1_bio->bios[r1_bio->read_disk];
  1125. if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
  1126. /* We have read all readable devices. If we haven't
  1127. * got the block, then there is no hope left.
  1128. * If we have, then we want to do a comparison
  1129. * and skip the write if everything is the same.
  1130. * If any blocks failed to read, then we need to
  1131. * attempt an over-write
  1132. */
  1133. int primary;
  1134. if (!test_bit(R1BIO_Uptodate, &r1_bio->state)) {
  1135. for (i=0; i<mddev->raid_disks; i++)
  1136. if (r1_bio->bios[i]->bi_end_io == end_sync_read)
  1137. md_error(mddev, conf->mirrors[i].rdev);
  1138. md_done_sync(mddev, r1_bio->sectors, 1);
  1139. put_buf(r1_bio);
  1140. return;
  1141. }
  1142. for (primary=0; primary<mddev->raid_disks; primary++)
  1143. if (r1_bio->bios[primary]->bi_end_io == end_sync_read &&
  1144. test_bit(BIO_UPTODATE, &r1_bio->bios[primary]->bi_flags)) {
  1145. r1_bio->bios[primary]->bi_end_io = NULL;
  1146. rdev_dec_pending(conf->mirrors[primary].rdev, mddev);
  1147. break;
  1148. }
  1149. r1_bio->read_disk = primary;
  1150. for (i=0; i<mddev->raid_disks; i++)
  1151. if (r1_bio->bios[i]->bi_end_io == end_sync_read) {
  1152. int j;
  1153. int vcnt = r1_bio->sectors >> (PAGE_SHIFT- 9);
  1154. struct bio *pbio = r1_bio->bios[primary];
  1155. struct bio *sbio = r1_bio->bios[i];
  1156. if (test_bit(BIO_UPTODATE, &sbio->bi_flags)) {
  1157. for (j = vcnt; j-- ; ) {
  1158. struct page *p, *s;
  1159. p = pbio->bi_io_vec[j].bv_page;
  1160. s = sbio->bi_io_vec[j].bv_page;
  1161. if (memcmp(page_address(p),
  1162. page_address(s),
  1163. PAGE_SIZE))
  1164. break;
  1165. }
  1166. } else
  1167. j = 0;
  1168. if (j >= 0)
  1169. mddev->resync_mismatches += r1_bio->sectors;
  1170. if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)
  1171. && test_bit(BIO_UPTODATE, &sbio->bi_flags))) {
  1172. sbio->bi_end_io = NULL;
  1173. rdev_dec_pending(conf->mirrors[i].rdev, mddev);
  1174. } else {
  1175. /* fixup the bio for reuse */
  1176. int size;
  1177. sbio->bi_vcnt = vcnt;
  1178. sbio->bi_size = r1_bio->sectors << 9;
  1179. sbio->bi_idx = 0;
  1180. sbio->bi_phys_segments = 0;
  1181. sbio->bi_flags &= ~(BIO_POOL_MASK - 1);
  1182. sbio->bi_flags |= 1 << BIO_UPTODATE;
  1183. sbio->bi_next = NULL;
  1184. sbio->bi_sector = r1_bio->sector +
  1185. conf->mirrors[i].rdev->data_offset;
  1186. sbio->bi_bdev = conf->mirrors[i].rdev->bdev;
  1187. size = sbio->bi_size;
  1188. for (j = 0; j < vcnt ; j++) {
  1189. struct bio_vec *bi;
  1190. bi = &sbio->bi_io_vec[j];
  1191. bi->bv_offset = 0;
  1192. if (size > PAGE_SIZE)
  1193. bi->bv_len = PAGE_SIZE;
  1194. else
  1195. bi->bv_len = size;
  1196. size -= PAGE_SIZE;
  1197. memcpy(page_address(bi->bv_page),
  1198. page_address(pbio->bi_io_vec[j].bv_page),
  1199. PAGE_SIZE);
  1200. }
  1201. }
  1202. }
  1203. }
  1204. if (!test_bit(R1BIO_Uptodate, &r1_bio->state)) {
  1205. /* ouch - failed to read all of that.
  1206. * Try some synchronous reads of other devices to get
  1207. * good data, much like with normal read errors. Only
  1208. * read into the pages we already have so we don't
  1209. * need to re-issue the read request.
  1210. * We don't need to freeze the array, because being in an
  1211. * active sync request, there is no normal IO, and
  1212. * no overlapping syncs.
  1213. */
  1214. sector_t sect = r1_bio->sector;
  1215. int sectors = r1_bio->sectors;
  1216. int idx = 0;
  1217. while(sectors) {
  1218. int s = sectors;
  1219. int d = r1_bio->read_disk;
  1220. int success = 0;
  1221. mdk_rdev_t *rdev;
  1222. if (s > (PAGE_SIZE>>9))
  1223. s = PAGE_SIZE >> 9;
  1224. do {
  1225. if (r1_bio->bios[d]->bi_end_io == end_sync_read) {
  1226. /* No rcu protection needed here devices
  1227. * can only be removed when no resync is
  1228. * active, and resync is currently active
  1229. */
  1230. rdev = conf->mirrors[d].rdev;
  1231. if (sync_page_io(rdev->bdev,
  1232. sect + rdev->data_offset,
  1233. s<<9,
  1234. bio->bi_io_vec[idx].bv_page,
  1235. READ)) {
  1236. success = 1;
  1237. break;
  1238. }
  1239. }
  1240. d++;
  1241. if (d == conf->raid_disks)
  1242. d = 0;
  1243. } while (!success && d != r1_bio->read_disk);
  1244. if (success) {
  1245. int start = d;
  1246. /* write it back and re-read */
  1247. set_bit(R1BIO_Uptodate, &r1_bio->state);
  1248. while (d != r1_bio->read_disk) {
  1249. if (d == 0)
  1250. d = conf->raid_disks;
  1251. d--;
  1252. if (r1_bio->bios[d]->bi_end_io != end_sync_read)
  1253. continue;
  1254. rdev = conf->mirrors[d].rdev;
  1255. atomic_add(s, &rdev->corrected_errors);
  1256. if (sync_page_io(rdev->bdev,
  1257. sect + rdev->data_offset,
  1258. s<<9,
  1259. bio->bi_io_vec[idx].bv_page,
  1260. WRITE) == 0)
  1261. md_error(mddev, rdev);
  1262. }
  1263. d = start;
  1264. while (d != r1_bio->read_disk) {
  1265. if (d == 0)
  1266. d = conf->raid_disks;
  1267. d--;
  1268. if (r1_bio->bios[d]->bi_end_io != end_sync_read)
  1269. continue;
  1270. rdev = conf->mirrors[d].rdev;
  1271. if (sync_page_io(rdev->bdev,
  1272. sect + rdev->data_offset,
  1273. s<<9,
  1274. bio->bi_io_vec[idx].bv_page,
  1275. READ) == 0)
  1276. md_error(mddev, rdev);
  1277. }
  1278. } else {
  1279. char b[BDEVNAME_SIZE];
  1280. /* Cannot read from anywhere, array is toast */
  1281. md_error(mddev, conf->mirrors[r1_bio->read_disk].rdev);
  1282. printk(KERN_ALERT "md/raid1:%s: %s: unrecoverable I/O read error"
  1283. " for block %llu\n",
  1284. mdname(mddev),
  1285. bdevname(bio->bi_bdev, b),
  1286. (unsigned long long)r1_bio->sector);
  1287. md_done_sync(mddev, r1_bio->sectors, 0);
  1288. put_buf(r1_bio);
  1289. return;
  1290. }
  1291. sectors -= s;
  1292. sect += s;
  1293. idx ++;
  1294. }
  1295. }
  1296. /*
  1297. * schedule writes
  1298. */
  1299. atomic_set(&r1_bio->remaining, 1);
  1300. for (i = 0; i < disks ; i++) {
  1301. wbio = r1_bio->bios[i];
  1302. if (wbio->bi_end_io == NULL ||
  1303. (wbio->bi_end_io == end_sync_read &&
  1304. (i == r1_bio->read_disk ||
  1305. !test_bit(MD_RECOVERY_SYNC, &mddev->recovery))))
  1306. continue;
  1307. wbio->bi_rw = WRITE;
  1308. wbio->bi_end_io = end_sync_write;
  1309. atomic_inc(&r1_bio->remaining);
  1310. md_sync_acct(conf->mirrors[i].rdev->bdev, wbio->bi_size >> 9);
  1311. generic_make_request(wbio);
  1312. }
  1313. if (atomic_dec_and_test(&r1_bio->remaining)) {
  1314. /* if we're here, all write(s) have completed, so clean up */
  1315. md_done_sync(mddev, r1_bio->sectors, 1);
  1316. put_buf(r1_bio);
  1317. }
  1318. }
  1319. /*
  1320. * This is a kernel thread which:
  1321. *
  1322. * 1. Retries failed read operations on working mirrors.
  1323. * 2. Updates the raid superblock when problems encounter.
  1324. * 3. Performs writes following reads for array syncronising.
  1325. */
  1326. static void fix_read_error(conf_t *conf, int read_disk,
  1327. sector_t sect, int sectors)
  1328. {
  1329. mddev_t *mddev = conf->mddev;
  1330. while(sectors) {
  1331. int s = sectors;
  1332. int d = read_disk;
  1333. int success = 0;
  1334. int start;
  1335. mdk_rdev_t *rdev;
  1336. if (s > (PAGE_SIZE>>9))
  1337. s = PAGE_SIZE >> 9;
  1338. do {
  1339. /* Note: no rcu protection needed here
  1340. * as this is synchronous in the raid1d thread
  1341. * which is the thread that might remove
  1342. * a device. If raid1d ever becomes multi-threaded....
  1343. */
  1344. rdev = conf->mirrors[d].rdev;
  1345. if (rdev &&
  1346. test_bit(In_sync, &rdev->flags) &&
  1347. sync_page_io(rdev->bdev,
  1348. sect + rdev->data_offset,
  1349. s<<9,
  1350. conf->tmppage, READ))
  1351. success = 1;
  1352. else {
  1353. d++;
  1354. if (d == conf->raid_disks)
  1355. d = 0;
  1356. }
  1357. } while (!success && d != read_disk);
  1358. if (!success) {
  1359. /* Cannot read from anywhere -- bye bye array */
  1360. md_error(mddev, conf->mirrors[read_disk].rdev);
  1361. break;
  1362. }
  1363. /* write it back and re-read */
  1364. start = d;
  1365. while (d != read_disk) {
  1366. if (d==0)
  1367. d = conf->raid_disks;
  1368. d--;
  1369. rdev = conf->mirrors[d].rdev;
  1370. if (rdev &&
  1371. test_bit(In_sync, &rdev->flags)) {
  1372. if (sync_page_io(rdev->bdev,
  1373. sect + rdev->data_offset,
  1374. s<<9, conf->tmppage, WRITE)
  1375. == 0)
  1376. /* Well, this device is dead */
  1377. md_error(mddev, rdev);
  1378. }
  1379. }
  1380. d = start;
  1381. while (d != read_disk) {
  1382. char b[BDEVNAME_SIZE];
  1383. if (d==0)
  1384. d = conf->raid_disks;
  1385. d--;
  1386. rdev = conf->mirrors[d].rdev;
  1387. if (rdev &&
  1388. test_bit(In_sync, &rdev->flags)) {
  1389. if (sync_page_io(rdev->bdev,
  1390. sect + rdev->data_offset,
  1391. s<<9, conf->tmppage, READ)
  1392. == 0)
  1393. /* Well, this device is dead */
  1394. md_error(mddev, rdev);
  1395. else {
  1396. atomic_add(s, &rdev->corrected_errors);
  1397. printk(KERN_INFO
  1398. "md/raid1:%s: read error corrected "
  1399. "(%d sectors at %llu on %s)\n",
  1400. mdname(mddev), s,
  1401. (unsigned long long)(sect +
  1402. rdev->data_offset),
  1403. bdevname(rdev->bdev, b));
  1404. }
  1405. }
  1406. }
  1407. sectors -= s;
  1408. sect += s;
  1409. }
  1410. }
  1411. static void raid1d(mddev_t *mddev)
  1412. {
  1413. r1bio_t *r1_bio;
  1414. struct bio *bio;
  1415. unsigned long flags;
  1416. conf_t *conf = mddev->private;
  1417. struct list_head *head = &conf->retry_list;
  1418. int unplug=0;
  1419. mdk_rdev_t *rdev;
  1420. md_check_recovery(mddev);
  1421. for (;;) {
  1422. char b[BDEVNAME_SIZE];
  1423. unplug += flush_pending_writes(conf);
  1424. spin_lock_irqsave(&conf->device_lock, flags);
  1425. if (list_empty(head)) {
  1426. spin_unlock_irqrestore(&conf->device_lock, flags);
  1427. break;
  1428. }
  1429. r1_bio = list_entry(head->prev, r1bio_t, retry_list);
  1430. list_del(head->prev);
  1431. conf->nr_queued--;
  1432. spin_unlock_irqrestore(&conf->device_lock, flags);
  1433. mddev = r1_bio->mddev;
  1434. conf = mddev->private;
  1435. if (test_bit(R1BIO_IsSync, &r1_bio->state)) {
  1436. sync_request_write(mddev, r1_bio);
  1437. unplug = 1;
  1438. } else if (test_bit(R1BIO_BarrierRetry, &r1_bio->state)) {
  1439. /* some requests in the r1bio were BIO_RW_BARRIER
  1440. * requests which failed with -EOPNOTSUPP. Hohumm..
  1441. * Better resubmit without the barrier.
  1442. * We know which devices to resubmit for, because
  1443. * all others have had their bios[] entry cleared.
  1444. * We already have a nr_pending reference on these rdevs.
  1445. */
  1446. int i;
  1447. const bool do_sync = bio_rw_flagged(r1_bio->master_bio, BIO_RW_SYNCIO);
  1448. clear_bit(R1BIO_BarrierRetry, &r1_bio->state);
  1449. clear_bit(R1BIO_Barrier, &r1_bio->state);
  1450. for (i=0; i < conf->raid_disks; i++)
  1451. if (r1_bio->bios[i])
  1452. atomic_inc(&r1_bio->remaining);
  1453. for (i=0; i < conf->raid_disks; i++)
  1454. if (r1_bio->bios[i]) {
  1455. struct bio_vec *bvec;
  1456. int j;
  1457. bio = bio_clone(r1_bio->master_bio, GFP_NOIO);
  1458. /* copy pages from the failed bio, as
  1459. * this might be a write-behind device */
  1460. __bio_for_each_segment(bvec, bio, j, 0)
  1461. bvec->bv_page = bio_iovec_idx(r1_bio->bios[i], j)->bv_page;
  1462. bio_put(r1_bio->bios[i]);
  1463. bio->bi_sector = r1_bio->sector +
  1464. conf->mirrors[i].rdev->data_offset;
  1465. bio->bi_bdev = conf->mirrors[i].rdev->bdev;
  1466. bio->bi_end_io = raid1_end_write_request;
  1467. bio->bi_rw = WRITE |
  1468. (do_sync << BIO_RW_SYNCIO);
  1469. bio->bi_private = r1_bio;
  1470. r1_bio->bios[i] = bio;
  1471. generic_make_request(bio);
  1472. }
  1473. } else {
  1474. int disk;
  1475. /* we got a read error. Maybe the drive is bad. Maybe just
  1476. * the block and we can fix it.
  1477. * We freeze all other IO, and try reading the block from
  1478. * other devices. When we find one, we re-write
  1479. * and check it that fixes the read error.
  1480. * This is all done synchronously while the array is
  1481. * frozen
  1482. */
  1483. if (mddev->ro == 0) {
  1484. freeze_array(conf);
  1485. fix_read_error(conf, r1_bio->read_disk,
  1486. r1_bio->sector,
  1487. r1_bio->sectors);
  1488. unfreeze_array(conf);
  1489. } else
  1490. md_error(mddev,
  1491. conf->mirrors[r1_bio->read_disk].rdev);
  1492. bio = r1_bio->bios[r1_bio->read_disk];
  1493. if ((disk=read_balance(conf, r1_bio)) == -1) {
  1494. printk(KERN_ALERT "md/raid1:%s: %s: unrecoverable I/O"
  1495. " read error for block %llu\n",
  1496. mdname(mddev),
  1497. bdevname(bio->bi_bdev,b),
  1498. (unsigned long long)r1_bio->sector);
  1499. raid_end_bio_io(r1_bio);
  1500. } else {
  1501. const bool do_sync = bio_rw_flagged(r1_bio->master_bio, BIO_RW_SYNCIO);
  1502. r1_bio->bios[r1_bio->read_disk] =
  1503. mddev->ro ? IO_BLOCKED : NULL;
  1504. r1_bio->read_disk = disk;
  1505. bio_put(bio);
  1506. bio = bio_clone(r1_bio->master_bio, GFP_NOIO);
  1507. r1_bio->bios[r1_bio->read_disk] = bio;
  1508. rdev = conf->mirrors[disk].rdev;
  1509. if (printk_ratelimit())
  1510. printk(KERN_ERR "md/raid1:%s: redirecting sector %llu to"
  1511. " other mirror: %s\n",
  1512. mdname(mddev),
  1513. (unsigned long long)r1_bio->sector,
  1514. bdevname(rdev->bdev,b));
  1515. bio->bi_sector = r1_bio->sector + rdev->data_offset;
  1516. bio->bi_bdev = rdev->bdev;
  1517. bio->bi_end_io = raid1_end_read_request;
  1518. bio->bi_rw = READ | (do_sync << BIO_RW_SYNCIO);
  1519. bio->bi_private = r1_bio;
  1520. unplug = 1;
  1521. generic_make_request(bio);
  1522. }
  1523. }
  1524. cond_resched();
  1525. }
  1526. if (unplug)
  1527. unplug_slaves(mddev);
  1528. }
  1529. static int init_resync(conf_t *conf)
  1530. {
  1531. int buffs;
  1532. buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE;
  1533. BUG_ON(conf->r1buf_pool);
  1534. conf->r1buf_pool = mempool_create(buffs, r1buf_pool_alloc, r1buf_pool_free,
  1535. conf->poolinfo);
  1536. if (!conf->r1buf_pool)
  1537. return -ENOMEM;
  1538. conf->next_resync = 0;
  1539. return 0;
  1540. }
  1541. /*
  1542. * perform a "sync" on one "block"
  1543. *
  1544. * We need to make sure that no normal I/O request - particularly write
  1545. * requests - conflict with active sync requests.
  1546. *
  1547. * This is achieved by tracking pending requests and a 'barrier' concept
  1548. * that can be installed to exclude normal IO requests.
  1549. */
  1550. static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
  1551. {
  1552. conf_t *conf = mddev->private;
  1553. r1bio_t *r1_bio;
  1554. struct bio *bio;
  1555. sector_t max_sector, nr_sectors;
  1556. int disk = -1;
  1557. int i;
  1558. int wonly = -1;
  1559. int write_targets = 0, read_targets = 0;
  1560. int sync_blocks;
  1561. int still_degraded = 0;
  1562. if (!conf->r1buf_pool)
  1563. if (init_resync(conf))
  1564. return 0;
  1565. max_sector = mddev->dev_sectors;
  1566. if (sector_nr >= max_sector) {
  1567. /* If we aborted, we need to abort the
  1568. * sync on the 'current' bitmap chunk (there will
  1569. * only be one in raid1 resync.
  1570. * We can find the current addess in mddev->curr_resync
  1571. */
  1572. if (mddev->curr_resync < max_sector) /* aborted */
  1573. bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
  1574. &sync_blocks, 1);
  1575. else /* completed sync */
  1576. conf->fullsync = 0;
  1577. bitmap_close_sync(mddev->bitmap);
  1578. close_sync(conf);
  1579. return 0;
  1580. }
  1581. if (mddev->bitmap == NULL &&
  1582. mddev->recovery_cp == MaxSector &&
  1583. !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) &&
  1584. conf->fullsync == 0) {
  1585. *skipped = 1;
  1586. return max_sector - sector_nr;
  1587. }
  1588. /* before building a request, check if we can skip these blocks..
  1589. * This call the bitmap_start_sync doesn't actually record anything
  1590. */
  1591. if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
  1592. !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
  1593. /* We can skip this block, and probably several more */
  1594. *skipped = 1;
  1595. return sync_blocks;
  1596. }
  1597. /*
  1598. * If there is non-resync activity waiting for a turn,
  1599. * and resync is going fast enough,
  1600. * then let it though before starting on this new sync request.
  1601. */
  1602. if (!go_faster && conf->nr_waiting)
  1603. msleep_interruptible(1000);
  1604. bitmap_cond_end_sync(mddev->bitmap, sector_nr);
  1605. raise_barrier(conf);
  1606. conf->next_resync = sector_nr;
  1607. r1_bio = mempool_alloc(conf->r1buf_pool, GFP_NOIO);
  1608. rcu_read_lock();
  1609. /*
  1610. * If we get a correctably read error during resync or recovery,
  1611. * we might want to read from a different device. So we
  1612. * flag all drives that could conceivably be read from for READ,
  1613. * and any others (which will be non-In_sync devices) for WRITE.
  1614. * If a read fails, we try reading from something else for which READ
  1615. * is OK.
  1616. */
  1617. r1_bio->mddev = mddev;
  1618. r1_bio->sector = sector_nr;
  1619. r1_bio->state = 0;
  1620. set_bit(R1BIO_IsSync, &r1_bio->state);
  1621. for (i=0; i < conf->raid_disks; i++) {
  1622. mdk_rdev_t *rdev;
  1623. bio = r1_bio->bios[i];
  1624. /* take from bio_init */
  1625. bio->bi_next = NULL;
  1626. bio->bi_flags |= 1 << BIO_UPTODATE;
  1627. bio->bi_rw = READ;
  1628. bio->bi_vcnt = 0;
  1629. bio->bi_idx = 0;
  1630. bio->bi_phys_segments = 0;
  1631. bio->bi_size = 0;
  1632. bio->bi_end_io = NULL;
  1633. bio->bi_private = NULL;
  1634. rdev = rcu_dereference(conf->mirrors[i].rdev);
  1635. if (rdev == NULL ||
  1636. test_bit(Faulty, &rdev->flags)) {
  1637. still_degraded = 1;
  1638. continue;
  1639. } else if (!test_bit(In_sync, &rdev->flags)) {
  1640. bio->bi_rw = WRITE;
  1641. bio->bi_end_io = end_sync_write;
  1642. write_targets ++;
  1643. } else {
  1644. /* may need to read from here */
  1645. bio->bi_rw = READ;
  1646. bio->bi_end_io = end_sync_read;
  1647. if (test_bit(WriteMostly, &rdev->flags)) {
  1648. if (wonly < 0)
  1649. wonly = i;
  1650. } else {
  1651. if (disk < 0)
  1652. disk = i;
  1653. }
  1654. read_targets++;
  1655. }
  1656. atomic_inc(&rdev->nr_pending);
  1657. bio->bi_sector = sector_nr + rdev->data_offset;
  1658. bio->bi_bdev = rdev->bdev;
  1659. bio->bi_private = r1_bio;
  1660. }
  1661. rcu_read_unlock();
  1662. if (disk < 0)
  1663. disk = wonly;
  1664. r1_bio->read_disk = disk;
  1665. if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) && read_targets > 0)
  1666. /* extra read targets are also write targets */
  1667. write_targets += read_targets-1;
  1668. if (write_targets == 0 || read_targets == 0) {
  1669. /* There is nowhere to write, so all non-sync
  1670. * drives must be failed - so we are finished
  1671. */
  1672. sector_t rv = max_sector - sector_nr;
  1673. *skipped = 1;
  1674. put_buf(r1_bio);
  1675. return rv;
  1676. }
  1677. if (max_sector > mddev->resync_max)
  1678. max_sector = mddev->resync_max; /* Don't do IO beyond here */
  1679. nr_sectors = 0;
  1680. sync_blocks = 0;
  1681. do {
  1682. struct page *page;
  1683. int len = PAGE_SIZE;
  1684. if (sector_nr + (len>>9) > max_sector)
  1685. len = (max_sector - sector_nr) << 9;
  1686. if (len == 0)
  1687. break;
  1688. if (sync_blocks == 0) {
  1689. if (!bitmap_start_sync(mddev->bitmap, sector_nr,
  1690. &sync_blocks, still_degraded) &&
  1691. !conf->fullsync &&
  1692. !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
  1693. break;
  1694. BUG_ON(sync_blocks < (PAGE_SIZE>>9));
  1695. if (len > (sync_blocks<<9))
  1696. len = sync_blocks<<9;
  1697. }
  1698. for (i=0 ; i < conf->raid_disks; i++) {
  1699. bio = r1_bio->bios[i];
  1700. if (bio->bi_end_io) {
  1701. page = bio->bi_io_vec[bio->bi_vcnt].bv_page;
  1702. if (bio_add_page(bio, page, len, 0) == 0) {
  1703. /* stop here */
  1704. bio->bi_io_vec[bio->bi_vcnt].bv_page = page;
  1705. while (i > 0) {
  1706. i--;
  1707. bio = r1_bio->bios[i];
  1708. if (bio->bi_end_io==NULL)
  1709. continue;
  1710. /* remove last page from this bio */
  1711. bio->bi_vcnt--;
  1712. bio->bi_size -= len;
  1713. bio->bi_flags &= ~(1<< BIO_SEG_VALID);
  1714. }
  1715. goto bio_full;
  1716. }
  1717. }
  1718. }
  1719. nr_sectors += len>>9;
  1720. sector_nr += len>>9;
  1721. sync_blocks -= (len>>9);
  1722. } while (r1_bio->bios[disk]->bi_vcnt < RESYNC_PAGES);
  1723. bio_full:
  1724. r1_bio->sectors = nr_sectors;
  1725. /* For a user-requested sync, we read all readable devices and do a
  1726. * compare
  1727. */
  1728. if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
  1729. atomic_set(&r1_bio->remaining, read_targets);
  1730. for (i=0; i<conf->raid_disks; i++) {
  1731. bio = r1_bio->bios[i];
  1732. if (bio->bi_end_io == end_sync_read) {
  1733. md_sync_acct(bio->bi_bdev, nr_sectors);
  1734. generic_make_request(bio);
  1735. }
  1736. }
  1737. } else {
  1738. atomic_set(&r1_bio->remaining, 1);
  1739. bio = r1_bio->bios[r1_bio->read_disk];
  1740. md_sync_acct(bio->bi_bdev, nr_sectors);
  1741. generic_make_request(bio);
  1742. }
  1743. return nr_sectors;
  1744. }
  1745. static sector_t raid1_size(mddev_t *mddev, sector_t sectors, int raid_disks)
  1746. {
  1747. if (sectors)
  1748. return sectors;
  1749. return mddev->dev_sectors;
  1750. }
  1751. static conf_t *setup_conf(mddev_t *mddev)
  1752. {
  1753. conf_t *conf;
  1754. int i;
  1755. mirror_info_t *disk;
  1756. mdk_rdev_t *rdev;
  1757. int err = -ENOMEM;
  1758. conf = kzalloc(sizeof(conf_t), GFP_KERNEL);
  1759. if (!conf)
  1760. goto abort;
  1761. conf->mirrors = kzalloc(sizeof(struct mirror_info)*mddev->raid_disks,
  1762. GFP_KERNEL);
  1763. if (!conf->mirrors)
  1764. goto abort;
  1765. conf->tmppage = alloc_page(GFP_KERNEL);
  1766. if (!conf->tmppage)
  1767. goto abort;
  1768. conf->poolinfo = kzalloc(sizeof(*conf->poolinfo), GFP_KERNEL);
  1769. if (!conf->poolinfo)
  1770. goto abort;
  1771. conf->poolinfo->raid_disks = mddev->raid_disks;
  1772. conf->r1bio_pool = mempool_create(NR_RAID1_BIOS, r1bio_pool_alloc,
  1773. r1bio_pool_free,
  1774. conf->poolinfo);
  1775. if (!conf->r1bio_pool)
  1776. goto abort;
  1777. conf->poolinfo->mddev = mddev;
  1778. spin_lock_init(&conf->device_lock);
  1779. list_for_each_entry(rdev, &mddev->disks, same_set) {
  1780. int disk_idx = rdev->raid_disk;
  1781. if (disk_idx >= mddev->raid_disks
  1782. || disk_idx < 0)
  1783. continue;
  1784. disk = conf->mirrors + disk_idx;
  1785. disk->rdev = rdev;
  1786. disk->head_position = 0;
  1787. }
  1788. conf->raid_disks = mddev->raid_disks;
  1789. conf->mddev = mddev;
  1790. INIT_LIST_HEAD(&conf->retry_list);
  1791. spin_lock_init(&conf->resync_lock);
  1792. init_waitqueue_head(&conf->wait_barrier);
  1793. bio_list_init(&conf->pending_bio_list);
  1794. bio_list_init(&conf->flushing_bio_list);
  1795. conf->last_used = -1;
  1796. for (i = 0; i < conf->raid_disks; i++) {
  1797. disk = conf->mirrors + i;
  1798. if (!disk->rdev ||
  1799. !test_bit(In_sync, &disk->rdev->flags)) {
  1800. disk->head_position = 0;
  1801. if (disk->rdev)
  1802. conf->fullsync = 1;
  1803. } else if (conf->last_used < 0)
  1804. /*
  1805. * The first working device is used as a
  1806. * starting point to read balancing.
  1807. */
  1808. conf->last_used = i;
  1809. }
  1810. err = -EIO;
  1811. if (conf->last_used < 0) {
  1812. printk(KERN_ERR "md/raid1:%s: no operational mirrors\n",
  1813. mdname(mddev));
  1814. goto abort;
  1815. }
  1816. err = -ENOMEM;
  1817. conf->thread = md_register_thread(raid1d, mddev, NULL);
  1818. if (!conf->thread) {
  1819. printk(KERN_ERR
  1820. "md/raid1:%s: couldn't allocate thread\n",
  1821. mdname(mddev));
  1822. goto abort;
  1823. }
  1824. return conf;
  1825. abort:
  1826. if (conf) {
  1827. if (conf->r1bio_pool)
  1828. mempool_destroy(conf->r1bio_pool);
  1829. kfree(conf->mirrors);
  1830. safe_put_page(conf->tmppage);
  1831. kfree(conf->poolinfo);
  1832. kfree(conf);
  1833. }
  1834. return ERR_PTR(err);
  1835. }
  1836. static int run(mddev_t *mddev)
  1837. {
  1838. conf_t *conf;
  1839. int i;
  1840. mdk_rdev_t *rdev;
  1841. if (mddev->level != 1) {
  1842. printk(KERN_ERR "md/raid1:%s: raid level not set to mirroring (%d)\n",
  1843. mdname(mddev), mddev->level);
  1844. return -EIO;
  1845. }
  1846. if (mddev->reshape_position != MaxSector) {
  1847. printk(KERN_ERR "md/raid1:%s: reshape_position set but not supported\n",
  1848. mdname(mddev));
  1849. return -EIO;
  1850. }
  1851. /*
  1852. * copy the already verified devices into our private RAID1
  1853. * bookkeeping area. [whatever we allocate in run(),
  1854. * should be freed in stop()]
  1855. */
  1856. if (mddev->private == NULL)
  1857. conf = setup_conf(mddev);
  1858. else
  1859. conf = mddev->private;
  1860. if (IS_ERR(conf))
  1861. return PTR_ERR(conf);
  1862. mddev->queue->queue_lock = &conf->device_lock;
  1863. list_for_each_entry(rdev, &mddev->disks, same_set) {
  1864. disk_stack_limits(mddev->gendisk, rdev->bdev,
  1865. rdev->data_offset << 9);
  1866. /* as we don't honour merge_bvec_fn, we must never risk
  1867. * violating it, so limit ->max_segments to 1 lying within
  1868. * a single page, as a one page request is never in violation.
  1869. */
  1870. if (rdev->bdev->bd_disk->queue->merge_bvec_fn) {
  1871. blk_queue_max_segments(mddev->queue, 1);
  1872. blk_queue_segment_boundary(mddev->queue,
  1873. PAGE_CACHE_SIZE - 1);
  1874. }
  1875. }
  1876. mddev->degraded = 0;
  1877. for (i=0; i < conf->raid_disks; i++)
  1878. if (conf->mirrors[i].rdev == NULL ||
  1879. !test_bit(In_sync, &conf->mirrors[i].rdev->flags) ||
  1880. test_bit(Faulty, &conf->mirrors[i].rdev->flags))
  1881. mddev->degraded++;
  1882. if (conf->raid_disks - mddev->degraded == 1)
  1883. mddev->recovery_cp = MaxSector;
  1884. if (mddev->recovery_cp != MaxSector)
  1885. printk(KERN_NOTICE "md/raid1:%s: not clean"
  1886. " -- starting background reconstruction\n",
  1887. mdname(mddev));
  1888. printk(KERN_INFO
  1889. "md/raid1:%s: active with %d out of %d mirrors\n",
  1890. mdname(mddev), mddev->raid_disks - mddev->degraded,
  1891. mddev->raid_disks);
  1892. /*
  1893. * Ok, everything is just fine now
  1894. */
  1895. mddev->thread = conf->thread;
  1896. conf->thread = NULL;
  1897. mddev->private = conf;
  1898. md_set_array_sectors(mddev, raid1_size(mddev, 0, 0));
  1899. mddev->queue->unplug_fn = raid1_unplug;
  1900. mddev->queue->backing_dev_info.congested_fn = raid1_congested;
  1901. mddev->queue->backing_dev_info.congested_data = mddev;
  1902. md_integrity_register(mddev);
  1903. return 0;
  1904. }
  1905. static int stop(mddev_t *mddev)
  1906. {
  1907. conf_t *conf = mddev->private;
  1908. struct bitmap *bitmap = mddev->bitmap;
  1909. /* wait for behind writes to complete */
  1910. if (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
  1911. printk(KERN_INFO "md/raid1:%s: behind writes in progress - waiting to stop.\n",
  1912. mdname(mddev));
  1913. /* need to kick something here to make sure I/O goes? */
  1914. wait_event(bitmap->behind_wait,
  1915. atomic_read(&bitmap->behind_writes) == 0);
  1916. }
  1917. raise_barrier(conf);
  1918. lower_barrier(conf);
  1919. md_unregister_thread(mddev->thread);
  1920. mddev->thread = NULL;
  1921. blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
  1922. if (conf->r1bio_pool)
  1923. mempool_destroy(conf->r1bio_pool);
  1924. kfree(conf->mirrors);
  1925. kfree(conf->poolinfo);
  1926. kfree(conf);
  1927. mddev->private = NULL;
  1928. return 0;
  1929. }
  1930. static int raid1_resize(mddev_t *mddev, sector_t sectors)
  1931. {
  1932. /* no resync is happening, and there is enough space
  1933. * on all devices, so we can resize.
  1934. * We need to make sure resync covers any new space.
  1935. * If the array is shrinking we should possibly wait until
  1936. * any io in the removed space completes, but it hardly seems
  1937. * worth it.
  1938. */
  1939. md_set_array_sectors(mddev, raid1_size(mddev, sectors, 0));
  1940. if (mddev->array_sectors > raid1_size(mddev, sectors, 0))
  1941. return -EINVAL;
  1942. set_capacity(mddev->gendisk, mddev->array_sectors);
  1943. revalidate_disk(mddev->gendisk);
  1944. if (sectors > mddev->dev_sectors &&
  1945. mddev->recovery_cp == MaxSector) {
  1946. mddev->recovery_cp = mddev->dev_sectors;
  1947. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  1948. }
  1949. mddev->dev_sectors = sectors;
  1950. mddev->resync_max_sectors = sectors;
  1951. return 0;
  1952. }
  1953. static int raid1_reshape(mddev_t *mddev)
  1954. {
  1955. /* We need to:
  1956. * 1/ resize the r1bio_pool
  1957. * 2/ resize conf->mirrors
  1958. *
  1959. * We allocate a new r1bio_pool if we can.
  1960. * Then raise a device barrier and wait until all IO stops.
  1961. * Then resize conf->mirrors and swap in the new r1bio pool.
  1962. *
  1963. * At the same time, we "pack" the devices so that all the missing
  1964. * devices have the higher raid_disk numbers.
  1965. */
  1966. mempool_t *newpool, *oldpool;
  1967. struct pool_info *newpoolinfo;
  1968. mirror_info_t *newmirrors;
  1969. conf_t *conf = mddev->private;
  1970. int cnt, raid_disks;
  1971. unsigned long flags;
  1972. int d, d2, err;
  1973. /* Cannot change chunk_size, layout, or level */
  1974. if (mddev->chunk_sectors != mddev->new_chunk_sectors ||
  1975. mddev->layout != mddev->new_layout ||
  1976. mddev->level != mddev->new_level) {
  1977. mddev->new_chunk_sectors = mddev->chunk_sectors;
  1978. mddev->new_layout = mddev->layout;
  1979. mddev->new_level = mddev->level;
  1980. return -EINVAL;
  1981. }
  1982. err = md_allow_write(mddev);
  1983. if (err)
  1984. return err;
  1985. raid_disks = mddev->raid_disks + mddev->delta_disks;
  1986. if (raid_disks < conf->raid_disks) {
  1987. cnt=0;
  1988. for (d= 0; d < conf->raid_disks; d++)
  1989. if (conf->mirrors[d].rdev)
  1990. cnt++;
  1991. if (cnt > raid_disks)
  1992. return -EBUSY;
  1993. }
  1994. newpoolinfo = kmalloc(sizeof(*newpoolinfo), GFP_KERNEL);
  1995. if (!newpoolinfo)
  1996. return -ENOMEM;
  1997. newpoolinfo->mddev = mddev;
  1998. newpoolinfo->raid_disks = raid_disks;
  1999. newpool = mempool_create(NR_RAID1_BIOS, r1bio_pool_alloc,
  2000. r1bio_pool_free, newpoolinfo);
  2001. if (!newpool) {
  2002. kfree(newpoolinfo);
  2003. return -ENOMEM;
  2004. }
  2005. newmirrors = kzalloc(sizeof(struct mirror_info) * raid_disks, GFP_KERNEL);
  2006. if (!newmirrors) {
  2007. kfree(newpoolinfo);
  2008. mempool_destroy(newpool);
  2009. return -ENOMEM;
  2010. }
  2011. raise_barrier(conf);
  2012. /* ok, everything is stopped */
  2013. oldpool = conf->r1bio_pool;
  2014. conf->r1bio_pool = newpool;
  2015. for (d = d2 = 0; d < conf->raid_disks; d++) {
  2016. mdk_rdev_t *rdev = conf->mirrors[d].rdev;
  2017. if (rdev && rdev->raid_disk != d2) {
  2018. char nm[20];
  2019. sprintf(nm, "rd%d", rdev->raid_disk);
  2020. sysfs_remove_link(&mddev->kobj, nm);
  2021. rdev->raid_disk = d2;
  2022. sprintf(nm, "rd%d", rdev->raid_disk);
  2023. sysfs_remove_link(&mddev->kobj, nm);
  2024. if (sysfs_create_link(&mddev->kobj,
  2025. &rdev->kobj, nm))
  2026. printk(KERN_WARNING
  2027. "md/raid1:%s: cannot register "
  2028. "%s\n",
  2029. mdname(mddev), nm);
  2030. }
  2031. if (rdev)
  2032. newmirrors[d2++].rdev = rdev;
  2033. }
  2034. kfree(conf->mirrors);
  2035. conf->mirrors = newmirrors;
  2036. kfree(conf->poolinfo);
  2037. conf->poolinfo = newpoolinfo;
  2038. spin_lock_irqsave(&conf->device_lock, flags);
  2039. mddev->degraded += (raid_disks - conf->raid_disks);
  2040. spin_unlock_irqrestore(&conf->device_lock, flags);
  2041. conf->raid_disks = mddev->raid_disks = raid_disks;
  2042. mddev->delta_disks = 0;
  2043. conf->last_used = 0; /* just make sure it is in-range */
  2044. lower_barrier(conf);
  2045. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  2046. md_wakeup_thread(mddev->thread);
  2047. mempool_destroy(oldpool);
  2048. return 0;
  2049. }
  2050. static void raid1_quiesce(mddev_t *mddev, int state)
  2051. {
  2052. conf_t *conf = mddev->private;
  2053. switch(state) {
  2054. case 2: /* wake for suspend */
  2055. wake_up(&conf->wait_barrier);
  2056. break;
  2057. case 1:
  2058. raise_barrier(conf);
  2059. break;
  2060. case 0:
  2061. lower_barrier(conf);
  2062. break;
  2063. }
  2064. }
  2065. static void *raid1_takeover(mddev_t *mddev)
  2066. {
  2067. /* raid1 can take over:
  2068. * raid5 with 2 devices, any layout or chunk size
  2069. */
  2070. if (mddev->level == 5 && mddev->raid_disks == 2) {
  2071. conf_t *conf;
  2072. mddev->new_level = 1;
  2073. mddev->new_layout = 0;
  2074. mddev->new_chunk_sectors = 0;
  2075. conf = setup_conf(mddev);
  2076. if (!IS_ERR(conf))
  2077. conf->barrier = 1;
  2078. return conf;
  2079. }
  2080. return ERR_PTR(-EINVAL);
  2081. }
  2082. static struct mdk_personality raid1_personality =
  2083. {
  2084. .name = "raid1",
  2085. .level = 1,
  2086. .owner = THIS_MODULE,
  2087. .make_request = make_request,
  2088. .run = run,
  2089. .stop = stop,
  2090. .status = status,
  2091. .error_handler = error,
  2092. .hot_add_disk = raid1_add_disk,
  2093. .hot_remove_disk= raid1_remove_disk,
  2094. .spare_active = raid1_spare_active,
  2095. .sync_request = sync_request,
  2096. .resize = raid1_resize,
  2097. .size = raid1_size,
  2098. .check_reshape = raid1_reshape,
  2099. .quiesce = raid1_quiesce,
  2100. .takeover = raid1_takeover,
  2101. };
  2102. static int __init raid_init(void)
  2103. {
  2104. return register_md_personality(&raid1_personality);
  2105. }
  2106. static void raid_exit(void)
  2107. {
  2108. unregister_md_personality(&raid1_personality);
  2109. }
  2110. module_init(raid_init);
  2111. module_exit(raid_exit);
  2112. MODULE_LICENSE("GPL");
  2113. MODULE_DESCRIPTION("RAID1 (mirroring) personality for MD");
  2114. MODULE_ALIAS("md-personality-3"); /* RAID1 */
  2115. MODULE_ALIAS("md-raid1");
  2116. MODULE_ALIAS("md-level-1");