raid10.c 65 KB

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