raid10.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826
  1. /*
  2. * raid10.c : Multiple Devices driver for Linux
  3. *
  4. * Copyright (C) 2000-2004 Neil Brown
  5. *
  6. * RAID-10 support for md.
  7. *
  8. * Base on code in raid1.c. See raid1.c for futher copyright information.
  9. *
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * (for example /usr/src/linux/COPYING); if not, write to the Free
  18. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/raid/raid10.h>
  21. /*
  22. * RAID10 provides a combination of RAID0 and RAID1 functionality.
  23. * The layout of data is defined by
  24. * chunk_size
  25. * raid_disks
  26. * near_copies (stored in low byte of layout)
  27. * far_copies (stored in second byte of layout)
  28. *
  29. * The data to be stored is divided into chunks using chunksize.
  30. * Each device is divided into far_copies sections.
  31. * In each section, chunks are laid out in a style similar to raid0, but
  32. * near_copies copies of each chunk is stored (each on a different drive).
  33. * The starting device for each section is offset near_copies from the starting
  34. * device of the previous section.
  35. * Thus there are (near_copies*far_copies) of each chunk, and each is on a different
  36. * drive.
  37. * near_copies and far_copies must be at least one, and their product is at most
  38. * raid_disks.
  39. */
  40. /*
  41. * Number of guaranteed r10bios in case of extreme VM load:
  42. */
  43. #define NR_RAID10_BIOS 256
  44. static void unplug_slaves(mddev_t *mddev);
  45. static void * r10bio_pool_alloc(gfp_t gfp_flags, void *data)
  46. {
  47. conf_t *conf = data;
  48. r10bio_t *r10_bio;
  49. int size = offsetof(struct r10bio_s, devs[conf->copies]);
  50. /* allocate a r10bio with room for raid_disks entries in the bios array */
  51. r10_bio = kmalloc(size, gfp_flags);
  52. if (r10_bio)
  53. memset(r10_bio, 0, size);
  54. else
  55. unplug_slaves(conf->mddev);
  56. return r10_bio;
  57. }
  58. static void r10bio_pool_free(void *r10_bio, void *data)
  59. {
  60. kfree(r10_bio);
  61. }
  62. #define RESYNC_BLOCK_SIZE (64*1024)
  63. //#define RESYNC_BLOCK_SIZE PAGE_SIZE
  64. #define RESYNC_SECTORS (RESYNC_BLOCK_SIZE >> 9)
  65. #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
  66. #define RESYNC_WINDOW (2048*1024)
  67. /*
  68. * When performing a resync, we need to read and compare, so
  69. * we need as many pages are there are copies.
  70. * When performing a recovery, we need 2 bios, one for read,
  71. * one for write (we recover only one drive per r10buf)
  72. *
  73. */
  74. static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
  75. {
  76. conf_t *conf = data;
  77. struct page *page;
  78. r10bio_t *r10_bio;
  79. struct bio *bio;
  80. int i, j;
  81. int nalloc;
  82. r10_bio = r10bio_pool_alloc(gfp_flags, conf);
  83. if (!r10_bio) {
  84. unplug_slaves(conf->mddev);
  85. return NULL;
  86. }
  87. if (test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
  88. nalloc = conf->copies; /* resync */
  89. else
  90. nalloc = 2; /* recovery */
  91. /*
  92. * Allocate bios.
  93. */
  94. for (j = nalloc ; j-- ; ) {
  95. bio = bio_alloc(gfp_flags, RESYNC_PAGES);
  96. if (!bio)
  97. goto out_free_bio;
  98. r10_bio->devs[j].bio = bio;
  99. }
  100. /*
  101. * Allocate RESYNC_PAGES data pages and attach them
  102. * where needed.
  103. */
  104. for (j = 0 ; j < nalloc; j++) {
  105. bio = r10_bio->devs[j].bio;
  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. }
  112. }
  113. return r10_bio;
  114. out_free_pages:
  115. for ( ; i > 0 ; i--)
  116. __free_page(bio->bi_io_vec[i-1].bv_page);
  117. while (j--)
  118. for (i = 0; i < RESYNC_PAGES ; i++)
  119. __free_page(r10_bio->devs[j].bio->bi_io_vec[i].bv_page);
  120. j = -1;
  121. out_free_bio:
  122. while ( ++j < nalloc )
  123. bio_put(r10_bio->devs[j].bio);
  124. r10bio_pool_free(r10_bio, conf);
  125. return NULL;
  126. }
  127. static void r10buf_pool_free(void *__r10_bio, void *data)
  128. {
  129. int i;
  130. conf_t *conf = data;
  131. r10bio_t *r10bio = __r10_bio;
  132. int j;
  133. for (j=0; j < conf->copies; j++) {
  134. struct bio *bio = r10bio->devs[j].bio;
  135. if (bio) {
  136. for (i = 0; i < RESYNC_PAGES; i++) {
  137. __free_page(bio->bi_io_vec[i].bv_page);
  138. bio->bi_io_vec[i].bv_page = NULL;
  139. }
  140. bio_put(bio);
  141. }
  142. }
  143. r10bio_pool_free(r10bio, conf);
  144. }
  145. static void put_all_bios(conf_t *conf, r10bio_t *r10_bio)
  146. {
  147. int i;
  148. for (i = 0; i < conf->copies; i++) {
  149. struct bio **bio = & r10_bio->devs[i].bio;
  150. if (*bio)
  151. bio_put(*bio);
  152. *bio = NULL;
  153. }
  154. }
  155. static inline void free_r10bio(r10bio_t *r10_bio)
  156. {
  157. unsigned long flags;
  158. conf_t *conf = mddev_to_conf(r10_bio->mddev);
  159. /*
  160. * Wake up any possible resync thread that waits for the device
  161. * to go idle.
  162. */
  163. spin_lock_irqsave(&conf->resync_lock, flags);
  164. if (!--conf->nr_pending) {
  165. wake_up(&conf->wait_idle);
  166. wake_up(&conf->wait_resume);
  167. }
  168. spin_unlock_irqrestore(&conf->resync_lock, flags);
  169. put_all_bios(conf, r10_bio);
  170. mempool_free(r10_bio, conf->r10bio_pool);
  171. }
  172. static inline void put_buf(r10bio_t *r10_bio)
  173. {
  174. conf_t *conf = mddev_to_conf(r10_bio->mddev);
  175. unsigned long flags;
  176. mempool_free(r10_bio, conf->r10buf_pool);
  177. spin_lock_irqsave(&conf->resync_lock, flags);
  178. if (!conf->barrier)
  179. BUG();
  180. --conf->barrier;
  181. wake_up(&conf->wait_resume);
  182. wake_up(&conf->wait_idle);
  183. if (!--conf->nr_pending) {
  184. wake_up(&conf->wait_idle);
  185. wake_up(&conf->wait_resume);
  186. }
  187. spin_unlock_irqrestore(&conf->resync_lock, flags);
  188. }
  189. static void reschedule_retry(r10bio_t *r10_bio)
  190. {
  191. unsigned long flags;
  192. mddev_t *mddev = r10_bio->mddev;
  193. conf_t *conf = mddev_to_conf(mddev);
  194. spin_lock_irqsave(&conf->device_lock, flags);
  195. list_add(&r10_bio->retry_list, &conf->retry_list);
  196. spin_unlock_irqrestore(&conf->device_lock, flags);
  197. md_wakeup_thread(mddev->thread);
  198. }
  199. /*
  200. * raid_end_bio_io() is called when we have finished servicing a mirrored
  201. * operation and are ready to return a success/failure code to the buffer
  202. * cache layer.
  203. */
  204. static void raid_end_bio_io(r10bio_t *r10_bio)
  205. {
  206. struct bio *bio = r10_bio->master_bio;
  207. bio_endio(bio, bio->bi_size,
  208. test_bit(R10BIO_Uptodate, &r10_bio->state) ? 0 : -EIO);
  209. free_r10bio(r10_bio);
  210. }
  211. /*
  212. * Update disk head position estimator based on IRQ completion info.
  213. */
  214. static inline void update_head_pos(int slot, r10bio_t *r10_bio)
  215. {
  216. conf_t *conf = mddev_to_conf(r10_bio->mddev);
  217. conf->mirrors[r10_bio->devs[slot].devnum].head_position =
  218. r10_bio->devs[slot].addr + (r10_bio->sectors);
  219. }
  220. static int raid10_end_read_request(struct bio *bio, unsigned int bytes_done, int error)
  221. {
  222. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  223. r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
  224. int slot, dev;
  225. conf_t *conf = mddev_to_conf(r10_bio->mddev);
  226. if (bio->bi_size)
  227. return 1;
  228. slot = r10_bio->read_slot;
  229. dev = r10_bio->devs[slot].devnum;
  230. /*
  231. * this branch is our 'one mirror IO has finished' event handler:
  232. */
  233. if (!uptodate)
  234. md_error(r10_bio->mddev, conf->mirrors[dev].rdev);
  235. else
  236. /*
  237. * Set R10BIO_Uptodate in our master bio, so that
  238. * we will return a good error code to the higher
  239. * levels even if IO on some other mirrored buffer fails.
  240. *
  241. * The 'master' represents the composite IO operation to
  242. * user-side. So if something waits for IO, then it will
  243. * wait for the 'master' bio.
  244. */
  245. set_bit(R10BIO_Uptodate, &r10_bio->state);
  246. update_head_pos(slot, r10_bio);
  247. /*
  248. * we have only one bio on the read side
  249. */
  250. if (uptodate)
  251. raid_end_bio_io(r10_bio);
  252. else {
  253. /*
  254. * oops, read error:
  255. */
  256. char b[BDEVNAME_SIZE];
  257. if (printk_ratelimit())
  258. printk(KERN_ERR "raid10: %s: rescheduling sector %llu\n",
  259. bdevname(conf->mirrors[dev].rdev->bdev,b), (unsigned long long)r10_bio->sector);
  260. reschedule_retry(r10_bio);
  261. }
  262. rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev);
  263. return 0;
  264. }
  265. static int raid10_end_write_request(struct bio *bio, unsigned int bytes_done, int error)
  266. {
  267. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  268. r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
  269. int slot, dev;
  270. conf_t *conf = mddev_to_conf(r10_bio->mddev);
  271. if (bio->bi_size)
  272. return 1;
  273. for (slot = 0; slot < conf->copies; slot++)
  274. if (r10_bio->devs[slot].bio == bio)
  275. break;
  276. dev = r10_bio->devs[slot].devnum;
  277. /*
  278. * this branch is our 'one mirror IO has finished' event handler:
  279. */
  280. if (!uptodate)
  281. md_error(r10_bio->mddev, conf->mirrors[dev].rdev);
  282. else
  283. /*
  284. * Set R10BIO_Uptodate in our master bio, so that
  285. * we will return a good error code for to the higher
  286. * levels even if IO on some other mirrored buffer fails.
  287. *
  288. * The 'master' represents the composite IO operation to
  289. * user-side. So if something waits for IO, then it will
  290. * wait for the 'master' bio.
  291. */
  292. set_bit(R10BIO_Uptodate, &r10_bio->state);
  293. update_head_pos(slot, r10_bio);
  294. /*
  295. *
  296. * Let's see if all mirrored write operations have finished
  297. * already.
  298. */
  299. if (atomic_dec_and_test(&r10_bio->remaining)) {
  300. md_write_end(r10_bio->mddev);
  301. raid_end_bio_io(r10_bio);
  302. }
  303. rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev);
  304. return 0;
  305. }
  306. /*
  307. * RAID10 layout manager
  308. * Aswell as the chunksize and raid_disks count, there are two
  309. * parameters: near_copies and far_copies.
  310. * near_copies * far_copies must be <= raid_disks.
  311. * Normally one of these will be 1.
  312. * If both are 1, we get raid0.
  313. * If near_copies == raid_disks, we get raid1.
  314. *
  315. * Chunks are layed out in raid0 style with near_copies copies of the
  316. * first chunk, followed by near_copies copies of the next chunk and
  317. * so on.
  318. * If far_copies > 1, then after 1/far_copies of the array has been assigned
  319. * as described above, we start again with a device offset of near_copies.
  320. * So we effectively have another copy of the whole array further down all
  321. * the drives, but with blocks on different drives.
  322. * With this layout, and block is never stored twice on the one device.
  323. *
  324. * raid10_find_phys finds the sector offset of a given virtual sector
  325. * on each device that it is on. If a block isn't on a device,
  326. * that entry in the array is set to MaxSector.
  327. *
  328. * raid10_find_virt does the reverse mapping, from a device and a
  329. * sector offset to a virtual address
  330. */
  331. static void raid10_find_phys(conf_t *conf, r10bio_t *r10bio)
  332. {
  333. int n,f;
  334. sector_t sector;
  335. sector_t chunk;
  336. sector_t stripe;
  337. int dev;
  338. int slot = 0;
  339. /* now calculate first sector/dev */
  340. chunk = r10bio->sector >> conf->chunk_shift;
  341. sector = r10bio->sector & conf->chunk_mask;
  342. chunk *= conf->near_copies;
  343. stripe = chunk;
  344. dev = sector_div(stripe, conf->raid_disks);
  345. sector += stripe << conf->chunk_shift;
  346. /* and calculate all the others */
  347. for (n=0; n < conf->near_copies; n++) {
  348. int d = dev;
  349. sector_t s = sector;
  350. r10bio->devs[slot].addr = sector;
  351. r10bio->devs[slot].devnum = d;
  352. slot++;
  353. for (f = 1; f < conf->far_copies; f++) {
  354. d += conf->near_copies;
  355. if (d >= conf->raid_disks)
  356. d -= conf->raid_disks;
  357. s += conf->stride;
  358. r10bio->devs[slot].devnum = d;
  359. r10bio->devs[slot].addr = s;
  360. slot++;
  361. }
  362. dev++;
  363. if (dev >= conf->raid_disks) {
  364. dev = 0;
  365. sector += (conf->chunk_mask + 1);
  366. }
  367. }
  368. BUG_ON(slot != conf->copies);
  369. }
  370. static sector_t raid10_find_virt(conf_t *conf, sector_t sector, int dev)
  371. {
  372. sector_t offset, chunk, vchunk;
  373. while (sector > conf->stride) {
  374. sector -= conf->stride;
  375. if (dev < conf->near_copies)
  376. dev += conf->raid_disks - conf->near_copies;
  377. else
  378. dev -= conf->near_copies;
  379. }
  380. offset = sector & conf->chunk_mask;
  381. chunk = sector >> conf->chunk_shift;
  382. vchunk = chunk * conf->raid_disks + dev;
  383. sector_div(vchunk, conf->near_copies);
  384. return (vchunk << conf->chunk_shift) + offset;
  385. }
  386. /**
  387. * raid10_mergeable_bvec -- tell bio layer if a two requests can be merged
  388. * @q: request queue
  389. * @bio: the buffer head that's been built up so far
  390. * @biovec: the request that could be merged to it.
  391. *
  392. * Return amount of bytes we can accept at this offset
  393. * If near_copies == raid_disk, there are no striping issues,
  394. * but in that case, the function isn't called at all.
  395. */
  396. static int raid10_mergeable_bvec(request_queue_t *q, struct bio *bio,
  397. struct bio_vec *bio_vec)
  398. {
  399. mddev_t *mddev = q->queuedata;
  400. sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
  401. int max;
  402. unsigned int chunk_sectors = mddev->chunk_size >> 9;
  403. unsigned int bio_sectors = bio->bi_size >> 9;
  404. max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9;
  405. if (max < 0) max = 0; /* bio_add cannot handle a negative return */
  406. if (max <= bio_vec->bv_len && bio_sectors == 0)
  407. return bio_vec->bv_len;
  408. else
  409. return max;
  410. }
  411. /*
  412. * This routine returns the disk from which the requested read should
  413. * be done. There is a per-array 'next expected sequential IO' sector
  414. * number - if this matches on the next IO then we use the last disk.
  415. * There is also a per-disk 'last know head position' sector that is
  416. * maintained from IRQ contexts, both the normal and the resync IO
  417. * completion handlers update this position correctly. If there is no
  418. * perfect sequential match then we pick the disk whose head is closest.
  419. *
  420. * If there are 2 mirrors in the same 2 devices, performance degrades
  421. * because position is mirror, not device based.
  422. *
  423. * The rdev for the device selected will have nr_pending incremented.
  424. */
  425. /*
  426. * FIXME: possibly should rethink readbalancing and do it differently
  427. * depending on near_copies / far_copies geometry.
  428. */
  429. static int read_balance(conf_t *conf, r10bio_t *r10_bio)
  430. {
  431. const unsigned long this_sector = r10_bio->sector;
  432. int disk, slot, nslot;
  433. const int sectors = r10_bio->sectors;
  434. sector_t new_distance, current_distance;
  435. mdk_rdev_t *rdev;
  436. raid10_find_phys(conf, r10_bio);
  437. rcu_read_lock();
  438. /*
  439. * Check if we can balance. We can balance on the whole
  440. * device if no resync is going on, or below the resync window.
  441. * We take the first readable disk when above the resync window.
  442. */
  443. if (conf->mddev->recovery_cp < MaxSector
  444. && (this_sector + sectors >= conf->next_resync)) {
  445. /* make sure that disk is operational */
  446. slot = 0;
  447. disk = r10_bio->devs[slot].devnum;
  448. while ((rdev = rcu_dereference(conf->mirrors[disk].rdev)) == NULL ||
  449. !test_bit(In_sync, &rdev->flags)) {
  450. slot++;
  451. if (slot == conf->copies) {
  452. slot = 0;
  453. disk = -1;
  454. break;
  455. }
  456. disk = r10_bio->devs[slot].devnum;
  457. }
  458. goto rb_out;
  459. }
  460. /* make sure the disk is operational */
  461. slot = 0;
  462. disk = r10_bio->devs[slot].devnum;
  463. while ((rdev=rcu_dereference(conf->mirrors[disk].rdev)) == NULL ||
  464. !test_bit(In_sync, &rdev->flags)) {
  465. slot ++;
  466. if (slot == conf->copies) {
  467. disk = -1;
  468. goto rb_out;
  469. }
  470. disk = r10_bio->devs[slot].devnum;
  471. }
  472. current_distance = abs(r10_bio->devs[slot].addr -
  473. conf->mirrors[disk].head_position);
  474. /* Find the disk whose head is closest */
  475. for (nslot = slot; nslot < conf->copies; nslot++) {
  476. int ndisk = r10_bio->devs[nslot].devnum;
  477. if ((rdev=rcu_dereference(conf->mirrors[ndisk].rdev)) == NULL ||
  478. !test_bit(In_sync, &rdev->flags))
  479. continue;
  480. if (!atomic_read(&rdev->nr_pending)) {
  481. disk = ndisk;
  482. slot = nslot;
  483. break;
  484. }
  485. new_distance = abs(r10_bio->devs[nslot].addr -
  486. conf->mirrors[ndisk].head_position);
  487. if (new_distance < current_distance) {
  488. current_distance = new_distance;
  489. disk = ndisk;
  490. slot = nslot;
  491. }
  492. }
  493. rb_out:
  494. r10_bio->read_slot = slot;
  495. /* conf->next_seq_sect = this_sector + sectors;*/
  496. if (disk >= 0 && (rdev=rcu_dereference(conf->mirrors[disk].rdev))!= NULL)
  497. atomic_inc(&conf->mirrors[disk].rdev->nr_pending);
  498. rcu_read_unlock();
  499. return disk;
  500. }
  501. static void unplug_slaves(mddev_t *mddev)
  502. {
  503. conf_t *conf = mddev_to_conf(mddev);
  504. int i;
  505. rcu_read_lock();
  506. for (i=0; i<mddev->raid_disks; i++) {
  507. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  508. if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) {
  509. request_queue_t *r_queue = bdev_get_queue(rdev->bdev);
  510. atomic_inc(&rdev->nr_pending);
  511. rcu_read_unlock();
  512. if (r_queue->unplug_fn)
  513. r_queue->unplug_fn(r_queue);
  514. rdev_dec_pending(rdev, mddev);
  515. rcu_read_lock();
  516. }
  517. }
  518. rcu_read_unlock();
  519. }
  520. static void raid10_unplug(request_queue_t *q)
  521. {
  522. unplug_slaves(q->queuedata);
  523. }
  524. static int raid10_issue_flush(request_queue_t *q, struct gendisk *disk,
  525. sector_t *error_sector)
  526. {
  527. mddev_t *mddev = q->queuedata;
  528. conf_t *conf = mddev_to_conf(mddev);
  529. int i, ret = 0;
  530. rcu_read_lock();
  531. for (i=0; i<mddev->raid_disks && ret == 0; i++) {
  532. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  533. if (rdev && !test_bit(Faulty, &rdev->flags)) {
  534. struct block_device *bdev = rdev->bdev;
  535. request_queue_t *r_queue = bdev_get_queue(bdev);
  536. if (!r_queue->issue_flush_fn)
  537. ret = -EOPNOTSUPP;
  538. else {
  539. atomic_inc(&rdev->nr_pending);
  540. rcu_read_unlock();
  541. ret = r_queue->issue_flush_fn(r_queue, bdev->bd_disk,
  542. error_sector);
  543. rdev_dec_pending(rdev, mddev);
  544. rcu_read_lock();
  545. }
  546. }
  547. }
  548. rcu_read_unlock();
  549. return ret;
  550. }
  551. /*
  552. * Throttle resync depth, so that we can both get proper overlapping of
  553. * requests, but are still able to handle normal requests quickly.
  554. */
  555. #define RESYNC_DEPTH 32
  556. static void device_barrier(conf_t *conf, sector_t sect)
  557. {
  558. spin_lock_irq(&conf->resync_lock);
  559. wait_event_lock_irq(conf->wait_idle, !waitqueue_active(&conf->wait_resume),
  560. conf->resync_lock, unplug_slaves(conf->mddev));
  561. if (!conf->barrier++) {
  562. wait_event_lock_irq(conf->wait_idle, !conf->nr_pending,
  563. conf->resync_lock, unplug_slaves(conf->mddev));
  564. if (conf->nr_pending)
  565. BUG();
  566. }
  567. wait_event_lock_irq(conf->wait_resume, conf->barrier < RESYNC_DEPTH,
  568. conf->resync_lock, unplug_slaves(conf->mddev));
  569. conf->next_resync = sect;
  570. spin_unlock_irq(&conf->resync_lock);
  571. }
  572. static int make_request(request_queue_t *q, struct bio * bio)
  573. {
  574. mddev_t *mddev = q->queuedata;
  575. conf_t *conf = mddev_to_conf(mddev);
  576. mirror_info_t *mirror;
  577. r10bio_t *r10_bio;
  578. struct bio *read_bio;
  579. int i;
  580. int chunk_sects = conf->chunk_mask + 1;
  581. const int rw = bio_data_dir(bio);
  582. if (unlikely(bio_barrier(bio))) {
  583. bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
  584. return 0;
  585. }
  586. /* If this request crosses a chunk boundary, we need to
  587. * split it. This will only happen for 1 PAGE (or less) requests.
  588. */
  589. if (unlikely( (bio->bi_sector & conf->chunk_mask) + (bio->bi_size >> 9)
  590. > chunk_sects &&
  591. conf->near_copies < conf->raid_disks)) {
  592. struct bio_pair *bp;
  593. /* Sanity check -- queue functions should prevent this happening */
  594. if (bio->bi_vcnt != 1 ||
  595. bio->bi_idx != 0)
  596. goto bad_map;
  597. /* This is a one page bio that upper layers
  598. * refuse to split for us, so we need to split it.
  599. */
  600. bp = bio_split(bio, bio_split_pool,
  601. chunk_sects - (bio->bi_sector & (chunk_sects - 1)) );
  602. if (make_request(q, &bp->bio1))
  603. generic_make_request(&bp->bio1);
  604. if (make_request(q, &bp->bio2))
  605. generic_make_request(&bp->bio2);
  606. bio_pair_release(bp);
  607. return 0;
  608. bad_map:
  609. printk("raid10_make_request bug: can't convert block across chunks"
  610. " or bigger than %dk %llu %d\n", chunk_sects/2,
  611. (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
  612. bio_io_error(bio, bio->bi_size);
  613. return 0;
  614. }
  615. md_write_start(mddev, bio);
  616. /*
  617. * Register the new request and wait if the reconstruction
  618. * thread has put up a bar for new requests.
  619. * Continue immediately if no resync is active currently.
  620. */
  621. spin_lock_irq(&conf->resync_lock);
  622. wait_event_lock_irq(conf->wait_resume, !conf->barrier, conf->resync_lock, );
  623. conf->nr_pending++;
  624. spin_unlock_irq(&conf->resync_lock);
  625. disk_stat_inc(mddev->gendisk, ios[rw]);
  626. disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bio));
  627. r10_bio = mempool_alloc(conf->r10bio_pool, GFP_NOIO);
  628. r10_bio->master_bio = bio;
  629. r10_bio->sectors = bio->bi_size >> 9;
  630. r10_bio->mddev = mddev;
  631. r10_bio->sector = bio->bi_sector;
  632. if (rw == READ) {
  633. /*
  634. * read balancing logic:
  635. */
  636. int disk = read_balance(conf, r10_bio);
  637. int slot = r10_bio->read_slot;
  638. if (disk < 0) {
  639. raid_end_bio_io(r10_bio);
  640. return 0;
  641. }
  642. mirror = conf->mirrors + disk;
  643. read_bio = bio_clone(bio, GFP_NOIO);
  644. r10_bio->devs[slot].bio = read_bio;
  645. read_bio->bi_sector = r10_bio->devs[slot].addr +
  646. mirror->rdev->data_offset;
  647. read_bio->bi_bdev = mirror->rdev->bdev;
  648. read_bio->bi_end_io = raid10_end_read_request;
  649. read_bio->bi_rw = READ;
  650. read_bio->bi_private = r10_bio;
  651. generic_make_request(read_bio);
  652. return 0;
  653. }
  654. /*
  655. * WRITE:
  656. */
  657. /* first select target devices under spinlock and
  658. * inc refcount on their rdev. Record them by setting
  659. * bios[x] to bio
  660. */
  661. raid10_find_phys(conf, r10_bio);
  662. rcu_read_lock();
  663. for (i = 0; i < conf->copies; i++) {
  664. int d = r10_bio->devs[i].devnum;
  665. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[d].rdev);
  666. if (rdev &&
  667. !test_bit(Faulty, &rdev->flags)) {
  668. atomic_inc(&rdev->nr_pending);
  669. r10_bio->devs[i].bio = bio;
  670. } else
  671. r10_bio->devs[i].bio = NULL;
  672. }
  673. rcu_read_unlock();
  674. atomic_set(&r10_bio->remaining, 1);
  675. for (i = 0; i < conf->copies; i++) {
  676. struct bio *mbio;
  677. int d = r10_bio->devs[i].devnum;
  678. if (!r10_bio->devs[i].bio)
  679. continue;
  680. mbio = bio_clone(bio, GFP_NOIO);
  681. r10_bio->devs[i].bio = mbio;
  682. mbio->bi_sector = r10_bio->devs[i].addr+
  683. conf->mirrors[d].rdev->data_offset;
  684. mbio->bi_bdev = conf->mirrors[d].rdev->bdev;
  685. mbio->bi_end_io = raid10_end_write_request;
  686. mbio->bi_rw = WRITE;
  687. mbio->bi_private = r10_bio;
  688. atomic_inc(&r10_bio->remaining);
  689. generic_make_request(mbio);
  690. }
  691. if (atomic_dec_and_test(&r10_bio->remaining)) {
  692. md_write_end(mddev);
  693. raid_end_bio_io(r10_bio);
  694. }
  695. return 0;
  696. }
  697. static void status(struct seq_file *seq, mddev_t *mddev)
  698. {
  699. conf_t *conf = mddev_to_conf(mddev);
  700. int i;
  701. if (conf->near_copies < conf->raid_disks)
  702. seq_printf(seq, " %dK chunks", mddev->chunk_size/1024);
  703. if (conf->near_copies > 1)
  704. seq_printf(seq, " %d near-copies", conf->near_copies);
  705. if (conf->far_copies > 1)
  706. seq_printf(seq, " %d far-copies", conf->far_copies);
  707. seq_printf(seq, " [%d/%d] [", conf->raid_disks,
  708. conf->working_disks);
  709. for (i = 0; i < conf->raid_disks; i++)
  710. seq_printf(seq, "%s",
  711. conf->mirrors[i].rdev &&
  712. test_bit(In_sync, &conf->mirrors[i].rdev->flags) ? "U" : "_");
  713. seq_printf(seq, "]");
  714. }
  715. static void error(mddev_t *mddev, mdk_rdev_t *rdev)
  716. {
  717. char b[BDEVNAME_SIZE];
  718. conf_t *conf = mddev_to_conf(mddev);
  719. /*
  720. * If it is not operational, then we have already marked it as dead
  721. * else if it is the last working disks, ignore the error, let the
  722. * next level up know.
  723. * else mark the drive as failed
  724. */
  725. if (test_bit(In_sync, &rdev->flags)
  726. && conf->working_disks == 1)
  727. /*
  728. * Don't fail the drive, just return an IO error.
  729. * The test should really be more sophisticated than
  730. * "working_disks == 1", but it isn't critical, and
  731. * can wait until we do more sophisticated "is the drive
  732. * really dead" tests...
  733. */
  734. return;
  735. if (test_bit(In_sync, &rdev->flags)) {
  736. mddev->degraded++;
  737. conf->working_disks--;
  738. /*
  739. * if recovery is running, make sure it aborts.
  740. */
  741. set_bit(MD_RECOVERY_ERR, &mddev->recovery);
  742. }
  743. clear_bit(In_sync, &rdev->flags);
  744. set_bit(Faulty, &rdev->flags);
  745. mddev->sb_dirty = 1;
  746. printk(KERN_ALERT "raid10: Disk failure on %s, disabling device. \n"
  747. " Operation continuing on %d devices\n",
  748. bdevname(rdev->bdev,b), conf->working_disks);
  749. }
  750. static void print_conf(conf_t *conf)
  751. {
  752. int i;
  753. mirror_info_t *tmp;
  754. printk("RAID10 conf printout:\n");
  755. if (!conf) {
  756. printk("(!conf)\n");
  757. return;
  758. }
  759. printk(" --- wd:%d rd:%d\n", conf->working_disks,
  760. conf->raid_disks);
  761. for (i = 0; i < conf->raid_disks; i++) {
  762. char b[BDEVNAME_SIZE];
  763. tmp = conf->mirrors + i;
  764. if (tmp->rdev)
  765. printk(" disk %d, wo:%d, o:%d, dev:%s\n",
  766. i, !test_bit(In_sync, &tmp->rdev->flags),
  767. !test_bit(Faulty, &tmp->rdev->flags),
  768. bdevname(tmp->rdev->bdev,b));
  769. }
  770. }
  771. static void close_sync(conf_t *conf)
  772. {
  773. spin_lock_irq(&conf->resync_lock);
  774. wait_event_lock_irq(conf->wait_resume, !conf->barrier,
  775. conf->resync_lock, unplug_slaves(conf->mddev));
  776. spin_unlock_irq(&conf->resync_lock);
  777. if (conf->barrier) BUG();
  778. if (waitqueue_active(&conf->wait_idle)) BUG();
  779. mempool_destroy(conf->r10buf_pool);
  780. conf->r10buf_pool = NULL;
  781. }
  782. /* check if there are enough drives for
  783. * every block to appear on atleast one
  784. */
  785. static int enough(conf_t *conf)
  786. {
  787. int first = 0;
  788. do {
  789. int n = conf->copies;
  790. int cnt = 0;
  791. while (n--) {
  792. if (conf->mirrors[first].rdev)
  793. cnt++;
  794. first = (first+1) % conf->raid_disks;
  795. }
  796. if (cnt == 0)
  797. return 0;
  798. } while (first != 0);
  799. return 1;
  800. }
  801. static int raid10_spare_active(mddev_t *mddev)
  802. {
  803. int i;
  804. conf_t *conf = mddev->private;
  805. mirror_info_t *tmp;
  806. /*
  807. * Find all non-in_sync disks within the RAID10 configuration
  808. * and mark them in_sync
  809. */
  810. for (i = 0; i < conf->raid_disks; i++) {
  811. tmp = conf->mirrors + i;
  812. if (tmp->rdev
  813. && !test_bit(Faulty, &tmp->rdev->flags)
  814. && !test_bit(In_sync, &tmp->rdev->flags)) {
  815. conf->working_disks++;
  816. mddev->degraded--;
  817. set_bit(In_sync, &tmp->rdev->flags);
  818. }
  819. }
  820. print_conf(conf);
  821. return 0;
  822. }
  823. static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
  824. {
  825. conf_t *conf = mddev->private;
  826. int found = 0;
  827. int mirror;
  828. mirror_info_t *p;
  829. if (mddev->recovery_cp < MaxSector)
  830. /* only hot-add to in-sync arrays, as recovery is
  831. * very different from resync
  832. */
  833. return 0;
  834. if (!enough(conf))
  835. return 0;
  836. for (mirror=0; mirror < mddev->raid_disks; mirror++)
  837. if ( !(p=conf->mirrors+mirror)->rdev) {
  838. blk_queue_stack_limits(mddev->queue,
  839. rdev->bdev->bd_disk->queue);
  840. /* as we don't honour merge_bvec_fn, we must never risk
  841. * violating it, so limit ->max_sector to one PAGE, as
  842. * a one page request is never in violation.
  843. */
  844. if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
  845. mddev->queue->max_sectors > (PAGE_SIZE>>9))
  846. mddev->queue->max_sectors = (PAGE_SIZE>>9);
  847. p->head_position = 0;
  848. rdev->raid_disk = mirror;
  849. found = 1;
  850. rcu_assign_pointer(p->rdev, rdev);
  851. break;
  852. }
  853. print_conf(conf);
  854. return found;
  855. }
  856. static int raid10_remove_disk(mddev_t *mddev, int number)
  857. {
  858. conf_t *conf = mddev->private;
  859. int err = 0;
  860. mdk_rdev_t *rdev;
  861. mirror_info_t *p = conf->mirrors+ number;
  862. print_conf(conf);
  863. rdev = p->rdev;
  864. if (rdev) {
  865. if (test_bit(In_sync, &rdev->flags) ||
  866. atomic_read(&rdev->nr_pending)) {
  867. err = -EBUSY;
  868. goto abort;
  869. }
  870. p->rdev = NULL;
  871. synchronize_rcu();
  872. if (atomic_read(&rdev->nr_pending)) {
  873. /* lost the race, try later */
  874. err = -EBUSY;
  875. p->rdev = rdev;
  876. }
  877. }
  878. abort:
  879. print_conf(conf);
  880. return err;
  881. }
  882. static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error)
  883. {
  884. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  885. r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
  886. conf_t *conf = mddev_to_conf(r10_bio->mddev);
  887. int i,d;
  888. if (bio->bi_size)
  889. return 1;
  890. for (i=0; i<conf->copies; i++)
  891. if (r10_bio->devs[i].bio == bio)
  892. break;
  893. if (i == conf->copies)
  894. BUG();
  895. update_head_pos(i, r10_bio);
  896. d = r10_bio->devs[i].devnum;
  897. if (!uptodate)
  898. md_error(r10_bio->mddev,
  899. conf->mirrors[d].rdev);
  900. /* for reconstruct, we always reschedule after a read.
  901. * for resync, only after all reads
  902. */
  903. if (test_bit(R10BIO_IsRecover, &r10_bio->state) ||
  904. atomic_dec_and_test(&r10_bio->remaining)) {
  905. /* we have read all the blocks,
  906. * do the comparison in process context in raid10d
  907. */
  908. reschedule_retry(r10_bio);
  909. }
  910. rdev_dec_pending(conf->mirrors[d].rdev, conf->mddev);
  911. return 0;
  912. }
  913. static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
  914. {
  915. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  916. r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
  917. mddev_t *mddev = r10_bio->mddev;
  918. conf_t *conf = mddev_to_conf(mddev);
  919. int i,d;
  920. if (bio->bi_size)
  921. return 1;
  922. for (i = 0; i < conf->copies; i++)
  923. if (r10_bio->devs[i].bio == bio)
  924. break;
  925. d = r10_bio->devs[i].devnum;
  926. if (!uptodate)
  927. md_error(mddev, conf->mirrors[d].rdev);
  928. update_head_pos(i, r10_bio);
  929. while (atomic_dec_and_test(&r10_bio->remaining)) {
  930. if (r10_bio->master_bio == NULL) {
  931. /* the primary of several recovery bios */
  932. md_done_sync(mddev, r10_bio->sectors, 1);
  933. put_buf(r10_bio);
  934. break;
  935. } else {
  936. r10bio_t *r10_bio2 = (r10bio_t *)r10_bio->master_bio;
  937. put_buf(r10_bio);
  938. r10_bio = r10_bio2;
  939. }
  940. }
  941. rdev_dec_pending(conf->mirrors[d].rdev, mddev);
  942. return 0;
  943. }
  944. /*
  945. * Note: sync and recover and handled very differently for raid10
  946. * This code is for resync.
  947. * For resync, we read through virtual addresses and read all blocks.
  948. * If there is any error, we schedule a write. The lowest numbered
  949. * drive is authoritative.
  950. * However requests come for physical address, so we need to map.
  951. * For every physical address there are raid_disks/copies virtual addresses,
  952. * which is always are least one, but is not necessarly an integer.
  953. * This means that a physical address can span multiple chunks, so we may
  954. * have to submit multiple io requests for a single sync request.
  955. */
  956. /*
  957. * We check if all blocks are in-sync and only write to blocks that
  958. * aren't in sync
  959. */
  960. static void sync_request_write(mddev_t *mddev, r10bio_t *r10_bio)
  961. {
  962. conf_t *conf = mddev_to_conf(mddev);
  963. int i, first;
  964. struct bio *tbio, *fbio;
  965. atomic_set(&r10_bio->remaining, 1);
  966. /* find the first device with a block */
  967. for (i=0; i<conf->copies; i++)
  968. if (test_bit(BIO_UPTODATE, &r10_bio->devs[i].bio->bi_flags))
  969. break;
  970. if (i == conf->copies)
  971. goto done;
  972. first = i;
  973. fbio = r10_bio->devs[i].bio;
  974. /* now find blocks with errors */
  975. for (i=first+1 ; i < conf->copies ; i++) {
  976. int vcnt, j, d;
  977. if (!test_bit(BIO_UPTODATE, &r10_bio->devs[i].bio->bi_flags))
  978. continue;
  979. /* We know that the bi_io_vec layout is the same for
  980. * both 'first' and 'i', so we just compare them.
  981. * All vec entries are PAGE_SIZE;
  982. */
  983. tbio = r10_bio->devs[i].bio;
  984. vcnt = r10_bio->sectors >> (PAGE_SHIFT-9);
  985. for (j = 0; j < vcnt; j++)
  986. if (memcmp(page_address(fbio->bi_io_vec[j].bv_page),
  987. page_address(tbio->bi_io_vec[j].bv_page),
  988. PAGE_SIZE))
  989. break;
  990. if (j == vcnt)
  991. continue;
  992. /* Ok, we need to write this bio
  993. * First we need to fixup bv_offset, bv_len and
  994. * bi_vecs, as the read request might have corrupted these
  995. */
  996. tbio->bi_vcnt = vcnt;
  997. tbio->bi_size = r10_bio->sectors << 9;
  998. tbio->bi_idx = 0;
  999. tbio->bi_phys_segments = 0;
  1000. tbio->bi_hw_segments = 0;
  1001. tbio->bi_hw_front_size = 0;
  1002. tbio->bi_hw_back_size = 0;
  1003. tbio->bi_flags &= ~(BIO_POOL_MASK - 1);
  1004. tbio->bi_flags |= 1 << BIO_UPTODATE;
  1005. tbio->bi_next = NULL;
  1006. tbio->bi_rw = WRITE;
  1007. tbio->bi_private = r10_bio;
  1008. tbio->bi_sector = r10_bio->devs[i].addr;
  1009. for (j=0; j < vcnt ; j++) {
  1010. tbio->bi_io_vec[j].bv_offset = 0;
  1011. tbio->bi_io_vec[j].bv_len = PAGE_SIZE;
  1012. memcpy(page_address(tbio->bi_io_vec[j].bv_page),
  1013. page_address(fbio->bi_io_vec[j].bv_page),
  1014. PAGE_SIZE);
  1015. }
  1016. tbio->bi_end_io = end_sync_write;
  1017. d = r10_bio->devs[i].devnum;
  1018. atomic_inc(&conf->mirrors[d].rdev->nr_pending);
  1019. atomic_inc(&r10_bio->remaining);
  1020. md_sync_acct(conf->mirrors[d].rdev->bdev, tbio->bi_size >> 9);
  1021. tbio->bi_sector += conf->mirrors[d].rdev->data_offset;
  1022. tbio->bi_bdev = conf->mirrors[d].rdev->bdev;
  1023. generic_make_request(tbio);
  1024. }
  1025. done:
  1026. if (atomic_dec_and_test(&r10_bio->remaining)) {
  1027. md_done_sync(mddev, r10_bio->sectors, 1);
  1028. put_buf(r10_bio);
  1029. }
  1030. }
  1031. /*
  1032. * Now for the recovery code.
  1033. * Recovery happens across physical sectors.
  1034. * We recover all non-is_sync drives by finding the virtual address of
  1035. * each, and then choose a working drive that also has that virt address.
  1036. * There is a separate r10_bio for each non-in_sync drive.
  1037. * Only the first two slots are in use. The first for reading,
  1038. * The second for writing.
  1039. *
  1040. */
  1041. static void recovery_request_write(mddev_t *mddev, r10bio_t *r10_bio)
  1042. {
  1043. conf_t *conf = mddev_to_conf(mddev);
  1044. int i, d;
  1045. struct bio *bio, *wbio;
  1046. /* move the pages across to the second bio
  1047. * and submit the write request
  1048. */
  1049. bio = r10_bio->devs[0].bio;
  1050. wbio = r10_bio->devs[1].bio;
  1051. for (i=0; i < wbio->bi_vcnt; i++) {
  1052. struct page *p = bio->bi_io_vec[i].bv_page;
  1053. bio->bi_io_vec[i].bv_page = wbio->bi_io_vec[i].bv_page;
  1054. wbio->bi_io_vec[i].bv_page = p;
  1055. }
  1056. d = r10_bio->devs[1].devnum;
  1057. atomic_inc(&conf->mirrors[d].rdev->nr_pending);
  1058. md_sync_acct(conf->mirrors[d].rdev->bdev, wbio->bi_size >> 9);
  1059. generic_make_request(wbio);
  1060. }
  1061. /*
  1062. * This is a kernel thread which:
  1063. *
  1064. * 1. Retries failed read operations on working mirrors.
  1065. * 2. Updates the raid superblock when problems encounter.
  1066. * 3. Performs writes following reads for array syncronising.
  1067. */
  1068. static void raid10d(mddev_t *mddev)
  1069. {
  1070. r10bio_t *r10_bio;
  1071. struct bio *bio;
  1072. unsigned long flags;
  1073. conf_t *conf = mddev_to_conf(mddev);
  1074. struct list_head *head = &conf->retry_list;
  1075. int unplug=0;
  1076. mdk_rdev_t *rdev;
  1077. md_check_recovery(mddev);
  1078. for (;;) {
  1079. char b[BDEVNAME_SIZE];
  1080. spin_lock_irqsave(&conf->device_lock, flags);
  1081. if (list_empty(head))
  1082. break;
  1083. r10_bio = list_entry(head->prev, r10bio_t, retry_list);
  1084. list_del(head->prev);
  1085. spin_unlock_irqrestore(&conf->device_lock, flags);
  1086. mddev = r10_bio->mddev;
  1087. conf = mddev_to_conf(mddev);
  1088. if (test_bit(R10BIO_IsSync, &r10_bio->state)) {
  1089. sync_request_write(mddev, r10_bio);
  1090. unplug = 1;
  1091. } else if (test_bit(R10BIO_IsRecover, &r10_bio->state)) {
  1092. recovery_request_write(mddev, r10_bio);
  1093. unplug = 1;
  1094. } else {
  1095. int mirror;
  1096. bio = r10_bio->devs[r10_bio->read_slot].bio;
  1097. r10_bio->devs[r10_bio->read_slot].bio = NULL;
  1098. bio_put(bio);
  1099. mirror = read_balance(conf, r10_bio);
  1100. if (mirror == -1) {
  1101. printk(KERN_ALERT "raid10: %s: unrecoverable I/O"
  1102. " read error for block %llu\n",
  1103. bdevname(bio->bi_bdev,b),
  1104. (unsigned long long)r10_bio->sector);
  1105. raid_end_bio_io(r10_bio);
  1106. } else {
  1107. rdev = conf->mirrors[mirror].rdev;
  1108. if (printk_ratelimit())
  1109. printk(KERN_ERR "raid10: %s: redirecting sector %llu to"
  1110. " another mirror\n",
  1111. bdevname(rdev->bdev,b),
  1112. (unsigned long long)r10_bio->sector);
  1113. bio = bio_clone(r10_bio->master_bio, GFP_NOIO);
  1114. r10_bio->devs[r10_bio->read_slot].bio = bio;
  1115. bio->bi_sector = r10_bio->devs[r10_bio->read_slot].addr
  1116. + rdev->data_offset;
  1117. bio->bi_bdev = rdev->bdev;
  1118. bio->bi_rw = READ;
  1119. bio->bi_private = r10_bio;
  1120. bio->bi_end_io = raid10_end_read_request;
  1121. unplug = 1;
  1122. generic_make_request(bio);
  1123. }
  1124. }
  1125. }
  1126. spin_unlock_irqrestore(&conf->device_lock, flags);
  1127. if (unplug)
  1128. unplug_slaves(mddev);
  1129. }
  1130. static int init_resync(conf_t *conf)
  1131. {
  1132. int buffs;
  1133. buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE;
  1134. if (conf->r10buf_pool)
  1135. BUG();
  1136. conf->r10buf_pool = mempool_create(buffs, r10buf_pool_alloc, r10buf_pool_free, conf);
  1137. if (!conf->r10buf_pool)
  1138. return -ENOMEM;
  1139. conf->next_resync = 0;
  1140. return 0;
  1141. }
  1142. /*
  1143. * perform a "sync" on one "block"
  1144. *
  1145. * We need to make sure that no normal I/O request - particularly write
  1146. * requests - conflict with active sync requests.
  1147. *
  1148. * This is achieved by tracking pending requests and a 'barrier' concept
  1149. * that can be installed to exclude normal IO requests.
  1150. *
  1151. * Resync and recovery are handled very differently.
  1152. * We differentiate by looking at MD_RECOVERY_SYNC in mddev->recovery.
  1153. *
  1154. * For resync, we iterate over virtual addresses, read all copies,
  1155. * and update if there are differences. If only one copy is live,
  1156. * skip it.
  1157. * For recovery, we iterate over physical addresses, read a good
  1158. * value for each non-in_sync drive, and over-write.
  1159. *
  1160. * So, for recovery we may have several outstanding complex requests for a
  1161. * given address, one for each out-of-sync device. We model this by allocating
  1162. * a number of r10_bio structures, one for each out-of-sync device.
  1163. * As we setup these structures, we collect all bio's together into a list
  1164. * which we then process collectively to add pages, and then process again
  1165. * to pass to generic_make_request.
  1166. *
  1167. * The r10_bio structures are linked using a borrowed master_bio pointer.
  1168. * This link is counted in ->remaining. When the r10_bio that points to NULL
  1169. * has its remaining count decremented to 0, the whole complex operation
  1170. * is complete.
  1171. *
  1172. */
  1173. static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
  1174. {
  1175. conf_t *conf = mddev_to_conf(mddev);
  1176. r10bio_t *r10_bio;
  1177. struct bio *biolist = NULL, *bio;
  1178. sector_t max_sector, nr_sectors;
  1179. int disk;
  1180. int i;
  1181. sector_t sectors_skipped = 0;
  1182. int chunks_skipped = 0;
  1183. if (!conf->r10buf_pool)
  1184. if (init_resync(conf))
  1185. return 0;
  1186. skipped:
  1187. max_sector = mddev->size << 1;
  1188. if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
  1189. max_sector = mddev->resync_max_sectors;
  1190. if (sector_nr >= max_sector) {
  1191. close_sync(conf);
  1192. *skipped = 1;
  1193. return sectors_skipped;
  1194. }
  1195. if (chunks_skipped >= conf->raid_disks) {
  1196. /* if there has been nothing to do on any drive,
  1197. * then there is nothing to do at all..
  1198. */
  1199. *skipped = 1;
  1200. return (max_sector - sector_nr) + sectors_skipped;
  1201. }
  1202. /* make sure whole request will fit in a chunk - if chunks
  1203. * are meaningful
  1204. */
  1205. if (conf->near_copies < conf->raid_disks &&
  1206. max_sector > (sector_nr | conf->chunk_mask))
  1207. max_sector = (sector_nr | conf->chunk_mask) + 1;
  1208. /*
  1209. * If there is non-resync activity waiting for us then
  1210. * put in a delay to throttle resync.
  1211. */
  1212. if (!go_faster && waitqueue_active(&conf->wait_resume))
  1213. msleep_interruptible(1000);
  1214. device_barrier(conf, sector_nr + RESYNC_SECTORS);
  1215. /* Again, very different code for resync and recovery.
  1216. * Both must result in an r10bio with a list of bios that
  1217. * have bi_end_io, bi_sector, bi_bdev set,
  1218. * and bi_private set to the r10bio.
  1219. * For recovery, we may actually create several r10bios
  1220. * with 2 bios in each, that correspond to the bios in the main one.
  1221. * In this case, the subordinate r10bios link back through a
  1222. * borrowed master_bio pointer, and the counter in the master
  1223. * includes a ref from each subordinate.
  1224. */
  1225. /* First, we decide what to do and set ->bi_end_io
  1226. * To end_sync_read if we want to read, and
  1227. * end_sync_write if we will want to write.
  1228. */
  1229. if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
  1230. /* recovery... the complicated one */
  1231. int i, j, k;
  1232. r10_bio = NULL;
  1233. for (i=0 ; i<conf->raid_disks; i++)
  1234. if (conf->mirrors[i].rdev &&
  1235. !test_bit(In_sync, &conf->mirrors[i].rdev->flags)) {
  1236. /* want to reconstruct this device */
  1237. r10bio_t *rb2 = r10_bio;
  1238. r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO);
  1239. spin_lock_irq(&conf->resync_lock);
  1240. conf->nr_pending++;
  1241. if (rb2) conf->barrier++;
  1242. spin_unlock_irq(&conf->resync_lock);
  1243. atomic_set(&r10_bio->remaining, 0);
  1244. r10_bio->master_bio = (struct bio*)rb2;
  1245. if (rb2)
  1246. atomic_inc(&rb2->remaining);
  1247. r10_bio->mddev = mddev;
  1248. set_bit(R10BIO_IsRecover, &r10_bio->state);
  1249. r10_bio->sector = raid10_find_virt(conf, sector_nr, i);
  1250. raid10_find_phys(conf, r10_bio);
  1251. for (j=0; j<conf->copies;j++) {
  1252. int d = r10_bio->devs[j].devnum;
  1253. if (conf->mirrors[d].rdev &&
  1254. test_bit(In_sync, &conf->mirrors[d].rdev->flags)) {
  1255. /* This is where we read from */
  1256. bio = r10_bio->devs[0].bio;
  1257. bio->bi_next = biolist;
  1258. biolist = bio;
  1259. bio->bi_private = r10_bio;
  1260. bio->bi_end_io = end_sync_read;
  1261. bio->bi_rw = 0;
  1262. bio->bi_sector = r10_bio->devs[j].addr +
  1263. conf->mirrors[d].rdev->data_offset;
  1264. bio->bi_bdev = conf->mirrors[d].rdev->bdev;
  1265. atomic_inc(&conf->mirrors[d].rdev->nr_pending);
  1266. atomic_inc(&r10_bio->remaining);
  1267. /* and we write to 'i' */
  1268. for (k=0; k<conf->copies; k++)
  1269. if (r10_bio->devs[k].devnum == i)
  1270. break;
  1271. bio = r10_bio->devs[1].bio;
  1272. bio->bi_next = biolist;
  1273. biolist = bio;
  1274. bio->bi_private = r10_bio;
  1275. bio->bi_end_io = end_sync_write;
  1276. bio->bi_rw = 1;
  1277. bio->bi_sector = r10_bio->devs[k].addr +
  1278. conf->mirrors[i].rdev->data_offset;
  1279. bio->bi_bdev = conf->mirrors[i].rdev->bdev;
  1280. r10_bio->devs[0].devnum = d;
  1281. r10_bio->devs[1].devnum = i;
  1282. break;
  1283. }
  1284. }
  1285. if (j == conf->copies) {
  1286. /* Cannot recover, so abort the recovery */
  1287. put_buf(r10_bio);
  1288. r10_bio = rb2;
  1289. if (!test_and_set_bit(MD_RECOVERY_ERR, &mddev->recovery))
  1290. printk(KERN_INFO "raid10: %s: insufficient working devices for recovery.\n",
  1291. mdname(mddev));
  1292. break;
  1293. }
  1294. }
  1295. if (biolist == NULL) {
  1296. while (r10_bio) {
  1297. r10bio_t *rb2 = r10_bio;
  1298. r10_bio = (r10bio_t*) rb2->master_bio;
  1299. rb2->master_bio = NULL;
  1300. put_buf(rb2);
  1301. }
  1302. goto giveup;
  1303. }
  1304. } else {
  1305. /* resync. Schedule a read for every block at this virt offset */
  1306. int count = 0;
  1307. r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO);
  1308. spin_lock_irq(&conf->resync_lock);
  1309. conf->nr_pending++;
  1310. spin_unlock_irq(&conf->resync_lock);
  1311. r10_bio->mddev = mddev;
  1312. atomic_set(&r10_bio->remaining, 0);
  1313. r10_bio->master_bio = NULL;
  1314. r10_bio->sector = sector_nr;
  1315. set_bit(R10BIO_IsSync, &r10_bio->state);
  1316. raid10_find_phys(conf, r10_bio);
  1317. r10_bio->sectors = (sector_nr | conf->chunk_mask) - sector_nr +1;
  1318. for (i=0; i<conf->copies; i++) {
  1319. int d = r10_bio->devs[i].devnum;
  1320. bio = r10_bio->devs[i].bio;
  1321. bio->bi_end_io = NULL;
  1322. if (conf->mirrors[d].rdev == NULL ||
  1323. test_bit(Faulty, &conf->mirrors[d].rdev->flags))
  1324. continue;
  1325. atomic_inc(&conf->mirrors[d].rdev->nr_pending);
  1326. atomic_inc(&r10_bio->remaining);
  1327. bio->bi_next = biolist;
  1328. biolist = bio;
  1329. bio->bi_private = r10_bio;
  1330. bio->bi_end_io = end_sync_read;
  1331. bio->bi_rw = 0;
  1332. bio->bi_sector = r10_bio->devs[i].addr +
  1333. conf->mirrors[d].rdev->data_offset;
  1334. bio->bi_bdev = conf->mirrors[d].rdev->bdev;
  1335. count++;
  1336. }
  1337. if (count < 2) {
  1338. for (i=0; i<conf->copies; i++) {
  1339. int d = r10_bio->devs[i].devnum;
  1340. if (r10_bio->devs[i].bio->bi_end_io)
  1341. rdev_dec_pending(conf->mirrors[d].rdev, mddev);
  1342. }
  1343. put_buf(r10_bio);
  1344. biolist = NULL;
  1345. goto giveup;
  1346. }
  1347. }
  1348. for (bio = biolist; bio ; bio=bio->bi_next) {
  1349. bio->bi_flags &= ~(BIO_POOL_MASK - 1);
  1350. if (bio->bi_end_io)
  1351. bio->bi_flags |= 1 << BIO_UPTODATE;
  1352. bio->bi_vcnt = 0;
  1353. bio->bi_idx = 0;
  1354. bio->bi_phys_segments = 0;
  1355. bio->bi_hw_segments = 0;
  1356. bio->bi_size = 0;
  1357. }
  1358. nr_sectors = 0;
  1359. do {
  1360. struct page *page;
  1361. int len = PAGE_SIZE;
  1362. disk = 0;
  1363. if (sector_nr + (len>>9) > max_sector)
  1364. len = (max_sector - sector_nr) << 9;
  1365. if (len == 0)
  1366. break;
  1367. for (bio= biolist ; bio ; bio=bio->bi_next) {
  1368. page = bio->bi_io_vec[bio->bi_vcnt].bv_page;
  1369. if (bio_add_page(bio, page, len, 0) == 0) {
  1370. /* stop here */
  1371. struct bio *bio2;
  1372. bio->bi_io_vec[bio->bi_vcnt].bv_page = page;
  1373. for (bio2 = biolist; bio2 && bio2 != bio; bio2 = bio2->bi_next) {
  1374. /* remove last page from this bio */
  1375. bio2->bi_vcnt--;
  1376. bio2->bi_size -= len;
  1377. bio2->bi_flags &= ~(1<< BIO_SEG_VALID);
  1378. }
  1379. goto bio_full;
  1380. }
  1381. disk = i;
  1382. }
  1383. nr_sectors += len>>9;
  1384. sector_nr += len>>9;
  1385. } while (biolist->bi_vcnt < RESYNC_PAGES);
  1386. bio_full:
  1387. r10_bio->sectors = nr_sectors;
  1388. while (biolist) {
  1389. bio = biolist;
  1390. biolist = biolist->bi_next;
  1391. bio->bi_next = NULL;
  1392. r10_bio = bio->bi_private;
  1393. r10_bio->sectors = nr_sectors;
  1394. if (bio->bi_end_io == end_sync_read) {
  1395. md_sync_acct(bio->bi_bdev, nr_sectors);
  1396. generic_make_request(bio);
  1397. }
  1398. }
  1399. if (sectors_skipped)
  1400. /* pretend they weren't skipped, it makes
  1401. * no important difference in this case
  1402. */
  1403. md_done_sync(mddev, sectors_skipped, 1);
  1404. return sectors_skipped + nr_sectors;
  1405. giveup:
  1406. /* There is nowhere to write, so all non-sync
  1407. * drives must be failed, so try the next chunk...
  1408. */
  1409. {
  1410. sector_t sec = max_sector - sector_nr;
  1411. sectors_skipped += sec;
  1412. chunks_skipped ++;
  1413. sector_nr = max_sector;
  1414. goto skipped;
  1415. }
  1416. }
  1417. static int run(mddev_t *mddev)
  1418. {
  1419. conf_t *conf;
  1420. int i, disk_idx;
  1421. mirror_info_t *disk;
  1422. mdk_rdev_t *rdev;
  1423. struct list_head *tmp;
  1424. int nc, fc;
  1425. sector_t stride, size;
  1426. if (mddev->level != 10) {
  1427. printk(KERN_ERR "raid10: %s: raid level not set correctly... (%d)\n",
  1428. mdname(mddev), mddev->level);
  1429. goto out;
  1430. }
  1431. nc = mddev->layout & 255;
  1432. fc = (mddev->layout >> 8) & 255;
  1433. if ((nc*fc) <2 || (nc*fc) > mddev->raid_disks ||
  1434. (mddev->layout >> 16)) {
  1435. printk(KERN_ERR "raid10: %s: unsupported raid10 layout: 0x%8x\n",
  1436. mdname(mddev), mddev->layout);
  1437. goto out;
  1438. }
  1439. /*
  1440. * copy the already verified devices into our private RAID10
  1441. * bookkeeping area. [whatever we allocate in run(),
  1442. * should be freed in stop()]
  1443. */
  1444. conf = kmalloc(sizeof(conf_t), GFP_KERNEL);
  1445. mddev->private = conf;
  1446. if (!conf) {
  1447. printk(KERN_ERR "raid10: couldn't allocate memory for %s\n",
  1448. mdname(mddev));
  1449. goto out;
  1450. }
  1451. memset(conf, 0, sizeof(*conf));
  1452. conf->mirrors = kmalloc(sizeof(struct mirror_info)*mddev->raid_disks,
  1453. GFP_KERNEL);
  1454. if (!conf->mirrors) {
  1455. printk(KERN_ERR "raid10: couldn't allocate memory for %s\n",
  1456. mdname(mddev));
  1457. goto out_free_conf;
  1458. }
  1459. memset(conf->mirrors, 0, sizeof(struct mirror_info)*mddev->raid_disks);
  1460. conf->near_copies = nc;
  1461. conf->far_copies = fc;
  1462. conf->copies = nc*fc;
  1463. conf->chunk_mask = (sector_t)(mddev->chunk_size>>9)-1;
  1464. conf->chunk_shift = ffz(~mddev->chunk_size) - 9;
  1465. stride = mddev->size >> (conf->chunk_shift-1);
  1466. sector_div(stride, fc);
  1467. conf->stride = stride << conf->chunk_shift;
  1468. conf->r10bio_pool = mempool_create(NR_RAID10_BIOS, r10bio_pool_alloc,
  1469. r10bio_pool_free, conf);
  1470. if (!conf->r10bio_pool) {
  1471. printk(KERN_ERR "raid10: couldn't allocate memory for %s\n",
  1472. mdname(mddev));
  1473. goto out_free_conf;
  1474. }
  1475. ITERATE_RDEV(mddev, rdev, tmp) {
  1476. disk_idx = rdev->raid_disk;
  1477. if (disk_idx >= mddev->raid_disks
  1478. || disk_idx < 0)
  1479. continue;
  1480. disk = conf->mirrors + disk_idx;
  1481. disk->rdev = rdev;
  1482. blk_queue_stack_limits(mddev->queue,
  1483. rdev->bdev->bd_disk->queue);
  1484. /* as we don't honour merge_bvec_fn, we must never risk
  1485. * violating it, so limit ->max_sector to one PAGE, as
  1486. * a one page request is never in violation.
  1487. */
  1488. if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
  1489. mddev->queue->max_sectors > (PAGE_SIZE>>9))
  1490. mddev->queue->max_sectors = (PAGE_SIZE>>9);
  1491. disk->head_position = 0;
  1492. if (!test_bit(Faulty, &rdev->flags) && test_bit(In_sync, &rdev->flags))
  1493. conf->working_disks++;
  1494. }
  1495. conf->raid_disks = mddev->raid_disks;
  1496. conf->mddev = mddev;
  1497. spin_lock_init(&conf->device_lock);
  1498. INIT_LIST_HEAD(&conf->retry_list);
  1499. spin_lock_init(&conf->resync_lock);
  1500. init_waitqueue_head(&conf->wait_idle);
  1501. init_waitqueue_head(&conf->wait_resume);
  1502. /* need to check that every block has at least one working mirror */
  1503. if (!enough(conf)) {
  1504. printk(KERN_ERR "raid10: not enough operational mirrors for %s\n",
  1505. mdname(mddev));
  1506. goto out_free_conf;
  1507. }
  1508. mddev->degraded = 0;
  1509. for (i = 0; i < conf->raid_disks; i++) {
  1510. disk = conf->mirrors + i;
  1511. if (!disk->rdev) {
  1512. disk->head_position = 0;
  1513. mddev->degraded++;
  1514. }
  1515. }
  1516. mddev->thread = md_register_thread(raid10d, mddev, "%s_raid10");
  1517. if (!mddev->thread) {
  1518. printk(KERN_ERR
  1519. "raid10: couldn't allocate thread for %s\n",
  1520. mdname(mddev));
  1521. goto out_free_conf;
  1522. }
  1523. printk(KERN_INFO
  1524. "raid10: raid set %s active with %d out of %d devices\n",
  1525. mdname(mddev), mddev->raid_disks - mddev->degraded,
  1526. mddev->raid_disks);
  1527. /*
  1528. * Ok, everything is just fine now
  1529. */
  1530. size = conf->stride * conf->raid_disks;
  1531. sector_div(size, conf->near_copies);
  1532. mddev->array_size = size/2;
  1533. mddev->resync_max_sectors = size;
  1534. mddev->queue->unplug_fn = raid10_unplug;
  1535. mddev->queue->issue_flush_fn = raid10_issue_flush;
  1536. /* Calculate max read-ahead size.
  1537. * We need to readahead at least twice a whole stripe....
  1538. * maybe...
  1539. */
  1540. {
  1541. int stripe = conf->raid_disks * mddev->chunk_size / PAGE_CACHE_SIZE;
  1542. stripe /= conf->near_copies;
  1543. if (mddev->queue->backing_dev_info.ra_pages < 2* stripe)
  1544. mddev->queue->backing_dev_info.ra_pages = 2* stripe;
  1545. }
  1546. if (conf->near_copies < mddev->raid_disks)
  1547. blk_queue_merge_bvec(mddev->queue, raid10_mergeable_bvec);
  1548. return 0;
  1549. out_free_conf:
  1550. if (conf->r10bio_pool)
  1551. mempool_destroy(conf->r10bio_pool);
  1552. kfree(conf->mirrors);
  1553. kfree(conf);
  1554. mddev->private = NULL;
  1555. out:
  1556. return -EIO;
  1557. }
  1558. static int stop(mddev_t *mddev)
  1559. {
  1560. conf_t *conf = mddev_to_conf(mddev);
  1561. md_unregister_thread(mddev->thread);
  1562. mddev->thread = NULL;
  1563. blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
  1564. if (conf->r10bio_pool)
  1565. mempool_destroy(conf->r10bio_pool);
  1566. kfree(conf->mirrors);
  1567. kfree(conf);
  1568. mddev->private = NULL;
  1569. return 0;
  1570. }
  1571. static mdk_personality_t raid10_personality =
  1572. {
  1573. .name = "raid10",
  1574. .owner = THIS_MODULE,
  1575. .make_request = make_request,
  1576. .run = run,
  1577. .stop = stop,
  1578. .status = status,
  1579. .error_handler = error,
  1580. .hot_add_disk = raid10_add_disk,
  1581. .hot_remove_disk= raid10_remove_disk,
  1582. .spare_active = raid10_spare_active,
  1583. .sync_request = sync_request,
  1584. };
  1585. static int __init raid_init(void)
  1586. {
  1587. return register_md_personality(RAID10, &raid10_personality);
  1588. }
  1589. static void raid_exit(void)
  1590. {
  1591. unregister_md_personality(RAID10);
  1592. }
  1593. module_init(raid_init);
  1594. module_exit(raid_exit);
  1595. MODULE_LICENSE("GPL");
  1596. MODULE_ALIAS("md-personality-9"); /* RAID10 */