From: David Chinner <dgc@sgi.com>
To: xfs@oss.sgi.com
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 1 of 2] Implement generic block_page_mkwrite() functionality
Date: Wed, 7 Feb 2007 23:55:27 +1100 [thread overview]
Message-ID: <20070207125527.GM44411608@melbourne.sgi.com> (raw)
In-Reply-To: <20070207124922.GK44411608@melbourne.sgi.com>
Mental Note: must remember to refresh patch after fixing compile
errors. New patch attached.
-
On Christoph's suggestion, take the guts of the proposed
xfs_vm_page_mkwrite function and implement it as a generic
core function as it used no specific XFS code at all.
This allows any filesystem to easily hook the ->page_mkwrite()
VM callout to allow them to set up pages dirtied by mmap
writes correctly for later writeout.
Signed-Off-By: Dave Chinner <dgc@sgi.com>
---
fs/buffer.c | 30 ++++++++++++++++++++++++++++++
include/linux/buffer_head.h | 2 ++
2 files changed, 32 insertions(+)
Index: 2.6.x-xfs-new/fs/buffer.c
===================================================================
--- 2.6.x-xfs-new.orig/fs/buffer.c 2007-02-07 23:00:05.000000000 +1100
+++ 2.6.x-xfs-new/fs/buffer.c 2007-02-07 23:09:47.642356116 +1100
@@ -2194,6 +2194,36 @@ int generic_commit_write(struct file *fi
return 0;
}
+/*
+ * block_page_mkwrite() is not allowed to change the file size as
+ * it gets called from a page fault handler when a page is first
+ * dirtied. Hence we must be careful to check for EOF conditions
+ * here. We set the page up correctly for a written page which means
+ * we get ENOSPC checking when writing into holes and correct
+ * delalloc and unwritten extent mapping on filesystems that support
+ * these features.
+ */
+int
+block_page_mkwrite(struct vm_area_struct *vma, struct page *page,
+ get_block_t get_block)
+{
+ struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
+ unsigned long end;
+ int ret = 0;
+
+ if (((page->index + 1) << PAGE_CACHE_SHIFT) > i_size_read(inode))
+ end = i_size_read(inode) & ~PAGE_CACHE_MASK;
+ else
+ end = PAGE_CACHE_SIZE;
+
+ lock_page(page);
+ ret = block_prepare_write(page, 0, end, get_block);
+ if (!ret)
+ ret = block_commit_write(page, 0, end);
+ unlock_page(page);
+
+ return ret;
+}
/*
* nobh_prepare_write()'s prereads are special: the buffer_heads are freed
Index: 2.6.x-xfs-new/include/linux/buffer_head.h
===================================================================
--- 2.6.x-xfs-new.orig/include/linux/buffer_head.h 2007-02-07 23:00:02.000000000 +1100
+++ 2.6.x-xfs-new/include/linux/buffer_head.h 2007-02-07 23:19:25.110816993 +1100
@@ -206,6 +206,8 @@ int cont_prepare_write(struct page*, uns
int generic_cont_expand(struct inode *inode, loff_t size);
int generic_cont_expand_simple(struct inode *inode, loff_t size);
int block_commit_write(struct page *page, unsigned from, unsigned to);
+int block_page_mkwrite(struct vm_area_struct *vma, struct page *page,
+ get_block_t get_block);
void block_sync_page(struct page *);
sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *);
int generic_commit_write(struct file *, struct page *, unsigned, unsigned);
next prev parent reply other threads:[~2007-02-07 12:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-07 12:49 [PATCH 1 of 2] Implement generic block_page_mkwrite() functionality David Chinner
2007-02-07 12:55 ` David Chinner [this message]
2007-02-07 13:00 ` Hugh Dickins
2007-02-07 14:44 ` David Chinner
2007-02-07 15:52 ` Chris Mason
2007-02-08 2:34 ` Nick Piggin
2007-02-07 15:56 ` Hugh Dickins
2007-02-07 22:50 ` David Chinner
2007-02-08 13:11 ` Chris Mason
2007-02-08 22:30 ` David Chinner
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=20070207125527.GM44411608@melbourne.sgi.com \
--to=dgc@sgi.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=xfs@oss.sgi.com \
/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;
as well as URLs for NNTP newsgroup(s).