raid6main.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251
  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 (!test_bit(Faulty, &rdev->flags)) {
  442. mddev->sb_dirty = 1;
  443. if (test_bit(In_sync, &rdev->flags)) {
  444. conf->working_disks--;
  445. mddev->degraded++;
  446. conf->failed_disks++;
  447. clear_bit(In_sync, &rdev->flags);
  448. /*
  449. * if recovery was running, make sure it aborts.
  450. */
  451. set_bit(MD_RECOVERY_ERR, &mddev->recovery);
  452. }
  453. set_bit(Faulty, &rdev->flags);
  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 || !test_bit(In_sync, &rdev->flags)) {
  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 = rcu_dereference(conf->disks[i].rdev);
  1306. if (rdev && test_bit(Faulty, &rdev->flags))
  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 = rcu_dereference(conf->disks[i].rdev);
  1374. if (rdev && !test_bit(Faulty, &rdev->flags) && 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 = rcu_dereference(conf->disks[i].rdev);
  1409. if (rdev && !test_bit(Faulty, &rdev->flags)) {
  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. const int rw = bio_data_dir(bi);
  1444. if (unlikely(bio_barrier(bi))) {
  1445. bio_endio(bi, bi->bi_size, -EOPNOTSUPP);
  1446. return 0;
  1447. }
  1448. md_write_start(mddev, bi);
  1449. disk_stat_inc(mddev->gendisk, ios[rw]);
  1450. disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bi));
  1451. logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1);
  1452. last_sector = bi->bi_sector + (bi->bi_size>>9);
  1453. bi->bi_next = NULL;
  1454. bi->bi_phys_segments = 1; /* over-loaded to count active stripes */
  1455. for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) {
  1456. DEFINE_WAIT(w);
  1457. new_sector = raid6_compute_sector(logical_sector,
  1458. raid_disks, data_disks, &dd_idx, &pd_idx, conf);
  1459. PRINTK("raid6: make_request, sector %llu logical %llu\n",
  1460. (unsigned long long)new_sector,
  1461. (unsigned long long)logical_sector);
  1462. retry:
  1463. prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE);
  1464. sh = get_active_stripe(conf, new_sector, pd_idx, (bi->bi_rw&RWA_MASK));
  1465. if (sh) {
  1466. if (!add_stripe_bio(sh, bi, dd_idx, (bi->bi_rw&RW_MASK))) {
  1467. /* Add failed due to overlap. Flush everything
  1468. * and wait a while
  1469. */
  1470. raid6_unplug_device(mddev->queue);
  1471. release_stripe(sh);
  1472. schedule();
  1473. goto retry;
  1474. }
  1475. finish_wait(&conf->wait_for_overlap, &w);
  1476. raid6_plug_device(conf);
  1477. handle_stripe(sh);
  1478. release_stripe(sh);
  1479. } else {
  1480. /* cannot get stripe for read-ahead, just give-up */
  1481. clear_bit(BIO_UPTODATE, &bi->bi_flags);
  1482. finish_wait(&conf->wait_for_overlap, &w);
  1483. break;
  1484. }
  1485. }
  1486. spin_lock_irq(&conf->device_lock);
  1487. if (--bi->bi_phys_segments == 0) {
  1488. int bytes = bi->bi_size;
  1489. if (rw == WRITE )
  1490. md_write_end(mddev);
  1491. bi->bi_size = 0;
  1492. bi->bi_end_io(bi, bytes, 0);
  1493. }
  1494. spin_unlock_irq(&conf->device_lock);
  1495. return 0;
  1496. }
  1497. /* FIXME go_faster isn't used */
  1498. static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
  1499. {
  1500. raid6_conf_t *conf = (raid6_conf_t *) mddev->private;
  1501. struct stripe_head *sh;
  1502. int sectors_per_chunk = conf->chunk_size >> 9;
  1503. sector_t x;
  1504. unsigned long stripe;
  1505. int chunk_offset;
  1506. int dd_idx, pd_idx;
  1507. sector_t first_sector;
  1508. int raid_disks = conf->raid_disks;
  1509. int data_disks = raid_disks - 2;
  1510. sector_t max_sector = mddev->size << 1;
  1511. int sync_blocks;
  1512. if (sector_nr >= max_sector) {
  1513. /* just being told to finish up .. nothing much to do */
  1514. unplug_slaves(mddev);
  1515. if (mddev->curr_resync < max_sector) /* aborted */
  1516. bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
  1517. &sync_blocks, 1);
  1518. else /* compelted sync */
  1519. conf->fullsync = 0;
  1520. bitmap_close_sync(mddev->bitmap);
  1521. return 0;
  1522. }
  1523. /* if there are 2 or more failed drives and we are trying
  1524. * to resync, then assert that we are finished, because there is
  1525. * nothing we can do.
  1526. */
  1527. if (mddev->degraded >= 2 && test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
  1528. sector_t rv = (mddev->size << 1) - sector_nr;
  1529. *skipped = 1;
  1530. return rv;
  1531. }
  1532. if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
  1533. !conf->fullsync && sync_blocks >= STRIPE_SECTORS) {
  1534. /* we can skip this block, and probably more */
  1535. sync_blocks /= STRIPE_SECTORS;
  1536. *skipped = 1;
  1537. return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */
  1538. }
  1539. x = sector_nr;
  1540. chunk_offset = sector_div(x, sectors_per_chunk);
  1541. stripe = x;
  1542. BUG_ON(x != stripe);
  1543. first_sector = raid6_compute_sector((sector_t)stripe*data_disks*sectors_per_chunk
  1544. + chunk_offset, raid_disks, data_disks, &dd_idx, &pd_idx, conf);
  1545. sh = get_active_stripe(conf, sector_nr, pd_idx, 1);
  1546. if (sh == NULL) {
  1547. sh = get_active_stripe(conf, sector_nr, pd_idx, 0);
  1548. /* make sure we don't swamp the stripe cache if someone else
  1549. * is trying to get access
  1550. */
  1551. schedule_timeout_uninterruptible(1);
  1552. }
  1553. bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0);
  1554. spin_lock(&sh->lock);
  1555. set_bit(STRIPE_SYNCING, &sh->state);
  1556. clear_bit(STRIPE_INSYNC, &sh->state);
  1557. spin_unlock(&sh->lock);
  1558. handle_stripe(sh);
  1559. release_stripe(sh);
  1560. return STRIPE_SECTORS;
  1561. }
  1562. /*
  1563. * This is our raid6 kernel thread.
  1564. *
  1565. * We scan the hash table for stripes which can be handled now.
  1566. * During the scan, completed stripes are saved for us by the interrupt
  1567. * handler, so that they will not have to wait for our next wakeup.
  1568. */
  1569. static void raid6d (mddev_t *mddev)
  1570. {
  1571. struct stripe_head *sh;
  1572. raid6_conf_t *conf = mddev_to_conf(mddev);
  1573. int handled;
  1574. PRINTK("+++ raid6d active\n");
  1575. md_check_recovery(mddev);
  1576. handled = 0;
  1577. spin_lock_irq(&conf->device_lock);
  1578. while (1) {
  1579. struct list_head *first;
  1580. if (conf->seq_flush - conf->seq_write > 0) {
  1581. int seq = conf->seq_flush;
  1582. bitmap_unplug(mddev->bitmap);
  1583. conf->seq_write = seq;
  1584. activate_bit_delay(conf);
  1585. }
  1586. if (list_empty(&conf->handle_list) &&
  1587. atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD &&
  1588. !blk_queue_plugged(mddev->queue) &&
  1589. !list_empty(&conf->delayed_list))
  1590. raid6_activate_delayed(conf);
  1591. if (list_empty(&conf->handle_list))
  1592. break;
  1593. first = conf->handle_list.next;
  1594. sh = list_entry(first, struct stripe_head, lru);
  1595. list_del_init(first);
  1596. atomic_inc(&sh->count);
  1597. if (atomic_read(&sh->count)!= 1)
  1598. BUG();
  1599. spin_unlock_irq(&conf->device_lock);
  1600. handled++;
  1601. handle_stripe(sh);
  1602. release_stripe(sh);
  1603. spin_lock_irq(&conf->device_lock);
  1604. }
  1605. PRINTK("%d stripes handled\n", handled);
  1606. spin_unlock_irq(&conf->device_lock);
  1607. unplug_slaves(mddev);
  1608. PRINTK("--- raid6d inactive\n");
  1609. }
  1610. static int run(mddev_t *mddev)
  1611. {
  1612. raid6_conf_t *conf;
  1613. int raid_disk, memory;
  1614. mdk_rdev_t *rdev;
  1615. struct disk_info *disk;
  1616. struct list_head *tmp;
  1617. if (mddev->level != 6) {
  1618. PRINTK("raid6: %s: raid level not set to 6 (%d)\n", mdname(mddev), mddev->level);
  1619. return -EIO;
  1620. }
  1621. mddev->private = kmalloc (sizeof (raid6_conf_t)
  1622. + mddev->raid_disks * sizeof(struct disk_info),
  1623. GFP_KERNEL);
  1624. if ((conf = mddev->private) == NULL)
  1625. goto abort;
  1626. memset (conf, 0, sizeof (*conf) + mddev->raid_disks * sizeof(struct disk_info) );
  1627. conf->mddev = mddev;
  1628. if ((conf->stripe_hashtbl = (struct stripe_head **) __get_free_pages(GFP_ATOMIC, HASH_PAGES_ORDER)) == NULL)
  1629. goto abort;
  1630. memset(conf->stripe_hashtbl, 0, HASH_PAGES * PAGE_SIZE);
  1631. spin_lock_init(&conf->device_lock);
  1632. init_waitqueue_head(&conf->wait_for_stripe);
  1633. init_waitqueue_head(&conf->wait_for_overlap);
  1634. INIT_LIST_HEAD(&conf->handle_list);
  1635. INIT_LIST_HEAD(&conf->delayed_list);
  1636. INIT_LIST_HEAD(&conf->bitmap_list);
  1637. INIT_LIST_HEAD(&conf->inactive_list);
  1638. atomic_set(&conf->active_stripes, 0);
  1639. atomic_set(&conf->preread_active_stripes, 0);
  1640. PRINTK("raid6: run(%s) called.\n", mdname(mddev));
  1641. ITERATE_RDEV(mddev,rdev,tmp) {
  1642. raid_disk = rdev->raid_disk;
  1643. if (raid_disk >= mddev->raid_disks
  1644. || raid_disk < 0)
  1645. continue;
  1646. disk = conf->disks + raid_disk;
  1647. disk->rdev = rdev;
  1648. if (test_bit(In_sync, &rdev->flags)) {
  1649. char b[BDEVNAME_SIZE];
  1650. printk(KERN_INFO "raid6: device %s operational as raid"
  1651. " disk %d\n", bdevname(rdev->bdev,b),
  1652. raid_disk);
  1653. conf->working_disks++;
  1654. }
  1655. }
  1656. conf->raid_disks = mddev->raid_disks;
  1657. /*
  1658. * 0 for a fully functional array, 1 or 2 for a degraded array.
  1659. */
  1660. mddev->degraded = conf->failed_disks = conf->raid_disks - conf->working_disks;
  1661. conf->mddev = mddev;
  1662. conf->chunk_size = mddev->chunk_size;
  1663. conf->level = mddev->level;
  1664. conf->algorithm = mddev->layout;
  1665. conf->max_nr_stripes = NR_STRIPES;
  1666. /* device size must be a multiple of chunk size */
  1667. mddev->size &= ~(mddev->chunk_size/1024 -1);
  1668. mddev->resync_max_sectors = mddev->size << 1;
  1669. if (conf->raid_disks < 4) {
  1670. printk(KERN_ERR "raid6: not enough configured devices for %s (%d, minimum 4)\n",
  1671. mdname(mddev), conf->raid_disks);
  1672. goto abort;
  1673. }
  1674. if (!conf->chunk_size || conf->chunk_size % 4) {
  1675. printk(KERN_ERR "raid6: invalid chunk size %d for %s\n",
  1676. conf->chunk_size, mdname(mddev));
  1677. goto abort;
  1678. }
  1679. if (conf->algorithm > ALGORITHM_RIGHT_SYMMETRIC) {
  1680. printk(KERN_ERR
  1681. "raid6: unsupported parity algorithm %d for %s\n",
  1682. conf->algorithm, mdname(mddev));
  1683. goto abort;
  1684. }
  1685. if (mddev->degraded > 2) {
  1686. printk(KERN_ERR "raid6: not enough operational devices for %s"
  1687. " (%d/%d failed)\n",
  1688. mdname(mddev), conf->failed_disks, conf->raid_disks);
  1689. goto abort;
  1690. }
  1691. #if 0 /* FIX: For now */
  1692. if (mddev->degraded > 0 &&
  1693. mddev->recovery_cp != MaxSector) {
  1694. printk(KERN_ERR "raid6: cannot start dirty degraded array for %s\n", mdname(mddev));
  1695. goto abort;
  1696. }
  1697. #endif
  1698. {
  1699. mddev->thread = md_register_thread(raid6d, mddev, "%s_raid6");
  1700. if (!mddev->thread) {
  1701. printk(KERN_ERR
  1702. "raid6: couldn't allocate thread for %s\n",
  1703. mdname(mddev));
  1704. goto abort;
  1705. }
  1706. }
  1707. memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
  1708. conf->raid_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
  1709. if (grow_stripes(conf, conf->max_nr_stripes)) {
  1710. printk(KERN_ERR
  1711. "raid6: couldn't allocate %dkB for buffers\n", memory);
  1712. shrink_stripes(conf);
  1713. md_unregister_thread(mddev->thread);
  1714. goto abort;
  1715. } else
  1716. printk(KERN_INFO "raid6: allocated %dkB for %s\n",
  1717. memory, mdname(mddev));
  1718. if (mddev->degraded == 0)
  1719. printk(KERN_INFO "raid6: raid level %d set %s active with %d out of %d"
  1720. " devices, algorithm %d\n", conf->level, mdname(mddev),
  1721. mddev->raid_disks-mddev->degraded, mddev->raid_disks,
  1722. conf->algorithm);
  1723. else
  1724. printk(KERN_ALERT "raid6: raid level %d set %s active with %d"
  1725. " out of %d devices, algorithm %d\n", conf->level,
  1726. mdname(mddev), mddev->raid_disks - mddev->degraded,
  1727. mddev->raid_disks, conf->algorithm);
  1728. print_raid6_conf(conf);
  1729. /* read-ahead size must cover two whole stripes, which is
  1730. * 2 * (n-2) * chunksize where 'n' is the number of raid devices
  1731. */
  1732. {
  1733. int stripe = (mddev->raid_disks-2) * mddev->chunk_size
  1734. / PAGE_CACHE_SIZE;
  1735. if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe)
  1736. mddev->queue->backing_dev_info.ra_pages = 2 * stripe;
  1737. }
  1738. /* Ok, everything is just fine now */
  1739. mddev->array_size = mddev->size * (mddev->raid_disks - 2);
  1740. if (mddev->bitmap)
  1741. mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
  1742. mddev->queue->unplug_fn = raid6_unplug_device;
  1743. mddev->queue->issue_flush_fn = raid6_issue_flush;
  1744. return 0;
  1745. abort:
  1746. if (conf) {
  1747. print_raid6_conf(conf);
  1748. if (conf->stripe_hashtbl)
  1749. free_pages((unsigned long) conf->stripe_hashtbl,
  1750. HASH_PAGES_ORDER);
  1751. kfree(conf);
  1752. }
  1753. mddev->private = NULL;
  1754. printk(KERN_ALERT "raid6: failed to run raid set %s\n", mdname(mddev));
  1755. return -EIO;
  1756. }
  1757. static int stop (mddev_t *mddev)
  1758. {
  1759. raid6_conf_t *conf = (raid6_conf_t *) mddev->private;
  1760. md_unregister_thread(mddev->thread);
  1761. mddev->thread = NULL;
  1762. shrink_stripes(conf);
  1763. free_pages((unsigned long) conf->stripe_hashtbl, HASH_PAGES_ORDER);
  1764. blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
  1765. kfree(conf);
  1766. mddev->private = NULL;
  1767. return 0;
  1768. }
  1769. #if RAID6_DUMPSTATE
  1770. static void print_sh (struct seq_file *seq, struct stripe_head *sh)
  1771. {
  1772. int i;
  1773. seq_printf(seq, "sh %llu, pd_idx %d, state %ld.\n",
  1774. (unsigned long long)sh->sector, sh->pd_idx, sh->state);
  1775. seq_printf(seq, "sh %llu, count %d.\n",
  1776. (unsigned long long)sh->sector, atomic_read(&sh->count));
  1777. seq_printf(seq, "sh %llu, ", (unsigned long long)sh->sector);
  1778. for (i = 0; i < sh->raid_conf->raid_disks; i++) {
  1779. seq_printf(seq, "(cache%d: %p %ld) ",
  1780. i, sh->dev[i].page, sh->dev[i].flags);
  1781. }
  1782. seq_printf(seq, "\n");
  1783. }
  1784. static void printall (struct seq_file *seq, raid6_conf_t *conf)
  1785. {
  1786. struct stripe_head *sh;
  1787. int i;
  1788. spin_lock_irq(&conf->device_lock);
  1789. for (i = 0; i < NR_HASH; i++) {
  1790. sh = conf->stripe_hashtbl[i];
  1791. for (; sh; sh = sh->hash_next) {
  1792. if (sh->raid_conf != conf)
  1793. continue;
  1794. print_sh(seq, sh);
  1795. }
  1796. }
  1797. spin_unlock_irq(&conf->device_lock);
  1798. }
  1799. #endif
  1800. static void status (struct seq_file *seq, mddev_t *mddev)
  1801. {
  1802. raid6_conf_t *conf = (raid6_conf_t *) mddev->private;
  1803. int i;
  1804. seq_printf (seq, " level %d, %dk chunk, algorithm %d", mddev->level, mddev->chunk_size >> 10, mddev->layout);
  1805. seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->working_disks);
  1806. for (i = 0; i < conf->raid_disks; i++)
  1807. seq_printf (seq, "%s",
  1808. conf->disks[i].rdev &&
  1809. test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_");
  1810. seq_printf (seq, "]");
  1811. #if RAID6_DUMPSTATE
  1812. seq_printf (seq, "\n");
  1813. printall(seq, conf);
  1814. #endif
  1815. }
  1816. static void print_raid6_conf (raid6_conf_t *conf)
  1817. {
  1818. int i;
  1819. struct disk_info *tmp;
  1820. printk("RAID6 conf printout:\n");
  1821. if (!conf) {
  1822. printk("(conf==NULL)\n");
  1823. return;
  1824. }
  1825. printk(" --- rd:%d wd:%d fd:%d\n", conf->raid_disks,
  1826. conf->working_disks, conf->failed_disks);
  1827. for (i = 0; i < conf->raid_disks; i++) {
  1828. char b[BDEVNAME_SIZE];
  1829. tmp = conf->disks + i;
  1830. if (tmp->rdev)
  1831. printk(" disk %d, o:%d, dev:%s\n",
  1832. i, !test_bit(Faulty, &tmp->rdev->flags),
  1833. bdevname(tmp->rdev->bdev,b));
  1834. }
  1835. }
  1836. static int raid6_spare_active(mddev_t *mddev)
  1837. {
  1838. int i;
  1839. raid6_conf_t *conf = mddev->private;
  1840. struct disk_info *tmp;
  1841. for (i = 0; i < conf->raid_disks; i++) {
  1842. tmp = conf->disks + i;
  1843. if (tmp->rdev
  1844. && !test_bit(Faulty, &tmp->rdev->flags)
  1845. && !test_bit(In_sync, &tmp->rdev->flags)) {
  1846. mddev->degraded--;
  1847. conf->failed_disks--;
  1848. conf->working_disks++;
  1849. set_bit(In_sync, &tmp->rdev->flags);
  1850. }
  1851. }
  1852. print_raid6_conf(conf);
  1853. return 0;
  1854. }
  1855. static int raid6_remove_disk(mddev_t *mddev, int number)
  1856. {
  1857. raid6_conf_t *conf = mddev->private;
  1858. int err = 0;
  1859. mdk_rdev_t *rdev;
  1860. struct disk_info *p = conf->disks + number;
  1861. print_raid6_conf(conf);
  1862. rdev = p->rdev;
  1863. if (rdev) {
  1864. if (test_bit(In_sync, &rdev->flags) ||
  1865. atomic_read(&rdev->nr_pending)) {
  1866. err = -EBUSY;
  1867. goto abort;
  1868. }
  1869. p->rdev = NULL;
  1870. synchronize_rcu();
  1871. if (atomic_read(&rdev->nr_pending)) {
  1872. /* lost the race, try later */
  1873. err = -EBUSY;
  1874. p->rdev = rdev;
  1875. }
  1876. }
  1877. abort:
  1878. print_raid6_conf(conf);
  1879. return err;
  1880. }
  1881. static int raid6_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
  1882. {
  1883. raid6_conf_t *conf = mddev->private;
  1884. int found = 0;
  1885. int disk;
  1886. struct disk_info *p;
  1887. if (mddev->degraded > 2)
  1888. /* no point adding a device */
  1889. return 0;
  1890. /*
  1891. * find the disk ...
  1892. */
  1893. for (disk=0; disk < mddev->raid_disks; disk++)
  1894. if ((p=conf->disks + disk)->rdev == NULL) {
  1895. clear_bit(In_sync, &rdev->flags);
  1896. rdev->raid_disk = disk;
  1897. found = 1;
  1898. if (rdev->saved_raid_disk != disk)
  1899. conf->fullsync = 1;
  1900. rcu_assign_pointer(p->rdev, rdev);
  1901. break;
  1902. }
  1903. print_raid6_conf(conf);
  1904. return found;
  1905. }
  1906. static int raid6_resize(mddev_t *mddev, sector_t sectors)
  1907. {
  1908. /* no resync is happening, and there is enough space
  1909. * on all devices, so we can resize.
  1910. * We need to make sure resync covers any new space.
  1911. * If the array is shrinking we should possibly wait until
  1912. * any io in the removed space completes, but it hardly seems
  1913. * worth it.
  1914. */
  1915. sectors &= ~((sector_t)mddev->chunk_size/512 - 1);
  1916. mddev->array_size = (sectors * (mddev->raid_disks-2))>>1;
  1917. set_capacity(mddev->gendisk, mddev->array_size << 1);
  1918. mddev->changed = 1;
  1919. if (sectors/2 > mddev->size && mddev->recovery_cp == MaxSector) {
  1920. mddev->recovery_cp = mddev->size << 1;
  1921. set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  1922. }
  1923. mddev->size = sectors /2;
  1924. mddev->resync_max_sectors = sectors;
  1925. return 0;
  1926. }
  1927. static void raid6_quiesce(mddev_t *mddev, int state)
  1928. {
  1929. raid6_conf_t *conf = mddev_to_conf(mddev);
  1930. switch(state) {
  1931. case 1: /* stop all writes */
  1932. spin_lock_irq(&conf->device_lock);
  1933. conf->quiesce = 1;
  1934. wait_event_lock_irq(conf->wait_for_stripe,
  1935. atomic_read(&conf->active_stripes) == 0,
  1936. conf->device_lock, /* nothing */);
  1937. spin_unlock_irq(&conf->device_lock);
  1938. break;
  1939. case 0: /* re-enable writes */
  1940. spin_lock_irq(&conf->device_lock);
  1941. conf->quiesce = 0;
  1942. wake_up(&conf->wait_for_stripe);
  1943. spin_unlock_irq(&conf->device_lock);
  1944. break;
  1945. }
  1946. if (mddev->thread) {
  1947. if (mddev->bitmap)
  1948. mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
  1949. else
  1950. mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
  1951. md_wakeup_thread(mddev->thread);
  1952. }
  1953. }
  1954. static mdk_personality_t raid6_personality=
  1955. {
  1956. .name = "raid6",
  1957. .owner = THIS_MODULE,
  1958. .make_request = make_request,
  1959. .run = run,
  1960. .stop = stop,
  1961. .status = status,
  1962. .error_handler = error,
  1963. .hot_add_disk = raid6_add_disk,
  1964. .hot_remove_disk= raid6_remove_disk,
  1965. .spare_active = raid6_spare_active,
  1966. .sync_request = sync_request,
  1967. .resize = raid6_resize,
  1968. .quiesce = raid6_quiesce,
  1969. };
  1970. static int __init raid6_init (void)
  1971. {
  1972. int e;
  1973. e = raid6_select_algo();
  1974. if ( e )
  1975. return e;
  1976. return register_md_personality (RAID6, &raid6_personality);
  1977. }
  1978. static void raid6_exit (void)
  1979. {
  1980. unregister_md_personality (RAID6);
  1981. }
  1982. module_init(raid6_init);
  1983. module_exit(raid6_exit);
  1984. MODULE_LICENSE("GPL");
  1985. MODULE_ALIAS("md-personality-8"); /* RAID6 */