提交 f4e420dc 编写于 作者: C Christoph Hellwig 提交者: Al Viro

clean up write_begin usage for directories in pagecache

For filesystem that implement directories in pagecache we call
block_write_begin with an already allocated page for this code, while the
normal regular file write path uses the default block_write_begin behaviour.

Get rid of the __foofs_write_begin helper and opencode the normal write_begin
call in foofs_write_begin, while adding a new foofs_prepare_chunk helper for
the directory code.  The added benefit is that foofs_prepare_chunk has
a much saner calling convention.

Note that the interruptible flag passed into block_write_begin is always
ignored if we already pass in a page (see next patch for details), and
we never were doing truncations of exessive blocks for this case either so we
can switch directly to block_write_begin_newtrunc.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
上级 282dc178
...@@ -448,6 +448,12 @@ ino_t ext2_inode_by_name(struct inode *dir, struct qstr *child) ...@@ -448,6 +448,12 @@ ino_t ext2_inode_by_name(struct inode *dir, struct qstr *child)
return res; return res;
} }
static int ext2_prepare_chunk(struct page *page, loff_t pos, unsigned len)
{
return block_write_begin_newtrunc(NULL, page->mapping, pos, len, 0,
&page, NULL, ext2_get_block);
}
/* Releases the page */ /* Releases the page */
void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de, void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
struct page *page, struct inode *inode, int update_times) struct page *page, struct inode *inode, int update_times)
...@@ -458,8 +464,7 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de, ...@@ -458,8 +464,7 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
int err; int err;
lock_page(page); lock_page(page);
err = __ext2_write_begin(NULL, page->mapping, pos, len, err = ext2_prepare_chunk(page, pos, len);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
BUG_ON(err); BUG_ON(err);
de->inode = cpu_to_le32(inode->i_ino); de->inode = cpu_to_le32(inode->i_ino);
ext2_set_de_type(de, inode); ext2_set_de_type(de, inode);
...@@ -542,8 +547,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode) ...@@ -542,8 +547,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
got_it: got_it:
pos = page_offset(page) + pos = page_offset(page) +
(char*)de - (char*)page_address(page); (char*)de - (char*)page_address(page);
err = __ext2_write_begin(NULL, page->mapping, pos, rec_len, 0, err = ext2_prepare_chunk(page, pos, rec_len);
&page, NULL);
if (err) if (err)
goto out_unlock; goto out_unlock;
if (de->inode) { if (de->inode) {
...@@ -576,8 +580,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode) ...@@ -576,8 +580,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
*/ */
int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page ) int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
{ {
struct address_space *mapping = page->mapping; struct inode *inode = page->mapping->host;
struct inode *inode = mapping->host;
char *kaddr = page_address(page); char *kaddr = page_address(page);
unsigned from = ((char*)dir - kaddr) & ~(ext2_chunk_size(inode)-1); unsigned from = ((char*)dir - kaddr) & ~(ext2_chunk_size(inode)-1);
unsigned to = ((char *)dir - kaddr) + unsigned to = ((char *)dir - kaddr) +
...@@ -601,8 +604,7 @@ int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page ) ...@@ -601,8 +604,7 @@ int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
from = (char*)pde - (char*)page_address(page); from = (char*)pde - (char*)page_address(page);
pos = page_offset(page) + from; pos = page_offset(page) + from;
lock_page(page); lock_page(page);
err = __ext2_write_begin(NULL, page->mapping, pos, to - from, 0, err = ext2_prepare_chunk(page, pos, to - from);
&page, NULL);
BUG_ON(err); BUG_ON(err);
if (pde) if (pde)
pde->rec_len = ext2_rec_len_to_disk(to - from); pde->rec_len = ext2_rec_len_to_disk(to - from);
...@@ -621,8 +623,7 @@ int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page ) ...@@ -621,8 +623,7 @@ int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
*/ */
int ext2_make_empty(struct inode *inode, struct inode *parent) int ext2_make_empty(struct inode *inode, struct inode *parent)
{ {
struct address_space *mapping = inode->i_mapping; struct page *page = grab_cache_page(inode->i_mapping, 0);
struct page *page = grab_cache_page(mapping, 0);
unsigned chunk_size = ext2_chunk_size(inode); unsigned chunk_size = ext2_chunk_size(inode);
struct ext2_dir_entry_2 * de; struct ext2_dir_entry_2 * de;
int err; int err;
...@@ -631,8 +632,7 @@ int ext2_make_empty(struct inode *inode, struct inode *parent) ...@@ -631,8 +632,7 @@ int ext2_make_empty(struct inode *inode, struct inode *parent)
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
err = __ext2_write_begin(NULL, page->mapping, 0, chunk_size, 0, err = ext2_prepare_chunk(page, 0, chunk_size);
&page, NULL);
if (err) { if (err) {
unlock_page(page); unlock_page(page);
goto fail; goto fail;
......
...@@ -127,9 +127,6 @@ extern void ext2_set_inode_flags(struct inode *inode); ...@@ -127,9 +127,6 @@ extern void ext2_set_inode_flags(struct inode *inode);
extern void ext2_get_inode_flags(struct ext2_inode_info *); extern void ext2_get_inode_flags(struct ext2_inode_info *);
extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
u64 start, u64 len); u64 start, u64 len);
int __ext2_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata);
/* ioctl.c */ /* ioctl.c */
extern long ext2_ioctl(struct file *, unsigned int, unsigned long); extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
......
...@@ -765,14 +765,6 @@ ext2_readpages(struct file *file, struct address_space *mapping, ...@@ -765,14 +765,6 @@ ext2_readpages(struct file *file, struct address_space *mapping,
return mpage_readpages(mapping, pages, nr_pages, ext2_get_block); return mpage_readpages(mapping, pages, nr_pages, ext2_get_block);
} }
int __ext2_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{
return block_write_begin_newtrunc(file, mapping, pos, len, flags,
pagep, fsdata, ext2_get_block);
}
static int static int
ext2_write_begin(struct file *file, struct address_space *mapping, ext2_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags, loff_t pos, unsigned len, unsigned flags,
...@@ -781,7 +773,8 @@ ext2_write_begin(struct file *file, struct address_space *mapping, ...@@ -781,7 +773,8 @@ ext2_write_begin(struct file *file, struct address_space *mapping,
int ret; int ret;
*pagep = NULL; *pagep = NULL;
ret = __ext2_write_begin(file, mapping, pos, len, flags, pagep, fsdata); ret = block_write_begin_newtrunc(file, mapping, pos, len, flags,
pagep, fsdata, ext2_get_block);
if (ret < 0) if (ret < 0)
ext2_write_failed(mapping, pos + len); ext2_write_failed(mapping, pos + len);
return ret; return ret;
......
...@@ -271,8 +271,7 @@ int minix_add_link(struct dentry *dentry, struct inode *inode) ...@@ -271,8 +271,7 @@ int minix_add_link(struct dentry *dentry, struct inode *inode)
got_it: got_it:
pos = page_offset(page) + p - (char *)page_address(page); pos = page_offset(page) + p - (char *)page_address(page);
err = __minix_write_begin(NULL, page->mapping, pos, sbi->s_dirsize, err = minix_prepare_chunk(page, pos, sbi->s_dirsize);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
if (err) if (err)
goto out_unlock; goto out_unlock;
memcpy (namx, name, namelen); memcpy (namx, name, namelen);
...@@ -297,8 +296,7 @@ int minix_add_link(struct dentry *dentry, struct inode *inode) ...@@ -297,8 +296,7 @@ int minix_add_link(struct dentry *dentry, struct inode *inode)
int minix_delete_entry(struct minix_dir_entry *de, struct page *page) int minix_delete_entry(struct minix_dir_entry *de, struct page *page)
{ {
struct address_space *mapping = page->mapping; struct inode *inode = page->mapping->host;
struct inode *inode = (struct inode*)mapping->host;
char *kaddr = page_address(page); char *kaddr = page_address(page);
loff_t pos = page_offset(page) + (char*)de - kaddr; loff_t pos = page_offset(page) + (char*)de - kaddr;
struct minix_sb_info *sbi = minix_sb(inode->i_sb); struct minix_sb_info *sbi = minix_sb(inode->i_sb);
...@@ -306,8 +304,7 @@ int minix_delete_entry(struct minix_dir_entry *de, struct page *page) ...@@ -306,8 +304,7 @@ int minix_delete_entry(struct minix_dir_entry *de, struct page *page)
int err; int err;
lock_page(page); lock_page(page);
err = __minix_write_begin(NULL, mapping, pos, len, err = minix_prepare_chunk(page, pos, len);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
if (err == 0) { if (err == 0) {
if (sbi->s_version == MINIX_V3) if (sbi->s_version == MINIX_V3)
((minix3_dirent *) de)->inode = 0; ((minix3_dirent *) de)->inode = 0;
...@@ -325,16 +322,14 @@ int minix_delete_entry(struct minix_dir_entry *de, struct page *page) ...@@ -325,16 +322,14 @@ int minix_delete_entry(struct minix_dir_entry *de, struct page *page)
int minix_make_empty(struct inode *inode, struct inode *dir) int minix_make_empty(struct inode *inode, struct inode *dir)
{ {
struct address_space *mapping = inode->i_mapping; struct page *page = grab_cache_page(inode->i_mapping, 0);
struct page *page = grab_cache_page(mapping, 0);
struct minix_sb_info *sbi = minix_sb(inode->i_sb); struct minix_sb_info *sbi = minix_sb(inode->i_sb);
char *kaddr; char *kaddr;
int err; int err;
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
err = __minix_write_begin(NULL, mapping, 0, 2 * sbi->s_dirsize, err = minix_prepare_chunk(page, 0, 2 * sbi->s_dirsize);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
if (err) { if (err) {
unlock_page(page); unlock_page(page);
goto fail; goto fail;
...@@ -425,8 +420,7 @@ int minix_empty_dir(struct inode * inode) ...@@ -425,8 +420,7 @@ int minix_empty_dir(struct inode * inode)
void minix_set_link(struct minix_dir_entry *de, struct page *page, void minix_set_link(struct minix_dir_entry *de, struct page *page,
struct inode *inode) struct inode *inode)
{ {
struct address_space *mapping = page->mapping; struct inode *dir = page->mapping->host;
struct inode *dir = mapping->host;
struct minix_sb_info *sbi = minix_sb(dir->i_sb); struct minix_sb_info *sbi = minix_sb(dir->i_sb);
loff_t pos = page_offset(page) + loff_t pos = page_offset(page) +
(char *)de-(char*)page_address(page); (char *)de-(char*)page_address(page);
...@@ -434,8 +428,7 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page, ...@@ -434,8 +428,7 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page,
lock_page(page); lock_page(page);
err = __minix_write_begin(NULL, mapping, pos, sbi->s_dirsize, err = minix_prepare_chunk(page, pos, sbi->s_dirsize);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
if (err == 0) { if (err == 0) {
if (sbi->s_version == MINIX_V3) if (sbi->s_version == MINIX_V3)
((minix3_dirent *) de)->inode = inode->i_ino; ((minix3_dirent *) de)->inode = inode->i_ino;
......
...@@ -357,12 +357,10 @@ static int minix_readpage(struct file *file, struct page *page) ...@@ -357,12 +357,10 @@ static int minix_readpage(struct file *file, struct page *page)
return block_read_full_page(page,minix_get_block); return block_read_full_page(page,minix_get_block);
} }
int __minix_write_begin(struct file *file, struct address_space *mapping, int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len)
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{ {
return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, return block_write_begin_newtrunc(NULL, page->mapping, pos, len, 0,
minix_get_block); &page, NULL, minix_get_block);
} }
static int minix_write_begin(struct file *file, struct address_space *mapping, static int minix_write_begin(struct file *file, struct address_space *mapping,
...@@ -370,7 +368,8 @@ static int minix_write_begin(struct file *file, struct address_space *mapping, ...@@ -370,7 +368,8 @@ static int minix_write_begin(struct file *file, struct address_space *mapping,
struct page **pagep, void **fsdata) struct page **pagep, void **fsdata)
{ {
*pagep = NULL; *pagep = NULL;
return __minix_write_begin(file, mapping, pos, len, flags, pagep, fsdata); return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
minix_get_block);
} }
static sector_t minix_bmap(struct address_space *mapping, sector_t block) static sector_t minix_bmap(struct address_space *mapping, sector_t block)
......
...@@ -53,9 +53,7 @@ extern int minix_new_block(struct inode * inode); ...@@ -53,9 +53,7 @@ extern int minix_new_block(struct inode * inode);
extern void minix_free_block(struct inode *inode, unsigned long block); extern void minix_free_block(struct inode *inode, unsigned long block);
extern unsigned long minix_count_free_blocks(struct minix_sb_info *sbi); extern unsigned long minix_count_free_blocks(struct minix_sb_info *sbi);
extern int minix_getattr(struct vfsmount *, struct dentry *, struct kstat *); extern int minix_getattr(struct vfsmount *, struct dentry *, struct kstat *);
extern int __minix_write_begin(struct file *file, struct address_space *mapping, extern int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len);
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata);
extern void V1_minix_truncate(struct inode *); extern void V1_minix_truncate(struct inode *);
extern void V2_minix_truncate(struct inode *); extern void V2_minix_truncate(struct inode *);
......
...@@ -80,23 +80,11 @@ static unsigned nilfs_last_byte(struct inode *inode, unsigned long page_nr) ...@@ -80,23 +80,11 @@ static unsigned nilfs_last_byte(struct inode *inode, unsigned long page_nr)
return last_byte; return last_byte;
} }
static int nilfs_prepare_chunk_uninterruptible(struct page *page, static int nilfs_prepare_chunk(struct page *page, unsigned from, unsigned to)
struct address_space *mapping,
unsigned from, unsigned to)
{ {
loff_t pos = page_offset(page) + from; loff_t pos = page_offset(page) + from;
return block_write_begin(NULL, mapping, pos, to - from, return block_write_begin_newtrunc(NULL, page->mapping, pos, to - from,
AOP_FLAG_UNINTERRUPTIBLE, &page, 0, &page, NULL, nilfs_get_block);
NULL, nilfs_get_block);
}
static int nilfs_prepare_chunk(struct page *page,
struct address_space *mapping,
unsigned from, unsigned to)
{
loff_t pos = page_offset(page) + from;
return block_write_begin(NULL, mapping, pos, to - from, 0, &page,
NULL, nilfs_get_block);
} }
static void nilfs_commit_chunk(struct page *page, static void nilfs_commit_chunk(struct page *page,
...@@ -449,7 +437,7 @@ void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de, ...@@ -449,7 +437,7 @@ void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
int err; int err;
lock_page(page); lock_page(page);
err = nilfs_prepare_chunk_uninterruptible(page, mapping, from, to); err = nilfs_prepare_chunk(page, from, to);
BUG_ON(err); BUG_ON(err);
de->inode = cpu_to_le64(inode->i_ino); de->inode = cpu_to_le64(inode->i_ino);
nilfs_set_de_type(de, inode); nilfs_set_de_type(de, inode);
...@@ -530,7 +518,7 @@ int nilfs_add_link(struct dentry *dentry, struct inode *inode) ...@@ -530,7 +518,7 @@ int nilfs_add_link(struct dentry *dentry, struct inode *inode)
got_it: got_it:
from = (char *)de - (char *)page_address(page); from = (char *)de - (char *)page_address(page);
to = from + rec_len; to = from + rec_len;
err = nilfs_prepare_chunk(page, page->mapping, from, to); err = nilfs_prepare_chunk(page, from, to);
if (err) if (err)
goto out_unlock; goto out_unlock;
if (de->inode) { if (de->inode) {
...@@ -587,7 +575,7 @@ int nilfs_delete_entry(struct nilfs_dir_entry *dir, struct page *page) ...@@ -587,7 +575,7 @@ int nilfs_delete_entry(struct nilfs_dir_entry *dir, struct page *page)
if (pde) if (pde)
from = (char *)pde - (char *)page_address(page); from = (char *)pde - (char *)page_address(page);
lock_page(page); lock_page(page);
err = nilfs_prepare_chunk(page, mapping, from, to); err = nilfs_prepare_chunk(page, from, to);
BUG_ON(err); BUG_ON(err);
if (pde) if (pde)
pde->rec_len = cpu_to_le16(to - from); pde->rec_len = cpu_to_le16(to - from);
...@@ -615,7 +603,7 @@ int nilfs_make_empty(struct inode *inode, struct inode *parent) ...@@ -615,7 +603,7 @@ int nilfs_make_empty(struct inode *inode, struct inode *parent)
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
err = nilfs_prepare_chunk(page, mapping, 0, chunk_size); err = nilfs_prepare_chunk(page, 0, chunk_size);
if (unlikely(err)) { if (unlikely(err)) {
unlock_page(page); unlock_page(page);
goto fail; goto fail;
......
...@@ -218,8 +218,7 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) ...@@ -218,8 +218,7 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode)
pos = page_offset(page) + pos = page_offset(page) +
(char*)de - (char*)page_address(page); (char*)de - (char*)page_address(page);
lock_page(page); lock_page(page);
err = __sysv_write_begin(NULL, page->mapping, pos, SYSV_DIRSIZE, err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
if (err) if (err)
goto out_unlock; goto out_unlock;
memcpy (de->name, name, namelen); memcpy (de->name, name, namelen);
...@@ -239,15 +238,13 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) ...@@ -239,15 +238,13 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode)
int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page)
{ {
struct address_space *mapping = page->mapping; struct inode *inode = page->mapping->host;
struct inode *inode = (struct inode*)mapping->host;
char *kaddr = (char*)page_address(page); char *kaddr = (char*)page_address(page);
loff_t pos = page_offset(page) + (char *)de - kaddr; loff_t pos = page_offset(page) + (char *)de - kaddr;
int err; int err;
lock_page(page); lock_page(page);
err = __sysv_write_begin(NULL, mapping, pos, SYSV_DIRSIZE, err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
BUG_ON(err); BUG_ON(err);
de->inode = 0; de->inode = 0;
err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); err = dir_commit_chunk(page, pos, SYSV_DIRSIZE);
...@@ -259,16 +256,14 @@ int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) ...@@ -259,16 +256,14 @@ int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page)
int sysv_make_empty(struct inode *inode, struct inode *dir) int sysv_make_empty(struct inode *inode, struct inode *dir)
{ {
struct address_space *mapping = inode->i_mapping; struct page *page = grab_cache_page(inode->i_mapping, 0);
struct page *page = grab_cache_page(mapping, 0);
struct sysv_dir_entry * de; struct sysv_dir_entry * de;
char *base; char *base;
int err; int err;
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
err = __sysv_write_begin(NULL, mapping, 0, 2 * SYSV_DIRSIZE, err = sysv_prepare_chunk(page, 0, 2 * SYSV_DIRSIZE);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
if (err) { if (err) {
unlock_page(page); unlock_page(page);
goto fail; goto fail;
...@@ -341,15 +336,13 @@ int sysv_empty_dir(struct inode * inode) ...@@ -341,15 +336,13 @@ int sysv_empty_dir(struct inode * inode)
void sysv_set_link(struct sysv_dir_entry *de, struct page *page, void sysv_set_link(struct sysv_dir_entry *de, struct page *page,
struct inode *inode) struct inode *inode)
{ {
struct address_space *mapping = page->mapping; struct inode *dir = page->mapping->host;
struct inode *dir = mapping->host;
loff_t pos = page_offset(page) + loff_t pos = page_offset(page) +
(char *)de-(char*)page_address(page); (char *)de-(char*)page_address(page);
int err; int err;
lock_page(page); lock_page(page);
err = __sysv_write_begin(NULL, mapping, pos, SYSV_DIRSIZE, err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
BUG_ON(err); BUG_ON(err);
de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino);
err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); err = dir_commit_chunk(page, pos, SYSV_DIRSIZE);
......
...@@ -459,12 +459,10 @@ static int sysv_readpage(struct file *file, struct page *page) ...@@ -459,12 +459,10 @@ static int sysv_readpage(struct file *file, struct page *page)
return block_read_full_page(page,get_block); return block_read_full_page(page,get_block);
} }
int __sysv_write_begin(struct file *file, struct address_space *mapping, int sysv_prepare_chunk(struct page *page, loff_t pos, unsigned len)
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{ {
return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, return block_write_begin_newtrunc(NULL, page->mapping, pos, len, 0,
get_block); &page, NULL, get_block);
} }
static int sysv_write_begin(struct file *file, struct address_space *mapping, static int sysv_write_begin(struct file *file, struct address_space *mapping,
...@@ -472,7 +470,8 @@ static int sysv_write_begin(struct file *file, struct address_space *mapping, ...@@ -472,7 +470,8 @@ static int sysv_write_begin(struct file *file, struct address_space *mapping,
struct page **pagep, void **fsdata) struct page **pagep, void **fsdata)
{ {
*pagep = NULL; *pagep = NULL;
return __sysv_write_begin(file, mapping, pos, len, flags, pagep, fsdata); return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
get_block);
} }
static sector_t sysv_bmap(struct address_space *mapping, sector_t block) static sector_t sysv_bmap(struct address_space *mapping, sector_t block)
......
...@@ -136,9 +136,7 @@ extern unsigned long sysv_count_free_blocks(struct super_block *); ...@@ -136,9 +136,7 @@ extern unsigned long sysv_count_free_blocks(struct super_block *);
/* itree.c */ /* itree.c */
extern void sysv_truncate(struct inode *); extern void sysv_truncate(struct inode *);
extern int __sysv_write_begin(struct file *file, struct address_space *mapping, extern int sysv_prepare_chunk(struct page *page, loff_t pos, unsigned len);
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata);
/* inode.c */ /* inode.c */
extern struct inode *sysv_iget(struct super_block *, unsigned int); extern struct inode *sysv_iget(struct super_block *, unsigned int);
......
...@@ -95,8 +95,7 @@ void ufs_set_link(struct inode *dir, struct ufs_dir_entry *de, ...@@ -95,8 +95,7 @@ void ufs_set_link(struct inode *dir, struct ufs_dir_entry *de,
int err; int err;
lock_page(page); lock_page(page);
err = __ufs_write_begin(NULL, page->mapping, pos, len, err = ufs_prepare_chunk(page, pos, len);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
BUG_ON(err); BUG_ON(err);
de->d_ino = cpu_to_fs32(dir->i_sb, inode->i_ino); de->d_ino = cpu_to_fs32(dir->i_sb, inode->i_ino);
...@@ -381,8 +380,7 @@ int ufs_add_link(struct dentry *dentry, struct inode *inode) ...@@ -381,8 +380,7 @@ int ufs_add_link(struct dentry *dentry, struct inode *inode)
got_it: got_it:
pos = page_offset(page) + pos = page_offset(page) +
(char*)de - (char*)page_address(page); (char*)de - (char*)page_address(page);
err = __ufs_write_begin(NULL, page->mapping, pos, rec_len, err = ufs_prepare_chunk(page, pos, rec_len);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
if (err) if (err)
goto out_unlock; goto out_unlock;
if (de->d_ino) { if (de->d_ino) {
...@@ -518,7 +516,6 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir, ...@@ -518,7 +516,6 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir,
struct page * page) struct page * page)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct address_space *mapping = page->mapping;
char *kaddr = page_address(page); char *kaddr = page_address(page);
unsigned from = ((char*)dir - kaddr) & ~(UFS_SB(sb)->s_uspi->s_dirblksize - 1); unsigned from = ((char*)dir - kaddr) & ~(UFS_SB(sb)->s_uspi->s_dirblksize - 1);
unsigned to = ((char*)dir - kaddr) + fs16_to_cpu(sb, dir->d_reclen); unsigned to = ((char*)dir - kaddr) + fs16_to_cpu(sb, dir->d_reclen);
...@@ -549,8 +546,7 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir, ...@@ -549,8 +546,7 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir,
pos = page_offset(page) + from; pos = page_offset(page) + from;
lock_page(page); lock_page(page);
err = __ufs_write_begin(NULL, mapping, pos, to - from, err = ufs_prepare_chunk(page, pos, to - from);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
BUG_ON(err); BUG_ON(err);
if (pde) if (pde)
pde->d_reclen = cpu_to_fs16(sb, to - from); pde->d_reclen = cpu_to_fs16(sb, to - from);
...@@ -577,8 +573,7 @@ int ufs_make_empty(struct inode * inode, struct inode *dir) ...@@ -577,8 +573,7 @@ int ufs_make_empty(struct inode * inode, struct inode *dir)
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
err = __ufs_write_begin(NULL, mapping, 0, chunk_size, err = ufs_prepare_chunk(page, 0, chunk_size);
AOP_FLAG_UNINTERRUPTIBLE, &page, NULL);
if (err) { if (err) {
unlock_page(page); unlock_page(page);
goto fail; goto fail;
......
...@@ -558,12 +558,10 @@ static int ufs_readpage(struct file *file, struct page *page) ...@@ -558,12 +558,10 @@ static int ufs_readpage(struct file *file, struct page *page)
return block_read_full_page(page,ufs_getfrag_block); return block_read_full_page(page,ufs_getfrag_block);
} }
int __ufs_write_begin(struct file *file, struct address_space *mapping, int ufs_prepare_chunk(struct page *page, loff_t pos, unsigned len)
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{ {
return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, return block_write_begin_newtrunc(NULL, page->mapping, pos, len, 0,
ufs_getfrag_block); &page, NULL, ufs_getfrag_block);
} }
static int ufs_write_begin(struct file *file, struct address_space *mapping, static int ufs_write_begin(struct file *file, struct address_space *mapping,
...@@ -571,7 +569,8 @@ static int ufs_write_begin(struct file *file, struct address_space *mapping, ...@@ -571,7 +569,8 @@ static int ufs_write_begin(struct file *file, struct address_space *mapping,
struct page **pagep, void **fsdata) struct page **pagep, void **fsdata)
{ {
*pagep = NULL; *pagep = NULL;
return __ufs_write_begin(file, mapping, pos, len, flags, pagep, fsdata); return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
ufs_getfrag_block);
} }
static sector_t ufs_bmap(struct address_space *mapping, sector_t block) static sector_t ufs_bmap(struct address_space *mapping, sector_t block)
......
...@@ -257,9 +257,7 @@ ufs_set_inode_gid(struct super_block *sb, struct ufs_inode *inode, u32 value) ...@@ -257,9 +257,7 @@ ufs_set_inode_gid(struct super_block *sb, struct ufs_inode *inode, u32 value)
extern dev_t ufs_get_inode_dev(struct super_block *, struct ufs_inode_info *); extern dev_t ufs_get_inode_dev(struct super_block *, struct ufs_inode_info *);
extern void ufs_set_inode_dev(struct super_block *, struct ufs_inode_info *, dev_t); extern void ufs_set_inode_dev(struct super_block *, struct ufs_inode_info *, dev_t);
extern int __ufs_write_begin(struct file *file, struct address_space *mapping, extern int ufs_prepare_chunk(struct page *page, loff_t pos, unsigned len);
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata);
/* /*
* These functions manipulate ufs buffers * These functions manipulate ufs buffers
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册