Skip to content

Commit 2de6a3c

Browse files
Ryan Dingtorvalds
authored andcommitted
ocfs2: return the physical address in ocfs2_write_cluster
To support direct io in ocfs2_write_begin_nolock & ocfs2_write_end_nolock. Direct io needs to get the physical address from write_begin, to map the user page. This patch is to change the arg 'phys' of ocfs2_write_cluster to a pointer, so it can be retrieved to write_begin. And we can retrieve it to the direct io procedure. Signed-off-by: Ryan Ding <[email protected]> Reviewed-by: Junxiao Bi <[email protected]> Cc: Joseph Qi <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 46e6255 commit 2de6a3c

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

fs/ocfs2/aops.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ static int ocfs2_grab_pages_for_write(struct address_space *mapping,
15961596
* Prepare a single cluster for write one cluster into the file.
15971597
*/
15981598
static int ocfs2_write_cluster(struct address_space *mapping,
1599-
u32 phys, unsigned int new,
1599+
u32 *phys, unsigned int new,
16001600
unsigned int clear_unwritten,
16011601
unsigned int should_zero,
16021602
struct ocfs2_alloc_context *data_ac,
@@ -1605,9 +1605,10 @@ static int ocfs2_write_cluster(struct address_space *mapping,
16051605
loff_t user_pos, unsigned user_len)
16061606
{
16071607
int ret, i;
1608-
u64 v_blkno, p_blkno;
1608+
u64 p_blkno;
16091609
struct inode *inode = mapping->host;
16101610
struct ocfs2_extent_tree et;
1611+
int bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1);
16111612

16121613
if (new) {
16131614
u32 tmp_pos;
@@ -1641,34 +1642,31 @@ static int ocfs2_write_cluster(struct address_space *mapping,
16411642
ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode),
16421643
wc->w_di_bh);
16431644
ret = ocfs2_mark_extent_written(inode, &et,
1644-
wc->w_handle, cpos, 1, phys,
1645+
wc->w_handle, cpos, 1, *phys,
16451646
meta_ac, &wc->w_dealloc);
16461647
if (ret < 0) {
16471648
mlog_errno(ret);
16481649
goto out;
16491650
}
16501651
}
16511652

1652-
if (should_zero)
1653-
v_blkno = ocfs2_clusters_to_blocks(inode->i_sb, cpos);
1654-
else
1655-
v_blkno = user_pos >> inode->i_sb->s_blocksize_bits;
1656-
16571653
/*
16581654
* The only reason this should fail is due to an inability to
16591655
* find the extent added.
16601656
*/
1661-
ret = ocfs2_extent_map_get_blocks(inode, v_blkno, &p_blkno, NULL,
1662-
NULL);
1657+
ret = ocfs2_get_clusters(inode, cpos, phys, NULL, NULL);
16631658
if (ret < 0) {
16641659
mlog(ML_ERROR, "Get physical blkno failed for inode %llu, "
1665-
"at logical block %llu",
1666-
(unsigned long long)OCFS2_I(inode)->ip_blkno,
1667-
(unsigned long long)v_blkno);
1660+
"at logical cluster %u",
1661+
(unsigned long long)OCFS2_I(inode)->ip_blkno, cpos);
16681662
goto out;
16691663
}
16701664

1671-
BUG_ON(p_blkno == 0);
1665+
BUG_ON(*phys == 0);
1666+
1667+
p_blkno = ocfs2_clusters_to_blocks(inode->i_sb, *phys);
1668+
if (!should_zero)
1669+
p_blkno += (user_pos >> inode->i_sb->s_blocksize_bits) & (u64)(bpc - 1);
16721670

16731671
for(i = 0; i < wc->w_num_pages; i++) {
16741672
int tmpret;
@@ -1725,7 +1723,7 @@ static int ocfs2_write_cluster_by_desc(struct address_space *mapping,
17251723
if ((cluster_off + local_len) > osb->s_clustersize)
17261724
local_len = osb->s_clustersize - cluster_off;
17271725

1728-
ret = ocfs2_write_cluster(mapping, desc->c_phys,
1726+
ret = ocfs2_write_cluster(mapping, &desc->c_phys,
17291727
desc->c_new,
17301728
desc->c_clear_unwritten,
17311729
desc->c_needs_zero,

0 commit comments

Comments
 (0)