diff options
author | Jan Kara <jack@suse.cz> | 2017-05-18 19:36:24 -0400 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2017-05-25 12:42:25 -0400 |
commit | a54fba8f5a0dc36161cacdf2aa90f007f702ec1a (patch) | |
tree | 1a49d87ea7aa86cf684e603410ca5e359d72dc7f | |
parent | d7fd24257aa60316bf81093f7f909dc9475ae974 (diff) |
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 <jack@suse.cz>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r-- | fs/xfs/xfs_file.c | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index dc0e4cb7029b..5fb5a0958a14 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c | |||
@@ -1052,29 +1052,8 @@ xfs_find_get_desired_pgoff( | |||
1052 | want = min_t(pgoff_t, end - index, PAGEVEC_SIZE - 1) + 1; | 1052 | want = min_t(pgoff_t, end - index, PAGEVEC_SIZE - 1) + 1; |
1053 | nr_pages = pagevec_lookup(&pvec, inode->i_mapping, index, | 1053 | nr_pages = pagevec_lookup(&pvec, inode->i_mapping, index, |
1054 | want); | 1054 | want); |
1055 | /* | 1055 | if (nr_pages == 0) |
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 | } | ||
1076 | break; | 1056 | break; |
1077 | } | ||
1078 | 1057 | ||
1079 | for (i = 0; i < nr_pages; i++) { | 1058 | for (i = 0; i < nr_pages; i++) { |
1080 | struct page *page = pvec.pages[i]; | 1059 | struct page *page = pvec.pages[i]; |
@@ -1140,21 +1119,20 @@ xfs_find_get_desired_pgoff( | |||
1140 | 1119 | ||
1141 | /* | 1120 | /* |
1142 | * The number of returned pages less than our desired, search | 1121 | * The number of returned pages less than our desired, search |
1143 | * done. In this case, nothing was found for searching data, | 1122 | * done. |
1144 | * but we found a hole behind the last offset. | ||
1145 | */ | 1123 | */ |
1146 | if (nr_pages < want) { | 1124 | if (nr_pages < want) |
1147 | if (type == HOLE_OFF) { | ||
1148 | *offset = lastoff; | ||
1149 | found = true; | ||
1150 | } | ||
1151 | break; | 1125 | break; |
1152 | } | ||
1153 | 1126 | ||
1154 | index = pvec.pages[i - 1]->index + 1; | 1127 | index = pvec.pages[i - 1]->index + 1; |
1155 | pagevec_release(&pvec); | 1128 | pagevec_release(&pvec); |
1156 | } while (index <= end); | 1129 | } while (index <= end); |
1157 | 1130 | ||
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 | } | ||
1158 | out: | 1136 | out: |
1159 | pagevec_release(&pvec); | 1137 | pagevec_release(&pvec); |
1160 | return found; | 1138 | return found; |