Re: [PATCH 8/11] eCryptfs: Convert mmap functions to use persistent file
On Wed, Sep 19, 2007 at 10:50:57PM -0700, Andrew Morton wrote: > On Mon, 17 Sep 2007 16:50:16 -0500 Michael Halcrow <[EMAIL PROTECTED]> wrote: > > +ecryptfs_copy_up_encrypted_with_header(struct page *page, > > + struct ecryptfs_crypt_stat *crypt_stat) > > +{ ... > > + flush_dcache_page(page); > > + if (rc) { > > + ClearPageUptodate(page); > > + printk(KERN_ERR "%s: Error reading xattr " > > + "region; rc = [%d]\n", __FUNCTION__, rc); > > + goto out; > > + } > > + SetPageUptodate(page); > > I don't know what sort of page `page' refers to here, but normally we only > manipulate the page uptodate status under lock_page(). This is the page that eCryptfs gets via ecryptfs_aops->ecryptfs_readpage(), so this should be okay. The comment should make the fact that the page is locked explicit. Signed-off-by: Michael Halcrow <[EMAIL PROTECTED]> --- diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 04103ff..c6a8a33 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -111,7 +111,7 @@ static void set_header_info(char *page_virt, * ecryptfs_copy_up_encrypted_with_header * @page: Sort of a ``virtual'' representation of the encrypted lower *file. The actual lower file does not have the metadata in - *the header. + *the header. This is locked. * @crypt_stat: The eCryptfs inode's cryptographic context * * The ``view'' is the version of the file that userspace winds up - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 8/11] eCryptfs: Convert mmap functions to use persistent file
On Wed, Sep 19, 2007 at 10:50:57PM -0700, Andrew Morton wrote: On Mon, 17 Sep 2007 16:50:16 -0500 Michael Halcrow [EMAIL PROTECTED] wrote: +ecryptfs_copy_up_encrypted_with_header(struct page *page, + struct ecryptfs_crypt_stat *crypt_stat) +{ ... + flush_dcache_page(page); + if (rc) { + ClearPageUptodate(page); + printk(KERN_ERR %s: Error reading xattr + region; rc = [%d]\n, __FUNCTION__, rc); + goto out; + } + SetPageUptodate(page); I don't know what sort of page `page' refers to here, but normally we only manipulate the page uptodate status under lock_page(). This is the page that eCryptfs gets via ecryptfs_aops-ecryptfs_readpage(), so this should be okay. The comment should make the fact that the page is locked explicit. Signed-off-by: Michael Halcrow [EMAIL PROTECTED] --- diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 04103ff..c6a8a33 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -111,7 +111,7 @@ static void set_header_info(char *page_virt, * ecryptfs_copy_up_encrypted_with_header * @page: Sort of a ``virtual'' representation of the encrypted lower *file. The actual lower file does not have the metadata in - *the header. + *the header. This is locked. * @crypt_stat: The eCryptfs inode's cryptographic context * * The ``view'' is the version of the file that userspace winds up - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 8/11] eCryptfs: Convert mmap functions to use persistent file
On Mon, 17 Sep 2007 16:50:16 -0500 Michael Halcrow <[EMAIL PROTECTED]> wrote: > Convert readpage, prepare_write, and commit_write to use read_write.c > routines. Remove sync_page; I cannot think of a good reason for > implementing that in eCryptfs. > > Signed-off-by: Michael Halcrow <[EMAIL PROTECTED]> > --- > fs/ecryptfs/mmap.c | 199 > +++- > 1 files changed, 103 insertions(+), 96 deletions(-) > > diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c > index 60e635e..dd68dd3 100644 > --- a/fs/ecryptfs/mmap.c > +++ b/fs/ecryptfs/mmap.c > @@ -267,9 +267,78 @@ static void set_header_info(char *page_virt, > } > > /** > + * ecryptfs_copy_up_encrypted_with_header > + * @page: Sort of a ``virtual'' representation of the encrypted lower > + *file. The actual lower file does not have the metadata in > + *the header. > + * @crypt_stat: The eCryptfs inode's cryptographic context > + * > + * The ``view'' is the version of the file that userspace winds up > + * seeing, with the header information inserted. > + */ > +static int > +ecryptfs_copy_up_encrypted_with_header(struct page *page, > +struct ecryptfs_crypt_stat *crypt_stat) > +{ > + loff_t extent_num_in_page = 0; > + loff_t num_extents_per_page = (PAGE_CACHE_SIZE > +/ crypt_stat->extent_size); > + int rc = 0; > + > + while (extent_num_in_page < num_extents_per_page) { > + loff_t view_extent_num = ((page->index * num_extents_per_page) overflow? > + + extent_num_in_page); > + > + if (view_extent_num < crypt_stat->num_header_extents_at_front) { > + /* This is a header extent */ > + char *page_virt; > + > + page_virt = kmap_atomic(page, KM_USER0); > + memset(page_virt, 0, PAGE_CACHE_SIZE); > + /* TODO: Support more than one header extent */ > + if (view_extent_num == 0) { > + rc = ecryptfs_read_xattr_region( > + page_virt, page->mapping->host); > + set_header_info(page_virt, crypt_stat); > + } > + kunmap_atomic(page_virt, KM_USER0); > + flush_dcache_page(page); > + if (rc) { > + ClearPageUptodate(page); > + printk(KERN_ERR "%s: Error reading xattr " > +"region; rc = [%d]\n", __FUNCTION__, rc); > + goto out; > + } > + SetPageUptodate(page); I don't know what sort of page `page' refers to here, but normally we only manipulate the page uptodate status under lock_page(). > + } else { > + /* This is an encrypted data extent */ > + loff_t lower_offset = > + ((view_extent_num - > + crypt_stat->num_header_extents_at_front) > + * crypt_stat->extent_size); overflow? > + rc = ecryptfs_read_lower_page_segment( > + page, (lower_offset >> PAGE_CACHE_SHIFT), > + (lower_offset & ~PAGE_CACHE_MASK), > + crypt_stat->extent_size, page->mapping->host); > + if (rc) { > + printk(KERN_ERR "%s: Error attempting to read " > +"extent at offset [%lld] in the lower " > +"file; rc = [%d]\n", __FUNCTION__, > +lower_offset, rc); > + goto out; > + } > + } > + extent_num_in_page++; > + } > +out: > + return rc; > +} > + > +/** > * ecryptfs_readpage > - * @file: This is an ecryptfs file > - * @page: ecryptfs associated page to stick the read data into > + * @file: An eCryptfs file > + * @page: Page from eCryptfs inode mapping into which to stick the read data > * > * Read in a page, decrypting if necessary. > * > @@ -277,59 +346,35 @@ static void set_header_info(char *page_virt, > */ > static int ecryptfs_readpage(struct file *file, struct page *page) > { > + struct ecryptfs_crypt_stat *crypt_stat = > + > _inode_to_private(file->f_path.dentry->d_inode)->crypt_stat; > int rc = 0; > - struct ecryptfs_crypt_stat *crypt_stat; > > - BUG_ON(!(file && file->f_path.dentry && file->f_path.dentry->d_inode)); > - crypt_stat = _inode_to_private(file->f_path.dentry->d_inode) > - ->crypt_stat; > if (!crypt_stat > || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED) > || (crypt_stat->flags &
Re: [PATCH 8/11] eCryptfs: Convert mmap functions to use persistent file
On Mon, 17 Sep 2007 16:50:16 -0500 Michael Halcrow [EMAIL PROTECTED] wrote: Convert readpage, prepare_write, and commit_write to use read_write.c routines. Remove sync_page; I cannot think of a good reason for implementing that in eCryptfs. Signed-off-by: Michael Halcrow [EMAIL PROTECTED] --- fs/ecryptfs/mmap.c | 199 +++- 1 files changed, 103 insertions(+), 96 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 60e635e..dd68dd3 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -267,9 +267,78 @@ static void set_header_info(char *page_virt, } /** + * ecryptfs_copy_up_encrypted_with_header + * @page: Sort of a ``virtual'' representation of the encrypted lower + *file. The actual lower file does not have the metadata in + *the header. + * @crypt_stat: The eCryptfs inode's cryptographic context + * + * The ``view'' is the version of the file that userspace winds up + * seeing, with the header information inserted. + */ +static int +ecryptfs_copy_up_encrypted_with_header(struct page *page, +struct ecryptfs_crypt_stat *crypt_stat) +{ + loff_t extent_num_in_page = 0; + loff_t num_extents_per_page = (PAGE_CACHE_SIZE +/ crypt_stat-extent_size); + int rc = 0; + + while (extent_num_in_page num_extents_per_page) { + loff_t view_extent_num = ((page-index * num_extents_per_page) overflow? + + extent_num_in_page); + + if (view_extent_num crypt_stat-num_header_extents_at_front) { + /* This is a header extent */ + char *page_virt; + + page_virt = kmap_atomic(page, KM_USER0); + memset(page_virt, 0, PAGE_CACHE_SIZE); + /* TODO: Support more than one header extent */ + if (view_extent_num == 0) { + rc = ecryptfs_read_xattr_region( + page_virt, page-mapping-host); + set_header_info(page_virt, crypt_stat); + } + kunmap_atomic(page_virt, KM_USER0); + flush_dcache_page(page); + if (rc) { + ClearPageUptodate(page); + printk(KERN_ERR %s: Error reading xattr +region; rc = [%d]\n, __FUNCTION__, rc); + goto out; + } + SetPageUptodate(page); I don't know what sort of page `page' refers to here, but normally we only manipulate the page uptodate status under lock_page(). + } else { + /* This is an encrypted data extent */ + loff_t lower_offset = + ((view_extent_num - + crypt_stat-num_header_extents_at_front) + * crypt_stat-extent_size); overflow? + rc = ecryptfs_read_lower_page_segment( + page, (lower_offset PAGE_CACHE_SHIFT), + (lower_offset ~PAGE_CACHE_MASK), + crypt_stat-extent_size, page-mapping-host); + if (rc) { + printk(KERN_ERR %s: Error attempting to read +extent at offset [%lld] in the lower +file; rc = [%d]\n, __FUNCTION__, +lower_offset, rc); + goto out; + } + } + extent_num_in_page++; + } +out: + return rc; +} + +/** * ecryptfs_readpage - * @file: This is an ecryptfs file - * @page: ecryptfs associated page to stick the read data into + * @file: An eCryptfs file + * @page: Page from eCryptfs inode mapping into which to stick the read data * * Read in a page, decrypting if necessary. * @@ -277,59 +346,35 @@ static void set_header_info(char *page_virt, */ static int ecryptfs_readpage(struct file *file, struct page *page) { + struct ecryptfs_crypt_stat *crypt_stat = + ecryptfs_inode_to_private(file-f_path.dentry-d_inode)-crypt_stat; int rc = 0; - struct ecryptfs_crypt_stat *crypt_stat; - BUG_ON(!(file file-f_path.dentry file-f_path.dentry-d_inode)); - crypt_stat = ecryptfs_inode_to_private(file-f_path.dentry-d_inode) - -crypt_stat; if (!crypt_stat || !(crypt_stat-flags ECRYPTFS_ENCRYPTED) || (crypt_stat-flags ECRYPTFS_NEW_FILE)) { ecryptfs_printk(KERN_DEBUG, Passing through unencrypted page\n); -
[PATCH 8/11] eCryptfs: Convert mmap functions to use persistent file
Convert readpage, prepare_write, and commit_write to use read_write.c routines. Remove sync_page; I cannot think of a good reason for implementing that in eCryptfs. Signed-off-by: Michael Halcrow <[EMAIL PROTECTED]> --- fs/ecryptfs/mmap.c | 199 +++- 1 files changed, 103 insertions(+), 96 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 60e635e..dd68dd3 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -267,9 +267,78 @@ static void set_header_info(char *page_virt, } /** + * ecryptfs_copy_up_encrypted_with_header + * @page: Sort of a ``virtual'' representation of the encrypted lower + *file. The actual lower file does not have the metadata in + *the header. + * @crypt_stat: The eCryptfs inode's cryptographic context + * + * The ``view'' is the version of the file that userspace winds up + * seeing, with the header information inserted. + */ +static int +ecryptfs_copy_up_encrypted_with_header(struct page *page, + struct ecryptfs_crypt_stat *crypt_stat) +{ + loff_t extent_num_in_page = 0; + loff_t num_extents_per_page = (PAGE_CACHE_SIZE + / crypt_stat->extent_size); + int rc = 0; + + while (extent_num_in_page < num_extents_per_page) { + loff_t view_extent_num = ((page->index * num_extents_per_page) + + extent_num_in_page); + + if (view_extent_num < crypt_stat->num_header_extents_at_front) { + /* This is a header extent */ + char *page_virt; + + page_virt = kmap_atomic(page, KM_USER0); + memset(page_virt, 0, PAGE_CACHE_SIZE); + /* TODO: Support more than one header extent */ + if (view_extent_num == 0) { + rc = ecryptfs_read_xattr_region( + page_virt, page->mapping->host); + set_header_info(page_virt, crypt_stat); + } + kunmap_atomic(page_virt, KM_USER0); + flush_dcache_page(page); + if (rc) { + ClearPageUptodate(page); + printk(KERN_ERR "%s: Error reading xattr " + "region; rc = [%d]\n", __FUNCTION__, rc); + goto out; + } + SetPageUptodate(page); + } else { + /* This is an encrypted data extent */ + loff_t lower_offset = + ((view_extent_num - + crypt_stat->num_header_extents_at_front) +* crypt_stat->extent_size); + + rc = ecryptfs_read_lower_page_segment( + page, (lower_offset >> PAGE_CACHE_SHIFT), + (lower_offset & ~PAGE_CACHE_MASK), + crypt_stat->extent_size, page->mapping->host); + if (rc) { + printk(KERN_ERR "%s: Error attempting to read " + "extent at offset [%lld] in the lower " + "file; rc = [%d]\n", __FUNCTION__, + lower_offset, rc); + goto out; + } + } + extent_num_in_page++; + } +out: + return rc; +} + +/** * ecryptfs_readpage - * @file: This is an ecryptfs file - * @page: ecryptfs associated page to stick the read data into + * @file: An eCryptfs file + * @page: Page from eCryptfs inode mapping into which to stick the read data * * Read in a page, decrypting if necessary. * @@ -277,59 +346,35 @@ static void set_header_info(char *page_virt, */ static int ecryptfs_readpage(struct file *file, struct page *page) { + struct ecryptfs_crypt_stat *crypt_stat = + _inode_to_private(file->f_path.dentry->d_inode)->crypt_stat; int rc = 0; - struct ecryptfs_crypt_stat *crypt_stat; - BUG_ON(!(file && file->f_path.dentry && file->f_path.dentry->d_inode)); - crypt_stat = _inode_to_private(file->f_path.dentry->d_inode) - ->crypt_stat; if (!crypt_stat || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED) || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) { ecryptfs_printk(KERN_DEBUG, "Passing through unencrypted page\n"); - rc = ecryptfs_do_readpage(file, page, page->index); - if (rc) { - ecryptfs_printk(KERN_ERR, "Error reading page; rc = " -
[PATCH 8/11] eCryptfs: Convert mmap functions to use persistent file
Convert readpage, prepare_write, and commit_write to use read_write.c routines. Remove sync_page; I cannot think of a good reason for implementing that in eCryptfs. Signed-off-by: Michael Halcrow [EMAIL PROTECTED] --- fs/ecryptfs/mmap.c | 199 +++- 1 files changed, 103 insertions(+), 96 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 60e635e..dd68dd3 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -267,9 +267,78 @@ static void set_header_info(char *page_virt, } /** + * ecryptfs_copy_up_encrypted_with_header + * @page: Sort of a ``virtual'' representation of the encrypted lower + *file. The actual lower file does not have the metadata in + *the header. + * @crypt_stat: The eCryptfs inode's cryptographic context + * + * The ``view'' is the version of the file that userspace winds up + * seeing, with the header information inserted. + */ +static int +ecryptfs_copy_up_encrypted_with_header(struct page *page, + struct ecryptfs_crypt_stat *crypt_stat) +{ + loff_t extent_num_in_page = 0; + loff_t num_extents_per_page = (PAGE_CACHE_SIZE + / crypt_stat-extent_size); + int rc = 0; + + while (extent_num_in_page num_extents_per_page) { + loff_t view_extent_num = ((page-index * num_extents_per_page) + + extent_num_in_page); + + if (view_extent_num crypt_stat-num_header_extents_at_front) { + /* This is a header extent */ + char *page_virt; + + page_virt = kmap_atomic(page, KM_USER0); + memset(page_virt, 0, PAGE_CACHE_SIZE); + /* TODO: Support more than one header extent */ + if (view_extent_num == 0) { + rc = ecryptfs_read_xattr_region( + page_virt, page-mapping-host); + set_header_info(page_virt, crypt_stat); + } + kunmap_atomic(page_virt, KM_USER0); + flush_dcache_page(page); + if (rc) { + ClearPageUptodate(page); + printk(KERN_ERR %s: Error reading xattr + region; rc = [%d]\n, __FUNCTION__, rc); + goto out; + } + SetPageUptodate(page); + } else { + /* This is an encrypted data extent */ + loff_t lower_offset = + ((view_extent_num - + crypt_stat-num_header_extents_at_front) +* crypt_stat-extent_size); + + rc = ecryptfs_read_lower_page_segment( + page, (lower_offset PAGE_CACHE_SHIFT), + (lower_offset ~PAGE_CACHE_MASK), + crypt_stat-extent_size, page-mapping-host); + if (rc) { + printk(KERN_ERR %s: Error attempting to read + extent at offset [%lld] in the lower + file; rc = [%d]\n, __FUNCTION__, + lower_offset, rc); + goto out; + } + } + extent_num_in_page++; + } +out: + return rc; +} + +/** * ecryptfs_readpage - * @file: This is an ecryptfs file - * @page: ecryptfs associated page to stick the read data into + * @file: An eCryptfs file + * @page: Page from eCryptfs inode mapping into which to stick the read data * * Read in a page, decrypting if necessary. * @@ -277,59 +346,35 @@ static void set_header_info(char *page_virt, */ static int ecryptfs_readpage(struct file *file, struct page *page) { + struct ecryptfs_crypt_stat *crypt_stat = + ecryptfs_inode_to_private(file-f_path.dentry-d_inode)-crypt_stat; int rc = 0; - struct ecryptfs_crypt_stat *crypt_stat; - BUG_ON(!(file file-f_path.dentry file-f_path.dentry-d_inode)); - crypt_stat = ecryptfs_inode_to_private(file-f_path.dentry-d_inode) - -crypt_stat; if (!crypt_stat || !(crypt_stat-flags ECRYPTFS_ENCRYPTED) || (crypt_stat-flags ECRYPTFS_NEW_FILE)) { ecryptfs_printk(KERN_DEBUG, Passing through unencrypted page\n); - rc = ecryptfs_do_readpage(file, page, page-index); - if (rc) { - ecryptfs_printk(KERN_ERR, Error reading page; rc = - [%d]\n, rc); -