Convert ecryptfs to new aops. Signed-off-by: Nick Piggin <npiggin@xxxxxxx> --- Index: linux-2.6/fs/ecryptfs/mmap.c =================================================================== --- linux-2.6.orig/fs/ecryptfs/mmap.c +++ linux-2.6/fs/ecryptfs/mmap.c @@ -263,31 +263,38 @@ out: return 0; } -static int ecryptfs_prepare_write(struct file *file, struct page *page, - unsigned from, unsigned to) +static int ecryptfs_write_begin(struct file *file, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned flags, + struct page **pagep, void **fsdata) { + pgoff_t index = pos >> PAGE_CACHE_SHIFT; + struct page *page; int rc = 0; - if (from == 0 && to == PAGE_CACHE_SIZE) + page = __grab_cache_page(mapping, index); + if (!page) + return -ENOMEM; + + if (flags & AOP_FLAG_UNINTERRUPTIBLE && len == PAGE_CACHE_SIZE) goto out; /* If we are writing a full page, it will be up to date. */ if (!PageUptodate(page)) { - rc = ecryptfs_read_lower_page_segment(page, page->index, 0, + rc = ecryptfs_read_lower_page_segment(page, index, 0, PAGE_CACHE_SIZE, - page->mapping->host); + mapping->host); if (rc) { printk(KERN_ERR "%s: Error attemping to read lower " "page segment; rc = [%d]\n", __FUNCTION__, rc); - ClearPageUptodate(page); goto out; } else SetPageUptodate(page); } - if (page->index != 0) { + if (index != 0) { loff_t end_of_prev_pg_pos = - (((loff_t)page->index << PAGE_CACHE_SHIFT) - 1); + (((loff_t)index << PAGE_CACHE_SHIFT) - 1); - if (end_of_prev_pg_pos > i_size_read(page->mapping->host)) { + if (end_of_prev_pg_pos > i_size_read(mapping->host)) { rc = ecryptfs_truncate(file->f_path.dentry, end_of_prev_pg_pos); if (rc) { @@ -297,7 +304,7 @@ static int ecryptfs_prepare_write(struct goto out; } } - if (end_of_prev_pg_pos + 1 > i_size_read(page->mapping->host)) + if (end_of_prev_pg_pos + 1 > i_size_read(mapping->host)) zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0); } out: @@ -391,21 +398,25 @@ int ecryptfs_write_inode_size_to_metadat } /** - * ecryptfs_commit_write + * ecryptfs_write_end * @file: The eCryptfs file object + * @mapping: The eCryptfs object + * @pos, len: Ignored (we rotate the page IV on each write) * @page: The eCryptfs page - * @from: Ignored (we rotate the page IV on each write) - * @to: Ignored * * This is where we encrypt the data and pass the encrypted data to * the lower filesystem. In OpenPGP-compatible mode, we operate on * entire underlying packets. */ -static int ecryptfs_commit_write(struct file *file, struct page *page, - unsigned from, unsigned to) -{ - loff_t pos; - struct inode *ecryptfs_inode = page->mapping->host; +static int ecryptfs_write_end(struct file *file, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct page *page, void *fsdata) +{ + pgoff_t index = pos >> PAGE_CACHE_SHIFT; + unsigned from = pos & (PAGE_CACHE_SIZE - 1); + unsigned to = from + copied; + struct inode *ecryptfs_inode = mapping->host; struct ecryptfs_crypt_stat *crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)->crypt_stat; int rc; @@ -417,25 +428,22 @@ static int ecryptfs_commit_write(struct } else ecryptfs_printk(KERN_DEBUG, "Not a new file\n"); ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page" - "(page w/ index = [0x%.16x], to = [%d])\n", page->index, - to); + "(page w/ index = [0x%.16x], to = [%d])\n", index, to); /* Fills in zeros if 'to' goes beyond inode size */ rc = fill_zeros_to_end_of_page(page, to); if (rc) { ecryptfs_printk(KERN_WARNING, "Error attempting to fill " - "zeros in page with index = [0x%.16x]\n", - page->index); + "zeros in page with index = [0x%.16x]\n", index); goto out; } rc = ecryptfs_encrypt_page(page); if (rc) { ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper " - "index [0x%.16x])\n", page->index); + "index [0x%.16x])\n", index); goto out; } - pos = (((loff_t)page->index) << PAGE_CACHE_SHIFT) + to; - if (pos > i_size_read(ecryptfs_inode)) { - i_size_write(ecryptfs_inode, pos); + if (pos + copied > i_size_read(ecryptfs_inode)) { + i_size_write(ecryptfs_inode, pos + copied); ecryptfs_printk(KERN_DEBUG, "Expanded file size to " "[0x%.16x]\n", i_size_read(ecryptfs_inode)); } @@ -443,7 +451,11 @@ static int ecryptfs_commit_write(struct if (rc) printk(KERN_ERR "Error writing inode size to metadata; " "rc = [%d]\n", rc); + + rc = copied; out: + unlock_page(page); + page_cache_release(page); return rc; } @@ -464,7 +476,7 @@ static sector_t ecryptfs_bmap(struct add struct address_space_operations ecryptfs_aops = { .writepage = ecryptfs_writepage, .readpage = ecryptfs_readpage, - .prepare_write = ecryptfs_prepare_write, - .commit_write = ecryptfs_commit_write, + .write_begin = ecryptfs_write_begin, + .write_end = ecryptfs_write_end, .bmap = ecryptfs_bmap, }; - To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html