ecryptfs: remove unnecessary decrypt when extending a file

Removes an unecessary page decrypt from ecryptfs_begin_write when the
page is beyond the current file size. Previously, the call to
ecryptfs_decrypt_page would result in a read of 0 bytes, but still
attempt to decrypt an entire page. This patch detects that case and
merely zeros the page before marking it up-to-date.

Signed-off-by: Frank Swiderski <fes@chromium.org>
Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>

authored by Frank Swiderski and committed by Tyler Hicks 24562486 f24b3887

+14 -8
+14 -8
fs/ecryptfs/mmap.c
··· 290 290 return -ENOMEM; 291 291 *pagep = page; 292 292 293 + prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT); 293 294 if (!PageUptodate(page)) { 294 295 struct ecryptfs_crypt_stat *crypt_stat = 295 296 &ecryptfs_inode_to_private(mapping->host)->crypt_stat; ··· 336 335 SetPageUptodate(page); 337 336 } 338 337 } else { 339 - rc = ecryptfs_decrypt_page(page); 340 - if (rc) { 341 - printk(KERN_ERR "%s: Error decrypting page " 342 - "at index [%ld]; rc = [%d]\n", 343 - __func__, page->index, rc); 344 - ClearPageUptodate(page); 345 - goto out; 338 + if (prev_page_end_size 339 + >= i_size_read(page->mapping->host)) { 340 + zero_user(page, 0, PAGE_CACHE_SIZE); 341 + } else { 342 + rc = ecryptfs_decrypt_page(page); 343 + if (rc) { 344 + printk(KERN_ERR "%s: Error decrypting " 345 + "page at index [%ld]; " 346 + "rc = [%d]\n", 347 + __func__, page->index, rc); 348 + ClearPageUptodate(page); 349 + goto out; 350 + } 346 351 } 347 352 SetPageUptodate(page); 348 353 } 349 354 } 350 - prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT); 351 355 /* If creating a page or more of holes, zero them out via truncate. 352 356 * Note, this will increase i_size. */ 353 357 if (index != 0) {