Lines Matching refs:sh
62 static inline void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh) in __release_stripe() argument
64 if (atomic_dec_and_test(&sh->count)) { in __release_stripe()
65 if (!list_empty(&sh->lru)) in __release_stripe()
69 if (test_bit(STRIPE_HANDLE, &sh->state)) { in __release_stripe()
70 if (test_bit(STRIPE_DELAYED, &sh->state)) in __release_stripe()
71 list_add_tail(&sh->lru, &conf->delayed_list); in __release_stripe()
73 list_add_tail(&sh->lru, &conf->handle_list); in __release_stripe()
76 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { in __release_stripe()
81 list_add_tail(&sh->lru, &conf->inactive_list); in __release_stripe()
89 static void release_stripe(struct stripe_head *sh) in release_stripe() argument
91 raid5_conf_t *conf = sh->raid_conf; in release_stripe()
95 __release_stripe(conf, sh); in release_stripe()
99 static void remove_hash(struct stripe_head *sh) in remove_hash() argument
101 PRINTK("remove_hash(), stripe %lu\n", sh->sector); in remove_hash()
103 if (sh->hash_pprev) { in remove_hash()
104 if (sh->hash_next) in remove_hash()
105 sh->hash_next->hash_pprev = sh->hash_pprev; in remove_hash()
106 *sh->hash_pprev = sh->hash_next; in remove_hash()
107 sh->hash_pprev = NULL; in remove_hash()
111 static __inline__ void insert_hash(raid5_conf_t *conf, struct stripe_head *sh) in insert_hash() argument
113 struct stripe_head **shp = &stripe_hash(conf, sh->sector); in insert_hash()
115 PRINTK("insert_hash(), stripe %lu\n",sh->sector); in insert_hash()
118 if ((sh->hash_next = *shp) != NULL) in insert_hash()
119 (*shp)->hash_pprev = &sh->hash_next; in insert_hash()
120 *shp = sh; in insert_hash()
121 sh->hash_pprev = shp; in insert_hash()
128 struct stripe_head *sh = NULL; in get_free_stripe() local
135 sh = list_entry(first, struct stripe_head, lru); in get_free_stripe()
137 remove_hash(sh); in get_free_stripe()
140 return sh; in get_free_stripe()
143 static void shrink_buffers(struct stripe_head *sh, int num) in shrink_buffers() argument
149 bh = sh->bh_cache[i]; in shrink_buffers()
152 sh->bh_cache[i] = NULL; in shrink_buffers()
158 static int grow_buffers(struct stripe_head *sh, int num, int b_size, int priority) in grow_buffers() argument
178 sh->bh_cache[i] = bh; in grow_buffers()
184 static struct buffer_head *raid5_build_block (struct stripe_head *sh, int i);
186 static inline void init_stripe(struct stripe_head *sh, unsigned long sector) in init_stripe() argument
188 raid5_conf_t *conf = sh->raid_conf; in init_stripe()
191 if (atomic_read(&sh->count) != 0) in init_stripe()
193 if (test_bit(STRIPE_HANDLE, &sh->state)) in init_stripe()
197 PRINTK("init_stripe called, stripe %lu\n", sh->sector); in init_stripe()
199 remove_hash(sh); in init_stripe()
201 sh->sector = sector; in init_stripe()
202 sh->size = conf->buffer_size; in init_stripe()
203 sh->state = 0; in init_stripe()
206 if (sh->bh_read[i] || sh->bh_write[i] || sh->bh_written[i] || in init_stripe()
207 buffer_locked(sh->bh_cache[i])) { in init_stripe()
209 sh->sector, i, sh->bh_read[i], in init_stripe()
210 sh->bh_write[i], sh->bh_written[i], in init_stripe()
211 buffer_locked(sh->bh_cache[i])); in init_stripe()
214 clear_bit(BH_Uptodate, &sh->bh_cache[i]->b_state); in init_stripe()
215 raid5_build_block(sh, i); in init_stripe()
217 insert_hash(conf, sh); in init_stripe()
230 struct stripe_head *sh; in shrink_stripe_cache() local
231 while ((sh = conf->stripe_hashtbl[i])) in shrink_stripe_cache()
232 remove_hash(sh); in shrink_stripe_cache()
238 struct stripe_head *sh; in __find_stripe() local
242 for (sh = stripe_hash(conf, sector); sh; sh = sh->hash_next) in __find_stripe()
243 if (sh->sector == sector) in __find_stripe()
244 return sh; in __find_stripe()
251 struct stripe_head *sh; in get_active_stripe() local
296 sh = __find_stripe(conf, sector); in get_active_stripe()
297 if (!sh) { in get_active_stripe()
299 sh = get_free_stripe(conf); in get_active_stripe()
300 if (noblock && sh == NULL) in get_active_stripe()
302 if (!sh) { in get_active_stripe()
311 init_stripe(sh, sector); in get_active_stripe()
313 if (atomic_read(&sh->count)) { in get_active_stripe()
314 if (!list_empty(&sh->lru)) in get_active_stripe()
317 if (!test_bit(STRIPE_HANDLE, &sh->state)) in get_active_stripe()
319 if (list_empty(&sh->lru)) in get_active_stripe()
321 list_del_init(&sh->lru); in get_active_stripe()
324 } while (sh == NULL); in get_active_stripe()
326 if (sh) in get_active_stripe()
327 atomic_inc(&sh->count); in get_active_stripe()
330 return sh; in get_active_stripe()
335 struct stripe_head *sh; in grow_stripes() local
338 sh = kmalloc(sizeof(struct stripe_head), priority); in grow_stripes()
339 if (!sh) in grow_stripes()
341 memset(sh, 0, sizeof(*sh)); in grow_stripes()
342 sh->raid_conf = conf; in grow_stripes()
343 sh->lock = SPIN_LOCK_UNLOCKED; in grow_stripes()
345 if (grow_buffers(sh, conf->raid_disks, PAGE_SIZE, priority)) { in grow_stripes()
346 shrink_buffers(sh, conf->raid_disks); in grow_stripes()
347 kfree(sh); in grow_stripes()
351 atomic_set(&sh->count, 1); in grow_stripes()
353 INIT_LIST_HEAD(&sh->lru); in grow_stripes()
354 release_stripe(sh); in grow_stripes()
361 struct stripe_head *sh; in shrink_stripes() local
365 sh = get_free_stripe(conf); in shrink_stripes()
367 if (!sh) in shrink_stripes()
369 if (atomic_read(&sh->count)) in shrink_stripes()
371 shrink_buffers(sh, conf->raid_disks); in shrink_stripes()
372 kfree(sh); in shrink_stripes()
380 struct stripe_head *sh = bh->b_private; in raid5_end_read_request() local
381 raid5_conf_t *conf = sh->raid_conf; in raid5_end_read_request()
386 if (bh == sh->bh_cache[i]) in raid5_end_read_request()
389 …PRINTK("end_read_request %lu/%d, count: %d, uptodate %d.\n", sh->sector, i, atomic_read(&sh->count… in raid5_end_read_request()
403 buffer = sh->bh_read[i]; in raid5_end_read_request()
408 sh->bh_read[i] = buffer->b_reqnext; in raid5_end_read_request()
413 if (sh->bh_page[i]==NULL) in raid5_end_read_request()
425 if (sh->bh_page[i]) { in raid5_end_read_request()
426 bh->b_page = sh->bh_page[i]; in raid5_end_read_request()
428 sh->bh_page[i] = NULL; in raid5_end_read_request()
432 set_bit(STRIPE_HANDLE, &sh->state); in raid5_end_read_request()
433 release_stripe(sh); in raid5_end_read_request()
438 struct stripe_head *sh = bh->b_private; in raid5_end_write_request() local
439 raid5_conf_t *conf = sh->raid_conf; in raid5_end_write_request()
444 if (bh == sh->bh_cache[i]) in raid5_end_write_request()
447 …PRINTK("end_write_request %lu/%d, count %d, uptodate: %d.\n", sh->sector, i, atomic_read(&sh->coun… in raid5_end_write_request()
457 set_bit(STRIPE_HANDLE, &sh->state); in raid5_end_write_request()
458 __release_stripe(conf, sh); in raid5_end_write_request()
464 static struct buffer_head *raid5_build_block (struct stripe_head *sh, int i) in raid5_build_block() argument
466 raid5_conf_t *conf = sh->raid_conf; in raid5_build_block()
467 struct buffer_head *bh = sh->bh_cache[i]; in raid5_build_block()
468 unsigned long block = sh->sector / (sh->size >> 9); in raid5_build_block()
470 init_buffer(bh, raid5_end_read_request, sh); in raid5_build_block()
475 bh->b_size = sh->size; in raid5_build_block()
612 static unsigned long compute_blocknr(struct stripe_head *sh, int i)
614 raid5_conf_t *conf = sh->raid_conf;
616 unsigned long new_sector = sh->sector, check;
626 if (i > sh->pd_idx)
631 if (i < sh->pd_idx)
633 i -= (sh->pd_idx + 1);
641 blocknr = r_sector / (sh->size >> 9);
644 if (check != sh->sector || dummy1 != dd_idx || dummy2 != sh->pd_idx) {
660 static void compute_block(struct stripe_head *sh, int dd_idx) in compute_block() argument
662 raid5_conf_t *conf = sh->raid_conf; in compute_block()
666 PRINTK("compute_block, stripe %lu, idx %d\n", sh->sector, dd_idx); in compute_block()
669 memset(sh->bh_cache[dd_idx]->b_data, 0, sh->size); in compute_block()
670 bh_ptr[0] = sh->bh_cache[dd_idx]; in compute_block()
675 bh = sh->bh_cache[i]; in compute_block()
679 printk("compute_block() %d, stripe %lu, %d not present\n", dd_idx, sh->sector, i); in compute_block()
685 set_bit(BH_Uptodate, &sh->bh_cache[dd_idx]->b_state); in compute_block()
688 static void compute_parity(struct stripe_head *sh, int method) in compute_parity() argument
690 raid5_conf_t *conf = sh->raid_conf; in compute_parity()
691 int i, pd_idx = sh->pd_idx, disks = conf->raid_disks, count; in compute_parity()
695 PRINTK("compute_parity, stripe %lu, method %d\n", sh->sector, method); in compute_parity()
699 bh_ptr[0] = sh->bh_cache[pd_idx]; in compute_parity()
702 if (!buffer_uptodate(sh->bh_cache[pd_idx])) in compute_parity()
707 if (sh->bh_write[i] && in compute_parity()
708 buffer_uptodate(sh->bh_cache[i])) { in compute_parity()
709 bh_ptr[count++] = sh->bh_cache[i]; in compute_parity()
710 chosen[i] = sh->bh_write[i]; in compute_parity()
711 sh->bh_write[i] = sh->bh_write[i]->b_reqnext; in compute_parity()
712 chosen[i]->b_reqnext = sh->bh_written[i]; in compute_parity()
713 sh->bh_written[i] = chosen[i]; in compute_parity()
719 memset(sh->bh_cache[pd_idx]->b_data, 0, sh->size); in compute_parity()
721 if (i!=pd_idx && sh->bh_write[i]) { in compute_parity()
722 chosen[i] = sh->bh_write[i]; in compute_parity()
723 sh->bh_write[i] = sh->bh_write[i]->b_reqnext; in compute_parity()
724 chosen[i]->b_reqnext = sh->bh_written[i]; in compute_parity()
725 sh->bh_written[i] = chosen[i]; in compute_parity()
738 struct buffer_head *bh = sh->bh_cache[i]; in compute_parity()
742 bdata,sh->size); in compute_parity()
753 bh_ptr[count++] = sh->bh_cache[i]; in compute_parity()
760 bh_ptr[count++] = sh->bh_cache[i]; in compute_parity()
768 mark_buffer_uptodate(sh->bh_cache[pd_idx], 1); in compute_parity()
769 set_bit(BH_Lock, &sh->bh_cache[pd_idx]->b_state); in compute_parity()
771 mark_buffer_uptodate(sh->bh_cache[pd_idx], 0); in compute_parity()
774 static void add_stripe_bh (struct stripe_head *sh, struct buffer_head *bh, int dd_idx, int rw) in add_stripe_bh() argument
777 raid5_conf_t *conf = sh->raid_conf; in add_stripe_bh()
779 PRINTK("adding bh b#%lu to stripe s#%lu\n", bh->b_blocknr, sh->sector); in add_stripe_bh()
782 spin_lock(&sh->lock); in add_stripe_bh()
786 bhp = &sh->bh_read[dd_idx]; in add_stripe_bh()
788 bhp = &sh->bh_write[dd_idx]; in add_stripe_bh()
790 printk(KERN_NOTICE "raid5: multiple %d requests for sector %ld\n", rw, sh->sector); in add_stripe_bh()
795 spin_unlock(&sh->lock); in add_stripe_bh()
797 PRINTK("added bh b#%lu to stripe s#%lu, disk %d.\n", bh->b_blocknr, sh->sector, dd_idx); in add_stripe_bh()
822 static void handle_stripe(struct stripe_head *sh) in handle_stripe() argument
824 raid5_conf_t *conf = sh->raid_conf; in handle_stripe()
834 …PRINTK("handling stripe %ld, cnt=%d, pd_idx=%d\n", sh->sector, atomic_read(&sh->count), sh->pd_idx… in handle_stripe()
837 spin_lock(&sh->lock); in handle_stripe()
838 clear_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
839 clear_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
841 syncing = test_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
845 bh = sh->bh_cache[i]; in handle_stripe()
846 …tate 0x%lx read %p write %p written %p\n", i, bh->b_state, sh->bh_read[i], sh->bh_write[i], sh->bh… in handle_stripe()
848 if (buffer_uptodate(bh) && sh->bh_read[i]) { in handle_stripe()
852 rbh = sh->bh_read[i]; in handle_stripe()
853 sh->bh_read[i] = NULL; in handle_stripe()
872 if (sh->bh_read[i]) to_read++; in handle_stripe()
873 if (sh->bh_write[i]) to_write++; in handle_stripe()
874 if (sh->bh_written[i]) written++; in handle_stripe()
888 if (sh->bh_write[i]) to_write--; in handle_stripe()
889 while ((bh = sh->bh_write[i])) { in handle_stripe()
890 sh->bh_write[i] = bh->b_reqnext; in handle_stripe()
895 if (sh->bh_written[i]) written--; in handle_stripe()
896 while ((bh = sh->bh_written[i])) { in handle_stripe()
897 sh->bh_written[i] = bh->b_reqnext; in handle_stripe()
905 if (sh->bh_read[i]) to_read--; in handle_stripe()
906 while ((bh = sh->bh_read[i])) { in handle_stripe()
907 sh->bh_read[i] = bh->b_reqnext; in handle_stripe()
916 md_done_sync(conf->mddev, (sh->size>>9) - sh->sync_redone,0); in handle_stripe()
917 clear_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
924 bh = sh->bh_cache[sh->pd_idx]; in handle_stripe()
926 ( (conf->disks[sh->pd_idx].operational && !buffer_locked(bh) && buffer_uptodate(bh)) in handle_stripe()
927 || (failed == 1 && failed_num == sh->pd_idx)) in handle_stripe()
931 if (sh->bh_written[i]) { in handle_stripe()
932 bh = sh->bh_cache[i]; in handle_stripe()
933 if (!conf->disks[sh->pd_idx].operational || in handle_stripe()
938 wbh = sh->bh_written[i]; in handle_stripe()
939 sh->bh_written[i] = NULL; in handle_stripe()
955 bh = sh->bh_cache[i]; in handle_stripe()
957 (sh->bh_read[i] || syncing || (failed && sh->bh_read[failed_num]))) { in handle_stripe()
963 compute_block(sh, i); in handle_stripe()
970 if (sh->bh_page[i]) BUG(); in handle_stripe()
971 if (sh->bh_read[i] && !sh->bh_read[i]->b_reqnext && in handle_stripe()
973 sh->bh_page[i] = sh->bh_cache[i]->b_page; in handle_stripe()
974 sh->bh_cache[i]->b_page = sh->bh_read[i]->b_page; in handle_stripe()
975 sh->bh_cache[i]->b_data = sh->bh_read[i]->b_data; in handle_stripe()
984 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
992 bh = sh->bh_cache[i]; in handle_stripe()
993 if ((sh->bh_write[i] || i == sh->pd_idx) && in handle_stripe()
994 (!buffer_locked(bh) || sh->bh_page[i]) && in handle_stripe()
1003 if (!sh->bh_write[i] && i != sh->pd_idx && in handle_stripe()
1004 (!buffer_locked(bh) || sh->bh_page[i]) && in handle_stripe()
1010 PRINTK("for sector %ld, rmw=%d rcw=%d\n", sh->sector, rmw, rcw); in handle_stripe()
1011 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
1015 bh = sh->bh_cache[i]; in handle_stripe()
1016 if ((sh->bh_write[i] || i == sh->pd_idx) && in handle_stripe()
1019 if (test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in handle_stripe()
1026 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
1027 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
1034 bh = sh->bh_cache[i]; in handle_stripe()
1035 if (!sh->bh_write[i] && i != sh->pd_idx && in handle_stripe()
1038 if (test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in handle_stripe()
1045 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
1046 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
1053 compute_parity(sh, rcw==0 ? RECONSTRUCT_WRITE : READ_MODIFY_WRITE); in handle_stripe()
1056 if (buffer_locked(sh->bh_cache[i])) { in handle_stripe()
1061 || (i==sh->pd_idx && failed == 0)) in handle_stripe()
1062 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
1064 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { in handle_stripe()
1077 !test_bit(STRIPE_INSYNC, &sh->state) && failed <= 1) { in handle_stripe()
1078 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
1082 compute_parity(sh, CHECK_PARITY); in handle_stripe()
1084 bh = sh->bh_cache[sh->pd_idx]; in handle_stripe()
1088 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
1091 if (!test_bit(STRIPE_INSYNC, &sh->state)) { in handle_stripe()
1094 failed_num = sh->pd_idx; in handle_stripe()
1096 if (!buffer_uptodate(sh->bh_cache[failed_num])) { in handle_stripe()
1099 compute_block(sh, failed_num); in handle_stripe()
1104 bh = sh->bh_cache[failed_num]; in handle_stripe()
1108 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
1116 if (syncing && locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { in handle_stripe()
1117 md_done_sync(conf->mddev, (sh->size>>9) - sh->sync_redone,1); in handle_stripe()
1118 clear_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
1122 spin_unlock(&sh->lock); in handle_stripe()
1136 struct buffer_head *bh = sh->bh_cache[i]; in handle_stripe()
1149 PRINTK("for %ld schedule op %d on disc %d\n", sh->sector, action[i]-1, i); in handle_stripe()
1150 atomic_inc(&sh->count); in handle_stripe()
1155 PRINTK("skip op %d on disc %d for sector %ld\n", action[i]-1, i, sh->sector); in handle_stripe()
1157 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
1167 struct stripe_head *sh; in raid5_activate_delayed() local
1168 sh = list_entry(l, struct stripe_head, lru); in raid5_activate_delayed()
1170 clear_bit(STRIPE_DELAYED, &sh->state); in raid5_activate_delayed()
1171 if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in raid5_activate_delayed()
1173 list_add_tail(&sh->lru, &conf->handle_list); in raid5_activate_delayed()
1212 struct stripe_head *sh; in raid5_make_request() local
1223 sh = get_active_stripe(conf, new_sector, bh->b_size, read_ahead); in raid5_make_request()
1224 if (sh) { in raid5_make_request()
1225 sh->pd_idx = pd_idx; in raid5_make_request()
1227 add_stripe_bh(sh, bh, dd_idx, rw); in raid5_make_request()
1230 handle_stripe(sh); in raid5_make_request()
1231 release_stripe(sh); in raid5_make_request()
1257 struct stripe_head *sh; in raid5_sync_request() local
1268 sh = get_active_stripe(conf, sector_nr, 0, 0); in raid5_sync_request()
1269 bufsize = sh->size; in raid5_sync_request()
1270 redone = sector_nr - sh->sector; in raid5_sync_request()
1273 sh->pd_idx = pd_idx; in raid5_sync_request()
1274 spin_lock(&sh->lock); in raid5_sync_request()
1275 set_bit(STRIPE_SYNCING, &sh->state); in raid5_sync_request()
1276 clear_bit(STRIPE_INSYNC, &sh->state); in raid5_sync_request()
1277 sh->sync_redone = redone; in raid5_sync_request()
1278 spin_unlock(&sh->lock); in raid5_sync_request()
1280 handle_stripe(sh); in raid5_sync_request()
1281 release_stripe(sh); in raid5_sync_request()
1295 struct stripe_head *sh; in raid5d() local
1320 sh = list_entry(first, struct stripe_head, lru); in raid5d()
1323 atomic_inc(&sh->count); in raid5d()
1324 if (atomic_read(&sh->count)!= 1) in raid5d()
1329 handle_stripe(sh); in raid5d()
1330 release_stripe(sh); in raid5d()
1658 static void print_sh (struct stripe_head *sh) in print_sh() argument
1662 printk("sh %lu, size %d, pd_idx %d, state %ld.\n", sh->sector, sh->size, sh->pd_idx, sh->state); in print_sh()
1663 printk("sh %lu, count %d.\n", sh->sector, atomic_read(&sh->count)); in print_sh()
1664 printk("sh %lu, ", sh->sector); in print_sh()
1666 if (sh->bh_cache[i]) in print_sh()
1667 printk("(cache%d: %p %ld) ", i, sh->bh_cache[i], sh->bh_cache[i]->b_state); in print_sh()
1674 struct stripe_head *sh; in printall() local
1679 sh = conf->stripe_hashtbl[i]; in printall()
1680 for (; sh; sh = sh->hash_next) { in printall()
1681 if (sh->raid_conf != conf) in printall()
1683 print_sh(sh); in printall()