diff options
author | OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> | 2006-06-23 05:03:26 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-23 10:42:49 -0400 |
commit | 111ebb6e6f7bd7de6d722c5848e95621f43700d9 (patch) | |
tree | bb00b13001db9be201e9b6d31468a79f4d1240bf /fs/cifs/file.c | |
parent | 4c91c3648c620003cb7b21b8858f36cd6132e168 (diff) |
[PATCH] writeback: fix range handling
When a writeback_control's `start' and `end' fields are used to
indicate a one-byte-range starting at file offset zero, the required
values of .start=0,.end=0 mean that the ->writepages() implementation
has no way of telling that it is being asked to perform a range
request. Because we're currently overloading (start == 0 && end == 0)
to mean "this is not a write-a-range request".
To make all this sane, the patch changes range of writeback_control.
So caller does: If it is calling ->writepages() to write pages, it
sets range (range_start/end or range_cyclic) always.
And if range_cyclic is true, ->writepages() thinks the range is
cyclic, otherwise it just uses range_start and range_end.
This patch does,
- Add LLONG_MAX, LLONG_MIN, ULLONG_MAX to include/linux/kernel.h
-1 is usually ok for range_end (type is long long). But, if someone did,
range_end += val; range_end is "val - 1"
u64val = range_end >> bits; u64val is "~(0ULL)"
or something, they are wrong. So, this adds LLONG_MAX to avoid nasty
things, and uses LLONG_MAX for range_end.
- All callers of ->writepages() sets range_start/end or range_cyclic.
- Fix updates of ->writeback_index. It seems already bit strange.
If it starts at 0 and ended by check of nr_to_write, this last
index may reduce chance to scan end of file. So, this updates
->writeback_index only if range_cyclic is true or whole-file is
scanned.
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Anton Altaparmakov <aia21@cantab.net>
Cc: Steven French <sfrench@us.ibm.com>
Cc: "Vladimir V. Saveliev" <vs@namesys.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/cifs/file.c')
-rw-r--r-- | fs/cifs/file.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index e2b4ce1dad66..487ea8b3baaa 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -1079,9 +1079,9 @@ static int cifs_writepages(struct address_space *mapping, | |||
1079 | unsigned int bytes_written; | 1079 | unsigned int bytes_written; |
1080 | struct cifs_sb_info *cifs_sb; | 1080 | struct cifs_sb_info *cifs_sb; |
1081 | int done = 0; | 1081 | int done = 0; |
1082 | pgoff_t end = -1; | 1082 | pgoff_t end; |
1083 | pgoff_t index; | 1083 | pgoff_t index; |
1084 | int is_range = 0; | 1084 | int range_whole = 0; |
1085 | struct kvec iov[32]; | 1085 | struct kvec iov[32]; |
1086 | int len; | 1086 | int len; |
1087 | int n_iov = 0; | 1087 | int n_iov = 0; |
@@ -1122,16 +1122,14 @@ static int cifs_writepages(struct address_space *mapping, | |||
1122 | xid = GetXid(); | 1122 | xid = GetXid(); |
1123 | 1123 | ||
1124 | pagevec_init(&pvec, 0); | 1124 | pagevec_init(&pvec, 0); |
1125 | if (wbc->sync_mode == WB_SYNC_NONE) | 1125 | if (wbc->range_cyclic) { |
1126 | index = mapping->writeback_index; /* Start from prev offset */ | 1126 | index = mapping->writeback_index; /* Start from prev offset */ |
1127 | else { | 1127 | end = -1; |
1128 | index = 0; | 1128 | } else { |
1129 | scanned = 1; | 1129 | index = wbc->range_start >> PAGE_CACHE_SHIFT; |
1130 | } | 1130 | end = wbc->range_end >> PAGE_CACHE_SHIFT; |
1131 | if (wbc->start || wbc->end) { | 1131 | if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) |
1132 | index = wbc->start >> PAGE_CACHE_SHIFT; | 1132 | range_whole = 1; |
1133 | end = wbc->end >> PAGE_CACHE_SHIFT; | ||
1134 | is_range = 1; | ||
1135 | scanned = 1; | 1133 | scanned = 1; |
1136 | } | 1134 | } |
1137 | retry: | 1135 | retry: |
@@ -1167,7 +1165,7 @@ retry: | |||
1167 | break; | 1165 | break; |
1168 | } | 1166 | } |
1169 | 1167 | ||
1170 | if (unlikely(is_range) && (page->index > end)) { | 1168 | if (!wbc->range_cyclic && page->index > end) { |
1171 | done = 1; | 1169 | done = 1; |
1172 | unlock_page(page); | 1170 | unlock_page(page); |
1173 | break; | 1171 | break; |
@@ -1271,7 +1269,7 @@ retry: | |||
1271 | index = 0; | 1269 | index = 0; |
1272 | goto retry; | 1270 | goto retry; |
1273 | } | 1271 | } |
1274 | if (!is_range) | 1272 | if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) |
1275 | mapping->writeback_index = index; | 1273 | mapping->writeback_index = index; |
1276 | 1274 | ||
1277 | FreeXid(xid); | 1275 | FreeXid(xid); |