mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Trond Myklebust <Trond.Myklebust@netapp.com>
To: David Howells <dhowells@redhat.com>
Cc: viro@ftp.linux.org.uk, hch@infradead.org, sds@tycho.nsa.gov,
	casey@schaufler-ca.com, linux-kernel@vger.kernel.org,
	selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org
Subject: Re: [PATCH 10/22] CacheFiles: Add a hook to write a single page of data to an inode
Date: Fri, 21 Sep 2007 15:30:55 -0400	[thread overview]
Message-ID: <1190403055.6721.3.camel@heimdal.trondhjem.org> (raw)
In-Reply-To: <20070921144755.8323.45791.stgit@warthog.procyon.org.uk>

On Fri, 2007-09-21 at 15:47 +0100, David Howells wrote:
> Add an address space operation to write one single page of data to an inode at
> a page-aligned location (thus permitting the implementation to be highly
> optimised).
> 
> This is used by CacheFiles to store the contents of netfs pages into their
> backing file pages.
> 
> Supply a generic implementation for this that uses the prepare_write() and
> commit_write() address_space operations to bound a copy directly into the page
> cache.
> 
> Hook the Ext2 and Ext3 operations to the generic implementation.

So why do you need a new address space operation? AFAICS the generic
implementation will work for pretty much everyone who supports the
existing prepare_write()/commit_write().
Furthermore, you don't appear to supply any alternative "optimised"
implementations...

Trond


