Lines Matching refs:prev

579 static bool can_merge_front(struct badblocks *bb, int prev,  in can_merge_front()  argument
585 if (BB_ACK(p[prev]) == bad->ack && in can_merge_front()
586 (s < BB_END(p[prev]) || in can_merge_front()
587 (s == BB_END(p[prev]) && (BB_LEN(p[prev]) < BB_MAX_LEN)))) in can_merge_front()
597 static int front_merge(struct badblocks *bb, int prev, struct badblocks_context *bad) in front_merge() argument
604 WARN_ON(s > BB_END(p[prev])); in front_merge()
606 if (s < BB_END(p[prev])) { in front_merge()
607 merged = min_t(sector_t, sectors, BB_END(p[prev]) - s); in front_merge()
609 merged = min_t(sector_t, sectors, BB_MAX_LEN - BB_LEN(p[prev])); in front_merge()
610 if ((prev + 1) < bb->count && in front_merge()
611 merged > (BB_OFFSET(p[prev + 1]) - BB_END(p[prev]))) { in front_merge()
612 merged = BB_OFFSET(p[prev + 1]) - BB_END(p[prev]); in front_merge()
615 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), in front_merge()
616 BB_LEN(p[prev]) + merged, bad->ack); in front_merge()
633 static bool can_combine_front(struct badblocks *bb, int prev, in can_combine_front() argument
638 if ((prev > 0) && in can_combine_front()
639 (BB_OFFSET(p[prev]) == bad->start) && in can_combine_front()
640 (BB_END(p[prev - 1]) == BB_OFFSET(p[prev])) && in can_combine_front()
641 (BB_LEN(p[prev - 1]) + BB_LEN(p[prev]) <= BB_MAX_LEN) && in can_combine_front()
642 (BB_ACK(p[prev - 1]) == BB_ACK(p[prev]))) in can_combine_front()
654 static void front_combine(struct badblocks *bb, int prev) in front_combine() argument
658 p[prev - 1] = BB_MAKE(BB_OFFSET(p[prev - 1]), in front_combine()
659 BB_LEN(p[prev - 1]) + BB_LEN(p[prev]), in front_combine()
660 BB_ACK(p[prev])); in front_combine()
661 if ((prev + 1) < bb->count) in front_combine()
662 memmove(p + prev, p + prev + 1, (bb->count - prev - 1) * 8); in front_combine()
718 static bool can_front_overwrite(struct badblocks *bb, int prev, in can_front_overwrite() argument
724 WARN_ON(!overlap_front(bb, prev, bad)); in can_front_overwrite()
726 if (BB_ACK(p[prev]) >= bad->ack) in can_front_overwrite()
729 if (BB_END(p[prev]) <= (bad->start + bad->len)) { in can_front_overwrite()
730 len = BB_END(p[prev]) - bad->start; in can_front_overwrite()
731 if (BB_OFFSET(p[prev]) == bad->start) in can_front_overwrite()
738 if (BB_OFFSET(p[prev]) == bad->start) in can_front_overwrite()
761 static int front_overwrite(struct badblocks *bb, int prev, in front_overwrite() argument
765 sector_t orig_end = BB_END(p[prev]); in front_overwrite()
766 int orig_ack = BB_ACK(p[prev]); in front_overwrite()
770 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), BB_LEN(p[prev]), in front_overwrite()
774 if (BB_OFFSET(p[prev]) == bad->start) { in front_overwrite()
775 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), in front_overwrite()
777 memmove(p + prev + 2, p + prev + 1, in front_overwrite()
778 (bb->count - prev - 1) * 8); in front_overwrite()
779 p[prev + 1] = BB_MAKE(bad->start + bad->len, in front_overwrite()
780 orig_end - BB_END(p[prev]), in front_overwrite()
783 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), in front_overwrite()
784 bad->start - BB_OFFSET(p[prev]), in front_overwrite()
791 memmove(p + prev + 2, p + prev + 1, in front_overwrite()
792 (bb->count - prev - 1) * 8); in front_overwrite()
793 p[prev + 1] = BB_MAKE(bad->start, bad->len, bad->ack); in front_overwrite()
797 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), in front_overwrite()
798 bad->start - BB_OFFSET(p[prev]), in front_overwrite()
805 memmove(p + prev + 3, p + prev + 1, in front_overwrite()
806 (bb->count - prev - 1) * 8); in front_overwrite()
807 p[prev + 1] = BB_MAKE(bad->start, bad->len, bad->ack); in front_overwrite()
808 p[prev + 2] = BB_MAKE(BB_END(p[prev + 1]), in front_overwrite()
809 orig_end - BB_END(p[prev + 1]), in front_overwrite()
865 int prev = -1, hint = -1; in _badblocks_set() local
907 prev = prev_badblocks(bb, &bad, hint); in _badblocks_set()
910 if (prev < 0) { in _badblocks_set()
940 if (can_combine_front(bb, prev, &bad)) { in _badblocks_set()
941 front_combine(bb, prev); in _badblocks_set()
944 hint = prev; in _badblocks_set()
948 if (overlap_front(bb, prev, &bad)) { in _badblocks_set()
949 if (can_merge_front(bb, prev, &bad)) { in _badblocks_set()
950 len = front_merge(bb, prev, &bad); in _badblocks_set()
955 if (!can_front_overwrite(bb, prev, &bad, &extra)) { in _badblocks_set()
957 BB_END(p[prev]) - s, sectors); in _badblocks_set()
958 hint = prev; in _badblocks_set()
962 len = front_overwrite(bb, prev, &bad, extra); in _badblocks_set()
966 if (can_combine_front(bb, prev, &bad)) { in _badblocks_set()
967 front_combine(bb, prev); in _badblocks_set()
971 hint = prev; in _badblocks_set()
975 if (can_merge_front(bb, prev, &bad)) { in _badblocks_set()
976 len = front_merge(bb, prev, &bad); in _badblocks_set()
978 hint = prev; in _badblocks_set()
985 if (((prev + 1) < bb->count) && in _badblocks_set()
986 overlap_behind(bb, &bad, prev + 1) && in _badblocks_set()
987 ((s + sectors) >= BB_END(p[prev + 1]))) { in _badblocks_set()
988 len = BB_END(p[prev + 1]) - s; in _badblocks_set()
989 hint = prev + 1; in _badblocks_set()
1001 if ((prev + 1) < bb->count && in _badblocks_set()
1002 overlap_behind(bb, &bad, prev + 1)) in _badblocks_set()
1004 bad.len, BB_OFFSET(p[prev + 1]) - bad.start); in _badblocks_set()
1006 len = insert_at(bb, prev + 1, &bad); in _badblocks_set()
1009 hint = prev + 1; in _badblocks_set()
1025 if (prev >= 0 && in _badblocks_set()
1026 (prev + 1) < bb->count && in _badblocks_set()
1027 BB_END(p[prev]) == BB_OFFSET(p[prev + 1]) && in _badblocks_set()
1028 (BB_LEN(p[prev]) + BB_LEN(p[prev + 1])) <= BB_MAX_LEN && in _badblocks_set()
1029 BB_ACK(p[prev]) == BB_ACK(p[prev + 1])) { in _badblocks_set()
1030 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), in _badblocks_set()
1031 BB_LEN(p[prev]) + BB_LEN(p[prev + 1]), in _badblocks_set()
1032 BB_ACK(p[prev])); in _badblocks_set()
1034 if ((prev + 2) < bb->count) in _badblocks_set()
1035 memmove(p + prev + 1, p + prev + 2, in _badblocks_set()
1036 (bb->count - (prev + 2)) * 8); in _badblocks_set()
1073 static int front_clear(struct badblocks *bb, int prev, in front_clear() argument
1082 if (s == BB_OFFSET(p[prev])) { in front_clear()
1083 if (BB_LEN(p[prev]) > sectors) { in front_clear()
1084 p[prev] = BB_MAKE(BB_OFFSET(p[prev]) + sectors, in front_clear()
1085 BB_LEN(p[prev]) - sectors, in front_clear()
1086 BB_ACK(p[prev])); in front_clear()
1090 cleared = BB_LEN(p[prev]); in front_clear()
1091 if ((prev + 1) < bb->count) in front_clear()
1092 memmove(p + prev, p + prev + 1, in front_clear()
1093 (bb->count - prev - 1) * 8); in front_clear()
1096 } else if (s > BB_OFFSET(p[prev])) { in front_clear()
1097 if (BB_END(p[prev]) <= (s + sectors)) { in front_clear()
1098 cleared = BB_END(p[prev]) - s; in front_clear()
1099 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), in front_clear()
1100 s - BB_OFFSET(p[prev]), in front_clear()
1101 BB_ACK(p[prev])); in front_clear()
1116 static int front_splitting_clear(struct badblocks *bb, int prev, in front_splitting_clear() argument
1120 u64 end = BB_END(p[prev]); in front_splitting_clear()
1121 int ack = BB_ACK(p[prev]); in front_splitting_clear()
1125 p[prev] = BB_MAKE(BB_OFFSET(p[prev]), in front_splitting_clear()
1126 s - BB_OFFSET(p[prev]), in front_splitting_clear()
1128 memmove(p + prev + 2, p + prev + 1, (bb->count - prev - 1) * 8); in front_splitting_clear()
1129 p[prev + 1] = BB_MAKE(s + sectors, end - s - sectors, ack); in front_splitting_clear()
1137 int prev = -1, hint = -1; in _badblocks_clear() local
1181 prev = prev_badblocks(bb, &bad, hint); in _badblocks_clear()
1184 if (prev < 0) { in _badblocks_clear()
1200 if ((prev + 1) >= bb->count && !overlap_front(bb, prev, &bad)) { in _badblocks_clear()
1207 if (badblocks_full(bb) && (BB_OFFSET(p[prev]) < bad.start) && in _badblocks_clear()
1208 (BB_END(p[prev]) > (bad.start + sectors))) { in _badblocks_clear()
1213 if (overlap_front(bb, prev, &bad)) { in _badblocks_clear()
1214 if ((BB_OFFSET(p[prev]) < bad.start) && in _badblocks_clear()
1215 (BB_END(p[prev]) > (bad.start + bad.len))) { in _badblocks_clear()
1218 len = front_splitting_clear(bb, prev, &bad); in _badblocks_clear()
1228 len = front_clear(bb, prev, &bad, &deleted); in _badblocks_clear()
1231 hint = prev; in _badblocks_clear()
1238 if ((prev + 1) < bb->count && overlap_behind(bb, &bad, prev + 1)) { in _badblocks_clear()
1239 len = BB_OFFSET(p[prev + 1]) - bad.start; in _badblocks_clear()
1240 hint = prev + 1; in _badblocks_clear()
1278 int prev = -1, hint = -1, set = 0; in _badblocks_check() local
1312 prev = prev_badblocks(bb, &bad, hint); in _badblocks_check()
1315 if ((prev >= 0) && in _badblocks_check()
1316 ((prev + 1) >= bb->count) && !overlap_front(bb, prev, &bad)) { in _badblocks_check()
1322 if ((prev >= 0) && overlap_front(bb, prev, &bad)) { in _badblocks_check()
1323 if (BB_ACK(p[prev])) in _badblocks_check()
1328 if (BB_END(p[prev]) >= (s + sectors)) in _badblocks_check()
1331 len = BB_END(p[prev]) - s; in _badblocks_check()
1334 *first_bad = BB_OFFSET(p[prev]); in _badblocks_check()
1335 *bad_sectors = BB_LEN(p[prev]); in _badblocks_check()
1342 if ((prev + 1) < bb->count && overlap_behind(bb, &bad, prev + 1)) { in _badblocks_check()
1343 len = BB_OFFSET(p[prev + 1]) - bad.start; in _badblocks_check()
1344 hint = prev + 1; in _badblocks_check()