Skip to content

Commit a54fba8

Browse files
jankaradjwong
authored andcommitted
xfs: Move handling of missing page into one place in xfs_find_get_desired_pgoff()
Currently several places in xfs_find_get_desired_pgoff() handle the case of a missing page. Make them all handled in one place after the loop has terminated. Signed-off-by: Jan Kara <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent d7fd242 commit a54fba8

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

fs/xfs/xfs_file.c

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,29 +1052,8 @@ xfs_find_get_desired_pgoff(
10521052
want = min_t(pgoff_t, end - index, PAGEVEC_SIZE - 1) + 1;
10531053
nr_pages = pagevec_lookup(&pvec, inode->i_mapping, index,
10541054
want);
1055-
/*
1056-
* No page mapped into given range. If we are searching holes
1057-
* and if this is the first time we got into the loop, it means
1058-
* that the given offset is landed in a hole, return it.
1059-
*
1060-
* If we have already stepped through some block buffers to find
1061-
* holes but they all contains data. In this case, the last
1062-
* offset is already updated and pointed to the end of the last
1063-
* mapped page, if it does not reach the endpoint to search,
1064-
* that means there should be a hole between them.
1065-
*/
1066-
if (nr_pages == 0) {
1067-
/* Data search found nothing */
1068-
if (type == DATA_OFF)
1069-
break;
1070-
1071-
ASSERT(type == HOLE_OFF);
1072-
if (lastoff == startoff || lastoff < endoff) {
1073-
found = true;
1074-
*offset = lastoff;
1075-
}
1055+
if (nr_pages == 0)
10761056
break;
1077-
}
10781057

10791058
for (i = 0; i < nr_pages; i++) {
10801059
struct page *page = pvec.pages[i];
@@ -1140,21 +1119,20 @@ xfs_find_get_desired_pgoff(
11401119

11411120
/*
11421121
* The number of returned pages less than our desired, search
1143-
* done. In this case, nothing was found for searching data,
1144-
* but we found a hole behind the last offset.
1122+
* done.
11451123
*/
1146-
if (nr_pages < want) {
1147-
if (type == HOLE_OFF) {
1148-
*offset = lastoff;
1149-
found = true;
1150-
}
1124+
if (nr_pages < want)
11511125
break;
1152-
}
11531126

11541127
index = pvec.pages[i - 1]->index + 1;
11551128
pagevec_release(&pvec);
11561129
} while (index <= end);
11571130

1131+
/* No page at lastoff and we are not done - we found a hole. */
1132+
if (type == HOLE_OFF && lastoff < endoff) {
1133+
*offset = lastoff;
1134+
found = true;
1135+
}
11581136
out:
11591137
pagevec_release(&pvec);
11601138
return found;

0 commit comments

Comments
 (0)