Lines Matching refs:prev

577  * merged with the bad range (from the bad table) indexed by 'prev'.
579 static bool can_merge_front(struct badblocks *bb, int prev,
585 if (BB_ACK(p[prev]) == bad->ack &&
586 (s < BB_END(p[prev]) ||
587 (s == BB_END(p[prev]) && (BB_LEN(p[prev]) < BB_MAX_LEN))))
594 * (from bad table) indexed by 'prev'. The return value is sectors
597 static int front_merge(struct badblocks *bb, int prev, struct badblocks_context *bad)
604 WARN_ON(s > BB_END(p[prev]));
606 if (s < BB_END(p[prev])) {
607 merged = min_t(sector_t, sectors, BB_END(p[prev]) - s);
609 merged = min_t(sector_t, sectors, BB_MAX_LEN - BB_LEN(p[prev]));
610 if ((prev + 1) < bb->count &&
611 merged > (BB_OFFSET(p[prev + 1]) - BB_END(p[prev]))) {
612 merged = BB_OFFSET(p[prev + 1]) - BB_END(p[prev]);
615 p[prev] = BB_MAKE(BB_OFFSET(p[prev]),
616 BB_LEN(p[prev]) + merged, bad->ack);
624 * handle: If a bad range (indexed by 'prev' from bad table) exactly
625 * starts as bad->start, and the bad range ahead of 'prev' (indexed by
626 * 'prev - 1' from bad table) exactly ends at where 'prev' starts, and
630 * Return 'true' if bad ranges indexed by 'prev' and 'prev - 1' from bad
633 static bool can_combine_front(struct badblocks *bb, int prev,
638 if ((prev > 0) &&
639 (BB_OFFSET(p[prev]) == bad->start) &&
640 (BB_END(p[prev - 1]) == BB_OFFSET(p[prev])) &&
641 (BB_LEN(p[prev - 1]) + BB_LEN(p[prev]) <= BB_MAX_LEN) &&
642 (BB_ACK(p[prev - 1]) == BB_ACK(p[prev])))
648 * Combine the bad ranges indexed by 'prev' and 'prev - 1' (from bad
650 * 'prev - 1'.
654 static void front_combine(struct badblocks *bb, int prev)
658 p[prev - 1] = BB_MAKE(BB_OFFSET(p[prev - 1]),
659 BB_LEN(p[prev - 1]) + BB_LEN(p[prev]),
660 BB_ACK(p[prev]));
661 if ((prev + 1) < bb->count)
662 memmove(p + prev, p + prev + 1, (bb->count - prev - 1) * 8);
669 * by 'prev' does not cover the whole range indicated by 'bad'.
699 * range (from bad table) indexed by 'prev'.
702 * 'prev' when,
704 * range (from bad table) indexed by 'prev'.
706 * range 'prev'.
709 * indexed by 'prev', new range might be split from existing bad range,
718 static bool can_front_overwrite(struct badblocks *bb, int prev,
724 WARN_ON(!overlap_front(bb, prev, bad));
726 if (BB_ACK(p[prev]) >= bad->ack)
729 if (BB_END(p[prev]) <= (bad->start + bad->len)) {
730 len = BB_END(p[prev]) - bad->start;
731 if (BB_OFFSET(p[prev]) == bad->start)
738 if (BB_OFFSET(p[prev]) == bad->start)
742 * prev range will be split into two, beside the overwritten
756 * (from bad table) indexed by 'prev'.
761 static int front_overwrite(struct badblocks *bb, int prev,
765 sector_t orig_end = BB_END(p[prev]);
766 int orig_ack = BB_ACK(p[prev]);
770 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), BB_LEN(p[prev]),
774 if (BB_OFFSET(p[prev]) == bad->start) {
775 p[prev] = BB_MAKE(BB_OFFSET(p[prev]),
777 memmove(p + prev + 2, p + prev + 1,
778 (bb->count - prev - 1) * 8);
779 p[prev + 1] = BB_MAKE(bad->start + bad->len,
780 orig_end - BB_END(p[prev]),
783 p[prev] = BB_MAKE(BB_OFFSET(p[prev]),
784 bad->start - BB_OFFSET(p[prev]),
787 * prev +2 -> prev + 1 + 1, which is for,
788 * 1) prev + 1: the slot index of the previous one
791 memmove(p + prev + 2, p + prev + 1,
792 (bb->count - prev - 1) * 8);
793 p[prev + 1] = BB_MAKE(bad->start, bad->len, bad->ack);
797 p[prev] = BB_MAKE(BB_OFFSET(p[prev]),
798 bad->start - BB_OFFSET(p[prev]),
801 * prev + 3 -> prev + 1 + 2, which is for,
802 * 1) prev + 1: the slot index of the previous one
805 memmove(p + prev + 3, p + prev + 1,
806 (bb->count - prev - 1) * 8);
807 p[prev + 1] = BB_MAKE(bad->start, bad->len, bad->ack);
808 p[prev + 2] = BB_MAKE(BB_END(p[prev + 1]),
809 orig_end - BB_END(p[prev + 1]),
865 int prev = -1, hint = -1;
907 prev = prev_badblocks(bb, &bad, hint);
910 if (prev < 0) {
939 /* in case p[prev-1] can be merged with p[prev] */
940 if (can_combine_front(bb, prev, &bad)) {
941 front_combine(bb, prev);
944 hint = prev;
948 if (overlap_front(bb, prev, &bad)) {
949 if (can_merge_front(bb, prev, &bad)) {
950 len = front_merge(bb, prev, &bad);
955 if (!can_front_overwrite(bb, prev, &bad, &extra)) {
957 BB_END(p[prev]) - s, sectors);
958 hint = prev;
962 len = front_overwrite(bb, prev, &bad, extra);
966 if (can_combine_front(bb, prev, &bad)) {
967 front_combine(bb, prev);
971 hint = prev;
975 if (can_merge_front(bb, prev, &bad)) {
976 len = front_merge(bb, prev, &bad);
978 hint = prev;
985 if (((prev + 1) < bb->count) &&
986 overlap_behind(bb, &bad, prev + 1) &&
987 ((s + sectors) >= BB_END(p[prev + 1]))) {
988 len = BB_END(p[prev + 1]) - s;
989 hint = prev + 1;
1001 if ((prev + 1) < bb->count &&
1002 overlap_behind(bb, &bad, prev + 1))
1004 bad.len, BB_OFFSET(p[prev + 1]) - bad.start);
1006 len = insert_at(bb, prev + 1, &bad);
1009 hint = prev + 1;
1022 * merged. (prev < 0) condition is not handled here,
1025 if (prev >= 0 &&
1026 (prev + 1) < bb->count &&
1027 BB_END(p[prev]) == BB_OFFSET(p[prev + 1]) &&
1028 (BB_LEN(p[prev]) + BB_LEN(p[prev + 1])) <= BB_MAX_LEN &&
1029 BB_ACK(p[prev]) == BB_ACK(p[prev + 1])) {
1030 p[prev] = BB_MAKE(BB_OFFSET(p[prev]),
1031 BB_LEN(p[prev]) + BB_LEN(p[prev + 1]),
1032 BB_ACK(p[prev]));
1034 if ((prev + 2) < bb->count)
1035 memmove(p + prev + 1, p + prev + 2,
1036 (bb->count - (prev + 2)) * 8);
1073 static int front_clear(struct badblocks *bb, int prev,
1082 if (s == BB_OFFSET(p[prev])) {
1083 if (BB_LEN(p[prev]) > sectors) {
1084 p[prev] = BB_MAKE(BB_OFFSET(p[prev]) + sectors,
1085 BB_LEN(p[prev]) - sectors,
1086 BB_ACK(p[prev]));
1089 /* BB_LEN(p[prev]) <= sectors */
1090 cleared = BB_LEN(p[prev]);
1091 if ((prev + 1) < bb->count)
1092 memmove(p + prev, p + prev + 1,
1093 (bb->count - prev - 1) * 8);
1096 } else if (s > BB_OFFSET(p[prev])) {
1097 if (BB_END(p[prev]) <= (s + sectors)) {
1098 cleared = BB_END(p[prev]) - s;
1099 p[prev] = BB_MAKE(BB_OFFSET(p[prev]),
1100 s - BB_OFFSET(p[prev]),
1101 BB_ACK(p[prev]));
1116 static int front_splitting_clear(struct badblocks *bb, int prev,
1120 u64 end = BB_END(p[prev]);
1121 int ack = BB_ACK(p[prev]);
1125 p[prev] = BB_MAKE(BB_OFFSET(p[prev]),
1126 s - BB_OFFSET(p[prev]),
1128 memmove(p + prev + 2, p + prev + 1, (bb->count - prev - 1) * 8);
1129 p[prev + 1] = BB_MAKE(s + sectors, end - s - sectors, ack);
1137 int prev = -1, hint = -1;
1181 prev = prev_badblocks(bb, &bad, hint);
1184 if (prev < 0) {
1200 if ((prev + 1) >= bb->count && !overlap_front(bb, prev, &bad)) {
1207 if (badblocks_full(bb) && (BB_OFFSET(p[prev]) < bad.start) &&
1208 (BB_END(p[prev]) > (bad.start + sectors))) {
1213 if (overlap_front(bb, prev, &bad)) {
1214 if ((BB_OFFSET(p[prev]) < bad.start) &&
1215 (BB_END(p[prev]) > (bad.start + bad.len))) {
1218 len = front_splitting_clear(bb, prev, &bad);
1228 len = front_clear(bb, prev, &bad, &deleted);
1231 hint = prev;
1238 if ((prev + 1) < bb->count && overlap_behind(bb, &bad, prev + 1)) {
1239 len = BB_OFFSET(p[prev + 1]) - bad.start;
1240 hint = prev + 1;
1278 int prev = -1, hint = -1, set = 0;
1312 prev = prev_badblocks(bb, &bad, hint);
1315 if ((prev >= 0) &&
1316 ((prev + 1) >= bb->count) && !overlap_front(bb, prev, &bad)) {
1322 if ((prev >= 0) && overlap_front(bb, prev, &bad)) {
1323 if (BB_ACK(p[prev]))
1328 if (BB_END(p[prev]) >= (s + sectors))
1331 len = BB_END(p[prev]) - s;
1334 *first_bad = BB_OFFSET(p[prev]);
1335 *bad_sectors = BB_LEN(p[prev]);
1342 if ((prev + 1) < bb->count && overlap_behind(bb, &bad, prev + 1)) {
1343 len = BB_OFFSET(p[prev + 1]) - bad.start;
1344 hint = prev + 1;