> Signed-Off-By: David Howells <dhowells@redhat.com>
> ---
> 
>  fs/ext2/inode.c    |    2 +
>  fs/ext3/inode.c    |    3 ++
>  include/linux/fs.h |    7 ++++
>  mm/filemap.c       |   95 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 107 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
> index 0079b2c..b3e4b50 100644
> --- a/fs/ext2/inode.c
> +++ b/fs/ext2/inode.c
> @@ -695,6 +695,7 @@ const struct address_space_operations ext2_aops = {
>  	.direct_IO		= ext2_direct_IO,
>  	.writepages		= ext2_writepages,
>  	.migratepage		= buffer_migrate_page,
> +	.write_one_page		= generic_file_buffered_write_one_page,
>  };
>  
>  const struct address_space_operations ext2_aops_xip = {
> @@ -713,6 +714,7 @@ const struct address_space_operations ext2_nobh_aops = {
>  	.direct_IO		= ext2_direct_IO,
>  	.writepages		= ext2_writepages,
>  	.migratepage		= buffer_migrate_page,
> +	.write_one_page		= generic_file_buffered_write_one_page,
>  };
>  
>  /*
> diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
> index de4e316..93809eb 100644
> --- a/fs/ext3/inode.c
> +++ b/fs/ext3/inode.c
> @@ -1713,6 +1713,7 @@ static const struct address_space_operations ext3_ordered_aops = {
>  	.releasepage	= ext3_releasepage,
>  	.direct_IO	= ext3_direct_IO,
>  	.migratepage	= buffer_migrate_page,
> +	.write_one_page	= generic_file_buffered_write_one_page,
>  };
>  
>  static const struct address_space_operations ext3_writeback_aops = {
> @@ -1727,6 +1728,7 @@ static const struct address_space_operations ext3_writeback_aops = {
>  	.releasepage	= ext3_releasepage,
>  	.direct_IO	= ext3_direct_IO,
>  	.migratepage	= buffer_migrate_page,
> +	.write_one_page	= generic_file_buffered_write_one_page,
>  };
>  
>  static const struct address_space_operations ext3_journalled_aops = {
> @@ -1740,6 +1742,7 @@ static const struct address_space_operations ext3_journalled_aops = {
>  	.bmap		= ext3_bmap,
>  	.invalidatepage	= ext3_invalidatepage,
>  	.releasepage	= ext3_releasepage,
> +	.write_one_page	= generic_file_buffered_write_one_page,
>  };
>  
>  void ext3_set_aops(struct inode *inode)
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index bf35441..38f67ac 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -434,6 +434,11 @@ struct address_space_operations {
>  	int (*migratepage) (struct address_space *,
>  			struct page *, struct page *);
>  	int (*launder_page) (struct page *);
> +	/* write the contents of the source page over the page at the specified
> +	 * index in the target address space (the source page does not need to
> +	 * be related to the target address space) */
> +	int (*write_one_page)(struct address_space *, pgoff_t, struct page *);
> +
>  };
>  
>  struct backing_dev_info;
> @@ -1669,6 +1674,8 @@ extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *,
>  		unsigned long *, loff_t, loff_t *, size_t, size_t);
>  extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *,
>  		unsigned long, loff_t, loff_t *, size_t, ssize_t);
> +extern int generic_file_buffered_write_one_page(struct address_space *,
> +						pgoff_t, struct page *);
>  extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
>  extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
>  extern void do_generic_mapping_read(struct address_space *mapping,
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 3a61923..21aeee9 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2016,6 +2016,101 @@ zero_length_segment:
>  }
>  EXPORT_SYMBOL(generic_file_buffered_write);
>  
> +/**
> + * generic_file_buffered_write_one_page - Write a single page of data to an
> + *	inode
> + * @mapping - The address space of the target inode
> + * @index - The target page in the target inode to fill
> + * @source - The data to write into the target page
> + *
> + * Write the data from the source page to the page in the nominated address
> + * space at the @index specified.  Note that the file will not be extended if
> + * the page crosses the EOF marker, in which case only the first part of the
> + * page will be written.
> + *
> + * The @source page does not need to have any association with the file or the
> + * target page offset.
> + */
> +int generic_file_buffered_write_one_page(struct address_space *mapping,
> +					 pgoff_t index,
> +					 struct page *source)
> +{
> +	const struct address_space_operations *a_ops = mapping->a_ops;
> +	struct pagevec	lru_pvec;
> +	struct page *page, *cached_page = NULL;
> +	unsigned psize;
> +	loff_t isize;
> +	long status = 0;
> +
> +	pagevec_init(&lru_pvec, 0);
> +
> +	page = __grab_cache_page(mapping, index, &cached_page, &lru_pvec);
> +	if (!page) {
> +		BUG_ON(cached_page);
> +		return -ENOMEM;
> +	}
> +
> +	psize = PAGE_CACHE_SIZE;
> +	isize = i_size_read(mapping->host);
> +	if ((isize >> PAGE_SHIFT) == index)
> +		psize = isize & (PAGE_SIZE - 1);
> +
> +	status = a_ops->prepare_write(NULL, page, 0, psize);
> +	if (unlikely(status)) {
> +		isize = i_size_read(mapping->host);
> +
> +		if (status != AOP_TRUNCATED_PAGE)
> +			unlock_page(page);
> +		page_cache_release(page);
> +		if (status == AOP_TRUNCATED_PAGE)
> +			goto sync;
> +
> +		/* prepare_write() may have instantiated a few blocks outside
> +		 * i_size.  Trim these off again.
> +		 */
> +		if ((1ULL << (index + 1)) > isize)
> +			vmtruncate(mapping->host, isize);
> +		goto sync;
> +	}
> +
> +	copy_highpage(page, source);
> +	flush_dcache_page(page);
> +
> +	status = a_ops->commit_write(NULL, page, 0, psize);
> +	if (status == AOP_TRUNCATED_PAGE) {
> +		page_cache_release(page);
> +		goto sync;
> +	}
> +
> +	if (status > 0)
> +		status = 0;
> +
> +	unlock_page(page);
> +	mark_page_accessed(page);
> +	page_cache_release(page);
> +	if (status < 0)
> +		return status;
> +
> +	balance_dirty_pages_ratelimited(mapping);
> +	cond_resched();
> +
> +sync:
> +	if (cached_page)
> +		page_cache_release(cached_page);
> +
> +	/* the caller must handle O_SYNC themselves, but we handle S_SYNC and
> +	 * MS_SYNCHRONOUS here */
> +	if (unlikely(IS_SYNC(mapping->host)) && !a_ops->writepage)
> +		status = generic_osync_inode(mapping->host, mapping,
> +					     OSYNC_METADATA | OSYNC_DATA);
> +
> +	/* the caller must handle O_DIRECT for themselves */
> +
> +	pagevec_lru_add(&lru_pvec);
> +	return status;
> +}
> +EXPORT_SYMBOL(generic_file_buffered_write_one_page);
> +
>  static ssize_t
>  __generic_file_aio_write_nolock(struct kiocb *iocb, const struct iovec *iov,
>  				unsigned long nr_segs, loff_t *ppos)

  reply	other threads:[~2007-09-21 19:31 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-21 14:47 [PATCH 00/22] Introduce credential record David Howells
2007-09-21 14:47 ` [PATCH 01/22] CRED: Introduce a COW credentials record David Howells
2007-09-21 14:47 ` [PATCH 02/22] CRED: Split the task security data and move part of it into struct cred David Howells
2007-09-21 14:47 ` [PATCH 03/22] CRED: Move the effective capabilities into the cred struct David Howells
2007-09-21 14:47 ` [PATCH 04/22] CRED: Request a credential record for a kernel service David Howells
2007-09-21 14:47 ` [PATCH 05/22] FS-Cache: Release page->private after failed readahead David Howells
2007-09-21 14:47 ` [PATCH 06/22] FS-Cache: Recruit a couple of page flags for cache management David Howells
2007-09-21 14:47 ` [PATCH 07/22] FS-Cache: Provide an add_wait_queue_tail() function David Howells
2007-09-21 14:47 ` [PATCH 08/22] FS-Cache: Generic filesystem caching facility David Howells
2007-09-21 14:47 ` [PATCH 09/22] CacheFiles: Add missing copy_page export for ia64 David Howells
2007-09-21 14:47 ` [PATCH 10/22] CacheFiles: Add a hook to write a single page of data to an inode David Howells
2007-09-21 19:30   ` Trond Myklebust [this message]
2007-09-21 23:11   ` David Howells
2007-09-21 14:48 ` [PATCH 11/22] CacheFiles: Permit the page lock state to be monitored David Howells
2007-09-21 19:33   ` Trond Myklebust
2007-09-21 23:14   ` David Howells
2007-09-21 14:48 ` [PATCH 12/22] CacheFiles: Export things for CacheFiles David Howells
2007-09-21 14:48 ` [PATCH 13/22] CacheFiles: A cache that backs onto a mounted filesystem David Howells
2007-09-21 14:48 ` [PATCH 14/22] NFS: Use local caching David Howells
2007-09-21 17:00   ` Peter Staubach
2007-09-21 23:22   ` David Howells
2007-09-21 23:37   ` David Howells
2007-09-24 13:31     ` Peter Staubach
2007-09-21 14:48 ` [PATCH 15/22] NFS: Configuration and mount option changes to enable local caching on NFS David Howells
2007-09-21 14:48 ` [PATCH 16/22] NFS: Display local caching state David Howells
2007-09-21 14:48 ` [PATCH 17/22] AFS: Add TestSetPageError() David Howells
2007-09-21 14:48 ` [PATCH 18/22] AFS: Add a function to excise a rejected write from the pagecache David Howells
2007-09-21 14:48 ` [PATCH 19/22] AFS: Improve handling of a rejected writeback David Howells
2007-09-21 14:48 ` [PATCH 20/22] AFS: Implement shared-writable mmap David Howells
2007-09-21 14:48 ` [PATCH 21/22] AF_RXRPC: Save the operation ID for debugging David Howells
2007-09-21 14:48 ` [PATCH 22/22] FS-Cache: Make kAFS use FS-Cache David Howells
2007-09-21 14:58 ` [PATCH 00/22] Introduce credential record David Howells
2007-09-21 15:36 ` Casey Schaufler
2007-09-21 15:40   ` David Howells
2007-09-21 16:04     ` Casey Schaufler
2007-09-21 23:18       ` David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1190403055.6721.3.camel@heimdal.trondhjem.org \
    --to=trond.myklebust@netapp.com \
    --cc=casey@schaufler-ca.com \
    --cc=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    --cc=viro@ftp.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®