raid6main.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  1. /*
  2. * raid6main.c : Multiple Devices driver for Linux
  3. * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman
  4. * Copyright (C) 1999, 2000 Ingo Molnar
  5. * Copyright (C) 2002, 2003 H. Peter Anvin
  6. *
  7. * RAID-6 management functions. This code is derived from raid5.c.
  8. * Last merge from raid5.c bkcvs version 1.79 (kernel 2.6.1).
  9. *
  10. * Thanks to Penguin Computing for making the RAID-6 development possible
  11. * by donating a test server!
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2, or (at your option)
  16. * any later version.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * (for example /usr/src/linux/COPYING); if not, write to the Free
  20. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/config.h>
  23. #include <linux/module.h>
  24. #include <linux/slab.h>
  25. #include <linux/highmem.h>
  26. #include <linux/bitops.h>
  27. #include <asm/atomic.h>
  28. #include "raid6.h"
  29. #include <linux/raid/bitmap.h>
  30. /*
  31. * Stripe cache
  32. */
  33. #define NR_STRIPES 256
  34. #define STRIPE_SIZE PAGE_SIZE
  35. #define STRIPE_SHIFT (PAGE_SHIFT - 9)
  36. #define STRIPE_SECTORS (STRIPE_SIZE>>9)
  37. #define IO_THRESHOLD 1
  38. #define HASH_PAGES 1
  39. #define HASH_PAGES_ORDER 0
  40. #define NR_HASH (HASH_PAGES * PAGE_SIZE / sizeof(struct stripe_head *))
  41. #define HASH_MASK (NR_HASH - 1)
  42. #define stripe_hash(conf, sect) ((conf)->stripe_hashtbl[((sect) >> STRIPE_SHIFT) & HASH_MASK])
  43. /* bio's attached to a stripe+device for I/O are linked together in bi_sector
  44. * order without overlap. There may be several bio's per stripe+device, and
  45. * a bio could span several devices.
  46. * When walking this list for a particular stripe+device, we must never proceed
  47. * beyond a bio that extends past this device, as the next bio might no longer
  48. * be valid.
  49. * This macro is used to determine the 'next' bio in the list, given the sector
  50. * of the current stripe+device
  51. */
  52. #define r5_next_bio(bio, sect) ( ( (bio)->bi_sector + ((bio)->bi_size>>9) < sect + STRIPE_SECTORS) ? (bio)->bi_next : NULL)
  53. /*
  54. * The following can be used to debug the driver
  55. */
  56. #define RAID6_DEBUG 0 /* Extremely verbose printk */
  57. #define RAID6_PARANOIA 1 /* Check spinlocks */
  58. #define RAID6_DUMPSTATE 0 /* Include stripe cache state in /proc/mdstat */
  59. #if RAID6_PARANOIA && defined(CONFIG_SMP)
  60. # define CHECK_DEVLOCK() assert_spin_locked(&conf->device_lock)
  61. #else
  62. # define CHECK_DEVLOCK()
  63. #endif
  64. #define PRINTK(x...) ((void)(RAID6_DEBUG && printk(KERN_DEBUG x)))
  65. #if RAID6_DEBUG
  66. #undef inline
  67. #undef __inline__
  68. #define inline
  69. #define __inline__
  70. #endif
  71. #if !RAID6_USE_EMPTY_ZERO_PAGE
  72. /* In .bss so it's zeroed */
  73. const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
  74. #endif
  75. static inline int raid6_next_disk(int disk, int raid_disks)
  76. {
  77. disk++;
  78. return (disk < raid_disks) ? disk : 0;
  79. }
  80. static void print_raid6_conf (raid6_conf_t *conf);
  81. static inline void __release_stripe(raid6_conf_t *conf, struct stripe_head *sh)
  82. {
  83. if (atomic_dec_and_test(&sh->count)) {
  84. if (!list_empty(&sh->lru))
  85. BUG();
  86. if (atomic_read(&conf->active_stripes)==0)
  87. BUG();
  88. if (test_bit(STRIPE_HANDLE, &sh->state)) {
  89. if (test_bit(STRIPE_DELAYED, &sh->state))
  90. list_add_tail(&sh->lru, &conf->delayed_list);
  91. else if (test_bit(STRIPE_BIT_DELAY, &sh->state) &&
  92. conf->seq_write == sh->bm_seq)
  93. list_add_tail(&sh->lru, &conf->bitmap_list);
  94. else {
  95. clear_bit(STRIPE_BIT_DELAY, &sh->state);
  96. list_add_tail(&sh->lru, &conf->handle_list);
  97. }
  98. md_wakeup_thread(conf->mddev->thread);
  99. } else {
  100. if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
  101. atomic_dec(&conf->preread_active_stripes);
  102. if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD)
  103. md_wakeup_thread(conf->mddev->thread);
  104. }
  105. list_add_tail(&sh->lru, &conf->inactive_list);
  106. atomic_dec(&conf->active_stripes);
  107. if (!conf->inactive_blocked ||
  108. atomic_read(&conf->active_stripes) < (NR_STRIPES*3/4))
  109. wake_up(&conf->wait_for_stripe);
  110. }
  111. }
  112. }
  113. static void release_stripe(struct stripe_head *sh)
  114. {
  115. raid6_conf_t *conf = sh->raid_conf;
  116. unsigned long flags;
  117. spin_lock_irqsave(&conf->device_lock, flags);
  118. __release_stripe(conf, sh);
  119. spin_unlock_irqrestore(&conf->device_lock, flags);
  120. }
  121. static void remove_hash(struct stripe_head *sh)
  122. {
  123. PRINTK("remove_hash(), stripe %llu\n", (unsigned long long)sh->sector);
  124. if (sh->hash_pprev) {
  125. if (sh->hash_next)
  126. sh->hash_next->hash_pprev = sh->hash_pprev;
  127. *sh->hash_pprev = sh->hash_next;
  128. sh->hash_pprev = NULL;
  129. }
  130. }
  131. static __inline__ void insert_hash(raid6_conf_t *conf, struct stripe_head *sh)
  132. {
  133. struct stripe_head **shp = &stripe_hash(conf, sh->sector);
  134. PRINTK("insert_hash(), stripe %llu\n", (unsigned long long)sh->sector);
  135. CHECK_DEVLOCK();
  136. if ((sh->hash_next = *shp) != NULL)
  137. (*shp)->hash_pprev = &sh->hash_next;
  138. *shp = sh;
  139. sh->hash_pprev = shp;
  140. }
  141. /* find an idle stripe, make sure it is unhashed, and return it. */
  142. static struct stripe_head *get_free_stripe(raid6_conf_t *conf)
  143. {
  144. struct stripe_head *sh = NULL;
  145. struct list_head *first;
  146. CHECK_DEVLOCK();
  147. if (list_empty(&conf->inactive_list))
  148. goto out;
  149. first = conf->inactive_list.next;
  150. sh = list_entry(first, struct stripe_head, lru);
  151. list_del_init(first);
  152. remove_hash(sh);
  153. atomic_inc(&conf->active_stripes);
  154. out:
  155. return sh;
  156. }
  157. static void shrink_buffers(struct stripe_head *sh, int num)
  158. {
  159. struct page *p;
  160. int i;
  161. for (i=0; i<num ; i++) {
  162. p = sh->dev[i].page;
  163. if (!p)
  164. continue;
  165. sh->dev[i].page = NULL;
  166. page_cache_release(p);
  167. }
  168. }
  169. static int grow_buffers(struct stripe_head *sh, int num)
  170. {
  171. int i;
  172. for (i=0; i<num; i++) {
  173. struct page *page;
  174. if (!(page = alloc_page(GFP_KERNEL))) {
  175. return 1;
  176. }
  177. sh->dev[i].page = page;
  178. }
  179. return 0;
  180. }
  181. static void raid6_build_block (struct stripe_head *sh, int i);
  182. static inline void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx)
  183. {
  184. raid6_conf_t *conf = sh->raid_conf;
  185. int disks = conf->raid_disks, i;
  186. if (atomic_read(&sh->count) != 0)
  187. BUG();
  188. if (test_bit(STRIPE_HANDLE, &sh->state))
  189. BUG();
  190. CHECK_DEVLOCK();
  191. PRINTK("init_stripe called, stripe %llu\n",
  192. (unsigned long long)sh->sector);
  193. remove_hash(sh);
  194. sh->sector = sector;
  195. sh->pd_idx = pd_idx;
  196. sh->state = 0;
  197. for (i=disks; i--; ) {
  198. struct r5dev *dev = &sh->dev[i];
  199. if (dev->toread || dev->towrite || dev->written ||
  200. test_bit(R5_LOCKED, &dev->flags)) {
  201. PRINTK("sector=%llx i=%d %p %p %p %d\n",
  202. (unsigned long long)sh->sector, i, dev->toread,
  203. dev->towrite, dev->written,
  204. test_bit(R5_LOCKED, &dev->flags));
  205. BUG();
  206. }
  207. dev->flags = 0;
  208. raid6_build_block(sh, i);
  209. }
  210. insert_hash(conf, sh);
  211. }
  212. static struct stripe_head *__find_stripe(raid6_conf_t *conf, sector_t sector)
  213. {
  214. struct stripe_head *sh;
  215. CHECK_DEVLOCK();
  216. PRINTK("__find_stripe, sector %llu\n", (unsigned long long)sector);
  217. for (sh = stripe_hash(conf, sector); sh; sh = sh->hash_next)
  218. if (sh->sector == sector)
  219. return sh;
  220. PRINTK("__stripe %llu not in cache\n", (unsigned long long)sector);
  221. return NULL;
  222. }
  223. static void unplug_slaves(mddev_t *mddev);
  224. static struct stripe_head *get_active_stripe(raid6_conf_t *conf, sector_t sector,
  225. int pd_idx, int noblock)
  226. {
  227. struct stripe_head *sh;
  228. PRINTK("get_stripe, sector %llu\n", (unsigned long long)sector);
  229. spin_lock_irq(&conf->device_lock);
  230. do {
  231. wait_event_lock_irq(conf->wait_for_stripe,
  232. conf->quiesce == 0,
  233. conf->device_lock, /* nothing */);
  234. sh = __find_stripe(conf, sector);
  235. if (!sh) {
  236. if (!conf->inactive_blocked)
  237. sh = get_free_stripe(conf);
  238. if (noblock && sh == NULL)
  239. break;
  240. if (!sh) {
  241. conf->inactive_blocked = 1;
  242. wait_event_lock_irq(conf->wait_for_stripe,
  243. !list_empty(&conf->inactive_list) &&
  244. (atomic_read(&conf->active_stripes) < (NR_STRIPES *3/4)
  245. || !conf->inactive_blocked),
  246. conf->device_lock,
  247. unplug_slaves(conf->mddev);
  248. );
  249. conf->inactive_blocked = 0;
  250. } else
  251. init_stripe(sh, sector, pd_idx);
  252. } else {
  253. if (atomic_read(&sh->count)) {
  254. if (!list_empty(&sh->lru))
  255. BUG();
  256. } else {
  257. if (!test_bit(STRIPE_HANDLE, &sh->state))
  258. atomic_inc(&conf->active_stripes);
  259. if (list_empty(&sh->lru))
  260. BUG();
  261. list_del_init(&sh->lru);
  262. }
  263. }
  264. } while (sh == NULL);
  265. if (sh)
  266. atomic_inc(&sh->count);
  267. spin_unlock_irq(&conf->device_lock);
  268. return sh;
  269. }
  270. static int grow_stripes(raid6_conf_t *conf, int num)
  271. {
  272. struct stripe_head *sh;
  273. kmem_cache_t *sc;
  274. int devs = conf->raid_disks;
  275. sprintf(conf->cache_name, "raid6/%s", mdname(conf->mddev));
  276. sc = kmem_cache_create(conf->cache_name,
  277. sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev),
  278. 0, 0, NULL, NULL);
  279. if (!sc)
  280. return 1;
  281. conf->slab_cache = sc;
  282. while (num--) {
  283. sh = kmem_cache_alloc(sc, GFP_KERNEL);
  284. if (!sh)
  285. return 1;
  286. memset(sh, 0, sizeof(*sh) + (devs-1)*sizeof(struct r5dev));
  287. sh->raid_conf = conf;
  288. spin_lock_init(&sh->lock);
  289. if (grow_buffers(sh, conf->raid_disks)) {
  290. shrink_buffers(sh, conf->raid_disks);
  291. kmem_cache_free(sc, sh);
  292. return 1;
  293. }
  294. /* we just created an active stripe so... */
  295. atomic_set(&sh->count, 1);
  296. atomic_inc(&conf->active_stripes);
  297. INIT_LIST_HEAD(&sh->lru);
  298. release_stripe(sh);
  299. }
  300. return 0;
  301. }
  302. static void shrink_stripes(raid6_conf_t *conf)
  303. {
  304. struct stripe_head *sh;
  305. while (1) {
  306. spin_lock_irq(&conf->device_lock);
  307. sh = get_free_stripe(conf);
  308. spin_unlock_irq(&conf->device_lock);
  309. if (!sh)
  310. break;
  311. if (atomic_read(&sh->count))
  312. BUG();
  313. shrink_buffers(sh, conf->raid_disks);
  314. kmem_cache_free(conf->slab_cache, sh);
  315. atomic_dec(&conf->active_stripes);
  316. }
  317. kmem_cache_destroy(conf->slab_cache);
  318. conf->slab_cache = NULL;
  319. }
  320. static int raid6_end_read_request (struct bio * bi, unsigned int bytes_done,
  321. int error)
  322. {
  323. struct stripe_head *sh = bi->bi_private;
  324. raid6_conf_t *conf = sh->raid_conf;
  325. int disks = conf->raid_disks, i;
  326. int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
  327. if (bi->bi_size)
  328. return 1;
  329. for (i=0 ; i<disks; i++)
  330. if (bi == &sh->dev[i].req)
  331. break;
  332. PRINTK("end_read_request %llu/%d, count: %d, uptodate %d.\n",
  333. (unsigned long long)sh->sector, i, atomic_read(&sh->count),
  334. uptodate);
  335. if (i == disks) {
  336. BUG();
  337. return 0;
  338. }
  339. if (uptodate) {
  340. #if 0
  341. struct bio *bio;
  342. unsigned long flags;
  343. spin_lock_irqsave(&conf->device_lock, flags);
  344. /* we can return a buffer if we bypassed the cache or
  345. * if the top buffer is not in highmem. If there are
  346. * multiple buffers, leave the extra work to
  347. * handle_stripe
  348. */
  349. buffer = sh->bh_read[i];
  350. if (buffer &&
  351. (!PageHighMem(buffer->b_page)
  352. || buffer->b_page == bh->b_page )
  353. ) {
  354. sh->bh_read[i] = buffer->b_reqnext;
  355. buffer->b_reqnext = NULL;
  356. } else
  357. buffer = NULL;
  358. spin_unlock_irqrestore(&conf->device_lock, flags);
  359. if (sh->bh_page[i]==bh->b_page)
  360. set_buffer_uptodate(bh);
  361. if (buffer) {
  362. if (buffer->b_page != bh->b_page)
  363. memcpy(buffer->b_data, bh->b_data, bh->b_size);
  364. buffer->b_end_io(buffer, 1);
  365. }
  366. #else
  367. set_bit(R5_UPTODATE, &sh->dev[i].flags);
  368. #endif
  369. } else {
  370. md_error(conf->mddev, conf->disks[i].rdev);
  371. clear_bit(R5_UPTODATE, &sh->dev[i].flags);
  372. }
  373. rdev_dec_pending(conf->disks[i].rdev, conf->mddev);
  374. #if 0
  375. /* must restore b_page before unlocking buffer... */
  376. if (sh->bh_page[i] != bh->b_page) {
  377. bh->b_page = sh->bh_page[i];
  378. bh->b_data = page_address(bh->b_page);
  379. clear_buffer_uptodate(bh);
  380. }
  381. #endif
  382. clear_bit(R5_LOCKED, &sh->dev[i].flags);
  383. set_bit(STRIPE_HANDLE, &sh->state);
  384. release_stripe(sh);
  385. return 0;
  386. }
  387. static int raid6_end_write_request (struct bio *bi, unsigned int bytes_done,
  388. int error)
  389. {
  390. struct stripe_head *sh = bi->bi_private;
  391. raid6_conf_t *conf = sh->raid_conf;
  392. int disks = conf->raid_disks, i;
  393. unsigned long flags;
  394. int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
  395. if (bi->bi_size)
  396. return 1;
  397. for (i=0 ; i<disks; i++)
  398. if (bi == &sh->dev[i].req)
  399. break;
  400. PRINTK("end_write_request %llu/%d, count %d, uptodate: %d.\n",
  401. (unsigned long long)sh->sector, i, atomic_read(&sh->count),
  402. uptodate);
  403. if (i == disks) {
  404. BUG();
  405. return 0;
  406. }
  407. spin_lock_irqsave(&conf->device_lock, flags);
  408. if (!uptodate)
  409. md_error(conf->mddev, conf->disks[i].rdev);
  410. rdev_dec_pending(conf->disks[i].rdev, conf->mddev);
  411. clear_bit(R5_LOCKED, &sh->dev[i].flags);
  412. set_bit(STRIPE_HANDLE, &sh->state);
  413. __release_stripe(conf, sh);
  414. spin_unlock_irqrestore(&conf->device_lock, flags);
  415. return 0;
  416. }
  417. static sector_t compute_blocknr(struct stripe_head *sh, int i);
  418. static void raid6_build_block (struct stripe_head *sh, int i)
  419. {
  420. struct r5dev *dev = &sh->dev[i];
  421. int pd_idx = sh->pd_idx;
  422. int qd_idx = raid6_next_disk(pd_idx, sh->raid_conf->raid_disks);
  423. bio_init(&dev->req);
  424. dev->req.bi_io_vec = &dev->vec;
  425. dev->req.bi_vcnt++;
  426. dev->req.bi_max_vecs++;
  427. dev->vec.bv_page = dev->page;
  428. dev->vec.bv_len = STRIPE_SIZE;
  429. dev->vec.bv_offset = 0;
  430. dev->req.bi_sector = sh->sector;
  431. dev->req.bi_private = sh;
  432. dev->flags = 0;
  433. if (i != pd_idx && i != qd_idx)
  434. dev->sector = compute_blocknr(sh, i);
  435. }
  436. static void error(mddev_t *mddev, mdk_rdev_t *rdev)
  437. {
  438. char b[BDEVNAME_SIZE];
  439. raid6_conf_t *conf = (raid6_conf_t *) mddev->private;
  440. PRINTK("raid6: error called\n");
  441. if (!rdev->faulty) {
  442. mddev->sb_dirty = 1;
  443. if (rdev->in_sync) {
  444. conf->working_disks--;
  445. mddev->degraded++;
  446. conf->failed_disks++;
  447. rdev->in_sync = 0;
  448. /*
  449. * if recovery was running, make sure it aborts.
  450. */
  451. set_bit(MD_RECOVERY_ERR, &mddev->recovery);
  452. }
  453. rdev->faulty = 1;
  454. printk (KERN_ALERT
  455. "raid6: Disk failure on %s, disabling device."
  456. " Operation continuing on %d devices\n",
  457. bdevname(rdev->bdev,b), conf->working_disks);
  458. }
  459. }
  460. /*
  461. * Input: a 'big' sector number,
  462. * Output: index of the data and parity disk, and the sector # in them.
  463. */
  464. static sector_t raid6_compute_sector(sector_t r_sector, unsigned int raid_disks,
  465. unsigned int data_disks, unsigned int * dd_idx,
  466. unsigned int * pd_idx, raid6_conf_t *conf)
  467. {
  468. long stripe;
  469. unsigned long chunk_number;
  470. unsigned int chunk_offset;
  471. sector_t new_sector;
  472. int sectors_per_chunk = conf->chunk_size >> 9;
  473. /* First compute the information on this sector */
  474. /*
  475. * Compute the chunk number and the sector offset inside the chunk
  476. */
  477. chunk_offset = sector_div(r_sector, sectors_per_chunk);
  478. chunk_number = r_sector;
  479. if ( r_sector != chunk_number ) {
  480. printk(KERN_CRIT "raid6: ERROR: r_sector = %llu, chunk_number = %lu\n",
  481. (unsigned long long)r_sector, (unsigned long)chunk_number);
  482. BUG();
  483. }
  484. /*
  485. * Compute the stripe number
  486. */
  487. stripe = chunk_number / data_disks;
  488. /*
  489. * Compute the data disk and parity disk indexes inside the stripe
  490. */
  491. *dd_idx = chunk_number % data_disks;
  492. /*
  493. * Select the parity disk based on the user selected algorithm.
  494. */
  495. /**** FIX THIS ****/
  496. switch (conf->algorithm) {
  497. case ALGORITHM_LEFT_ASYMMETRIC:
  498. *pd_idx = raid_disks - 1 - (stripe % raid_disks);
  499. if (*pd_idx == raid_disks-1)
  500. (*dd_idx)++; /* Q D D D P */
  501. else if (*dd_idx >= *pd_idx)
  502. (*dd_idx) += 2; /* D D P Q D */
  503. break;
  504. case ALGORITHM_RIGHT_ASYMMETRIC:
  505. *pd_idx = stripe % raid_disks;
  506. if (*pd_idx == raid_disks-1)
  507. (*dd_idx)++; /* Q D D D P */
  508. else if (*dd_idx >= *pd_idx)
  509. (*dd_idx) += 2; /* D D P Q D */
  510. break;
  511. case ALGORITHM_LEFT_SYMMETRIC:
  512. *pd_idx = raid_disks - 1 - (stripe % raid_disks);
  513. *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks;
  514. break;
  515. case ALGORITHM_RIGHT_SYMMETRIC:
  516. *pd_idx = stripe % raid_disks;
  517. *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks;
  518. break;
  519. default:
  520. printk (KERN_CRIT "raid6: unsupported algorithm %d\n",
  521. conf->algorithm);
  522. }
  523. PRINTK("raid6: chunk_number = %lu, pd_idx = %u, dd_idx = %u\n",
  524. chunk_number, *pd_idx, *dd_idx);
  525. /*
  526. * Finally, compute the new sector number
  527. */
  528. new_sector = (sector_t) stripe * sectors_per_chunk + chunk_offset;
  529. return new_sector;
  530. }
  531. static sector_t compute_blocknr(struct stripe_head *sh, int i)
  532. {
  533. raid6_conf_t *conf = sh->raid_conf;
  534. int raid_disks = conf->raid_disks, data_disks = raid_disks - 2;
  535. sector_t new_sector = sh->sector, check;
  536. int sectors_per_chunk = conf->chunk_size >> 9;
  537. sector_t stripe;
  538. int chunk_offset;
  539. int chunk_number, dummy1, dummy2, dd_idx = i;
  540. sector_t r_sector;
  541. int i0 = i;
  542. chunk_offset = sector_div(new_sector, sectors_per_chunk);
  543. stripe = new_sector;
  544. if ( new_sector != stripe ) {
  545. printk(KERN_CRIT "raid6: ERROR: new_sector = %llu, stripe = %lu\n",
  546. (unsigned long long)new_sector, (unsigned long)stripe);
  547. BUG();
  548. }
  549. switch (conf->algorithm) {
  550. case ALGORITHM_LEFT_ASYMMETRIC:
  551. case ALGORITHM_RIGHT_ASYMMETRIC:
  552. if (sh->pd_idx == raid_disks-1)
  553. i--; /* Q D D D P */
  554. else if (i > sh->pd_idx)
  555. i -= 2; /* D D P Q D */
  556. break;
  557. case ALGORITHM_LEFT_SYMMETRIC:
  558. case ALGORITHM_RIGHT_SYMMETRIC:
  559. if (sh->pd_idx == raid_disks-1)
  560. i--; /* Q D D D P */
  561. else {
  562. /* D D P Q D */
  563. if (i < sh->pd_idx)
  564. i += raid_disks;
  565. i -= (sh->pd_idx + 2);
  566. }
  567. break;
  568. default:
  569. printk (KERN_CRIT "raid6: unsupported algorithm %d\n",
  570. conf->algorithm);
  571. }
  572. PRINTK("raid6: compute_blocknr: pd_idx = %u, i0 = %u, i = %u\n", sh->pd_idx, i0, i);
  573. chunk_number = stripe * data_disks + i;
  574. r_sector = (sector_t)chunk_number * sectors_per_chunk + chunk_offset;
  575. check = raid6_compute_sector (r_sector, raid_disks, data_disks, &dummy1, &dummy2, conf);
  576. if (check != sh->sector || dummy1 != dd_idx || dummy2 != sh->pd_idx) {
  577. printk(KERN_CRIT "raid6: compute_blocknr: map not correct\n");
  578. return 0;
  579. }
  580. return r_sector;
  581. }
  582. /*
  583. * Copy data between a page in the stripe cache, and one or more bion
  584. * The page could align with the middle of the bio, or there could be
  585. * several bion, each with several bio_vecs, which cover part of the page
  586. * Multiple bion are linked together on bi_next. There may be extras
  587. * at the end of this list. We ignore them.
  588. */
  589. static void copy_data(int frombio, struct bio *bio,
  590. struct page *page,
  591. sector_t sector)
  592. {
  593. char *pa = page_address(page);
  594. struct bio_vec *bvl;
  595. int i;
  596. int page_offset;
  597. if (bio->bi_sector >= sector)
  598. page_offset = (signed)(bio->bi_sector - sector) * 512;
  599. else
  600. page_offset = (signed)(sector - bio->bi_sector) * -512;
  601. bio_for_each_segment(bvl, bio, i) {
  602. int len = bio_iovec_idx(bio,i)->bv_len;
  603. int clen;
  604. int b_offset = 0;
  605. if (page_offset < 0) {
  606. b_offset = -page_offset;
  607. page_offset += b_offset;
  608. len -= b_offset;
  609. }
  610. if (len > 0 && page_offset + len > STRIPE_SIZE)
  611. clen = STRIPE_SIZE - page_offset;
  612. else clen = len;
  613. if (clen > 0) {
  614. char *ba = __bio_kmap_atomic(bio, i, KM_USER0);
  615. if (frombio)
  616. memcpy(pa+page_offset, ba+b_offset, clen);
  617. else
  618. memcpy(ba+b_offset, pa+page_offset, clen);
  619. __bio_kunmap_atomic(ba, KM_USER0);
  620. }
  621. if (clen < len) /* hit end of page */
  622. break;
  623. page_offset += len;
  624. }
  625. }
  626. #define check_xor() do { \
  627. if (count == MAX_XOR_BLOCKS) { \
  628. xor_block(count, STRIPE_SIZE, ptr); \
  629. count = 1; \
  630. } \
  631. } while(0)
  632. /* Compute P and Q syndromes */
  633. static void compute_parity(struct stripe_head *sh, int method)
  634. {
  635. raid6_conf_t *conf = sh->raid_conf;
  636. int i, pd_idx = sh->pd_idx, qd_idx, d0_idx, disks = conf->raid_disks, count;
  637. struct bio *chosen;
  638. /**** FIX THIS: This could be very bad if disks is close to 256 ****/
  639. void *ptrs[disks];
  640. qd_idx = raid6_next_disk(pd_idx, disks);
  641. d0_idx = raid6_next_disk(qd_idx, disks);
  642. PRINTK("compute_parity, stripe %llu, method %d\n",
  643. (unsigned long long)sh->sector, method);
  644. switch(method) {
  645. case READ_MODIFY_WRITE:
  646. BUG(); /* READ_MODIFY_WRITE N/A for RAID-6 */
  647. case RECONSTRUCT_WRITE:
  648. for (i= disks; i-- ;)
  649. if ( i != pd_idx && i != qd_idx && sh->dev[i].towrite ) {
  650. chosen = sh->dev[i].towrite;
  651. sh->dev[i].towrite = NULL;
  652. if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
  653. wake_up(&conf->wait_for_overlap);
  654. if (sh->dev[i].written) BUG();
  655. sh->dev[i].written = chosen;
  656. }
  657. break;
  658. case CHECK_PARITY:
  659. BUG(); /* Not implemented yet */
  660. }
  661. for (i = disks; i--;)
  662. if (sh->dev[i].written) {
  663. sector_t sector = sh->dev[i].sector;
  664. struct bio *wbi = sh->dev[i].written;
  665. while (wbi && wbi->bi_sector < sector + STRIPE_SECTORS) {
  666. copy_data(1, wbi, sh->dev[i].page, sector);
  667. wbi = r5_next_bio(wbi, sector);
  668. }
  669. set_bit(R5_LOCKED, &sh->dev[i].flags);
  670. set_bit(R5_UPTODATE, &sh->dev[i].flags);
  671. }
  672. // switch(method) {
  673. // case RECONSTRUCT_WRITE:
  674. // case CHECK_PARITY:
  675. // case UPDATE_PARITY:
  676. /* Note that unlike RAID-5, the ordering of the disks matters greatly. */
  677. /* FIX: Is this ordering of drives even remotely optimal? */
  678. count = 0;
  679. i = d0_idx;
  680. do {
  681. ptrs[count++] = page_address(sh->dev[i].page);
  682. if (count <= disks-2 && !test_bit(R5_UPTODATE, &sh->dev[i].flags))
  683. printk("block %d/%d not uptodate on parity calc\n", i,count);
  684. i = raid6_next_disk(i, disks);
  685. } while ( i != d0_idx );
  686. // break;
  687. // }
  688. raid6_call.gen_syndrome(disks, STRIPE_SIZE, ptrs);
  689. switch(method) {
  690. case RECONSTRUCT_WRITE:
  691. set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
  692. set_bit(R5_UPTODATE, &sh->dev[qd_idx].flags);
  693. set_bit(R5_LOCKED, &sh->dev[pd_idx].flags);
  694. set_bit(R5_LOCKED, &sh->dev[qd_idx].flags);
  695. break;
  696. case UPDATE_PARITY:
  697. set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
  698. set_bit(R5_UPTODATE, &sh->dev[qd_idx].flags);
  699. break;
  700. }
  701. }
  702. /* Compute one missing block */
  703. static void compute_block_1(struct stripe_head *sh, int dd_idx)
  704. {
  705. raid6_conf_t *conf = sh->raid_conf;
  706. int i, count, disks = conf->raid_disks;
  707. void *ptr[MAX_XOR_BLOCKS], *p;
  708. int pd_idx = sh->pd_idx;
  709. int qd_idx = raid6_next_disk(pd_idx, disks);
  710. PRINTK("compute_block_1, stripe %llu, idx %d\n",
  711. (unsigned long long)sh->sector, dd_idx);
  712. if ( dd_idx == qd_idx ) {
  713. /* We're actually computing the Q drive */
  714. compute_parity(sh, UPDATE_PARITY);
  715. } else {
  716. ptr[0] = page_address(sh->dev[dd_idx].page);
  717. memset(ptr[0], 0, STRIPE_SIZE);
  718. count = 1;
  719. for (i = disks ; i--; ) {
  720. if (i == dd_idx || i == qd_idx)
  721. continue;
  722. p = page_address(sh->dev[i].page);
  723. if (test_bit(R5_UPTODATE, &sh->dev[i].flags))
  724. ptr[count++] = p;
  725. else
  726. printk("compute_block() %d, stripe %llu, %d"
  727. " not present\n", dd_idx,
  728. (unsigned long long)sh->sector, i);
  729. check_xor();
  730. }
  731. if (count != 1)
  732. xor_block(count, STRIPE_SIZE, ptr);
  733. set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags);
  734. }
  735. }
  736. /* Compute two missing blocks */
  737. static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2)
  738. {
  739. raid6_conf_t *conf = sh->raid_conf;
  740. int i, count, disks = conf->raid_disks;
  741. int pd_idx = sh->pd_idx;
  742. int qd_idx = raid6_next_disk(pd_idx, disks);
  743. int d0_idx = raid6_next_disk(qd_idx, disks);
  744. int faila, failb;
  745. /* faila and failb are disk numbers relative to d0_idx */
  746. /* pd_idx become disks-2 and qd_idx become disks-1 */
  747. faila = (dd_idx1 < d0_idx) ? dd_idx1+(disks-d0_idx) : dd_idx1-d0_idx;
  748. failb = (dd_idx2 < d0_idx) ? dd_idx2+(disks-d0_idx) : dd_idx2-d0_idx;
  749. BUG_ON(faila == failb);
  750. if ( failb < faila ) { int tmp = faila; faila = failb; failb = tmp; }
  751. PRINTK("compute_block_2, stripe %llu, idx %d,%d (%d,%d)\n",
  752. (unsigned long long)sh->sector, dd_idx1, dd_idx2, faila, failb);
  753. if ( failb == disks-1 ) {
  754. /* Q disk is one of the missing disks */
  755. if ( faila == disks-2 ) {
  756. /* Missing P+Q, just recompute */
  757. compute_parity(sh, UPDATE_PARITY);
  758. return;
  759. } else {
  760. /* We're missing D+Q; recompute D from P */
  761. compute_block_1(sh, (dd_idx1 == qd_idx) ? dd_idx2 : dd_idx1);
  762. compute_parity(sh, UPDATE_PARITY); /* Is this necessary? */
  763. return;
  764. }
  765. }
  766. /* We're missing D+P or D+D; build pointer table */
  767. {
  768. /**** FIX THIS: This could be very bad if disks is close to 256 ****/
  769. void *ptrs[disks];
  770. count = 0;
  771. i = d0_idx;
  772. do {
  773. ptrs[count++] = page_address(sh->dev[i].page);
  774. i = raid6_next_disk(i, disks);
  775. if (i != dd_idx1 && i != dd_idx2 &&
  776. !test_bit(R5_UPTODATE, &sh->dev[i].flags))
  777. printk("compute_2 with missing block %d/%d\n", count, i);
  778. } while ( i != d0_idx );
  779. if ( failb == disks-2 ) {
  780. /* We're missing D+P. */
  781. raid6_datap_recov(disks, STRIPE_SIZE, faila, ptrs);
  782. } else {
  783. /* We're missing D+D. */
  784. raid6_2data_recov(disks, STRIPE_SIZE, faila, failb, ptrs);
  785. }
  786. /* Both the above update both missing blocks */
  787. set_bit(R5_UPTODATE, &sh->dev[dd_idx1].flags);
  788. set_bit(R5_UPTODATE, &sh->dev[dd_idx2].flags);
  789. }
  790. }
  791. /*
  792. * Each stripe/dev can have one or more bion attached.
  793. * toread/towrite point to the first in a chain.
  794. * The bi_next chain must be in order.
  795. */
  796. static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite)
  797. {
  798. struct bio **bip;
  799. raid6_conf_t *conf = sh->raid_conf;
  800. int firstwrite=0;
  801. PRINTK("adding bh b#%llu to stripe s#%llu\n",
  802. (unsigned long long)bi->bi_sector,
  803. (unsigned long long)sh->sector);
  804. spin_lock(&sh->lock);
  805. spin_lock_irq(&conf->device_lock);
  806. if (forwrite) {
  807. bip = &sh->dev[dd_idx].towrite;
  808. if (*bip == NULL && sh->dev[dd_idx].written == NULL)
  809. firstwrite = 1;
  810. } else
  811. bip = &sh->dev[dd_idx].toread;
  812. while (*bip && (*bip)->bi_sector < bi->bi_sector) {
  813. if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector)
  814. goto overlap;
  815. bip = &(*bip)->bi_next;
  816. }
  817. if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9))
  818. goto overlap;
  819. if (*bip && bi->bi_next && (*bip) != bi->bi_next)
  820. BUG();
  821. if (*bip)
  822. bi->bi_next = *bip;
  823. *bip = bi;
  824. bi->bi_phys_segments ++;
  825. spin_unlock_irq(&conf->device_lock);
  826. spin_unlock(&sh->lock);
  827. PRINTK("added bi b#%llu to stripe s#%llu, disk %d.\n",
  828. (unsigned long long)bi->bi_sector,
  829. (unsigned long long)sh->sector, dd_idx);
  830. if (conf->mddev->bitmap && firstwrite) {
  831. sh->bm_seq = conf->seq_write;
  832. bitmap_startwrite(conf->mddev->bitmap, sh->sector,
  833. STRIPE_SECTORS, 0);
  834. set_bit(STRIPE_BIT_DELAY, &sh->state);
  835. }
  836. if (forwrite) {
  837. /* check if page is covered */
  838. sector_t sector = sh->dev[dd_idx].sector;
  839. for (bi=sh->dev[dd_idx].towrite;
  840. sector < sh->dev[dd_idx].sector + STRIPE_SECTORS &&
  841. bi && bi->bi_sector <= sector;
  842. bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) {
  843. if (bi->bi_sector + (bi->bi_size>>9) >= sector)
  844. sector = bi->bi_sector + (bi->bi_size>>9);
  845. }
  846. if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS)
  847. set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags);
  848. }
  849. return 1;
  850. overlap:
  851. set_bit(R5_Overlap, &sh->dev[dd_idx].flags);
  852. spin_unlock_irq(&conf->device_lock);
  853. spin_unlock(&sh->lock);
  854. return 0;
  855. }
  856. /*
  857. * handle_stripe - do things to a stripe.
  858. *
  859. * We lock the stripe and then examine the state of various bits
  860. * to see what needs to be done.
  861. * Possible results:
  862. * return some read request which now have data
  863. * return some write requests which are safely on disc
  864. * schedule a read on some buffers
  865. * schedule a write of some buffers
  866. * return confirmation of parity correctness
  867. *
  868. * Parity calculations are done inside the stripe lock
  869. * buffers are taken off read_list or write_list, and bh_cache buffers
  870. * get BH_Lock set before the stripe lock is released.
  871. *
  872. */
  873. static void handle_stripe(struct stripe_head *sh)
  874. {
  875. raid6_conf_t *conf = sh->raid_conf;
  876. int disks = conf->raid_disks;
  877. struct bio *return_bi= NULL;
  878. struct bio *bi;
  879. int i;
  880. int syncing;
  881. int locked=0, uptodate=0, to_read=0, to_write=0, failed=0, written=0;
  882. int non_overwrite = 0;
  883. int failed_num[2] = {0, 0};
  884. struct r5dev *dev, *pdev, *qdev;
  885. int pd_idx = sh->pd_idx;
  886. int qd_idx = raid6_next_disk(pd_idx, disks);
  887. int p_failed, q_failed;
  888. PRINTK("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d, qd_idx=%d\n",
  889. (unsigned long long)sh->sector, sh->state, atomic_read(&sh->count),
  890. pd_idx, qd_idx);
  891. spin_lock(&sh->lock);
  892. clear_bit(STRIPE_HANDLE, &sh->state);
  893. clear_bit(STRIPE_DELAYED, &sh->state);
  894. syncing = test_bit(STRIPE_SYNCING, &sh->state);
  895. /* Now to look around and see what can be done */
  896. for (i=disks; i--; ) {
  897. mdk_rdev_t *rdev;
  898. dev = &sh->dev[i];
  899. clear_bit(R5_Insync, &dev->flags);
  900. clear_bit(R5_Syncio, &dev->flags);
  901. PRINTK("check %d: state 0x%lx read %p write %p written %p\n",
  902. i, dev->flags, dev->toread, dev->towrite, dev->written);
  903. /* maybe we can reply to a read */
  904. if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread) {
  905. struct bio *rbi, *rbi2;
  906. PRINTK("Return read for disc %d\n", i);
  907. spin_lock_irq(&conf->device_lock);
  908. rbi = dev->toread;
  909. dev->toread = NULL;
  910. if (test_and_clear_bit(R5_Overlap, &dev->flags))
  911. wake_up(&conf->wait_for_overlap);
  912. spin_unlock_irq(&conf->device_lock);
  913. while (rbi && rbi->bi_sector < dev->sector + STRIPE_SECTORS) {
  914. copy_data(0, rbi, dev->page, dev->sector);
  915. rbi2 = r5_next_bio(rbi, dev->sector);
  916. spin_lock_irq(&conf->device_lock);
  917. if (--rbi->bi_phys_segments == 0) {
  918. rbi->bi_next = return_bi;
  919. return_bi = rbi;
  920. }
  921. spin_unlock_irq(&conf->device_lock);
  922. rbi = rbi2;
  923. }
  924. }
  925. /* now count some things */
  926. if (test_bit(R5_LOCKED, &dev->flags)) locked++;
  927. if (test_bit(R5_UPTODATE, &dev->flags)) uptodate++;
  928. if (dev->toread) to_read++;
  929. if (dev->towrite) {
  930. to_write++;
  931. if (!test_bit(R5_OVERWRITE, &dev->flags))
  932. non_overwrite++;
  933. }
  934. if (dev->written) written++;
  935. rdev = conf->disks[i].rdev; /* FIXME, should I be looking rdev */
  936. if (!rdev || !rdev->in_sync) {
  937. if ( failed < 2 )
  938. failed_num[failed] = i;
  939. failed++;
  940. } else
  941. set_bit(R5_Insync, &dev->flags);
  942. }
  943. PRINTK("locked=%d uptodate=%d to_read=%d"
  944. " to_write=%d failed=%d failed_num=%d,%d\n",
  945. locked, uptodate, to_read, to_write, failed,
  946. failed_num[0], failed_num[1]);
  947. /* check if the array has lost >2 devices and, if so, some requests might
  948. * need to be failed
  949. */
  950. if (failed > 2 && to_read+to_write+written) {
  951. for (i=disks; i--; ) {
  952. int bitmap_end = 0;
  953. spin_lock_irq(&conf->device_lock);
  954. /* fail all writes first */
  955. bi = sh->dev[i].towrite;
  956. sh->dev[i].towrite = NULL;
  957. if (bi) { to_write--; bitmap_end = 1; }
  958. if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
  959. wake_up(&conf->wait_for_overlap);
  960. while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS){
  961. struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector);
  962. clear_bit(BIO_UPTODATE, &bi->bi_flags);
  963. if (--bi->bi_phys_segments == 0) {
  964. md_write_end(conf->mddev);
  965. bi->bi_next = return_bi;
  966. return_bi = bi;
  967. }
  968. bi = nextbi;
  969. }
  970. /* and fail all 'written' */
  971. bi = sh->dev[i].written;
  972. sh->dev[i].written = NULL;
  973. if (bi) bitmap_end = 1;
  974. while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) {
  975. struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector);
  976. clear_bit(BIO_UPTODATE, &bi->bi_flags);
  977. if (--bi->bi_phys_segments == 0) {
  978. md_write_end(conf->mddev);
  979. bi->bi_next = return_bi;
  980. return_bi = bi;
  981. }
  982. bi = bi2;
  983. }
  984. /* fail any reads if this device is non-operational */
  985. if (!test_bit(R5_Insync, &sh->dev[i].flags)) {
  986. bi = sh->dev[i].toread;
  987. sh->dev[i].toread = NULL;
  988. if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
  989. wake_up(&conf->wait_for_overlap);
  990. if (bi) to_read--;
  991. while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS){
  992. struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector);
  993. clear_bit(BIO_UPTODATE, &bi->bi_flags);
  994. if (--bi->bi_phys_segments == 0) {
  995. bi->bi_next = return_bi;
  996. return_bi = bi;
  997. }
  998. bi = nextbi;
  999. }
  1000. }
  1001. spin_unlock_irq(&conf->device_lock);
  1002. if (bitmap_end)
  1003. bitmap_endwrite(conf->mddev->bitmap, sh->sector,
  1004. STRIPE_SECTORS, 0, 0);
  1005. }
  1006. }
  1007. if (failed > 2 && syncing) {
  1008. md_done_sync(conf->mddev, STRIPE_SECTORS,0);
  1009. clear_bit(STRIPE_SYNCING, &sh->state);
  1010. syncing = 0;
  1011. }
  1012. /*
  1013. * might be able to return some write requests if the parity blocks
  1014. * are safe, or on a failed drive
  1015. */
  1016. pdev = &sh->dev[pd_idx];
  1017. p_failed = (failed >= 1 && failed_num[0] == pd_idx)
  1018. || (failed >= 2 && failed_num[1] == pd_idx);
  1019. qdev = &sh->dev[qd_idx];
  1020. q_failed = (failed >= 1 && failed_num[0] == qd_idx)
  1021. || (failed >= 2 && failed_num[1] == qd_idx);
  1022. if ( written &&
  1023. ( p_failed || ((test_bit(R5_Insync, &pdev->flags)
  1024. && !test_bit(R5_LOCKED, &pdev->flags)
  1025. && test_bit(R5_UPTODATE, &pdev->flags))) ) &&
  1026. ( q_failed || ((test_bit(R5_Insync, &qdev->flags)
  1027. && !test_bit(R5_LOCKED, &qdev->flags)
  1028. && test_bit(R5_UPTODATE, &qdev->flags))) ) ) {
  1029. /* any written block on an uptodate or failed drive can be
  1030. * returned. Note that if we 'wrote' to a failed drive,
  1031. * it will be UPTODATE, but never LOCKED, so we don't need
  1032. * to test 'failed' directly.
  1033. */
  1034. for (i=disks; i--; )
  1035. if (sh->dev[i].written) {
  1036. dev = &sh->dev[i];
  1037. if (!test_bit(R5_LOCKED, &dev->flags) &&
  1038. test_bit(R5_UPTODATE, &dev->flags) ) {
  1039. /* We can return any write requests */
  1040. int bitmap_end = 0;
  1041. struct bio *wbi, *wbi2;
  1042. PRINTK("Return write for stripe %llu disc %d\n",
  1043. (unsigned long long)sh->sector, i);
  1044. spin_lock_irq(&conf->device_lock);
  1045. wbi = dev->written;
  1046. dev->written = NULL;
  1047. while (wbi && wbi->bi_sector < dev->sector + STRIPE_SECTORS) {
  1048. wbi2 = r5_next_bio(wbi, dev->sector);
  1049. if (--wbi->bi_phys_segments == 0) {
  1050. md_write_end(conf->mddev);
  1051. wbi->bi_next = return_bi;
  1052. return_bi = wbi;
  1053. }
  1054. wbi = wbi2;
  1055. }
  1056. if (dev->towrite == NULL)
  1057. bitmap_end = 1;
  1058. spin_unlock_irq(&conf->device_lock);
  1059. if (bitmap_end)
  1060. bitmap_endwrite(conf->mddev->bitmap, sh->sector,
  1061. STRIPE_SECTORS,
  1062. !test_bit(STRIPE_DEGRADED, &sh->state), 0);
  1063. }
  1064. }
  1065. }
  1066. /* Now we might consider reading some blocks, either to check/generate
  1067. * parity, or to satisfy requests
  1068. * or to load a block that is being partially written.
  1069. */
  1070. if (to_read || non_overwrite || (to_write && failed) || (syncing && (uptodate < disks))) {
  1071. for (i=disks; i--;) {
  1072. dev = &sh->dev[i];
  1073. if (!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) &&
  1074. (dev->toread ||
  1075. (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) ||
  1076. syncing ||
  1077. (failed >= 1 && (sh->dev[failed_num[0]].toread || to_write)) ||
  1078. (failed >= 2 && (sh->dev[failed_num[1]].toread || to_write))
  1079. )
  1080. ) {
  1081. /* we would like to get this block, possibly
  1082. * by computing it, but we might not be able to
  1083. */
  1084. if (uptodate == disks-1) {
  1085. PRINTK("Computing stripe %llu block %d\n",
  1086. (unsigned long long)sh->sector, i);
  1087. compute_block_1(sh, i);
  1088. uptodate++;
  1089. } else if ( uptodate == disks-2 && failed >= 2 ) {
  1090. /* Computing 2-failure is *very* expensive; only do it if failed >= 2 */
  1091. int other;
  1092. for (other=disks; other--;) {
  1093. if ( other == i )
  1094. continue;
  1095. if ( !test_bit(R5_UPTODATE, &sh->dev[other].flags) )
  1096. break;
  1097. }
  1098. BUG_ON(other < 0);
  1099. PRINTK("Computing stripe %llu blocks %d,%d\n",
  1100. (unsigned long long)sh->sector, i, other);
  1101. compute_block_2(sh, i, other);
  1102. uptodate += 2;
  1103. } else if (test_bit(R5_Insync, &dev->flags)) {
  1104. set_bit(R5_LOCKED, &dev->flags);
  1105. set_bit(R5_Wantread, &dev->flags);
  1106. #if 0
  1107. /* if I am just reading this block and we don't have
  1108. a failed drive, or any pending writes then sidestep the cache */
  1109. if (sh->bh_read[i] && !sh->bh_read[i]->b_reqnext &&
  1110. ! syncing && !failed && !to_write) {
  1111. sh->bh_cache[i]->b_page = sh->bh_read[i]->b_page;
  1112. sh->bh_cache[i]->b_data = sh->bh_read[i]->b_data;
  1113. }
  1114. #endif
  1115. locked++;
  1116. PRINTK("Reading block %d (sync=%d)\n",
  1117. i, syncing);
  1118. if (syncing)
  1119. md_sync_acct(conf->disks[i].rdev->bdev,
  1120. STRIPE_SECTORS);
  1121. }
  1122. }
  1123. }
  1124. set_bit(STRIPE_HANDLE, &sh->state);
  1125. }
  1126. /* now to consider writing and what else, if anything should be read */
  1127. if (to_write) {
  1128. int rcw=0, must_compute=0;
  1129. for (i=disks ; i--;) {
  1130. dev = &sh->dev[i];
  1131. /* Would I have to read this buffer for reconstruct_write */
  1132. if (!test_bit(R5_OVERWRITE, &dev->flags)
  1133. && i != pd_idx && i != qd_idx
  1134. && (!test_bit(R5_LOCKED, &dev->flags)
  1135. #if 0
  1136. || sh->bh_page[i] != bh->b_page
  1137. #endif
  1138. ) &&
  1139. !test_bit(R5_UPTODATE, &dev->flags)) {
  1140. if (test_bit(R5_Insync, &dev->flags)) rcw++;
  1141. else {
  1142. PRINTK("raid6: must_compute: disk %d flags=%#lx\n", i, dev->flags);
  1143. must_compute++;
  1144. }
  1145. }
  1146. }
  1147. PRINTK("for sector %llu, rcw=%d, must_compute=%d\n",
  1148. (unsigned long long)sh->sector, rcw, must_compute);
  1149. set_bit(STRIPE_HANDLE, &sh->state);
  1150. if (rcw > 0)
  1151. /* want reconstruct write, but need to get some data */
  1152. for (i=disks; i--;) {
  1153. dev = &sh->dev[i];
  1154. if (!test_bit(R5_OVERWRITE, &dev->flags)
  1155. && !(failed == 0 && (i == pd_idx || i == qd_idx))
  1156. && !test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) &&
  1157. test_bit(R5_Insync, &dev->flags)) {
  1158. if (test_bit(STRIPE_PREREAD_ACTIVE, &sh->state))
  1159. {
  1160. PRINTK("Read_old stripe %llu block %d for Reconstruct\n",
  1161. (unsigned long long)sh->sector, i);
  1162. set_bit(R5_LOCKED, &dev->flags);
  1163. set_bit(R5_Wantread, &dev->flags);
  1164. locked++;
  1165. } else {
  1166. PRINTK("Request delayed stripe %llu block %d for Reconstruct\n",
  1167. (unsigned long long)sh->sector, i);
  1168. set_bit(STRIPE_DELAYED, &sh->state);
  1169. set_bit(STRIPE_HANDLE, &sh->state);
  1170. }
  1171. }
  1172. }
  1173. /* now if nothing is locked, and if we have enough data, we can start a write request */
  1174. if (locked == 0 && rcw == 0 &&
  1175. !test_bit(STRIPE_BIT_DELAY, &sh->state)) {
  1176. if ( must_compute > 0 ) {
  1177. /* We have failed blocks and need to compute them */
  1178. switch ( failed ) {
  1179. case 0: BUG();
  1180. case 1: compute_block_1(sh, failed_num[0]); break;
  1181. case 2: compute_block_2(sh, failed_num[0], failed_num[1]); break;
  1182. default: BUG(); /* This request should have been failed? */
  1183. }
  1184. }
  1185. PRINTK("Computing parity for stripe %llu\n", (unsigned long long)sh->sector);
  1186. compute_parity(sh, RECONSTRUCT_WRITE);
  1187. /* now every locked buffer is ready to be written */
  1188. for (i=disks; i--;)
  1189. if (test_bit(R5_LOCKED, &sh->dev[i].flags)) {
  1190. PRINTK("Writing stripe %llu block %d\n",
  1191. (unsigned long long)sh->sector, i);
  1192. locked++;
  1193. set_bit(R5_Wantwrite, &sh->dev[i].flags);
  1194. #if 0 /**** FIX: I don't understand the logic here... ****/
  1195. if (!test_bit(R5_Insync, &sh->dev[i].flags)
  1196. || ((i==pd_idx || i==qd_idx) && failed == 0)) /* FIX? */
  1197. set_bit(STRIPE_INSYNC, &sh->state);
  1198. #endif
  1199. }
  1200. if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
  1201. atomic_dec(&conf->preread_active_stripes);
  1202. if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD)
  1203. md_wakeup_thread(conf->mddev->thread);
  1204. }
  1205. }
  1206. }
  1207. /* maybe we need to check and possibly fix the parity for this stripe
  1208. * Any reads will already have been scheduled, so we just see if enough data
  1209. * is available
  1210. */
  1211. if (syncing && locked == 0 &&
  1212. !test_bit(STRIPE_INSYNC, &sh->state) && failed <= 2) {
  1213. set_bit(STRIPE_HANDLE, &sh->state);
  1214. #if 0 /* RAID-6: Don't support CHECK PARITY yet */
  1215. if (failed == 0) {
  1216. char *pagea;
  1217. if (uptodate != disks)
  1218. BUG();
  1219. compute_parity(sh, CHECK_PARITY);
  1220. uptodate--;
  1221. pagea = page_address(sh->dev[pd_idx].page);
  1222. if ((*(u32*)pagea) == 0 &&
  1223. !memcmp(pagea, pagea+4, STRIPE_SIZE-4)) {
  1224. /* parity is correct (on disc, not in buffer any more) */
  1225. set_bit(STRIPE_INSYNC, &sh->state);
  1226. }
  1227. }
  1228. #endif
  1229. if (!test_bit(STRIPE_INSYNC, &sh->state)) {
  1230. int failed_needupdate[2];
  1231. struct r5dev *adev, *bdev;
  1232. if ( failed < 1 )
  1233. failed_num[0] = pd_idx;
  1234. if ( failed < 2 )
  1235. failed_num[1] = (failed_num[0] == qd_idx) ? pd_idx : qd_idx;
  1236. failed_needupdate[0] = !test_bit(R5_UPTODATE, &sh->dev[failed_num[0]].flags);
  1237. failed_needupdate[1] = !test_bit(R5_UPTODATE, &sh->dev[failed_num[1]].flags);
  1238. PRINTK("sync: failed=%d num=%d,%d fnu=%u%u\n",
  1239. failed, failed_num[0], failed_num[1], failed_needupdate[0], failed_needupdate[1]);
  1240. #if 0 /* RAID-6: This code seems to require that CHECK_PARITY destroys the uptodateness of the parity */
  1241. /* should be able to compute the missing block(s) and write to spare */
  1242. if ( failed_needupdate[0] ^ failed_needupdate[1] ) {
  1243. if (uptodate+1 != disks)
  1244. BUG();
  1245. compute_block_1(sh, failed_needupdate[0] ? failed_num[0] : failed_num[1]);
  1246. uptodate++;
  1247. } else if ( failed_needupdate[0] & failed_needupdate[1] ) {
  1248. if (uptodate+2 != disks)
  1249. BUG();
  1250. compute_block_2(sh, failed_num[0], failed_num[1]);
  1251. uptodate += 2;
  1252. }
  1253. #else
  1254. compute_block_2(sh, failed_num[0], failed_num[1]);
  1255. uptodate += failed_needupdate[0] + failed_needupdate[1];
  1256. #endif
  1257. if (uptodate != disks)
  1258. BUG();
  1259. PRINTK("Marking for sync stripe %llu blocks %d,%d\n",
  1260. (unsigned long long)sh->sector, failed_num[0], failed_num[1]);
  1261. /**** FIX: Should we really do both of these unconditionally? ****/
  1262. adev = &sh->dev[failed_num[0]];
  1263. locked += !test_bit(R5_LOCKED, &adev->flags);
  1264. set_bit(R5_LOCKED, &adev->flags);
  1265. set_bit(R5_Wantwrite, &adev->flags);
  1266. bdev = &sh->dev[failed_num[1]];
  1267. locked += !test_bit(R5_LOCKED, &bdev->flags);
  1268. set_bit(R5_LOCKED, &bdev->flags);
  1269. clear_bit(STRIPE_DEGRADED, &sh->state);
  1270. set_bit(R5_Wantwrite, &bdev->flags);
  1271. set_bit(STRIPE_INSYNC, &sh->state);
  1272. set_bit(R5_Syncio, &adev->flags);
  1273. set_bit(R5_Syncio, &bdev->flags);
  1274. }
  1275. }
  1276. if (syncing && locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) {
  1277. md_done_sync(conf->mddev, STRIPE_SECTORS,1);
  1278. clear_bit(STRIPE_SYNCING, &sh->state);
  1279. }
  1280. spin_unlock(&sh->lock);
  1281. while ((bi=return_bi)) {
  1282. int bytes = bi->bi_size;
  1283. return_bi = bi->bi_next;
  1284. bi->bi_next = NULL;
  1285. bi->bi_size = 0;
  1286. bi->bi_end_io(bi, bytes, 0);
  1287. }
  1288. for (i=disks; i-- ;) {
  1289. int rw;
  1290. struct bio *bi;
  1291. mdk_rdev_t *rdev;
  1292. if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags))
  1293. rw = 1;
  1294. else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags))
  1295. rw = 0;
  1296. else
  1297. continue;
  1298. bi = &sh->dev[i].req;
  1299. bi->bi_rw = rw;
  1300. if (rw)
  1301. bi->bi_end_io = raid6_end_write_request;
  1302. else
  1303. bi->bi_end_io = raid6_end_read_request;
  1304. rcu_read_lock();
  1305. rdev = conf->disks[i].rdev;
  1306. if (rdev && rdev->faulty)
  1307. rdev = NULL;
  1308. if (rdev)
  1309. atomic_inc(&rdev->nr_pending);
  1310. rcu_read_unlock();
  1311. if (rdev) {
  1312. if (test_bit(R5_Syncio, &sh->dev[i].flags))
  1313. md_sync_acct(rdev->bdev, STRIPE_SECTORS);
  1314. bi->bi_bdev = rdev->bdev;
  1315. PRINTK("for %llu schedule op %ld on disc %d\n",
  1316. (unsigned long long)sh->sector, bi->bi_rw, i);
  1317. atomic_inc(&sh->count);
  1318. bi->bi_sector = sh->sector + rdev->data_offset;
  1319. bi->bi_flags = 1 << BIO_UPTODATE;
  1320. bi->bi_vcnt = 1;
  1321. bi->bi_max_vecs = 1;
  1322. bi->bi_idx = 0;
  1323. bi->bi_io_vec = &sh->dev[i].vec;
  1324. bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
  1325. bi->bi_io_vec[0].bv_offset = 0;
  1326. bi->bi_size = STRIPE_SIZE;
  1327. bi->bi_next = NULL;
  1328. generic_make_request(bi);
  1329. } else {
  1330. if (rw == 1)
  1331. set_bit(STRIPE_DEGRADED, &sh->state);
  1332. PRINTK("skip op %ld on disc %d for sector %llu\n",
  1333. bi->bi_rw, i, (unsigned long long)sh->sector);
  1334. clear_bit(R5_LOCKED, &sh->dev[i].flags);
  1335. set_bit(STRIPE_HANDLE, &sh->state);
  1336. }
  1337. }
  1338. }
  1339. static inline void raid6_activate_delayed(raid6_conf_t *conf)
  1340. {
  1341. if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) {
  1342. while (!list_empty(&conf->delayed_list)) {
  1343. struct list_head *l = conf->delayed_list.next;
  1344. struct stripe_head *sh;
  1345. sh = list_entry(l, struct stripe_head, lru);
  1346. list_del_init(l);
  1347. clear_bit(STRIPE_DELAYED, &sh->state);
  1348. if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state))
  1349. atomic_inc(&conf->preread_active_stripes);
  1350. list_add_tail(&sh->lru, &conf->handle_list);
  1351. }
  1352. }
  1353. }
  1354. static inline void activate_bit_delay(raid6_conf_t *conf)
  1355. {
  1356. /* device_lock is held */
  1357. struct list_head head;
  1358. list_add(&head, &conf->bitmap_list);
  1359. list_del_init(&conf->bitmap_list);
  1360. while (!list_empty(&head)) {
  1361. struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru);
  1362. list_del_init(&sh->lru);
  1363. atomic_inc(&sh->count);
  1364. __release_stripe(conf, sh);
  1365. }
  1366. }
  1367. static void unplug_slaves(mddev_t *mddev)
  1368. {
  1369. raid6_conf_t *conf = mddev_to_conf(mddev);
  1370. int i;
  1371. rcu_read_lock();
  1372. for (i=0; i<mddev->raid_disks; i++) {
  1373. mdk_rdev_t *rdev = conf->disks[i].rdev;
  1374. if (rdev && !rdev->faulty && atomic_read(&rdev->nr_pending)) {
  1375. request_queue_t *r_queue = bdev_get_queue(rdev->bdev);
  1376. atomic_inc(&rdev->nr_pending);
  1377. rcu_read_unlock();
  1378. if (r_queue->unplug_fn)
  1379. r_queue->unplug_fn(r_queue);
  1380. rdev_dec_pending(rdev, mddev);
  1381. rcu_read_lock();
  1382. }
  1383. }
  1384. rcu_read_unlock();
  1385. }
  1386. static void raid6_unplug_device(request_queue_t *q)
  1387. {
  1388. mddev_t *mddev = q->queuedata;
  1389. raid6_conf_t *conf = mddev_to_conf(mddev);
  1390. unsigned long flags;
  1391. spin_lock_irqsave(&conf->device_lock, flags);
  1392. if (blk_remove_plug(q)) {
  1393. conf->seq_flush++;
  1394. raid6_activate_delayed(conf);
  1395. }
  1396. md_wakeup_thread(mddev->thread);
  1397. spin_unlock_irqrestore(&conf->device_lock, flags);
  1398. unplug_slaves(mddev);
  1399. }
  1400. static int raid6_issue_flush(request_queue_t *q, struct gendisk *disk,
  1401. sector_t *error_sector)
  1402. {
  1403. mddev_t *mddev = q->queuedata;
  1404. raid6_conf_t *conf = mddev_to_conf(mddev);
  1405. int i, ret = 0;
  1406. rcu_read_lock();
  1407. for (i=0; i<mddev->raid_disks && ret == 0; i++) {
  1408. mdk_rdev_t *rdev = conf->disks[i].rdev;
  1409. if (rdev && !rdev->faulty) {
  1410. struct block_device *bdev = rdev->bdev;
  1411. request_queue_t *r_queue = bdev_get_queue(bdev);
  1412. if (!r_queue->issue_flush_fn)
  1413. ret = -EOPNOTSUPP;
  1414. else {
  1415. atomic_inc(&rdev->nr_pending);
  1416. rcu_read_unlock();
  1417. ret = r_queue->issue_flush_fn(r_queue, bdev->bd_disk,
  1418. error_sector);
  1419. rdev_dec_pending(rdev, mddev);
  1420. rcu_read_lock();
  1421. }
  1422. }
  1423. }
  1424. rcu_read_unlock();
  1425. return ret;
  1426. }
  1427. static inline void raid6_plug_device(raid6_conf_t *conf)
  1428. {
  1429. spin_lock_irq(&conf->device_lock);
  1430. blk_plug_device(conf->mddev->queue);
  1431. spin_unlock_irq(&conf->device_lock);
  1432. }
  1433. static int make_request (request_queue_t *q, struct bio * bi)
  1434. {
  1435. mddev_t *mddev = q->queuedata;
  1436. raid6_conf_t *conf = mddev_to_conf(mddev);
  1437. const unsigned int raid_disks = conf->raid_disks;
  1438. const unsigned int data_disks = raid_disks - 2;
  1439. unsigned int dd_idx, pd_idx;
  1440. sector_t new_sector;
  1441. sector_t logical_sector, last_sector;
  1442. struct stripe_head *sh;
  1443. if (unlikely(bio_barrier(bi))) {
  1444. bio_endio(bi, bi->bi_size, -EOPNOTSUPP);
  1445. return 0;
  1446. }
  1447. md_write_start(mddev, bi);
  1448. if (bio_data_dir(bi)==WRITE) {
  1449. disk_stat_inc(mddev->gendisk, writes);
  1450. disk_stat_add(mddev->gendisk, write_sectors, bio_sectors(bi));
  1451. } else {
  1452. disk_stat_inc(mddev->gendisk, reads);
  1453. disk_stat_add(mddev->gendisk, read_sectors, bio_sectors(bi));
  1454. }
  1455. logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1);
  1456. last_sector = bi->bi_sector + (bi->bi_size>>9);
  1457. bi->bi_next = NULL;
  1458. bi->bi_phys_segments = 1; /* over-loaded to count active stripes */
  1459. for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) {
  1460. DEFINE_WAIT(w);
  1461. new_sector = raid6_compute_sector(logical_sector,
  1462. raid_disks, data_disks, &dd_idx, &pd_idx, conf);
  1463. PRINTK("raid6: make_request, sector %llu logical %llu\n",
  1464. (unsigned long long)new_sector,
  1465. (unsigned long long)logical_sector);
  1466. retry:
  1467. prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE);
  1468. sh = get_active_stripe(conf, new_sector, pd_idx, (bi->bi_rw&RWA_MASK));
  1469. if (sh) {
  1470. if (!add_stripe_bio(sh, bi, dd_idx, (bi->bi_rw&RW_MASK))) {
  1471. /* Add failed due to overlap. Flush everything
  1472. * and wait a while
  1473. */
  1474. raid6_unplug_device(mddev->queue);
  1475. release_stripe(sh);
  1476. schedule();
  1477. goto retry;
  1478. }
  1479. finish_wait(&conf->wait_for_overlap, &w);
  1480. raid6_plug_device(conf);
  1481. handle_stripe(sh);
  1482. release_stripe(sh);
  1483. } else {
  1484. /* cannot get stripe for read-ahead, just give-up */
  1485. clear_bit(BIO_UPTODATE, &bi->bi_flags);
  1486. finish_wait(&conf->wait_for_overlap, &w);
  1487. break;
  1488. }
  1489. }
  1490. spin_lock_irq(&conf->device_lock);
  1491. if (--bi->bi_phys_segments == 0) {
  1492. int bytes = bi->bi_size;
  1493. if ( bio_data_dir(bi) == WRITE )
  1494. md_write_end(mddev);
  1495. bi->bi_size = 0;
  1496. bi->bi_end_io(bi, bytes, 0);
  1497. }
  1498. spin_unlock_irq(&conf->device_lock);
  1499. return 0;
  1500. }
  1501. /* FIXME go_faster isn't used */
  1502. static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
  1503. {
  1504. raid6_conf_t *conf = (raid6_conf_t *) mddev->private;
  1505. struct stripe_head *sh;
  1506. int sectors_per_chunk = conf->chunk_size >> 9;
  1507. sector_t x;
  1508. unsigned long stripe;
  1509. int chunk_offset;
  1510. int dd_idx, pd_idx;
  1511. sector_t first_sector;
  1512. int raid_disks = conf->raid_disks;
  1513. int data_disks = raid_disks - 2;
  1514. sector_t max_sector = mddev->size << 1;
  1515. int sync_blocks;
  1516. if (sector_nr >= max_sector) {
  1517. /* just being told to finish up .. nothing much to do */
  1518. unplug_slaves(mddev);
  1519. if (mddev->curr_resync < max_sector) /* aborted */
  1520. bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
  1521. &sync_blocks, 1);
  1522. else /* compelted sync */
  1523. conf->fullsync = 0;
  1524. bitmap_close_sync(mddev->bitmap);
  1525. return 0;
  1526. }
  1527. /* if there are 2 or more failed drives and we are trying
  1528. * to resync, then assert that we are finished, because there is
  1529. * nothing we can do.
  1530. */
  1531. if (mddev->degraded >= 2 && test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
  1532. sector_t rv = (mddev->size << 1) - sector_nr;
  1533. *skipped = 1;
  1534. return rv;
  1535. }
  1536. if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
  1537. !conf->fullsync && sync_blocks >= STRIPE_SECTORS) {
  1538. /* we can skip this block, and probably more */
  1539. sync_blocks /= STRIPE_SECTORS;
  1540. *skipped = 1;
  1541. return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */
  1542. }
  1543. x = sector_nr;
  1544. chunk_offset = sector_div(x, sectors_per_chunk);
  1545. stripe = x;
  1546. BUG_ON(x != stripe);
  1547. first_sector = raid6_compute_sector((sector_t)stripe*data_disks*sectors_per_chunk
  1548. + chunk_offset, raid_disks, data_disks, &dd_idx, &pd_idx, conf);
  1549. sh = get_active_stripe(conf, sector_nr, pd_idx, 1);
  1550. if (sh == NULL) {
  1551. sh = get_active_stripe(conf, sector_nr, pd_idx, 0);
  1552. /* make sure we don't swamp the stripe cache if someone else
  1553. * is trying to get access
  1554. */
  1555. set_current_state(TASK_UNINTERRUPTIBLE);
  1556. schedule_timeout(1);
  1557. }
  1558. bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0);
  1559. spin_lock(&sh->lock);
  1560. set_bit(STRIPE_SYNCING, &sh->state);
  1561. clear_bit(STRIPE_INSYNC, &sh->state);
  1562. spin_unlock(&sh->lock);
  1563. handle_stripe(sh);
  1564. release_stripe(sh);
  1565. return STRIPE_SECTORS;
  1566. }
  1567. /*
  1568. * This is our raid6 kernel thread.
  1569. *
  1570. * We scan the hash table for stripes which can be handled now.
  1571. * During the scan, completed stripes are saved for us by the interrupt
  1572. * handler, so that they will not have to wait for our next wakeup.
  1573. */
  1574. static void raid6d (mddev_t *mddev)
  1575. {
  1576. struct stripe_head *sh;
  1577. raid6_conf_t *conf = mddev_to_conf(mddev);
  1578. int handled;
  1579. PRINTK("+++ raid6d active\n");
  1580. md_check_recovery(mddev);
  1581. handled = 0;
  1582. spin_lock_irq(&conf->device_lock);
  1583. while (1) {
  1584. struct list_head *first;
  1585. if (conf->seq_flush - conf->seq_write > 0) {
  1586. int seq = conf->seq_flush;
  1587. bitmap_unplug(mddev->bitmap);
  1588. conf->seq_write = seq;
  1589. activate_bit_delay(conf);
  1590. }
  1591. if (list_empty(&conf->handle_list) &&
  1592. atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD &&
  1593. !blk_queue_plugged(mddev->queue) &&
  1594. !list_empty(&conf->delayed_list))
  1595. raid6_activate_delayed(conf);
  1596. if (list_empty(&conf->handle_list))
  1597. break;
  1598. first = conf->handle_list.next;
  1599. sh = list_entry(first, struct stripe_head, lru);
  1600. list_del_init(first);
  1601. atomic_inc(&sh->count);
  1602. if (atomic_read(&sh->count)!= 1)
  1603. BUG();
  1604. spin_unlock_irq(&conf->device_lock);
  1605. handled++;
  1606. handle_stripe(sh);
  1607. release_stripe(sh);
  1608. spin_lock_irq(&conf->device_lock);
  1609. }
  1610. PRINTK("%d stripes handled\n", handled);
  1611. spin_unlock_irq(&conf->device_lock);
  1612. unplug_slaves(mddev);
  1613. PRINTK("--- raid6d inactive\n");
  1614. }
  1615. static int run(mddev_t *mddev)
  1616. {
  1617. raid6_conf_t *conf;
  1618. int raid_disk, memory;
  1619. mdk_rdev_t *rdev;
  1620. struct disk_info *disk;
  1621. struct list_head *tmp;
  1622. if (mddev->level != 6) {
  1623. PRINTK("raid6: %s: raid level not set to 6 (%d)\n", mdname(mddev), mddev->level);
  1624. return -EIO;
  1625. }
  1626. mddev->private = kmalloc (sizeof (raid6_conf_t)
  1627. + mddev->raid_disks * sizeof(struct disk_info),
  1628. GFP_KERNEL);
  1629. if ((conf = mddev->private) == NULL)
  1630. goto abort;
  1631. memset (conf, 0, sizeof (*conf) + mddev->raid_disks * sizeof(struct disk_info) );
  1632. conf->mddev = mddev;
  1633. if ((conf->stripe_hashtbl = (struct stripe_head **) __get_free_pages(GFP_ATOMIC, HASH_PAGES_ORDER)) == NULL)
  1634. goto abort;
  1635. memset(conf->stripe_hashtbl, 0, HASH_PAGES * PAGE_SIZE);
  1636. spin_lock_init(&conf->device_lock);
  1637. init_waitqueue_head(&conf->wait_for_stripe);
  1638. init_waitqueue_head(&conf->wait_for_overlap);
  1639. INIT_LIST_HEAD(&conf->handle_list);
  1640. INIT_LIST_HEAD(&conf->delayed_list);
  1641. INIT_LIST_HEAD(&conf->bitmap_list);
  1642. INIT_LIST_HEAD(&conf->inactive_list);
  1643. atomic_set(&conf->active_stripes, 0);
  1644. atomic_set(&conf->preread_active_stripes, 0);
  1645. PRINTK("raid6: run(%s) called.\n", mdname(mddev));
  1646. ITERATE_RDEV(mddev,rdev,tmp) {
  1647. raid_disk = rdev->raid_disk;
  1648. if (raid_disk >= mddev->raid_disks
  1649. || raid_disk < 0)
  1650. continue;
  1651. disk = conf->disks + raid_disk;
  1652. disk->rdev = rdev;
  1653. if (rdev->in_sync) {
  1654. char b[BDEVNAME_SIZE];
  1655. printk(KERN_INFO "raid6: device %s operational as raid"
  1656. " disk %d\n", bdevname(rdev->bdev,b),
  1657. raid_disk);
  1658. conf->working_disks++;
  1659. }
  1660. }
  1661. conf->raid_disks = mddev->raid_disks;
  1662. /*
  1663. * 0 for a fully functional array, 1 or 2 for a degraded array.
  1664. */
  1665. mddev->degraded = conf->failed_disks = conf->raid_disks - conf->working_disks;
  1666. conf->mddev = mddev;
  1667. conf->chunk_size = mddev->chunk_size;
  1668. conf->level = mddev->level;
  1669. conf->algorithm = mddev->layout;
  1670. conf->max_nr_stripes = NR_STRIPES;
  1671. /* device size must be a multiple of chunk size */
  1672. mddev->size &= ~(mddev->chunk_size/1024 -1);
  1673. mddev->resync_max_sectors = mddev->size << 1;
  1674. if (conf->raid_disks < 4) {
  1675. printk(KERN_ERR "raid6: not enough configured devices for %s (%d, minimum 4)\n",
  1676. mdname(mddev), conf->raid_disks);
  1677. goto abort;
  1678. }
  1679. if (!conf->chunk_size || conf->chunk_size % 4) {
  1680. printk(KERN_ERR "raid6: invalid chunk size %d for %s\n",
  1681. conf->chunk_size, mdname(mddev));
  1682. goto abort;
  1683. }
  1684. if (conf->algorithm > ALGORITHM_RIGHT_SYMMETRIC) {
  1685. printk(KERN_ERR
  1686. "raid6: unsupported parity algorithm %d for %s\n",
  1687. conf->algorithm, mdname(mddev));
  1688. goto abort;
  1689. }
  1690. if (mddev->degraded > 2) {
  1691. printk(KERN_ERR "raid6: not enough operational devices for %s"
  1692. " (%d/%d failed)\n",
  1693. mdname(mddev), conf->failed_disks, conf->raid_disks);
  1694. goto abort;
  1695. }
  1696. #if 0 /* FIX: For now */
  1697. if (mddev->degraded > 0 &&
  1698. mddev->recovery_cp != MaxSector) {
  1699. printk(KERN_ERR "raid6: cannot start dirty degraded array for %s\n", mdname(mddev));
  1700. goto abort;
  1701. }
  1702. #endif
  1703. {
  1704. mddev->thread = md_register_thread(raid6d, mddev, "%s_raid6");
  1705. if (!mddev->thread) {
  1706. printk(KERN_ERR
  1707. "raid6: couldn't allocate thread for %s\n",
  1708. mdname(mddev));
  1709. goto abort;
  1710. }
  1711. }
  1712. memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
  1713. conf->raid_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
  1714. if (grow_stripes(conf, conf->max_nr_stripes)) {
  1715. printk(KERN_ERR
  1716. "raid6: couldn't allocate %dkB for buffers\n", memory);
  1717. shrink_stripes(conf);
  1718. md_unregister_thread(mddev->thread);
  1719. goto abort;
  1720. } else
  1721. printk(KERN_INFO "raid6: allocated %dkB for %s\n",
  1722. memory, mdname(mddev));
  1723. if (mddev->degraded == 0)
  1724. printk(KERN_INFO "raid6: raid level %d set %s active with %d out of %d"
  1725. " devices, algorithm %d\n", conf->level, mdname(mddev),
  1726. mddev->raid_disks-mddev->degraded, mddev->raid_disks,
  1727. conf->algorithm);
  1728. else
  1729. printk(KERN_ALERT "raid6: raid level %d set %s active with %d"
  1730. " out of %d devices, algorithm %d\n", conf->level,
  1731. mdname(mddev), mddev->raid_disks - mddev->degraded,
  1732. mddev->raid_disks, conf->algorithm);
  1733. print_raid6_conf(conf);
  1734. /* read-ahead size must cover two whole stripes, which is
  1735. * 2 * (n-2) * chunksize where 'n' is the number of raid devices
  1736. */
  1737. {
  1738. int stripe = (mddev->raid_disks-2) * mddev->chunk_size
  1739. / PAGE_CACHE_SIZE;
  1740. if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe)
  1741. mddev->queue->backing_dev_info.ra_pages = 2 * stripe;
  1742. }
  1743. /* Ok, everything is just fine now */
  1744. mddev->array_size = mddev->size * (mddev->raid_disks - 2);
  1745. if (mddev->bitmap)
  1746. mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
  1747. mddev->queue->unplug_fn = raid6_unplug_device;
  1748. mddev->queue->issue_flush_fn = raid6_issue_flush;
  1749. return 0;
  1750. abort:
  1751. if (conf) {
  1752. print_raid6_conf(conf);
  1753. if (conf->stripe_hashtbl)
  1754. free_pages((unsigned long) conf->stripe_hashtbl,
  1755. HASH_PAGES_ORDER);
  1756. kfree(conf);
  1757. }
  1758. mddev->private = NULL;
  1759. printk(KERN_ALERT "raid6: failed to run raid set %s\n", mdname(mddev));
  1760. return -EIO;
  1761. }
  1762. static int stop (mddev_t *mddev)
  1763. {
  1764. raid6_conf_t *conf = (raid6_conf_t *) mddev->private;
  1765. md_unregister_thread(mddev->thread);
  1766. mddev->thread = NULL;
  1767. shrink_stripes(conf);
  1768. free_pages((unsigned long) conf->stripe_hashtbl, HASH_PAGES_ORDER);
  1769. blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
  1770. kfree(conf);
  1771. mddev->private = NULL;
  1772. return 0;
  1773. }
  1774. #if RAID6_DUMPSTATE
  1775. static void print_sh (struct seq_file *seq, struct stripe_head *sh)
  1776. {
  1777. int i;
  1778. seq_printf(seq, "sh %llu, pd_idx %d, state %ld.\n",
  1779. (unsigned long long)sh->sector, sh->pd_idx, sh->state);
  1780. seq_printf(seq, "sh %llu, count %d.\n",
  1781. (unsigned long long)sh->sector, atomic_read(&sh->count));
  1782. seq_printf(seq, "sh %llu, ", (unsigned long long)sh->sector);
  1783. for (i = 0; i < sh->raid_conf->raid_disks; i++) {
  1784. seq_printf(seq, "(cache%d: %p %ld) ",
  1785. i, sh->dev[i].page, sh->dev[i].flags);
  1786. }
  1787. seq_printf(seq, "\n");
  1788. }
  1789. static void printall (struct seq_file *seq, raid6_conf_t *conf)
  1790. {
  1791. struct stripe_head *sh;
  1792. int i;
  1793. spin_lock_irq(&conf->device_lock);
  1794. for (i = 0; i < NR_HASH; i++) {
  1795. sh = conf->stripe_hashtbl[i];
  1796. for (; sh; sh = sh->hash_next) {
  1797. if (sh->raid_conf != conf)
  1798. continue;
  1799. print_sh(seq, sh);
  1800. }
  1801. }
  1802. spin_unlock_irq(&conf->device_lock);
  1803. }
  1804. #endif
  1805. static void status (struct seq_file *seq, mddev_t *mddev)
  1806. {
  1807. raid6_conf_t *conf = (raid6_conf_t *) mddev->private;
  1808. int i;
  1809. seq_printf (seq, " level %d, %dk chunk, algorithm %d", mddev->level, mddev->chunk_size >> 10, mddev->layout);
  1810. seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->working_disks);
  1811. for (i = 0; i < conf->raid_disks; i++)
  1812. seq_printf (seq, "%s",
  1813. conf->disks[i].rdev &&
  1814. conf->disks[i].rdev->in_sync ? "U" : "_");
  1815. seq_printf (seq, "]");
  1816. #if RAID6_DUMPSTATE
  1817. seq_printf (seq, "\n");
  1818. printall(seq, conf);
  1819. #endif
  1820. }
  1821. static void print_raid6_conf (raid6_conf_t *conf)
  1822. {
  1823. int i;
  1824. struct disk_info *tmp;
  1825. printk("RAID6 conf printout:\n");
  1826. if (!conf) {
  1827. printk("(conf==NULL)\n");
  1828. return;
  1829. }
  1830. printk(" --- rd:%d wd:%d fd:%d\n", conf->raid_disks,
  1831. conf->working_disks, conf->failed_disks);
  1832. for (i = 0; i < conf->raid_disks; i++) {
  1833. char b[BDEVNAME_SIZE];
  1834. tmp = conf->disks + i;
  1835. if (tmp->rdev)
  1836. printk(" disk %d, o:%d, dev:%s\n",
  1837. i, !tmp->rdev->faulty,
  1838. bdevname(tmp->rdev->bdev,b));
  1839. }
  1840. }
  1841. static int raid6_spare_active(mddev_t *mddev)
  1842. {
  1843. int i;
  1844. raid6_conf_t *conf = mddev->private;
  1845. struct disk_info *tmp;
  1846. for (i = 0; i < conf->raid_disks; i++) {
  1847. tmp = conf->disks + i;
  1848. if (tmp->rdev
  1849. && !tmp->rdev->faulty
  1850. && !tmp->rdev->in_sync) {
  1851. mddev->degraded--;
  1852. conf->failed_disks--;
  1853. conf->working_disks++;
  1854. tmp->rdev->in_sync = 1;
  1855. }
  1856. }
  1857. print_raid6_conf(conf);
  1858. return 0;
  1859. }
  1860. static int raid6_remove_disk(mddev_t *mddev, int number)
  1861. {
  1862. raid6_conf_t *conf = mddev->private;
  1863. int err = 0;
  1864. mdk_rdev_t *rdev;
  1865. struct disk_info *p = conf->disks + number;
  1866. print_raid6_conf(conf);
  1867. rdev = p->rdev;
  1868. if (rdev) {
  1869. if (rdev->in_sync ||
  1870. atomic_read(&rdev->nr_pending)) {
  1871. err = -EBUSY;
  1872. goto abort;
  1873. }
  1874. p->rdev = NULL;
  1875. synchronize_rcu();
  1876. if (atomic_read(&rdev->nr_pending)) {
  1877. /* lost the race, try later */
  1878. err = -EBUSY;
  1879. p->rdev = rdev;
  1880. }
  1881. }
  1882. abort:
  1883. print_raid6_conf(conf);
  1884. return err;
  1885. }
  1886. static int raid6_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
  1887. {
  1888. raid6_conf_t *conf = mddev->private;
  1889. int found = 0;
  1890. int disk;
  1891. struct disk_info *p;
  1892. if (mddev->degraded > 2)
  1893. /* no point adding a device */
  1894. return 0;
  1895. /*
  1896. * find the disk ...
  1897. */
  1898. for (disk=0; disk < mddev->raid_disks; disk++)
  1899. if ((p=conf->disks + disk)->rdev == NULL) {
  1900. rdev->in_sync = 0;
  1901. rdev->raid_disk = disk;
  1902. found = 1;
  1903. if (rdev->saved_raid_disk != disk)
  1904. conf->fullsync = 1;
  1905. p->rdev = rdev;
  1906. break;
  1907. }
  1908. print_raid6_conf(conf);
  1909. return found;
  1910. }
  1911. static int raid6_resize(mddev_t *mddev, sector_t sectors)
  1912. {
  1913. /* no resync is happening, and there is enough space
  1914. * on all devices, so we can resize.
  1915. * We need to make sure resync covers any new space.
  1916. * If the array is shrinking we should possibly wait until
  1917. * any io in the removed space completes, but it hardly seems
  1918. * worth it.
  1919. */
  1920. sectors &= ~((sector_t)mddev->chunk_size/512 - 1);
  1921. mddev->array_size = (sectors * (mddev->raid_disks-2))>>1;
  1922. set_capacity(mddev->gendisk, mddev->array_size << 1);
  1923. mddev->changed = 1;
  1924. if (sectors/2 > mddev->size && mddev->recovery_cp == MaxSector) {
  1925. mddev->recovery_cp = mddev->size << 1;
  1926. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  1927. }
  1928. mddev->size = sectors /2;
  1929. mddev->resync_max_sectors = sectors;
  1930. return 0;
  1931. }
  1932. static void raid6_quiesce(mddev_t *mddev, int state)
  1933. {
  1934. raid6_conf_t *conf = mddev_to_conf(mddev);
  1935. switch(state) {
  1936. case 1: /* stop all writes */
  1937. spin_lock_irq(&conf->device_lock);
  1938. conf->quiesce = 1;
  1939. wait_event_lock_irq(conf->wait_for_stripe,
  1940. atomic_read(&conf->active_stripes) == 0,
  1941. conf->device_lock, /* nothing */);
  1942. spin_unlock_irq(&conf->device_lock);
  1943. break;
  1944. case 0: /* re-enable writes */
  1945. spin_lock_irq(&conf->device_lock);
  1946. conf->quiesce = 0;
  1947. wake_up(&conf->wait_for_stripe);
  1948. spin_unlock_irq(&conf->device_lock);
  1949. break;
  1950. }
  1951. if (mddev->thread) {
  1952. if (mddev->bitmap)
  1953. mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
  1954. else
  1955. mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
  1956. md_wakeup_thread(mddev->thread);
  1957. }
  1958. }
  1959. static mdk_personality_t raid6_personality=
  1960. {
  1961. .name = "raid6",
  1962. .owner = THIS_MODULE,
  1963. .make_request = make_request,
  1964. .run = run,
  1965. .stop = stop,
  1966. .status = status,
  1967. .error_handler = error,
  1968. .hot_add_disk = raid6_add_disk,
  1969. .hot_remove_disk= raid6_remove_disk,
  1970. .spare_active = raid6_spare_active,
  1971. .sync_request = sync_request,
  1972. .resize = raid6_resize,
  1973. .quiesce = raid6_quiesce,
  1974. };
  1975. static int __init raid6_init (void)
  1976. {
  1977. int e;
  1978. e = raid6_select_algo();
  1979. if ( e )
  1980. return e;
  1981. return register_md_personality (RAID6, &raid6_personality);
  1982. }
  1983. static void raid6_exit (void)
  1984. {
  1985. unregister_md_personality (RAID6);
  1986. }
  1987. module_init(raid6_init);
  1988. module_exit(raid6_exit);
  1989. MODULE_LICENSE("GPL");
  1990. MODULE_ALIAS("md-personality-8"); /* RAID6 */