Commit 24562486be76cf223b8d911f45e1d26eb3364b13

Authored by Frank Swiderski
Committed by Tyler Hicks
1 parent f24b38874e

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>

Showing 1 changed file with 14 additions and 8 deletions Side-by-side Diff

... ... @@ -290,6 +290,7 @@
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;
296 297  
... ... @@ -335,18 +336,23 @@
335 336 SetPageUptodate(page);
336 337 }
337 338 } else {
338   - rc = ecryptfs_decrypt_page(page);
339   - if (rc) {
340   - printk(KERN_ERR "%s: Error decrypting page "
341   - "at index [%ld]; rc = [%d]\n",
342   - __func__, page->index, rc);
343   - ClearPageUptodate(page);
344   - goto out;
  339 + if (prev_page_end_size
  340 + >= i_size_read(page->mapping->host)) {
  341 + zero_user(page, 0, PAGE_CACHE_SIZE);
  342 + } else {
  343 + rc = ecryptfs_decrypt_page(page);
  344 + if (rc) {
  345 + printk(KERN_ERR "%s: Error decrypting "
  346 + "page at index [%ld]; "
  347 + "rc = [%d]\n",
  348 + __func__, page->index, rc);
  349 + ClearPageUptodate(page);
  350 + goto out;
  351 + }
345 352 }
346 353 SetPageUptodate(page);
347 354 }
348 355 }
349   - prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT);
350 356 /* If creating a page or more of holes, zero them out via truncate.
351 357 * Note, this will increase i_size. */
352 358 if (index != 0) {