Skip to content

Commit ebdec24

Browse files
Christoph HellwigAl Viro
authored andcommitted
fs: kill block_prepare_write
__block_write_begin and block_prepare_write are identical except for slightly different calling conventions. Convert all callers to the __block_write_begin calling conventions and drop block_prepare_write. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 56b0dac commit ebdec24

14 files changed

Lines changed: 39 additions & 73 deletions

File tree

‎fs/buffer.c‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,9 +1834,11 @@ void page_zero_new_buffers(struct page *page, unsigned from, unsigned to)
18341834
}
18351835
EXPORT_SYMBOL(page_zero_new_buffers);
18361836

1837-
int block_prepare_write(struct page *page, unsigned from, unsigned to,
1837+
int __block_write_begin(struct page *page, loff_t pos, unsigned len,
18381838
get_block_t *get_block)
18391839
{
1840+
unsigned from = pos & (PAGE_CACHE_SIZE - 1);
1841+
unsigned to = from + len;
18401842
struct inode *inode = page->mapping->host;
18411843
unsigned block_start, block_end;
18421844
sector_t block;
@@ -1916,7 +1918,7 @@ int block_prepare_write(struct page *page, unsigned from, unsigned to,
19161918
}
19171919
return err;
19181920
}
1919-
EXPORT_SYMBOL(block_prepare_write);
1921+
EXPORT_SYMBOL(__block_write_begin);
19201922

19211923
static int __block_commit_write(struct inode *inode, struct page *page,
19221924
unsigned from, unsigned to)
@@ -1953,15 +1955,6 @@ static int __block_commit_write(struct inode *inode, struct page *page,
19531955
return 0;
19541956
}
19551957

1956-
int __block_write_begin(struct page *page, loff_t pos, unsigned len,
1957-
get_block_t *get_block)
1958-
{
1959-
unsigned start = pos & (PAGE_CACHE_SIZE - 1);
1960-
1961-
return block_prepare_write(page, start, start + len, get_block);
1962-
}
1963-
EXPORT_SYMBOL(__block_write_begin);
1964-
19651958
/*
19661959
* block_write_begin takes care of the basic task of block allocation and
19671960
* bringing partial write blocks uptodate first.
@@ -2379,7 +2372,7 @@ block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
23792372
else
23802373
end = PAGE_CACHE_SIZE;
23812374

2382-
ret = block_prepare_write(page, 0, end, get_block);
2375+
ret = __block_write_begin(page, 0, end, get_block);
23832376
if (!ret)
23842377
ret = block_commit_write(page, 0, end);
23852378

‎fs/ext3/inode.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,8 +1696,8 @@ static int ext3_journalled_writepage(struct page *page,
16961696
* doesn't seem much point in redirtying the page here.
16971697
*/
16981698
ClearPageChecked(page);
1699-
ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE,
1700-
ext3_get_block);
1699+
ret = __block_write_begin(page, 0, PAGE_CACHE_SIZE,
1700+
ext3_get_block);
17011701
if (ret != 0) {
17021702
ext3_journal_stop(handle);
17031703
goto out_unlock;

‎fs/ext4/inode.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,10 +1538,10 @@ static int do_journal_get_write_access(handle_t *handle,
15381538
if (!buffer_mapped(bh) || buffer_freed(bh))
15391539
return 0;
15401540
/*
1541-
* __block_prepare_write() could have dirtied some buffers. Clean
1541+
* __block_write_begin() could have dirtied some buffers. Clean
15421542
* the dirty bit as jbd2_journal_get_write_access() could complain
15431543
* otherwise about fs integrity issues. Setting of the dirty bit
1544-
* by __block_prepare_write() isn't a real problem here as we clear
1544+
* by __block_write_begin() isn't a real problem here as we clear
15451545
* the bit before releasing a page lock and thus writeback cannot
15461546
* ever write the buffer.
15471547
*/
@@ -2550,8 +2550,7 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
25502550
if (buffer_delay(bh))
25512551
return 0; /* Not sure this could or should happen */
25522552
/*
2553-
* XXX: __block_prepare_write() unmaps passed block,
2554-
* is it OK?
2553+
* XXX: __block_write_begin() unmaps passed block, is it OK?
25552554
*/
25562555
ret = ext4_da_reserve_space(inode, iblock);
25572556
if (ret)
@@ -2583,7 +2582,7 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
25832582
/*
25842583
* This function is used as a standard get_block_t calback function
25852584
* when there is no desire to allocate any blocks. It is used as a
2586-
* callback function for block_prepare_write() and block_write_full_page().
2585+
* callback function for block_write_begin() and block_write_full_page().
25872586
* These functions should only try to map a single block at a time.
25882587
*
25892588
* Since this function doesn't do block allocations even if the caller
@@ -2743,7 +2742,7 @@ static int ext4_writepage(struct page *page,
27432742
* all are mapped and non delay. We don't want to
27442743
* do block allocation here.
27452744
*/
2746-
ret = block_prepare_write(page, 0, len,
2745+
ret = __block_write_begin(page, 0, len,
27472746
noalloc_get_block_write);
27482747
if (!ret) {
27492748
page_bufs = page_buffers(page);

‎fs/gfs2/aops.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
618618
struct gfs2_alloc *al = NULL;
619619
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
620620
unsigned from = pos & (PAGE_CACHE_SIZE - 1);
621-
unsigned to = from + len;
622621
struct page *page;
623622

624623
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ip->i_gh);
@@ -691,7 +690,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
691690
}
692691

693692
prepare_write:
694-
error = block_prepare_write(page, from, to, gfs2_block_map);
693+
error = __block_write_begin(page, from, len, gfs2_block_map);
695694
out:
696695
if (error == 0)
697696
return 0;

‎fs/gfs2/ops_inode.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ static int write_empty_blocks(struct page *page, unsigned from, unsigned to)
12941294
int error;
12951295

12961296
if (!page_has_buffers(page)) {
1297-
error = block_prepare_write(page, from, to, gfs2_block_map);
1297+
error = __block_write_begin(page, from, to - from, gfs2_block_map);
12981298
if (unlikely(error))
12991299
return error;
13001300

@@ -1313,7 +1313,7 @@ static int write_empty_blocks(struct page *page, unsigned from, unsigned to)
13131313
next += bh->b_size;
13141314
if (buffer_mapped(bh)) {
13151315
if (end) {
1316-
error = block_prepare_write(page, start, end,
1316+
error = __block_write_begin(page, start, end - start,
13171317
gfs2_block_map);
13181318
if (unlikely(error))
13191319
return error;
@@ -1328,7 +1328,7 @@ static int write_empty_blocks(struct page *page, unsigned from, unsigned to)
13281328
} while (next < to);
13291329

13301330
if (end) {
1331-
error = block_prepare_write(page, start, end, gfs2_block_map);
1331+
error = __block_write_begin(page, start, end - start, gfs2_block_map);
13321332
if (unlikely(error))
13331333
return error;
13341334
empty_write_end(page, start, end);

‎fs/ocfs2/aops.c‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ int ocfs2_get_block(struct inode *inode, sector_t iblock,
165165
* ocfs2 never allocates in this function - the only time we
166166
* need to use BH_New is when we're extending i_size on a file
167167
* system which doesn't support holes, in which case BH_New
168-
* allows block_prepare_write() to zero.
168+
* allows __block_write_begin() to zero.
169169
*
170170
* If we see this on a sparse file system, then a truncate has
171171
* raced us and removed the cluster. In this case, we clear
@@ -407,21 +407,6 @@ static int ocfs2_writepage(struct page *page, struct writeback_control *wbc)
407407
return ret;
408408
}
409409

410-
/*
411-
* This is called from ocfs2_write_zero_page() which has handled it's
412-
* own cluster locking and has ensured allocation exists for those
413-
* blocks to be written.
414-
*/
415-
int ocfs2_prepare_write_nolock(struct inode *inode, struct page *page,
416-
unsigned from, unsigned to)
417-
{
418-
int ret;
419-
420-
ret = block_prepare_write(page, from, to, ocfs2_get_block);
421-
422-
return ret;
423-
}
424-
425410
/* Taken from ext3. We don't necessarily need the full blown
426411
* functionality yet, but IMHO it's better to cut and paste the whole
427412
* thing so we can avoid introducing our own bugs (and easily pick up
@@ -732,7 +717,7 @@ static int ocfs2_should_read_blk(struct inode *inode, struct page *page,
732717
}
733718

734719
/*
735-
* Some of this taken from block_prepare_write(). We already have our
720+
* Some of this taken from __block_write_begin(). We already have our
736721
* mapping by now though, and the entire write will be allocating or
737722
* it won't, so not much need to use BH_New.
738723
*

‎fs/ocfs2/aops.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#ifndef OCFS2_AOPS_H
2323
#define OCFS2_AOPS_H
2424

25-
int ocfs2_prepare_write_nolock(struct inode *inode, struct page *page,
26-
unsigned from, unsigned to);
27-
2825
handle_t *ocfs2_start_walk_page_trans(struct inode *inode,
2926
struct page *page,
3027
unsigned from,

‎fs/ocfs2/file.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -796,13 +796,12 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
796796
block_end = block_start + (1 << inode->i_blkbits);
797797

798798
/*
799-
* block_start is block-aligned. Bump it by one to
800-
* force ocfs2_{prepare,commit}_write() to zero the
799+
* block_start is block-aligned. Bump it by one to force
800+
* __block_write_begin and block_commit_write to zero the
801801
* whole block.
802802
*/
803-
ret = ocfs2_prepare_write_nolock(inode, page,
804-
block_start + 1,
805-
block_start + 1);
803+
ret = __block_write_begin(page, block_start + 1, 0,
804+
ocfs2_get_block);
806805
if (ret < 0) {
807806
mlog_errno(ret);
808807
goto out_unlock;

‎fs/reiserfs/inode.c‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
int reiserfs_commit_write(struct file *f, struct page *page,
2424
unsigned from, unsigned to);
25-
int reiserfs_prepare_write(struct file *f, struct page *page,
26-
unsigned from, unsigned to);
2725

2826
void reiserfs_evict_inode(struct inode *inode)
2927
{
@@ -165,7 +163,7 @@ inline void make_le_item_head(struct item_head *ih, const struct cpu_key *key,
165163
** but tail is still sitting in a direct item, and we can't write to
166164
** it. So, look through this page, and check all the mapped buffers
167165
** to make sure they have valid block numbers. Any that don't need
168-
** to be unmapped, so that block_prepare_write will correctly call
166+
** to be unmapped, so that __block_write_begin will correctly call
169167
** reiserfs_get_block to convert the tail into an unformatted node
170168
*/
171169
static inline void fix_tail_page_for_writing(struct page *page)
@@ -439,13 +437,13 @@ static int reiserfs_bmap(struct inode *inode, sector_t block,
439437
}
440438

441439
/* special version of get_block that is only used by grab_tail_page right
442-
** now. It is sent to block_prepare_write, and when you try to get a
440+
** now. It is sent to __block_write_begin, and when you try to get a
443441
** block past the end of the file (or a block from a hole) it returns
444-
** -ENOENT instead of a valid buffer. block_prepare_write expects to
442+
** -ENOENT instead of a valid buffer. __block_write_begin expects to
445443
** be able to do i/o on the buffers returned, unless an error value
446444
** is also returned.
447445
**
448-
** So, this allows block_prepare_write to be used for reading a single block
446+
** So, this allows __block_write_begin to be used for reading a single block
449447
** in a page. Where it does not produce a valid page for holes, or past the
450448
** end of the file. This turns out to be exactly what we need for reading
451449
** tails for conversion.
@@ -558,11 +556,12 @@ static int convert_tail_for_hole(struct inode *inode,
558556
**
559557
** We must fix the tail page for writing because it might have buffers
560558
** that are mapped, but have a block number of 0. This indicates tail
561-
** data that has been read directly into the page, and block_prepare_write
562-
** won't trigger a get_block in this case.
559+
** data that has been read directly into the page, and
560+
** __block_write_begin won't trigger a get_block in this case.
563561
*/
564562
fix_tail_page_for_writing(tail_page);
565-
retval = reiserfs_prepare_write(NULL, tail_page, tail_start, tail_end);
563+
retval = __reiserfs_write_begin(tail_page, tail_start,
564+
tail_end - tail_start);
566565
if (retval)
567566
goto unlock;
568567

@@ -2033,7 +2032,7 @@ static int grab_tail_page(struct inode *inode,
20332032
/* start within the page of the last block in the file */
20342033
start = (offset / blocksize) * blocksize;
20352034

2036-
error = block_prepare_write(page, start, offset,
2035+
error = __block_write_begin(page, start, offset - start,
20372036
reiserfs_get_block_create_0);
20382037
if (error)
20392038
goto unlock;
@@ -2628,8 +2627,7 @@ static int reiserfs_write_begin(struct file *file,
26282627
return ret;
26292628
}
26302629

2631-
int reiserfs_prepare_write(struct file *f, struct page *page,
2632-
unsigned from, unsigned to)
2630+
int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len)
26332631
{
26342632
struct inode *inode = page->mapping->host;
26352633
int ret;
@@ -2650,7 +2648,7 @@ int reiserfs_prepare_write(struct file *f, struct page *page,
26502648
th->t_refcount++;
26512649
}
26522650

2653-
ret = block_prepare_write(page, from, to, reiserfs_get_block);
2651+
ret = __block_write_begin(page, from, len, reiserfs_get_block);
26542652
if (ret && reiserfs_transaction_running(inode->i_sb)) {
26552653
struct reiserfs_transaction_handle *th = current->journal_info;
26562654
/* this gets a little ugly. If reiserfs_get_block returned an

‎fs/reiserfs/ioctl.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ long reiserfs_compat_ioctl(struct file *file, unsigned int cmd,
160160

161161
int reiserfs_commit_write(struct file *f, struct page *page,
162162
unsigned from, unsigned to);
163-
int reiserfs_prepare_write(struct file *f, struct page *page,
164-
unsigned from, unsigned to);
165163
/*
166164
** reiserfs_unpack
167165
** Function try to convert tail from direct item into indirect.
@@ -200,7 +198,7 @@ int reiserfs_unpack(struct inode *inode, struct file *filp)
200198
}
201199

202200
/* we unpack by finding the page with the tail, and calling
203-
** reiserfs_prepare_write on that page. This will force a
201+
** __reiserfs_write_begin on that page. This will force a
204202
** reiserfs_get_block to unpack the tail for us.
205203
*/
206204
index = inode->i_size >> PAGE_CACHE_SHIFT;
@@ -210,7 +208,7 @@ int reiserfs_unpack(struct inode *inode, struct file *filp)
210208
if (!page) {
211209
goto out;
212210
}
213-
retval = reiserfs_prepare_write(NULL, page, write_from, write_from);
211+
retval = __reiserfs_write_begin(page, write_from, 0);
214212
if (retval)
215213
goto out_unlock;
216214

0 commit comments

Comments
 (0)