raid10.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830
  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. /* This optimisation is debatable, and completely destroys
  481. * sequential read speed for 'far copies' arrays. So only
  482. * keep it for 'near' arrays, and review those later.
  483. */
  484. if (conf->near_copies > 1 && !atomic_read(&rdev->nr_pending)) {
  485. disk = ndisk;
  486. slot = nslot;
  487. break;
  488. }
  489. new_distance = abs(r10_bio->devs[nslot].addr -
  490. conf->mirrors[ndisk].head_position);
  491. if (new_distance < current_distance) {
  492. current_distance = new_distance;
  493. disk = ndisk;
  494. slot = nslot;
  495. }
  496. }
  497. rb_out:
  498. r10_bio->read_slot = slot;
  499. /* conf->next_seq_sect = this_sector + sectors;*/
  500. if (disk >= 0 && (rdev=rcu_dereference(conf->mirrors[disk].rdev))!= NULL)
  501. atomic_inc(&conf->mirrors[disk].rdev->nr_pending);
  502. rcu_read_unlock();
  503. return disk;
  504. }
  505. static void unplug_slaves(mddev_t *mddev)
  506. {
  507. conf_t *conf = mddev_to_conf(mddev);
  508. int i;
  509. rcu_read_lock();
  510. for (i=0; i<mddev->raid_disks; i++) {
  511. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  512. if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) {
  513. request_queue_t *r_queue = bdev_get_queue(rdev->bdev);
  514. atomic_inc(&rdev->nr_pending);
  515. rcu_read_unlock();
  516. if (r_queue->unplug_fn)
  517. r_queue->unplug_fn(r_queue);
  518. rdev_dec_pending(rdev, mddev);
  519. rcu_read_lock();
  520. }
  521. }
  522. rcu_read_unlock();
  523. }
  524. static void raid10_unplug(request_queue_t *q)
  525. {
  526. unplug_slaves(q->queuedata);
  527. }
  528. static int raid10_issue_flush(request_queue_t *q, struct gendisk *disk,
  529. sector_t *error_sector)
  530. {
  531. mddev_t *mddev = q->queuedata;
  532. conf_t *conf = mddev_to_conf(mddev);
  533. int i, ret = 0;
  534. rcu_read_lock();
  535. for (i=0; i<mddev->raid_disks && ret == 0; i++) {
  536. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
  537. if (rdev && !test_bit(Faulty, &rdev->flags)) {
  538. struct block_device *bdev = rdev->bdev;
  539. request_queue_t *r_queue = bdev_get_queue(bdev);
  540. if (!r_queue->issue_flush_fn)
  541. ret = -EOPNOTSUPP;
  542. else {
  543. atomic_inc(&rdev->nr_pending);
  544. rcu_read_unlock();
  545. ret = r_queue->issue_flush_fn(r_queue, bdev->bd_disk,
  546. error_sector);
  547. rdev_dec_pending(rdev, mddev);
  548. rcu_read_lock();
  549. }
  550. }
  551. }
  552. rcu_read_unlock();
  553. return ret;
  554. }
  555. /*
  556. * Throttle resync depth, so that we can both get proper overlapping of
  557. * requests, but are still able to handle normal requests quickly.
  558. */
  559. #define RESYNC_DEPTH 32
  560. static void device_barrier(conf_t *conf, sector_t sect)
  561. {
  562. spin_lock_irq(&conf->resync_lock);
  563. wait_event_lock_irq(conf->wait_idle, !waitqueue_active(&conf->wait_resume),
  564. conf->resync_lock, unplug_slaves(conf->mddev));
  565. if (!conf->barrier++) {
  566. wait_event_lock_irq(conf->wait_idle, !conf->nr_pending,
  567. conf->resync_lock, unplug_slaves(conf->mddev));
  568. if (conf->nr_pending)
  569. BUG();
  570. }
  571. wait_event_lock_irq(conf->wait_resume, conf->barrier < RESYNC_DEPTH,
  572. conf->resync_lock, unplug_slaves(conf->mddev));
  573. conf->next_resync = sect;
  574. spin_unlock_irq(&conf->resync_lock);
  575. }
  576. static int make_request(request_queue_t *q, struct bio * bio)
  577. {
  578. mddev_t *mddev = q->queuedata;
  579. conf_t *conf = mddev_to_conf(mddev);
  580. mirror_info_t *mirror;
  581. r10bio_t *r10_bio;
  582. struct bio *read_bio;
  583. int i;
  584. int chunk_sects = conf->chunk_mask + 1;
  585. const int rw = bio_data_dir(bio);
  586. if (unlikely(bio_barrier(bio))) {
  587. bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
  588. return 0;
  589. }
  590. /* If this request crosses a chunk boundary, we need to
  591. * split it. This will only happen for 1 PAGE (or less) requests.
  592. */
  593. if (unlikely( (bio->bi_sector & conf->chunk_mask) + (bio->bi_size >> 9)
  594. > chunk_sects &&
  595. conf->near_copies < conf->raid_disks)) {
  596. struct bio_pair *bp;
  597. /* Sanity check -- queue functions should prevent this happening */
  598. if (bio->bi_vcnt != 1 ||
  599. bio->bi_idx != 0)
  600. goto bad_map;
  601. /* This is a one page bio that upper layers
  602. * refuse to split for us, so we need to split it.
  603. */
  604. bp = bio_split(bio, bio_split_pool,
  605. chunk_sects - (bio->bi_sector & (chunk_sects - 1)) );
  606. if (make_request(q, &bp->bio1))
  607. generic_make_request(&bp->bio1);
  608. if (make_request(q, &bp->bio2))
  609. generic_make_request(&bp->bio2);
  610. bio_pair_release(bp);
  611. return 0;
  612. bad_map:
  613. printk("raid10_make_request bug: can't convert block across chunks"
  614. " or bigger than %dk %llu %d\n", chunk_sects/2,
  615. (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
  616. bio_io_error(bio, bio->bi_size);
  617. return 0;
  618. }
  619. md_write_start(mddev, bio);
  620. /*
  621. * Register the new request and wait if the reconstruction
  622. * thread has put up a bar for new requests.
  623. * Continue immediately if no resync is active currently.
  624. */
  625. spin_lock_irq(&conf->resync_lock);
  626. wait_event_lock_irq(conf->wait_resume, !conf->barrier, conf->resync_lock, );
  627. conf->nr_pending++;
  628. spin_unlock_irq(&conf->resync_lock);
  629. disk_stat_inc(mddev->gendisk, ios[rw]);
  630. disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bio));
  631. r10_bio = mempool_alloc(conf->r10bio_pool, GFP_NOIO);
  632. r10_bio->master_bio = bio;
  633. r10_bio->sectors = bio->bi_size >> 9;
  634. r10_bio->mddev = mddev;
  635. r10_bio->sector = bio->bi_sector;
  636. if (rw == READ) {
  637. /*
  638. * read balancing logic:
  639. */
  640. int disk = read_balance(conf, r10_bio);
  641. int slot = r10_bio->read_slot;
  642. if (disk < 0) {
  643. raid_end_bio_io(r10_bio);
  644. return 0;
  645. }
  646. mirror = conf->mirrors + disk;
  647. read_bio = bio_clone(bio, GFP_NOIO);
  648. r10_bio->devs[slot].bio = read_bio;
  649. read_bio->bi_sector = r10_bio->devs[slot].addr +
  650. mirror->rdev->data_offset;
  651. read_bio->bi_bdev = mirror->rdev->bdev;
  652. read_bio->bi_end_io = raid10_end_read_request;
  653. read_bio->bi_rw = READ;
  654. read_bio->bi_private = r10_bio;
  655. generic_make_request(read_bio);
  656. return 0;
  657. }
  658. /*
  659. * WRITE:
  660. */
  661. /* first select target devices under spinlock and
  662. * inc refcount on their rdev. Record them by setting
  663. * bios[x] to bio
  664. */
  665. raid10_find_phys(conf, r10_bio);
  666. rcu_read_lock();
  667. for (i = 0; i < conf->copies; i++) {
  668. int d = r10_bio->devs[i].devnum;
  669. mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[d].rdev);
  670. if (rdev &&
  671. !test_bit(Faulty, &rdev->flags)) {
  672. atomic_inc(&rdev->nr_pending);
  673. r10_bio->devs[i].bio = bio;
  674. } else
  675. r10_bio->devs[i].bio = NULL;
  676. }
  677. rcu_read_unlock();
  678. atomic_set(&r10_bio->remaining, 1);
  679. for (i = 0; i < conf->copies; i++) {
  680. struct bio *mbio;
  681. int d = r10_bio->devs[i].devnum;
  682. if (!r10_bio->devs[i].bio)
  683. continue;
  684. mbio = bio_clone(bio, GFP_NOIO);
  685. r10_bio->devs[i].bio = mbio;
  686. mbio->bi_sector = r10_bio->devs[i].addr+
  687. conf->mirrors[d].rdev->data_offset;
  688. mbio->bi_bdev = conf->mirrors[d].rdev->bdev;
  689. mbio->bi_end_io = raid10_end_write_request;
  690. mbio->bi_rw = WRITE;
  691. mbio->bi_private = r10_bio;
  692. atomic_inc(&r10_bio->remaining);
  693. generic_make_request(mbio);
  694. }
  695. if (atomic_dec_and_test(&r10_bio->remaining)) {
  696. md_write_end(mddev);
  697. raid_end_bio_io(r10_bio);
  698. }
  699. return 0;
  700. }
  701. static void status(struct seq_file *seq, mddev_t *mddev)
  702. {
  703. conf_t *conf = mddev_to_conf(mddev);
  704. int i;
  705. if (conf->near_copies < conf->raid_disks)
  706. seq_printf(seq, " %dK chunks", mddev->chunk_size/1024);
  707. if (conf->near_copies > 1)
  708. seq_printf(seq, " %d near-copies", conf->near_copies);
  709. if (conf->far_copies > 1)
  710. seq_printf(seq, " %d far-copies", conf->far_copies);
  711. seq_printf(seq, " [%d/%d] [", conf->raid_disks,
  712. conf->working_disks);
  713. for (i = 0; i < conf->raid_disks; i++)
  714. seq_printf(seq, "%s",
  715. conf->mirrors[i].rdev &&
  716. test_bit(In_sync, &conf->mirrors[i].rdev->flags) ? "U" : "_");
  717. seq_printf(seq, "]");
  718. }
  719. static void error(mddev_t *mddev, mdk_rdev_t *rdev)
  720. {
  721. char b[BDEVNAME_SIZE];
  722. conf_t *conf = mddev_to_conf(mddev);
  723. /*
  724. * If it is not operational, then we have already marked it as dead
  725. * else if it is the last working disks, ignore the error, let the
  726. * next level up know.
  727. * else mark the drive as failed
  728. */
  729. if (test_bit(In_sync, &rdev->flags)
  730. && conf->working_disks == 1)
  731. /*
  732. * Don't fail the drive, just return an IO error.
  733. * The test should really be more sophisticated than
  734. * "working_disks == 1", but it isn't critical, and
  735. * can wait until we do more sophisticated "is the drive
  736. * really dead" tests...
  737. */
  738. return;
  739. if (test_bit(In_sync, &rdev->flags)) {
  740. mddev->degraded++;
  741. conf->working_disks--;
  742. /*
  743. * if recovery is running, make sure it aborts.
  744. */
  745. set_bit(MD_RECOVERY_ERR, &mddev->recovery);
  746. }
  747. clear_bit(In_sync, &rdev->flags);
  748. set_bit(Faulty, &rdev->flags);
  749. mddev->sb_dirty = 1;
  750. printk(KERN_ALERT "raid10: Disk failure on %s, disabling device. \n"
  751. " Operation continuing on %d devices\n",
  752. bdevname(rdev->bdev,b), conf->working_disks);
  753. }
  754. static void print_conf(conf_t *conf)
  755. {
  756. int i;
  757. mirror_info_t *tmp;
  758. printk("RAID10 conf printout:\n");
  759. if (!conf) {
  760. printk("(!conf)\n");
  761. return;
  762. }
  763. printk(" --- wd:%d rd:%d\n", conf->working_disks,
  764. conf->raid_disks);
  765. for (i = 0; i < conf->raid_disks; i++) {
  766. char b[BDEVNAME_SIZE];
  767. tmp = conf->mirrors + i;
  768. if (tmp->rdev)
  769. printk(" disk %d, wo:%d, o:%d, dev:%s\n",
  770. i, !test_bit(In_sync, &tmp->rdev->flags),
  771. !test_bit(Faulty, &tmp->rdev->flags),
  772. bdevname(tmp->rdev->bdev,b));
  773. }
  774. }
  775. static void close_sync(conf_t *conf)
  776. {
  777. spin_lock_irq(&conf->resync_lock);
  778. wait_event_lock_irq(conf->wait_resume, !conf->barrier,
  779. conf->resync_lock, unplug_slaves(conf->mddev));
  780. spin_unlock_irq(&conf->resync_lock);
  781. if (conf->barrier) BUG();
  782. if (waitqueue_active(&conf->wait_idle)) BUG();
  783. mempool_destroy(conf->r10buf_pool);
  784. conf->r10buf_pool = NULL;
  785. }
  786. /* check if there are enough drives for
  787. * every block to appear on atleast one
  788. */
  789. static int enough(conf_t *conf)
  790. {
  791. int first = 0;
  792. do {
  793. int n = conf->copies;
  794. int cnt = 0;
  795. while (n--) {
  796. if (conf->mirrors[first].rdev)
  797. cnt++;
  798. first = (first+1) % conf->raid_disks;
  799. }
  800. if (cnt == 0)
  801. return 0;
  802. } while (first != 0);
  803. return 1;
  804. }
  805. static int raid10_spare_active(mddev_t *mddev)
  806. {
  807. int i;
  808. conf_t *conf = mddev->private;
  809. mirror_info_t *tmp;
  810. /*
  811. * Find all non-in_sync disks within the RAID10 configuration
  812. * and mark them in_sync
  813. */
  814. for (i = 0; i < conf->raid_disks; i++) {
  815. tmp = conf->mirrors + i;
  816. if (tmp->rdev
  817. && !test_bit(Faulty, &tmp->rdev->flags)
  818. && !test_bit(In_sync, &tmp->rdev->flags)) {
  819. conf->working_disks++;
  820. mddev->degraded--;
  821. set_bit(In_sync, &tmp->rdev->flags);
  822. }
  823. }
  824. print_conf(conf);
  825. return 0;
  826. }
  827. static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
  828. {
  829. conf_t *conf = mddev->private;
  830. int found = 0;
  831. int mirror;
  832. mirror_info_t *p;
  833. if (mddev->recovery_cp < MaxSector)
  834. /* only hot-add to in-sync arrays, as recovery is
  835. * very different from resync
  836. */
  837. return 0;
  838. if (!enough(conf))
  839. return 0;
  840. for (mirror=0; mirror < mddev->raid_disks; mirror++)
  841. if ( !(p=conf->mirrors+mirror)->rdev) {
  842. blk_queue_stack_limits(mddev->queue,
  843. rdev->bdev->bd_disk->queue);
  844. /* as we don't honour merge_bvec_fn, we must never risk
  845. * violating it, so limit ->max_sector to one PAGE, as
  846. * a one page request is never in violation.
  847. */
  848. if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
  849. mddev->queue->max_sectors > (PAGE_SIZE>>9))
  850. mddev->queue->max_sectors = (PAGE_SIZE>>9);
  851. p->head_position = 0;
  852. rdev->raid_disk = mirror;
  853. found = 1;
  854. rcu_assign_pointer(p->rdev, rdev);
  855. break;
  856. }
  857. print_conf(conf);
  858. return found;
  859. }
  860. static int raid10_remove_disk(mddev_t *mddev, int number)
  861. {
  862. conf_t *conf = mddev->private;
  863. int err = 0;
  864. mdk_rdev_t *rdev;
  865. mirror_info_t *p = conf->mirrors+ number;
  866. print_conf(conf);
  867. rdev = p->rdev;
  868. if (rdev) {
  869. if (test_bit(In_sync, &rdev->flags) ||
  870. atomic_read(&rdev->nr_pending)) {
  871. err = -EBUSY;
  872. goto abort;
  873. }
  874. p->rdev = NULL;
  875. synchronize_rcu();
  876. if (atomic_read(&rdev->nr_pending)) {
  877. /* lost the race, try later */
  878. err = -EBUSY;
  879. p->rdev = rdev;
  880. }
  881. }
  882. abort:
  883. print_conf(conf);
  884. return err;
  885. }
  886. static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error)
  887. {
  888. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  889. r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
  890. conf_t *conf = mddev_to_conf(r10_bio->mddev);
  891. int i,d;
  892. if (bio->bi_size)
  893. return 1;
  894. for (i=0; i<conf->copies; i++)
  895. if (r10_bio->devs[i].bio == bio)
  896. break;
  897. if (i == conf->copies)
  898. BUG();
  899. update_head_pos(i, r10_bio);
  900. d = r10_bio->devs[i].devnum;
  901. if (!uptodate)
  902. md_error(r10_bio->mddev,
  903. conf->mirrors[d].rdev);
  904. /* for reconstruct, we always reschedule after a read.
  905. * for resync, only after all reads
  906. */
  907. if (test_bit(R10BIO_IsRecover, &r10_bio->state) ||
  908. atomic_dec_and_test(&r10_bio->remaining)) {
  909. /* we have read all the blocks,
  910. * do the comparison in process context in raid10d
  911. */
  912. reschedule_retry(r10_bio);
  913. }
  914. rdev_dec_pending(conf->mirrors[d].rdev, conf->mddev);
  915. return 0;
  916. }
  917. static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
  918. {
  919. int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
  920. r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
  921. mddev_t *mddev = r10_bio->mddev;
  922. conf_t *conf = mddev_to_conf(mddev);
  923. int i,d;
  924. if (bio->bi_size)
  925. return 1;
  926. for (i = 0; i < conf->copies; i++)
  927. if (r10_bio->devs[i].bio == bio)
  928. break;
  929. d = r10_bio->devs[i].devnum;
  930. if (!uptodate)
  931. md_error(mddev, conf->mirrors[d].rdev);
  932. update_head_pos(i, r10_bio);
  933. while (atomic_dec_and_test(&r10_bio->remaining)) {
  934. if (r10_bio->master_bio == NULL) {
  935. /* the primary of several recovery bios */
  936. md_done_sync(mddev, r10_bio->sectors, 1);
  937. put_buf(r10_bio);
  938. break;
  939. } else {
  940. r10bio_t *r10_bio2 = (r10bio_t *)r10_bio->master_bio;
  941. put_buf(r10_bio);
  942. r10_bio = r10_bio2;
  943. }
  944. }
  945. rdev_dec_pending(conf->mirrors[d].rdev, mddev);
  946. return 0;
  947. }
  948. /*
  949. * Note: sync and recover and handled very differently for raid10
  950. * This code is for resync.
  951. * For resync, we read through virtual addresses and read all blocks.
  952. * If there is any error, we schedule a write. The lowest numbered
  953. * drive is authoritative.
  954. * However requests come for physical address, so we need to map.
  955. * For every physical address there are raid_disks/copies virtual addresses,
  956. * which is always are least one, but is not necessarly an integer.
  957. * This means that a physical address can span multiple chunks, so we may
  958. * have to submit multiple io requests for a single sync request.
  959. */
  960. /*
  961. * We check if all blocks are in-sync and only write to blocks that
  962. * aren't in sync
  963. */
  964. static void sync_request_write(mddev_t *mddev, r10bio_t *r10_bio)
  965. {
  966. conf_t *conf = mddev_to_conf(mddev);
  967. int i, first;
  968. struct bio *tbio, *fbio;
  969. atomic_set(&r10_bio->remaining, 1);
  970. /* find the first device with a block */
  971. for (i=0; i<conf->copies; i++)
  972. if (test_bit(BIO_UPTODATE, &r10_bio->devs[i].bio->bi_flags))
  973. break;
  974. if (i == conf->copies)
  975. goto done;
  976. first = i;
  977. fbio = r10_bio->devs[i].bio;
  978. /* now find blocks with errors */
  979. for (i=first+1 ; i < conf->copies ; i++) {
  980. int vcnt, j, d;
  981. if (!test_bit(BIO_UPTODATE, &r10_bio->devs[i].bio->bi_flags))
  982. continue;
  983. /* We know that the bi_io_vec layout is the same for
  984. * both 'first' and 'i', so we just compare them.
  985. * All vec entries are PAGE_SIZE;
  986. */
  987. tbio = r10_bio->devs[i].bio;
  988. vcnt = r10_bio->sectors >> (PAGE_SHIFT-9);
  989. for (j = 0; j < vcnt; j++)
  990. if (memcmp(page_address(fbio->bi_io_vec[j].bv_page),
  991. page_address(tbio->bi_io_vec[j].bv_page),
  992. PAGE_SIZE))
  993. break;
  994. if (j == vcnt)
  995. continue;
  996. /* Ok, we need to write this bio
  997. * First we need to fixup bv_offset, bv_len and
  998. * bi_vecs, as the read request might have corrupted these
  999. */
  1000. tbio->bi_vcnt = vcnt;
  1001. tbio->bi_size = r10_bio->sectors << 9;
  1002. tbio->bi_idx = 0;
  1003. tbio->bi_phys_segments = 0;
  1004. tbio->bi_hw_segments = 0;
  1005. tbio->bi_hw_front_size = 0;
  1006. tbio->bi_hw_back_size = 0;
  1007. tbio->bi_flags &= ~(BIO_POOL_MASK - 1);
  1008. tbio->bi_flags |= 1 << BIO_UPTODATE;
  1009. tbio->bi_next = NULL;
  1010. tbio->bi_rw = WRITE;
  1011. tbio->bi_private = r10_bio;
  1012. tbio->bi_sector = r10_bio->devs[i].addr;
  1013. for (j=0; j < vcnt ; j++) {
  1014. tbio->bi_io_vec[j].bv_offset = 0;
  1015. tbio->bi_io_vec[j].bv_len = PAGE_SIZE;
  1016. memcpy(page_address(tbio->bi_io_vec[j].bv_page),
  1017. page_address(fbio->bi_io_vec[j].bv_page),
  1018. PAGE_SIZE);
  1019. }
  1020. tbio->bi_end_io = end_sync_write;
  1021. d = r10_bio->devs[i].devnum;
  1022. atomic_inc(&conf->mirrors[d].rdev->nr_pending);
  1023. atomic_inc(&r10_bio->remaining);
  1024. md_sync_acct(conf->mirrors[d].rdev->bdev, tbio->bi_size >> 9);
  1025. tbio->bi_sector += conf->mirrors[d].rdev->data_offset;
  1026. tbio->bi_bdev = conf->mirrors[d].rdev->bdev;
  1027. generic_make_request(tbio);
  1028. }
  1029. done:
  1030. if (atomic_dec_and_test(&r10_bio->remaining)) {
  1031. md_done_sync(mddev, r10_bio->sectors, 1);
  1032. put_buf(r10_bio);
  1033. }
  1034. }
  1035. /*
  1036. * Now for the recovery code.
  1037. * Recovery happens across physical sectors.
  1038. * We recover all non-is_sync drives by finding the virtual address of
  1039. * each, and then choose a working drive that also has that virt address.
  1040. * There is a separate r10_bio for each non-in_sync drive.
  1041. * Only the first two slots are in use. The first for reading,
  1042. * The second for writing.
  1043. *
  1044. */
  1045. static void recovery_request_write(mddev_t *mddev, r10bio_t *r10_bio)
  1046. {
  1047. conf_t *conf = mddev_to_conf(mddev);
  1048. int i, d;
  1049. struct bio *bio, *wbio;
  1050. /* move the pages across to the second bio
  1051. * and submit the write request
  1052. */
  1053. bio = r10_bio->devs[0].bio;
  1054. wbio = r10_bio->devs[1].bio;
  1055. for (i=0; i < wbio->bi_vcnt; i++) {
  1056. struct page *p = bio->bi_io_vec[i].bv_page;
  1057. bio->bi_io_vec[i].bv_page = wbio->bi_io_vec[i].bv_page;
  1058. wbio->bi_io_vec[i].bv_page = p;
  1059. }
  1060. d = r10_bio->devs[1].devnum;
  1061. atomic_inc(&conf->mirrors[d].rdev->nr_pending);
  1062. md_sync_acct(conf->mirrors[d].rdev->bdev, wbio->bi_size >> 9);
  1063. generic_make_request(wbio);
  1064. }
  1065. /*
  1066. * This is a kernel thread which:
  1067. *
  1068. * 1. Retries failed read operations on working mirrors.
  1069. * 2. Updates the raid superblock when problems encounter.
  1070. * 3. Performs writes following reads for array syncronising.
  1071. */
  1072. static void raid10d(mddev_t *mddev)
  1073. {
  1074. r10bio_t *r10_bio;
  1075. struct bio *bio;
  1076. unsigned long flags;
  1077. conf_t *conf = mddev_to_conf(mddev);
  1078. struct list_head *head = &conf->retry_list;
  1079. int unplug=0;
  1080. mdk_rdev_t *rdev;
  1081. md_check_recovery(mddev);
  1082. for (;;) {
  1083. char b[BDEVNAME_SIZE];
  1084. spin_lock_irqsave(&conf->device_lock, flags);
  1085. if (list_empty(head))
  1086. break;
  1087. r10_bio = list_entry(head->prev, r10bio_t, retry_list);
  1088. list_del(head->prev);
  1089. spin_unlock_irqrestore(&conf->device_lock, flags);
  1090. mddev = r10_bio->mddev;
  1091. conf = mddev_to_conf(mddev);
  1092. if (test_bit(R10BIO_IsSync, &r10_bio->state)) {
  1093. sync_request_write(mddev, r10_bio);
  1094. unplug = 1;
  1095. } else if (test_bit(R10BIO_IsRecover, &r10_bio->state)) {
  1096. recovery_request_write(mddev, r10_bio);
  1097. unplug = 1;
  1098. } else {
  1099. int mirror;
  1100. bio = r10_bio->devs[r10_bio->read_slot].bio;
  1101. r10_bio->devs[r10_bio->read_slot].bio = NULL;
  1102. bio_put(bio);
  1103. mirror = read_balance(conf, r10_bio);
  1104. if (mirror == -1) {
  1105. printk(KERN_ALERT "raid10: %s: unrecoverable I/O"
  1106. " read error for block %llu\n",
  1107. bdevname(bio->bi_bdev,b),
  1108. (unsigned long long)r10_bio->sector);
  1109. raid_end_bio_io(r10_bio);
  1110. } else {
  1111. rdev = conf->mirrors[mirror].rdev;
  1112. if (printk_ratelimit())
  1113. printk(KERN_ERR "raid10: %s: redirecting sector %llu to"
  1114. " another mirror\n",
  1115. bdevname(rdev->bdev,b),
  1116. (unsigned long long)r10_bio->sector);
  1117. bio = bio_clone(r10_bio->master_bio, GFP_NOIO);
  1118. r10_bio->devs[r10_bio->read_slot].bio = bio;
  1119. bio->bi_sector = r10_bio->devs[r10_bio->read_slot].addr
  1120. + rdev->data_offset;
  1121. bio->bi_bdev = rdev->bdev;
  1122. bio->bi_rw = READ;
  1123. bio->bi_private = r10_bio;
  1124. bio->bi_end_io = raid10_end_read_request;
  1125. unplug = 1;
  1126. generic_make_request(bio);
  1127. }
  1128. }
  1129. }
  1130. spin_unlock_irqrestore(&conf->device_lock, flags);
  1131. if (unplug)
  1132. unplug_slaves(mddev);
  1133. }
  1134. static int init_resync(conf_t *conf)
  1135. {
  1136. int buffs;
  1137. buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE;
  1138. if (conf->r10buf_pool)
  1139. BUG();
  1140. conf->r10buf_pool = mempool_create(buffs, r10buf_pool_alloc, r10buf_pool_free, conf);
  1141. if (!conf->r10buf_pool)
  1142. return -ENOMEM;
  1143. conf->next_resync = 0;
  1144. return 0;
  1145. }
  1146. /*
  1147. * perform a "sync" on one "block"
  1148. *
  1149. * We need to make sure that no normal I/O request - particularly write
  1150. * requests - conflict with active sync requests.
  1151. *
  1152. * This is achieved by tracking pending requests and a 'barrier' concept
  1153. * that can be installed to exclude normal IO requests.
  1154. *
  1155. * Resync and recovery are handled very differently.
  1156. * We differentiate by looking at MD_RECOVERY_SYNC in mddev->recovery.
  1157. *
  1158. * For resync, we iterate over virtual addresses, read all copies,
  1159. * and update if there are differences. If only one copy is live,
  1160. * skip it.
  1161. * For recovery, we iterate over physical addresses, read a good
  1162. * value for each non-in_sync drive, and over-write.
  1163. *
  1164. * So, for recovery we may have several outstanding complex requests for a
  1165. * given address, one for each out-of-sync device. We model this by allocating
  1166. * a number of r10_bio structures, one for each out-of-sync device.
  1167. * As we setup these structures, we collect all bio's together into a list
  1168. * which we then process collectively to add pages, and then process again
  1169. * to pass to generic_make_request.
  1170. *
  1171. * The r10_bio structures are linked using a borrowed master_bio pointer.
  1172. * This link is counted in ->remaining. When the r10_bio that points to NULL
  1173. * has its remaining count decremented to 0, the whole complex operation
  1174. * is complete.
  1175. *
  1176. */
  1177. static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
  1178. {
  1179. conf_t *conf = mddev_to_conf(mddev);
  1180. r10bio_t *r10_bio;
  1181. struct bio *biolist = NULL, *bio;
  1182. sector_t max_sector, nr_sectors;
  1183. int disk;
  1184. int i;
  1185. sector_t sectors_skipped = 0;
  1186. int chunks_skipped = 0;
  1187. if (!conf->r10buf_pool)
  1188. if (init_resync(conf))
  1189. return 0;
  1190. skipped:
  1191. max_sector = mddev->size << 1;
  1192. if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
  1193. max_sector = mddev->resync_max_sectors;
  1194. if (sector_nr >= max_sector) {
  1195. close_sync(conf);
  1196. *skipped = 1;
  1197. return sectors_skipped;
  1198. }
  1199. if (chunks_skipped >= conf->raid_disks) {
  1200. /* if there has been nothing to do on any drive,
  1201. * then there is nothing to do at all..
  1202. */
  1203. *skipped = 1;
  1204. return (max_sector - sector_nr) + sectors_skipped;
  1205. }
  1206. /* make sure whole request will fit in a chunk - if chunks
  1207. * are meaningful
  1208. */
  1209. if (conf->near_copies < conf->raid_disks &&
  1210. max_sector > (sector_nr | conf->chunk_mask))
  1211. max_sector = (sector_nr | conf->chunk_mask) + 1;
  1212. /*
  1213. * If there is non-resync activity waiting for us then
  1214. * put in a delay to throttle resync.
  1215. */
  1216. if (!go_faster && waitqueue_active(&conf->wait_resume))
  1217. msleep_interruptible(1000);
  1218. device_barrier(conf, sector_nr + RESYNC_SECTORS);
  1219. /* Again, very different code for resync and recovery.
  1220. * Both must result in an r10bio with a list of bios that
  1221. * have bi_end_io, bi_sector, bi_bdev set,
  1222. * and bi_private set to the r10bio.
  1223. * For recovery, we may actually create several r10bios
  1224. * with 2 bios in each, that correspond to the bios in the main one.
  1225. * In this case, the subordinate r10bios link back through a
  1226. * borrowed master_bio pointer, and the counter in the master
  1227. * includes a ref from each subordinate.
  1228. */
  1229. /* First, we decide what to do and set ->bi_end_io
  1230. * To end_sync_read if we want to read, and
  1231. * end_sync_write if we will want to write.
  1232. */
  1233. if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
  1234. /* recovery... the complicated one */
  1235. int i, j, k;
  1236. r10_bio = NULL;
  1237. for (i=0 ; i<conf->raid_disks; i++)
  1238. if (conf->mirrors[i].rdev &&
  1239. !test_bit(In_sync, &conf->mirrors[i].rdev->flags)) {
  1240. /* want to reconstruct this device */
  1241. r10bio_t *rb2 = r10_bio;
  1242. r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO);
  1243. spin_lock_irq(&conf->resync_lock);
  1244. conf->nr_pending++;
  1245. if (rb2) conf->barrier++;
  1246. spin_unlock_irq(&conf->resync_lock);
  1247. atomic_set(&r10_bio->remaining, 0);
  1248. r10_bio->master_bio = (struct bio*)rb2;
  1249. if (rb2)
  1250. atomic_inc(&rb2->remaining);
  1251. r10_bio->mddev = mddev;
  1252. set_bit(R10BIO_IsRecover, &r10_bio->state);
  1253. r10_bio->sector = raid10_find_virt(conf, sector_nr, i);
  1254. raid10_find_phys(conf, r10_bio);
  1255. for (j=0; j<conf->copies;j++) {
  1256. int d = r10_bio->devs[j].devnum;
  1257. if (conf->mirrors[d].rdev &&
  1258. test_bit(In_sync, &conf->mirrors[d].rdev->flags)) {
  1259. /* This is where we read from */
  1260. bio = r10_bio->devs[0].bio;
  1261. bio->bi_next = biolist;
  1262. biolist = bio;
  1263. bio->bi_private = r10_bio;
  1264. bio->bi_end_io = end_sync_read;
  1265. bio->bi_rw = 0;
  1266. bio->bi_sector = r10_bio->devs[j].addr +
  1267. conf->mirrors[d].rdev->data_offset;
  1268. bio->bi_bdev = conf->mirrors[d].rdev->bdev;
  1269. atomic_inc(&conf->mirrors[d].rdev->nr_pending);
  1270. atomic_inc(&r10_bio->remaining);
  1271. /* and we write to 'i' */
  1272. for (k=0; k<conf->copies; k++)
  1273. if (r10_bio->devs[k].devnum == i)
  1274. break;
  1275. bio = r10_bio->devs[1].bio;
  1276. bio->bi_next = biolist;
  1277. biolist = bio;
  1278. bio->bi_private = r10_bio;
  1279. bio->bi_end_io = end_sync_write;
  1280. bio->bi_rw = 1;
  1281. bio->bi_sector = r10_bio->devs[k].addr +
  1282. conf->mirrors[i].rdev->data_offset;
  1283. bio->bi_bdev = conf->mirrors[i].rdev->bdev;
  1284. r10_bio->devs[0].devnum = d;
  1285. r10_bio->devs[1].devnum = i;
  1286. break;
  1287. }
  1288. }
  1289. if (j == conf->copies) {
  1290. /* Cannot recover, so abort the recovery */
  1291. put_buf(r10_bio);
  1292. r10_bio = rb2;
  1293. if (!test_and_set_bit(MD_RECOVERY_ERR, &mddev->recovery))
  1294. printk(KERN_INFO "raid10: %s: insufficient working devices for recovery.\n",
  1295. mdname(mddev));
  1296. break;
  1297. }
  1298. }
  1299. if (biolist == NULL) {
  1300. while (r10_bio) {
  1301. r10bio_t *rb2 = r10_bio;
  1302. r10_bio = (r10bio_t*) rb2->master_bio;
  1303. rb2->master_bio = NULL;
  1304. put_buf(rb2);
  1305. }
  1306. goto giveup;
  1307. }
  1308. } else {
  1309. /* resync. Schedule a read for every block at this virt offset */
  1310. int count = 0;
  1311. r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO);
  1312. spin_lock_irq(&conf->resync_lock);
  1313. conf->nr_pending++;
  1314. spin_unlock_irq(&conf->resync_lock);
  1315. r10_bio->mddev = mddev;
  1316. atomic_set(&r10_bio->remaining, 0);
  1317. r10_bio->master_bio = NULL;
  1318. r10_bio->sector = sector_nr;
  1319. set_bit(R10BIO_IsSync, &r10_bio->state);
  1320. raid10_find_phys(conf, r10_bio);
  1321. r10_bio->sectors = (sector_nr | conf->chunk_mask) - sector_nr +1;
  1322. for (i=0; i<conf->copies; i++) {
  1323. int d = r10_bio->devs[i].devnum;
  1324. bio = r10_bio->devs[i].bio;
  1325. bio->bi_end_io = NULL;
  1326. if (conf->mirrors[d].rdev == NULL ||
  1327. test_bit(Faulty, &conf->mirrors[d].rdev->flags))
  1328. continue;
  1329. atomic_inc(&conf->mirrors[d].rdev->nr_pending);
  1330. atomic_inc(&r10_bio->remaining);
  1331. bio->bi_next = biolist;
  1332. biolist = bio;
  1333. bio->bi_private = r10_bio;
  1334. bio->bi_end_io = end_sync_read;
  1335. bio->bi_rw = 0;
  1336. bio->bi_sector = r10_bio->devs[i].addr +
  1337. conf->mirrors[d].rdev->data_offset;
  1338. bio->bi_bdev = conf->mirrors[d].rdev->bdev;
  1339. count++;
  1340. }
  1341. if (count < 2) {
  1342. for (i=0; i<conf->copies; i++) {
  1343. int d = r10_bio->devs[i].devnum;
  1344. if (r10_bio->devs[i].bio->bi_end_io)
  1345. rdev_dec_pending(conf->mirrors[d].rdev, mddev);
  1346. }
  1347. put_buf(r10_bio);
  1348. biolist = NULL;
  1349. goto giveup;
  1350. }
  1351. }
  1352. for (bio = biolist; bio ; bio=bio->bi_next) {
  1353. bio->bi_flags &= ~(BIO_POOL_MASK - 1);
  1354. if (bio->bi_end_io)
  1355. bio->bi_flags |= 1 << BIO_UPTODATE;
  1356. bio->bi_vcnt = 0;
  1357. bio->bi_idx = 0;
  1358. bio->bi_phys_segments = 0;
  1359. bio->bi_hw_segments = 0;
  1360. bio->bi_size = 0;
  1361. }
  1362. nr_sectors = 0;
  1363. do {
  1364. struct page *page;
  1365. int len = PAGE_SIZE;
  1366. disk = 0;
  1367. if (sector_nr + (len>>9) > max_sector)
  1368. len = (max_sector - sector_nr) << 9;
  1369. if (len == 0)
  1370. break;
  1371. for (bio= biolist ; bio ; bio=bio->bi_next) {
  1372. page = bio->bi_io_vec[bio->bi_vcnt].bv_page;
  1373. if (bio_add_page(bio, page, len, 0) == 0) {
  1374. /* stop here */
  1375. struct bio *bio2;
  1376. bio->bi_io_vec[bio->bi_vcnt].bv_page = page;
  1377. for (bio2 = biolist; bio2 && bio2 != bio; bio2 = bio2->bi_next) {
  1378. /* remove last page from this bio */
  1379. bio2->bi_vcnt--;
  1380. bio2->bi_size -= len;
  1381. bio2->bi_flags &= ~(1<< BIO_SEG_VALID);
  1382. }
  1383. goto bio_full;
  1384. }
  1385. disk = i;
  1386. }
  1387. nr_sectors += len>>9;
  1388. sector_nr += len>>9;
  1389. } while (biolist->bi_vcnt < RESYNC_PAGES);
  1390. bio_full:
  1391. r10_bio->sectors = nr_sectors;
  1392. while (biolist) {
  1393. bio = biolist;
  1394. biolist = biolist->bi_next;
  1395. bio->bi_next = NULL;
  1396. r10_bio = bio->bi_private;
  1397. r10_bio->sectors = nr_sectors;
  1398. if (bio->bi_end_io == end_sync_read) {
  1399. md_sync_acct(bio->bi_bdev, nr_sectors);
  1400. generic_make_request(bio);
  1401. }
  1402. }
  1403. if (sectors_skipped)
  1404. /* pretend they weren't skipped, it makes
  1405. * no important difference in this case
  1406. */
  1407. md_done_sync(mddev, sectors_skipped, 1);
  1408. return sectors_skipped + nr_sectors;
  1409. giveup:
  1410. /* There is nowhere to write, so all non-sync
  1411. * drives must be failed, so try the next chunk...
  1412. */
  1413. {
  1414. sector_t sec = max_sector - sector_nr;
  1415. sectors_skipped += sec;
  1416. chunks_skipped ++;
  1417. sector_nr = max_sector;
  1418. goto skipped;
  1419. }
  1420. }
  1421. static int run(mddev_t *mddev)
  1422. {
  1423. conf_t *conf;
  1424. int i, disk_idx;
  1425. mirror_info_t *disk;
  1426. mdk_rdev_t *rdev;
  1427. struct list_head *tmp;
  1428. int nc, fc;
  1429. sector_t stride, size;
  1430. if (mddev->level != 10) {
  1431. printk(KERN_ERR "raid10: %s: raid level not set correctly... (%d)\n",
  1432. mdname(mddev), mddev->level);
  1433. goto out;
  1434. }
  1435. nc = mddev->layout & 255;
  1436. fc = (mddev->layout >> 8) & 255;
  1437. if ((nc*fc) <2 || (nc*fc) > mddev->raid_disks ||
  1438. (mddev->layout >> 16)) {
  1439. printk(KERN_ERR "raid10: %s: unsupported raid10 layout: 0x%8x\n",
  1440. mdname(mddev), mddev->layout);
  1441. goto out;
  1442. }
  1443. /*
  1444. * copy the already verified devices into our private RAID10
  1445. * bookkeeping area. [whatever we allocate in run(),
  1446. * should be freed in stop()]
  1447. */
  1448. conf = kmalloc(sizeof(conf_t), GFP_KERNEL);
  1449. mddev->private = conf;
  1450. if (!conf) {
  1451. printk(KERN_ERR "raid10: couldn't allocate memory for %s\n",
  1452. mdname(mddev));
  1453. goto out;
  1454. }
  1455. memset(conf, 0, sizeof(*conf));
  1456. conf->mirrors = kmalloc(sizeof(struct mirror_info)*mddev->raid_disks,
  1457. GFP_KERNEL);
  1458. if (!conf->mirrors) {
  1459. printk(KERN_ERR "raid10: couldn't allocate memory for %s\n",
  1460. mdname(mddev));
  1461. goto out_free_conf;
  1462. }
  1463. memset(conf->mirrors, 0, sizeof(struct mirror_info)*mddev->raid_disks);
  1464. conf->near_copies = nc;
  1465. conf->far_copies = fc;
  1466. conf->copies = nc*fc;
  1467. conf->chunk_mask = (sector_t)(mddev->chunk_size>>9)-1;
  1468. conf->chunk_shift = ffz(~mddev->chunk_size) - 9;
  1469. stride = mddev->size >> (conf->chunk_shift-1);
  1470. sector_div(stride, fc);
  1471. conf->stride = stride << conf->chunk_shift;
  1472. conf->r10bio_pool = mempool_create(NR_RAID10_BIOS, r10bio_pool_alloc,
  1473. r10bio_pool_free, conf);
  1474. if (!conf->r10bio_pool) {
  1475. printk(KERN_ERR "raid10: couldn't allocate memory for %s\n",
  1476. mdname(mddev));
  1477. goto out_free_conf;
  1478. }
  1479. ITERATE_RDEV(mddev, rdev, tmp) {
  1480. disk_idx = rdev->raid_disk;
  1481. if (disk_idx >= mddev->raid_disks
  1482. || disk_idx < 0)
  1483. continue;
  1484. disk = conf->mirrors + disk_idx;
  1485. disk->rdev = rdev;
  1486. blk_queue_stack_limits(mddev->queue,
  1487. rdev->bdev->bd_disk->queue);
  1488. /* as we don't honour merge_bvec_fn, we must never risk
  1489. * violating it, so limit ->max_sector to one PAGE, as
  1490. * a one page request is never in violation.
  1491. */
  1492. if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
  1493. mddev->queue->max_sectors > (PAGE_SIZE>>9))
  1494. mddev->queue->max_sectors = (PAGE_SIZE>>9);
  1495. disk->head_position = 0;
  1496. if (!test_bit(Faulty, &rdev->flags) && test_bit(In_sync, &rdev->flags))
  1497. conf->working_disks++;
  1498. }
  1499. conf->raid_disks = mddev->raid_disks;
  1500. conf->mddev = mddev;
  1501. spin_lock_init(&conf->device_lock);
  1502. INIT_LIST_HEAD(&conf->retry_list);
  1503. spin_lock_init(&conf->resync_lock);
  1504. init_waitqueue_head(&conf->wait_idle);
  1505. init_waitqueue_head(&conf->wait_resume);
  1506. /* need to check that every block has at least one working mirror */
  1507. if (!enough(conf)) {
  1508. printk(KERN_ERR "raid10: not enough operational mirrors for %s\n",
  1509. mdname(mddev));
  1510. goto out_free_conf;
  1511. }
  1512. mddev->degraded = 0;
  1513. for (i = 0; i < conf->raid_disks; i++) {
  1514. disk = conf->mirrors + i;
  1515. if (!disk->rdev) {
  1516. disk->head_position = 0;
  1517. mddev->degraded++;
  1518. }
  1519. }
  1520. mddev->thread = md_register_thread(raid10d, mddev, "%s_raid10");
  1521. if (!mddev->thread) {
  1522. printk(KERN_ERR
  1523. "raid10: couldn't allocate thread for %s\n",
  1524. mdname(mddev));
  1525. goto out_free_conf;
  1526. }
  1527. printk(KERN_INFO
  1528. "raid10: raid set %s active with %d out of %d devices\n",
  1529. mdname(mddev), mddev->raid_disks - mddev->degraded,
  1530. mddev->raid_disks);
  1531. /*
  1532. * Ok, everything is just fine now
  1533. */
  1534. size = conf->stride * conf->raid_disks;
  1535. sector_div(size, conf->near_copies);
  1536. mddev->array_size = size/2;
  1537. mddev->resync_max_sectors = size;
  1538. mddev->queue->unplug_fn = raid10_unplug;
  1539. mddev->queue->issue_flush_fn = raid10_issue_flush;
  1540. /* Calculate max read-ahead size.
  1541. * We need to readahead at least twice a whole stripe....
  1542. * maybe...
  1543. */
  1544. {
  1545. int stripe = conf->raid_disks * mddev->chunk_size / PAGE_CACHE_SIZE;
  1546. stripe /= conf->near_copies;
  1547. if (mddev->queue->backing_dev_info.ra_pages < 2* stripe)
  1548. mddev->queue->backing_dev_info.ra_pages = 2* stripe;
  1549. }
  1550. if (conf->near_copies < mddev->raid_disks)
  1551. blk_queue_merge_bvec(mddev->queue, raid10_mergeable_bvec);
  1552. return 0;
  1553. out_free_conf:
  1554. if (conf->r10bio_pool)
  1555. mempool_destroy(conf->r10bio_pool);
  1556. kfree(conf->mirrors);
  1557. kfree(conf);
  1558. mddev->private = NULL;
  1559. out:
  1560. return -EIO;
  1561. }
  1562. static int stop(mddev_t *mddev)
  1563. {
  1564. conf_t *conf = mddev_to_conf(mddev);
  1565. md_unregister_thread(mddev->thread);
  1566. mddev->thread = NULL;
  1567. blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
  1568. if (conf->r10bio_pool)
  1569. mempool_destroy(conf->r10bio_pool);
  1570. kfree(conf->mirrors);
  1571. kfree(conf);
  1572. mddev->private = NULL;
  1573. return 0;
  1574. }
  1575. static mdk_personality_t raid10_personality =
  1576. {
  1577. .name = "raid10",
  1578. .owner = THIS_MODULE,
  1579. .make_request = make_request,
  1580. .run = run,
  1581. .stop = stop,
  1582. .status = status,
  1583. .error_handler = error,
  1584. .hot_add_disk = raid10_add_disk,
  1585. .hot_remove_disk= raid10_remove_disk,
  1586. .spare_active = raid10_spare_active,
  1587. .sync_request = sync_request,
  1588. };
  1589. static int __init raid_init(void)
  1590. {
  1591. return register_md_personality(RAID10, &raid10_personality);
  1592. }
  1593. static void raid_exit(void)
  1594. {
  1595. unregister_md_personality(RAID10);
  1596. }
  1597. module_init(raid_init);
  1598. module_exit(raid_exit);
  1599. MODULE_LICENSE("GPL");
  1600. MODULE_ALIAS("md-personality-9"); /* RAID10 */