Lines Matching refs:eb
184 static loff_t mtdswap_eb_offset(struct mtdswap_dev *d, struct swap_eb *eb)
186 return (loff_t)(eb - d->eb_data) * d->mtd->erasesize;
189 static void mtdswap_eb_detach(struct mtdswap_dev *d, struct swap_eb *eb)
194 if (eb->root) {
195 tp = container_of(eb->root, struct mtdswap_tree, root);
199 rb_erase(&eb->rb, eb->root);
203 static void __mtdswap_rb_add(struct rb_root *root, struct swap_eb *eb)
212 if (eb->erase_count > cur->erase_count)
218 rb_link_node(&eb->rb, parent, p);
219 rb_insert_color(&eb->rb, root);
222 static void mtdswap_rb_add(struct mtdswap_dev *d, struct swap_eb *eb, int idx)
226 if (eb->root == &d->trees[idx].root)
229 mtdswap_eb_detach(d, eb);
231 __mtdswap_rb_add(root, eb);
232 eb->root = root;
251 static int mtdswap_handle_badblock(struct mtdswap_dev *d, struct swap_eb *eb)
257 eb->flags |= EBLOCK_BAD;
258 mtdswap_eb_detach(d, eb);
259 eb->root = NULL;
265 offset = mtdswap_eb_offset(d, eb);
279 static int mtdswap_handle_write_error(struct mtdswap_dev *d, struct swap_eb *eb)
281 unsigned int marked = eb->flags & EBLOCK_FAILED;
284 eb->flags |= EBLOCK_FAILED;
285 if (curr_write == eb) {
289 mtdswap_rb_add(d, eb, MTDSWAP_FAILING);
294 return mtdswap_handle_badblock(d, eb);
321 static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
328 offset = mtdswap_eb_offset(d, eb);
350 eb->erase_count = le32_to_cpu(data->count);
360 eb->flags |= EBLOCK_NOMAGIC;
367 static int mtdswap_write_marker(struct mtdswap_dev *d, struct swap_eb *eb,
382 n.count = cpu_to_le32(eb->erase_count);
384 offset = mtdswap_eb_offset(d, eb);
388 offset = mtdswap_eb_offset(d, eb) + d->mtd->writesize;
397 mtdswap_handle_write_error(d, eb);
420 struct swap_eb *eb;
425 eb = d->eb_data + i;
427 if (eb->flags & (EBLOCK_NOMAGIC | EBLOCK_BAD | EBLOCK_READERR))
430 __mtdswap_rb_add(&hist_root, eb);
443 eb = d->eb_data + i;
445 if (eb->flags & (EBLOCK_NOMAGIC | EBLOCK_READERR))
446 eb->erase_count = median;
448 if (eb->flags & (EBLOCK_NOMAGIC | EBLOCK_BAD | EBLOCK_READERR))
451 rb_erase(&eb->rb, &hist_root);
459 struct swap_eb *eb;
462 eb = d->eb_data + i;
464 status = mtdswap_read_markers(d, eb);
466 eb->flags |= EBLOCK_READERR;
468 eb->flags |= EBLOCK_BAD;
484 eb->flags |= (idx << EBLOCK_IDX_SHIFT);
490 eb = d->eb_data + i;
492 if (eb->flags & EBLOCK_BAD)
495 idx = eb->flags >> EBLOCK_IDX_SHIFT;
496 mtdswap_rb_add(d, eb, idx);
504 static void mtdswap_store_eb(struct mtdswap_dev *d, struct swap_eb *eb)
506 unsigned int weight = eb->active_count;
509 if (eb == d->curr_write)
512 if (eb->flags & EBLOCK_BITFLIP)
513 mtdswap_rb_add(d, eb, MTDSWAP_BITFLIP);
514 else if (eb->flags & (EBLOCK_READERR | EBLOCK_FAILED))
515 mtdswap_rb_add(d, eb, MTDSWAP_FAILING);
517 mtdswap_rb_add(d, eb, MTDSWAP_USED);
519 mtdswap_rb_add(d, eb, MTDSWAP_DIRTY);
521 mtdswap_rb_add(d, eb, MTDSWAP_LOWFRAG);
523 mtdswap_rb_add(d, eb, MTDSWAP_HIFRAG);
526 static int mtdswap_erase_block(struct mtdswap_dev *d, struct swap_eb *eb)
533 eb->erase_count++;
534 if (eb->erase_count > d->max_erase_count)
535 d->max_erase_count = eb->erase_count;
539 erase.addr = mtdswap_eb_offset(d, eb);
555 mtdswap_handle_badblock(d, eb);
568 struct swap_eb *eb;
576 eb = rb_entry(rb_first(clean_root), struct swap_eb, rb);
577 rb_erase(&eb->rb, clean_root);
578 eb->root = NULL;
581 ret = mtdswap_write_marker(d, eb, MTDSWAP_TYPE_DIRTY);
588 d->curr_write = eb;
618 struct swap_eb *eb;
630 eb = d->eb_data + (*bp / d->pages_per_eblk);
634 eb->active_count--;
646 eb->active_count--;
648 mtdswap_handle_write_error(d, eb);
669 eb->active_count--;
679 struct swap_eb *eb, *oldeb;
719 eb = d->eb_data + *newblock / d->pages_per_eblk;
722 eb = d->eb_data + oldblock / d->pages_per_eblk;
723 eb->active_count--;
733 static int mtdswap_gc_eblock(struct mtdswap_dev *d, struct swap_eb *eb)
739 eblk_base = (eb - d->eb_data) * d->pages_per_eblk;
849 struct swap_eb *eb = NULL;
861 eb = rb_entry(rb_first(rp), struct swap_eb, rb);
863 rb_erase(&eb->rb, rp);
864 eb->root = NULL;
866 return eb;
875 struct swap_eb *eb)
891 base = mtdswap_eb_offset(d, eb);
925 ret = mtdswap_erase_block(d, eb);
930 eb->flags &= ~EBLOCK_READERR;
934 mtdswap_handle_badblock(d, eb);
940 struct swap_eb *eb;
946 eb = mtdswap_pick_gc_eblk(d, background);
947 if (!eb)
950 ret = mtdswap_gc_eblock(d, eb);
954 if (eb->flags & EBLOCK_FAILED) {
955 mtdswap_handle_badblock(d, eb);
959 eb->flags &= ~EBLOCK_BITFLIP;
960 ret = mtdswap_erase_block(d, eb);
961 if ((eb->flags & EBLOCK_READERR) &&
962 (ret || !mtdswap_eblk_passes(d, eb)))
966 ret = mtdswap_write_marker(d, eb, MTDSWAP_TYPE_CLEAN);
969 mtdswap_rb_add(d, eb, MTDSWAP_CLEAN);
971 mtdswap_rb_add(d, eb, MTDSWAP_DIRTY);
1025 struct swap_eb *eb;
1043 eb = d->eb_data + (mapped / d->pages_per_eblk);
1044 eb->active_count--;
1045 mtdswap_store_eb(d, eb);
1056 eb = d->eb_data + (newblock / d->pages_per_eblk);
1085 struct swap_eb *eb;
1107 eb = d->eb_data + (realblock / d->pages_per_eblk);
1118 eb->flags |= EBLOCK_BITFLIP;
1119 mtdswap_rb_add(d, eb, MTDSWAP_BITFLIP);
1125 eb->flags |= EBLOCK_READERR;
1126 mtdswap_rb_add(d, eb, MTDSWAP_FAILING);
1147 struct swap_eb *eb;
1155 eb = d->eb_data + (mapped / d->pages_per_eblk);
1156 eb->active_count--;
1157 mtdswap_store_eb(d, eb);