Skip to content

Commit 807b7eb

Browse files
Badari Pulavartytorvalds
authored andcommitted
ecryptfs: convert to use new aops
Convert ecryptfs to use write_begin/write_end Signed-off-by: Nick Piggin <npiggin@suse.de> Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com> Acked-by: Michael Halcrow <mhalcrow@us.ibm.com> Cc: Dave Kleikamp <shaggy@austin.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7d6c704 commit 807b7eb

1 file changed

Lines changed: 50 additions & 31 deletions

File tree

‎fs/ecryptfs/mmap.c‎

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -265,22 +265,34 @@ static int fill_zeros_to_end_of_page(struct page *page, unsigned int to)
265265
}
266266

267267
/**
268-
* ecryptfs_prepare_write
268+
* ecryptfs_write_begin
269269
* @file: The eCryptfs file
270-
* @page: The eCryptfs page
271-
* @from: The start byte from which we will write
272-
* @to: The end byte to which we will write
270+
* @mapping: The eCryptfs object
271+
* @pos: The file offset at which to start writing
272+
* @len: Length of the write
273+
* @flags: Various flags
274+
* @pagep: Pointer to return the page
275+
* @fsdata: Pointer to return fs data (unused)
273276
*
274277
* This function must zero any hole we create
275278
*
276279
* Returns zero on success; non-zero otherwise
277280
*/
278-
static int ecryptfs_prepare_write(struct file *file, struct page *page,
279-
unsigned from, unsigned to)
281+
static int ecryptfs_write_begin(struct file *file,
282+
struct address_space *mapping,
283+
loff_t pos, unsigned len, unsigned flags,
284+
struct page **pagep, void **fsdata)
280285
{
286+
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
287+
struct page *page;
281288
loff_t prev_page_end_size;
282289
int rc = 0;
283290

291+
page = __grab_cache_page(mapping, index);
292+
if (!page)
293+
return -ENOMEM;
294+
*pagep = page;
295+
284296
if (!PageUptodate(page)) {
285297
struct ecryptfs_crypt_stat *crypt_stat =
286298
&ecryptfs_inode_to_private(
@@ -289,8 +301,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
289301
if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)
290302
|| (crypt_stat->flags & ECRYPTFS_NEW_FILE)) {
291303
rc = ecryptfs_read_lower_page_segment(
292-
page, page->index, 0, PAGE_CACHE_SIZE,
293-
page->mapping->host);
304+
page, index, 0, PAGE_CACHE_SIZE, mapping->host);
294305
if (rc) {
295306
printk(KERN_ERR "%s: Error attemping to read "
296307
"lower page segment; rc = [%d]\n",
@@ -316,8 +327,8 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
316327
SetPageUptodate(page);
317328
} else {
318329
rc = ecryptfs_read_lower_page_segment(
319-
page, page->index, 0, PAGE_CACHE_SIZE,
320-
page->mapping->host);
330+
page, index, 0, PAGE_CACHE_SIZE,
331+
mapping->host);
321332
if (rc) {
322333
printk(KERN_ERR "%s: Error reading "
323334
"page; rc = [%d]\n",
@@ -339,10 +350,10 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
339350
SetPageUptodate(page);
340351
}
341352
}
342-
prev_page_end_size = ((loff_t)page->index << PAGE_CACHE_SHIFT);
353+
prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT);
343354
/* If creating a page or more of holes, zero them out via truncate.
344355
* Note, this will increase i_size. */
345-
if (page->index != 0) {
356+
if (index != 0) {
346357
if (prev_page_end_size > i_size_read(page->mapping->host)) {
347358
rc = ecryptfs_truncate(file->f_path.dentry,
348359
prev_page_end_size);
@@ -357,8 +368,8 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
357368
}
358369
/* Writing to a new page, and creating a small hole from start
359370
* of page? Zero it out. */
360-
if ((i_size_read(page->mapping->host) == prev_page_end_size)
361-
&& (from != 0))
371+
if ((i_size_read(mapping->host) == prev_page_end_size)
372+
&& (pos != 0))
362373
zero_user(page, 0, PAGE_CACHE_SIZE);
363374
out:
364375
return rc;
@@ -445,21 +456,28 @@ int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode)
445456
}
446457

447458
/**
448-
* ecryptfs_commit_write
459+
* ecryptfs_write_end
449460
* @file: The eCryptfs file object
461+
* @mapping: The eCryptfs object
462+
* @pos: The file position
463+
* @len: The length of the data (unused)
464+
* @copied: The amount of data copied
450465
* @page: The eCryptfs page
451-
* @from: Ignored (we rotate the page IV on each write)
452-
* @to: Ignored
466+
* @fsdata: The fsdata (unused)
453467
*
454468
* This is where we encrypt the data and pass the encrypted data to
455469
* the lower filesystem. In OpenPGP-compatible mode, we operate on
456470
* entire underlying packets.
457471
*/
458-
static int ecryptfs_commit_write(struct file *file, struct page *page,
459-
unsigned from, unsigned to)
472+
static int ecryptfs_write_end(struct file *file,
473+
struct address_space *mapping,
474+
loff_t pos, unsigned len, unsigned copied,
475+
struct page *page, void *fsdata)
460476
{
461-
loff_t pos;
462-
struct inode *ecryptfs_inode = page->mapping->host;
477+
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
478+
unsigned from = pos & (PAGE_CACHE_SIZE - 1);
479+
unsigned to = from + copied;
480+
struct inode *ecryptfs_inode = mapping->host;
463481
struct ecryptfs_crypt_stat *crypt_stat =
464482
&ecryptfs_inode_to_private(file->f_path.dentry->d_inode)->crypt_stat;
465483
int rc;
@@ -471,33 +489,34 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
471489
} else
472490
ecryptfs_printk(KERN_DEBUG, "Not a new file\n");
473491
ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
474-
"(page w/ index = [0x%.16x], to = [%d])\n", page->index,
475-
to);
492+
"(page w/ index = [0x%.16x], to = [%d])\n", index, to);
476493
/* Fills in zeros if 'to' goes beyond inode size */
477494
rc = fill_zeros_to_end_of_page(page, to);
478495
if (rc) {
479496
ecryptfs_printk(KERN_WARNING, "Error attempting to fill "
480-
"zeros in page with index = [0x%.16x]\n",
481-
page->index);
497+
"zeros in page with index = [0x%.16x]\n", index);
482498
goto out;
483499
}
484500
rc = ecryptfs_encrypt_page(page);
485501
if (rc) {
486502
ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper "
487-
"index [0x%.16x])\n", page->index);
503+
"index [0x%.16x])\n", index);
488504
goto out;
489505
}
490-
pos = (((loff_t)page->index) << PAGE_CACHE_SHIFT) + to;
491-
if (pos > i_size_read(ecryptfs_inode)) {
492-
i_size_write(ecryptfs_inode, pos);
506+
if (pos + copied > i_size_read(ecryptfs_inode)) {
507+
i_size_write(ecryptfs_inode, pos + copied);
493508
ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
494509
"[0x%.16x]\n", i_size_read(ecryptfs_inode));
495510
}
496511
rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode);
497512
if (rc)
498513
printk(KERN_ERR "Error writing inode size to metadata; "
499514
"rc = [%d]\n", rc);
515+
else
516+
rc = copied;
500517
out:
518+
unlock_page(page);
519+
page_cache_release(page);
501520
return rc;
502521
}
503522

@@ -518,7 +537,7 @@ static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block)
518537
struct address_space_operations ecryptfs_aops = {
519538
.writepage = ecryptfs_writepage,
520539
.readpage = ecryptfs_readpage,
521-
.prepare_write = ecryptfs_prepare_write,
522-
.commit_write = ecryptfs_commit_write,
540+
.write_begin = ecryptfs_write_begin,
541+
.write_end = ecryptfs_write_end,
523542
.bmap = ecryptfs_bmap,
524543
};

0 commit comments

Comments
 (0)