raid10.c 65 KB

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