diff options
author | Anton Altaparmakov <aia21@cam.ac.uk> | 2007-11-03 03:38:59 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-11-03 15:27:21 -0400 |
commit | ebab89909e0dc716282d5e7f6e73a3155fe66d4a (patch) | |
tree | 8cee9ff6f9e0a08c6f08853e38e563514e92a99e | |
parent | 74521c28e550c4ec265cda14114bd9b908e9de34 (diff) |
NTFS: Fix read regression.
The regression was caused by:
commit[a32ea1e1f925399e0d81ca3f7394a44a6dafa12c] Fix read/truncate race
This causes ntfs_readpage() to be called for a zero i_size inode, which
failed when the file was compressed and non-resident.
Thanks a lot to Mike Galbraith for reporting the issue and tracking down
the commit that caused the regression.
Looking into it I found three bugs which the patch fixes.
Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
Tested-by: Mike Galbraith <efault@gmx.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/ntfs/aops.c | 10 | ||||
-rw-r--r-- | fs/ntfs/attrib.c | 5 | ||||
-rw-r--r-- | fs/ntfs/compress.c | 10 |
3 files changed, 20 insertions, 5 deletions
diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c index cfdc7900d271..ad87cb01299b 100644 --- a/fs/ntfs/aops.c +++ b/fs/ntfs/aops.c | |||
@@ -405,6 +405,15 @@ static int ntfs_readpage(struct file *file, struct page *page) | |||
405 | 405 | ||
406 | retry_readpage: | 406 | retry_readpage: |
407 | BUG_ON(!PageLocked(page)); | 407 | BUG_ON(!PageLocked(page)); |
408 | vi = page->mapping->host; | ||
409 | i_size = i_size_read(vi); | ||
410 | /* Is the page fully outside i_size? (truncate in progress) */ | ||
411 | if (unlikely(page->index >= (i_size + PAGE_CACHE_SIZE - 1) >> | ||
412 | PAGE_CACHE_SHIFT)) { | ||
413 | zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); | ||
414 | ntfs_debug("Read outside i_size - truncated?"); | ||
415 | goto done; | ||
416 | } | ||
408 | /* | 417 | /* |
409 | * This can potentially happen because we clear PageUptodate() during | 418 | * This can potentially happen because we clear PageUptodate() during |
410 | * ntfs_writepage() of MstProtected() attributes. | 419 | * ntfs_writepage() of MstProtected() attributes. |
@@ -413,7 +422,6 @@ retry_readpage: | |||
413 | unlock_page(page); | 422 | unlock_page(page); |
414 | return 0; | 423 | return 0; |
415 | } | 424 | } |
416 | vi = page->mapping->host; | ||
417 | ni = NTFS_I(vi); | 425 | ni = NTFS_I(vi); |
418 | /* | 426 | /* |
419 | * Only $DATA attributes can be encrypted and only unnamed $DATA | 427 | * Only $DATA attributes can be encrypted and only unnamed $DATA |
diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index 92dabdcf2b80..50d3b0c258e3 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c | |||
@@ -179,10 +179,7 @@ int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn, ntfs_attr_search_ctx *ctx) | |||
179 | * ntfs_mapping_pairs_decompress() fails. | 179 | * ntfs_mapping_pairs_decompress() fails. |
180 | */ | 180 | */ |
181 | end_vcn = sle64_to_cpu(a->data.non_resident.highest_vcn) + 1; | 181 | end_vcn = sle64_to_cpu(a->data.non_resident.highest_vcn) + 1; |
182 | if (!a->data.non_resident.lowest_vcn && end_vcn == 1) | 182 | if (unlikely(vcn && vcn >= end_vcn)) { |
183 | end_vcn = sle64_to_cpu(a->data.non_resident.allocated_size) >> | ||
184 | ni->vol->cluster_size_bits; | ||
185 | if (unlikely(vcn >= end_vcn)) { | ||
186 | err = -ENOENT; | 183 | err = -ENOENT; |
187 | goto err_out; | 184 | goto err_out; |
188 | } | 185 | } |
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c index d98daf59e0b6..d1619d05eb23 100644 --- a/fs/ntfs/compress.c +++ b/fs/ntfs/compress.c | |||
@@ -561,6 +561,16 @@ int ntfs_read_compressed_block(struct page *page) | |||
561 | read_unlock_irqrestore(&ni->size_lock, flags); | 561 | read_unlock_irqrestore(&ni->size_lock, flags); |
562 | max_page = ((i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT) - | 562 | max_page = ((i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT) - |
563 | offset; | 563 | offset; |
564 | /* Is the page fully outside i_size? (truncate in progress) */ | ||
565 | if (xpage >= max_page) { | ||
566 | kfree(bhs); | ||
567 | kfree(pages); | ||
568 | zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); | ||
569 | ntfs_debug("Compressed read outside i_size - truncated?"); | ||
570 | SetPageUptodate(page); | ||
571 | unlock_page(page); | ||
572 | return 0; | ||
573 | } | ||
564 | if (nr_pages < max_page) | 574 | if (nr_pages < max_page) |
565 | max_page = nr_pages; | 575 | max_page = nr_pages; |
566 | for (i = 0; i < max_page; i++, offset++) { | 576 | for (i = 0; i < max_page; i++, offset++) { |