Skip to content

Commit ea0f04e

Browse files
Christoph HellwigAl Viro
authored andcommitted
get rid of nobh_write_begin_newtrunc
Move the call to vmtruncate to get rid of accessive blocks to the only remaining caller and rename the non-truncating version to nobh_write_begin. Get rid of the superflous file argument to it while we're at it. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent eafdc7d commit ea0f04e

4 files changed

Lines changed: 17 additions & 46 deletions

File tree

‎fs/buffer.c‎

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,11 +2510,11 @@ static void attach_nobh_buffers(struct page *page, struct buffer_head *head)
25102510
}
25112511

25122512
/*
2513-
* Filesystems implementing the new truncate sequence should use the
2514-
* _newtrunc postfix variant which won't incorrectly call vmtruncate.
2513+
* On entry, the page is fully not uptodate.
2514+
* On exit the page is fully uptodate in the areas outside (from,to)
25152515
* The filesystem needs to handle block truncation upon failure.
25162516
*/
2517-
int nobh_write_begin_newtrunc(struct file *file, struct address_space *mapping,
2517+
int nobh_write_begin(struct address_space *mapping,
25182518
loff_t pos, unsigned len, unsigned flags,
25192519
struct page **pagep, void **fsdata,
25202520
get_block_t *get_block)
@@ -2547,7 +2547,7 @@ int nobh_write_begin_newtrunc(struct file *file, struct address_space *mapping,
25472547
unlock_page(page);
25482548
page_cache_release(page);
25492549
*pagep = NULL;
2550-
return block_write_begin_newtrunc(file, mapping, pos, len,
2550+
return block_write_begin_newtrunc(NULL, mapping, pos, len,
25512551
flags, pagep, fsdata, get_block);
25522552
}
25532553

@@ -2654,35 +2654,6 @@ int nobh_write_begin_newtrunc(struct file *file, struct address_space *mapping,
26542654

26552655
return ret;
26562656
}
2657-
EXPORT_SYMBOL(nobh_write_begin_newtrunc);
2658-
2659-
/*
2660-
* On entry, the page is fully not uptodate.
2661-
* On exit the page is fully uptodate in the areas outside (from,to)
2662-
*/
2663-
int nobh_write_begin(struct file *file, struct address_space *mapping,
2664-
loff_t pos, unsigned len, unsigned flags,
2665-
struct page **pagep, void **fsdata,
2666-
get_block_t *get_block)
2667-
{
2668-
int ret;
2669-
2670-
ret = nobh_write_begin_newtrunc(file, mapping, pos, len, flags,
2671-
pagep, fsdata, get_block);
2672-
2673-
/*
2674-
* prepare_write() may have instantiated a few blocks
2675-
* outside i_size. Trim these off again. Don't need
2676-
* i_size_read because we hold i_mutex.
2677-
*/
2678-
if (unlikely(ret)) {
2679-
loff_t isize = mapping->host->i_size;
2680-
if (pos + len > isize)
2681-
vmtruncate(mapping->host, isize);
2682-
}
2683-
2684-
return ret;
2685-
}
26862657
EXPORT_SYMBOL(nobh_write_begin);
26872658

26882659
int nobh_write_end(struct file *file, struct address_space *mapping,

‎fs/ext2/inode.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,8 @@ ext2_nobh_write_begin(struct file *file, struct address_space *mapping,
806806
{
807807
int ret;
808808

809-
/*
810-
* Dir-in-pagecache still uses ext2_write_begin. Would have to rework
811-
* directory handling code to pass around offsets rather than struct
812-
* pages in order to make this work easily.
813-
*/
814-
ret = nobh_write_begin_newtrunc(file, mapping, pos, len, flags, pagep,
815-
fsdata, ext2_get_block);
809+
ret = nobh_write_begin(mapping, pos, len, flags, pagep, fsdata,
810+
ext2_get_block);
816811
if (ret < 0)
817812
ext2_write_failed(mapping, pos + len);
818813
return ret;

‎fs/jfs/inode.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,17 @@ static int jfs_write_begin(struct file *file, struct address_space *mapping,
303303
loff_t pos, unsigned len, unsigned flags,
304304
struct page **pagep, void **fsdata)
305305
{
306-
return nobh_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
306+
int ret;
307+
308+
ret = nobh_write_begin(mapping, pos, len, flags, pagep, fsdata,
307309
jfs_get_block);
310+
if (unlikely(ret)) {
311+
loff_t isize = mapping->host->i_size;
312+
if (pos + len > isize)
313+
vmtruncate(mapping->host, isize);
314+
}
315+
316+
return ret;
308317
}
309318

310319
static sector_t jfs_bmap(struct address_space *mapping, sector_t block)

‎include/linux/buffer_head.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,7 @@ void block_sync_page(struct page *);
231231
sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *);
232232
int block_truncate_page(struct address_space *, loff_t, get_block_t *);
233233
int file_fsync(struct file *, int);
234-
int nobh_write_begin_newtrunc(struct file *, struct address_space *,
235-
loff_t, unsigned, unsigned,
236-
struct page **, void **, get_block_t*);
237-
int nobh_write_begin(struct file *, struct address_space *,
238-
loff_t, unsigned, unsigned,
234+
int nobh_write_begin(struct address_space *, loff_t, unsigned, unsigned,
239235
struct page **, void **, get_block_t*);
240236
int nobh_write_end(struct file *, struct address_space *,
241237
loff_t, unsigned, unsigned,

0 commit comments

Comments
 (0)